aboutsummaryrefslogtreecommitdiff
path: root/jerry-core/ecma/builtin-objects/ecma-builtin-global.c
blob: 293e6860aa1b454d8b619898c6f4cd9f6d45e28f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
/* Copyright JS Foundation and other contributors, http://js.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "ecma-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-eval.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#include "lit-char-helpers.h"
#include "lit-magic-strings.h"
#include "lit-strings.h"
#include "vm.h"
#include "jrt-libc-includes.h"
#include "jrt-bit-fields.h"

#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"

#define BUILTIN_INC_HEADER_NAME "ecma-builtin-global.inc.h"
#define BUILTIN_UNDERSCORED_ID global
#include "ecma-builtin-internal-routines-template.inc.h"

/** \addtogroup ecma ECMA
 * @{
 *
 * \addtogroup ecmabuiltins
 * @{
 *
 * \addtogroup global ECMA Global object built-in
 * @{
 */

/**
 * The Global object's 'eval' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.2.1
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_eval (ecma_value_t this_arg, /**< this argument */
                                 ecma_value_t x) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  uint32_t parse_opts = vm_is_direct_eval_form_call () ? ECMA_PARSE_DIRECT_EVAL : ECMA_PARSE_NO_OPTS;

  /* See also: ECMA-262 v5, 10.1.1 */
  if (parse_opts && vm_is_strict_mode ())
  {
    JERRY_ASSERT (parse_opts & ECMA_PARSE_DIRECT_EVAL);
    parse_opts |= ECMA_PARSE_STRICT_MODE;
  }

  if (!ecma_is_value_string (x))
  {
    /* step 1 */
    ret_value = ecma_copy_value (x);
  }
  else
  {
    /* steps 2 to 8 */
    ret_value = ecma_op_eval (ecma_get_string_from_value (x),
                              parse_opts);
  }

  return ret_value;
} /* ecma_builtin_global_object_eval */

/**
 * The Global object's 'parseInt' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.2.2
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_parse_int (ecma_value_t this_arg, /**< this argument */
                                      ecma_value_t string, /**< routine's first argument */
                                      ecma_value_t radix) /**< routine's second argument */
{
  JERRY_UNUSED (this_arg);
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  /* 1. */
  ECMA_TRY_CATCH (string_var, ecma_op_to_string (string), ret_value);

  ecma_string_t *number_str_p = ecma_get_string_from_value (string_var);
  ECMA_STRING_TO_UTF8_STRING (number_str_p, string_buff, string_buff_size);

  if (string_buff_size > 0)
  {
    const lit_utf8_byte_t *string_curr_p = (lit_utf8_byte_t *) string_buff;
    const lit_utf8_byte_t *string_end_p = string_buff + string_buff_size;

    /* 2. Remove leading whitespace. */

    const lit_utf8_byte_t *start_p = string_end_p;
    const lit_utf8_byte_t *end_p = start_p;

    while (string_curr_p < string_end_p)
    {
      ecma_char_t current_char = lit_utf8_read_next (&string_curr_p);

      if (!lit_char_is_white_space (current_char)
          && !lit_char_is_line_terminator (current_char))
      {
        lit_utf8_decr (&string_curr_p);
        start_p = string_curr_p;
        break;
      }
    }

    if (string_curr_p < string_end_p)
    {
      /* 3. */
      int sign = 1;

      /* 4. */
      ecma_char_t current = lit_utf8_read_next (&string_curr_p);
      if (current == LIT_CHAR_MINUS)
      {
        sign = -1;
      }

      /* 5. */
      if (current == LIT_CHAR_MINUS || current == LIT_CHAR_PLUS)
      {
        start_p = string_curr_p;
        if (string_curr_p < string_end_p)
        {
          current = lit_utf8_read_next (&string_curr_p);
        }
      }

      /* 6. */
      ECMA_OP_TO_NUMBER_TRY_CATCH (radix_num, radix, ret_value);
      int32_t rad = ecma_number_to_int32 (radix_num);

      /* 7.*/
      bool strip_prefix = true;

      /* 8. */
      if (rad != 0)
      {
        /* 8.a */
        if (rad < 2 || rad > 36)
        {
          ret_value = ecma_make_nan_value ();
        }
        /* 8.b */
        else if (rad != 16)
        {
          strip_prefix = false;
        }
      }
      /* 9. */
      else
      {
        rad = 10;
      }

      if (ecma_is_value_empty (ret_value))
      {
        /* 10. */
        if (strip_prefix
            && ((end_p - start_p) >= 2)
            && (current == LIT_CHAR_0))
        {
          ecma_char_t next = *string_curr_p;
          if (next == LIT_CHAR_LOWERCASE_X || next == LIT_CHAR_UPPERCASE_X)
          {
            /* Skip the 'x' or 'X' characters. */
            start_p = ++string_curr_p;
            rad = 16;
          }
        }

        /* 11. Check if characters are in [0, Radix - 1]. We also convert them to number values in the process. */
        string_curr_p = start_p;
        while (string_curr_p < string_end_p)
        {
          ecma_char_t current_char = *string_curr_p++;
          int32_t current_number;

          if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
          {
            current_number = current_char - LIT_CHAR_LOWERCASE_A + 10;
          }
          else if ((current_char >= LIT_CHAR_UPPERCASE_A && current_char <= LIT_CHAR_UPPERCASE_Z))
          {
            current_number = current_char - LIT_CHAR_UPPERCASE_A + 10;
          }
          else if (lit_char_is_decimal_digit (current_char))
          {
            current_number = current_char - LIT_CHAR_0;
          }
          else
          {
            /* Not a valid number char, set value to radix so it fails to pass as a valid character. */
            current_number = rad;
          }

          if (!(current_number < rad))
          {
            end_p = --string_curr_p;
            break;
          }
        }

        /* 12. */
        if (end_p == start_p)
        {
          ret_value = ecma_make_nan_value ();
        }
      }

      if (ecma_is_value_empty (ret_value))
      {
        ecma_number_t value = ECMA_NUMBER_ZERO;
        ecma_number_t multiplier = 1.0f;

        /* 13. and 14. */
        string_curr_p = end_p;

        while (string_curr_p > start_p)
        {
          ecma_char_t current_char = *(--string_curr_p);
          ecma_number_t current_number = ECMA_NUMBER_MINUS_ONE;

          if ((current_char >= LIT_CHAR_LOWERCASE_A && current_char <= LIT_CHAR_LOWERCASE_Z))
          {
            current_number =  (ecma_number_t) current_char - LIT_CHAR_LOWERCASE_A + 10;
          }
          else if ((current_char >= LIT_CHAR_UPPERCASE_A && current_char <= LIT_CHAR_UPPERCASE_Z))
          {
            current_number =  (ecma_number_t) current_char - LIT_CHAR_UPPERCASE_A + 10;
          }
          else
          {
            JERRY_ASSERT (lit_char_is_decimal_digit (current_char));
            current_number =  (ecma_number_t) current_char - LIT_CHAR_0;
          }

          value += current_number * multiplier;
          multiplier *= (ecma_number_t) rad;
        }

        /* 15. */
        if (sign < 0)
        {
          value *= (ecma_number_t) sign;
        }

        ret_value = ecma_make_number_value (value);
      }

      ECMA_OP_TO_NUMBER_FINALIZE (radix_num);
    }
    else
    {
      ret_value = ecma_make_nan_value ();
    }

  }
  else
  {
    ret_value = ecma_make_nan_value ();
  }

  ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size);
  ECMA_FINALIZE (string_var);
  return ret_value;
} /* ecma_builtin_global_object_parse_int */

/**
 * The Global object's 'parseFloat' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.2.3
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_parse_float (ecma_value_t this_arg, /**< this argument */
                                        ecma_value_t string) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  /* 1. */
  ECMA_TRY_CATCH (string_var, ecma_op_to_string (string), ret_value);

  ecma_string_t *number_str_p = ecma_get_string_from_value (string_var);
  ECMA_STRING_TO_UTF8_STRING (number_str_p, string_buff, string_buff_size);

  if (string_buff_size > 0)
  {
    const lit_utf8_byte_t *str_curr_p = string_buff;
    const lit_utf8_byte_t *str_end_p = string_buff + string_buff_size;

    const lit_utf8_byte_t *start_p = str_end_p;
    const lit_utf8_byte_t *end_p = str_end_p;

    /* 2. Find first non whitespace char and set starting position. */
    while (str_curr_p < str_end_p)
    {
      ecma_char_t current_char = lit_utf8_read_next (&str_curr_p);

      if (!lit_char_is_white_space (current_char)
          && !lit_char_is_line_terminator (current_char))
      {
        lit_utf8_decr (&str_curr_p);
        start_p = str_curr_p;
        break;
      }
    }

    bool sign = false;
    ecma_char_t current;

    if (str_curr_p < str_end_p)
    {
      /* Check if sign is present. */
      current = *str_curr_p;
      if (current == LIT_CHAR_MINUS)
      {
        sign = true;
      }

      if (current == LIT_CHAR_MINUS || current == LIT_CHAR_PLUS)
      {
        /* Set starting position to be after the sign character. */
        start_p = ++str_curr_p;
      }
    }

    const lit_utf8_byte_t *infinity_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
    lit_utf8_byte_t *infinity_str_curr_p = (lit_utf8_byte_t *) infinity_str_p;
    lit_utf8_byte_t *infinity_str_end_p = infinity_str_curr_p + sizeof (*infinity_str_p);

    /* Check if string is equal to "Infinity". */
    while (str_curr_p < str_end_p
           && *str_curr_p++ == *infinity_str_curr_p++)
    {
      if (infinity_str_curr_p == infinity_str_end_p)
      {
        /* String matched Infinity. */
        ret_value = ecma_make_number_value (ecma_number_make_infinity (sign));
        break;
      }
    }

    /* Reset to starting position. */
    str_curr_p = start_p;

    if (ecma_is_value_empty (ret_value) && str_curr_p < str_end_p)
    {
      current = *str_curr_p;

      bool has_whole_part = false;
      bool has_fraction_part = false;

      /* Check digits of whole part. */
      if (lit_char_is_decimal_digit (current))
      {
        has_whole_part = true;
        str_curr_p++;

        while (str_curr_p < str_end_p)
        {
          current = *str_curr_p++;
          if (!lit_char_is_decimal_digit (current))
          {
            str_curr_p--;
            break;
          }
        }
      }


      /* Set end position to the end of whole part. */
      end_p = str_curr_p;
      if (str_curr_p < str_end_p)
      {
        current = *str_curr_p;

        /* Check decimal point. */
        if (current == LIT_CHAR_DOT)
        {
          str_curr_p++;

          if (str_curr_p < str_end_p)
          {
            current = *str_curr_p;

            if (lit_char_is_decimal_digit (current))
            {
              has_fraction_part = true;

              /* Check digits of fractional part. */
              while (str_curr_p < str_end_p)
              {
                current = *str_curr_p++;
                if (!lit_char_is_decimal_digit (current))
                {
                  str_curr_p--;
                  break;
                }
              }

              /* Set end position to end of fraction part. */
              end_p = str_curr_p;
            }
          }
        }
      }


      if (str_curr_p < str_end_p)
      {
        current = *str_curr_p++;
      }

      /* Check exponent. */
      if ((current == LIT_CHAR_LOWERCASE_E || current == LIT_CHAR_UPPERCASE_E)
          && (has_whole_part || has_fraction_part)
          && str_curr_p < str_end_p)
      {
        current = *str_curr_p++;

        /* Check sign of exponent. */
        if ((current == LIT_CHAR_PLUS || current == LIT_CHAR_MINUS)
             && str_curr_p < str_end_p)
        {
          current = *str_curr_p++;
        }

        if (lit_char_is_decimal_digit (current))
        {
          /* Check digits of exponent part. */
          while (str_curr_p < str_end_p)
          {
            current = *str_curr_p++;
            if (!lit_char_is_decimal_digit (current))
            {
              str_curr_p--;
              break;
            }
          }

          /* Set end position to end of exponent part. */
          end_p = str_curr_p;
        }
      }

      /* String did not contain a valid number. */
      if (start_p == end_p)
      {
        ret_value = ecma_make_nan_value ();
      }
      else
      {
        /* 5. */
        ecma_number_t ret_num = ecma_utf8_string_to_number (start_p,
                                                            (lit_utf8_size_t) (end_p - start_p));

        if (sign)
        {
          ret_num *= ECMA_NUMBER_MINUS_ONE;
        }

        ret_value = ecma_make_number_value (ret_num);
      }
    }
    /* String ended after sign character, or was empty after removing leading whitespace. */
    else if (ecma_is_value_empty (ret_value))
    {
      ret_value = ecma_make_nan_value ();
    }
  }
  /* String length is zero. */
  else
  {
    ret_value = ecma_make_nan_value ();
  }

  ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size);
  ECMA_FINALIZE (string_var);

  return ret_value;
} /* ecma_builtin_global_object_parse_float */

/**
 * The Global object's 'isNaN' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.2.4
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_is_nan (ecma_value_t this_arg, /**< this argument */
                                   ecma_value_t arg) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);

  bool is_nan = ecma_number_is_nan (arg_num);

  ret_value = is_nan ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;

  ECMA_OP_TO_NUMBER_FINALIZE (arg_num);

  return ret_value;
} /* ecma_builtin_global_object_is_nan */

/**
 * The Global object's 'isFinite' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.2.5
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_is_finite (ecma_value_t this_arg, /**< this argument */
                                      ecma_value_t arg) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);

  bool is_finite = !(ecma_number_is_nan (arg_num)
                     || ecma_number_is_infinity (arg_num));

  ret_value = is_finite ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;

  ECMA_OP_TO_NUMBER_FINALIZE (arg_num);

  return ret_value;
} /* ecma_builtin_global_object_is_finite */

/**
 * Helper function to check whether a character is in a character bitset.
 *
 * @return true if the character is in the character bitset.
 */
static bool
ecma_builtin_global_object_character_is_in (uint32_t character, /**< character */
                                            const uint8_t *bitset) /**< character set */
{
  JERRY_ASSERT (character < 128);
  return (bitset[character >> 3] & (1u << (character & 0x7))) != 0;
} /* ecma_builtin_global_object_character_is_in */

/**
 * Unescaped URI characters bitset:
 *   One bit for each character between 0 - 127.
 *   Bit is set if the character is in the unescaped URI set.
 */
static const uint8_t unescaped_uri_set[16] =
{
  0x0, 0x0, 0x0, 0x0, 0xda, 0xff, 0xff, 0xaf,
  0xff, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x47
};

/**
 * Unescaped URI component characters bitset:
 *   One bit for each character between 0 - 127.
 *   Bit is set if the character is in the unescaped component URI set.
 */
static const uint8_t unescaped_uri_component_set[16] =
{
  0x0, 0x0, 0x0, 0x0, 0x82, 0x67, 0xff, 0x3,
  0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x47
};

/**
 * Format is a percent sign followed by two hex digits.
 */
#define URI_ENCODED_BYTE_SIZE (3)

/**
 * Helper function to decode URI.
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri, /**< uri argument */
                                              const uint8_t *reserved_uri_bitset) /**< reserved characters bitset */
{
  JERRY_UNUSED (uri);
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  ECMA_TRY_CATCH (string,
                  ecma_op_to_string (uri),
                  ret_value);

  JERRY_ASSERT (ecma_is_value_string (string));

  ecma_string_t *input_string_p = ecma_get_string_from_value (string);
  lit_utf8_size_t input_size = ecma_string_get_size (input_string_p);

  JMEM_DEFINE_LOCAL_ARRAY (input_start_p,
                           input_size + 1,
                           lit_utf8_byte_t);

  ecma_string_to_utf8_bytes (input_string_p, input_start_p, input_size);

  input_start_p[input_size] = LIT_BYTE_NULL;

  lit_utf8_byte_t *input_char_p = input_start_p;
  lit_utf8_byte_t *input_end_p = input_start_p + input_size;
  lit_utf8_size_t output_size = 0;

  /*
   * The URI decoding has two major phases: first we validate the input,
   * and compute the length of the output, then we decode the input.
   */

  while (input_char_p < input_end_p)
  {
    /*
     * We expect that the input is a valid UTF-8 sequence,
     * so characters >= 0x80 can be let through.
     */

    if (*input_char_p != '%')
    {
      output_size++;
      input_char_p++;
      continue;
    }

    ecma_char_t decoded_byte;

    if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &decoded_byte))
    {
      ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid hexadecimal value."));
      break;
    }

    input_char_p += URI_ENCODED_BYTE_SIZE;

    if (decoded_byte <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
    {
      /*
       * We don't decode those bytes, which are part of reserved_uri_bitset
       * but not part of unescaped_uri_component_set.
       */
      if (ecma_builtin_global_object_character_is_in (decoded_byte, reserved_uri_bitset)
          && !ecma_builtin_global_object_character_is_in (decoded_byte, unescaped_uri_component_set))
      {
        output_size += URI_ENCODED_BYTE_SIZE;
      }
      else
      {
        output_size++;
      }
    }
    else if ((decoded_byte & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER)
    {
      output_size += 3;
    }
    else
    {
      output_size++;
    }
  }

  if (ecma_is_value_empty (ret_value))
  {
    JMEM_DEFINE_LOCAL_ARRAY (output_start_p,
                            output_size,
                            lit_utf8_byte_t);

    input_char_p = input_start_p;
    lit_utf8_byte_t *output_char_p = output_start_p;

    while (input_char_p < input_end_p)
    {
      /* Input decode. */
      if (*input_char_p != '%')
      {
        *output_char_p = *input_char_p;
        output_char_p++;
        input_char_p++;
        continue;
      }

      ecma_char_t decoded_byte;

      if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &decoded_byte))
      {
        ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid hexadecimal value."));
        break;
      }

      input_char_p += URI_ENCODED_BYTE_SIZE;

      if (decoded_byte <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
      {
        if (ecma_builtin_global_object_character_is_in (decoded_byte, reserved_uri_bitset)
            && !ecma_builtin_global_object_character_is_in (decoded_byte, unescaped_uri_component_set))
        {
          *output_char_p = '%';
          output_char_p++;
          input_char_p -= 2;
        }
        else
        {
          *output_char_p++ = (lit_utf8_byte_t) decoded_byte;
        }
      }
      else
      {
        uint32_t bytes_count;

        if ((decoded_byte & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER)
        {
          bytes_count = 2;
        }
        else if ((decoded_byte & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER)
        {
          bytes_count = 3;
        }
        else if ((decoded_byte & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER)
        {
          bytes_count = 4;
        }
        else
        {
          ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid UTF8 character."));
          break;
        }

        lit_utf8_byte_t octets[LIT_UTF8_MAX_BYTES_IN_CODE_POINT];
        octets[0] = (lit_utf8_byte_t) decoded_byte;
        bool is_valid = true;

        for (uint32_t i = 1; i < bytes_count; i++)
        {
          if (input_char_p >= input_end_p || *input_char_p != '%')
          {
            is_valid = false;
            break;
          }
          else
          {
            ecma_char_t chr;

            if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &chr)
                || ((chr & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER))
            {
              is_valid = false;
              break;
            }

            octets[i] = (lit_utf8_byte_t) chr;
            input_char_p += URI_ENCODED_BYTE_SIZE;
          }
        }

        if (!is_valid
            || !lit_is_valid_utf8_string (octets, bytes_count))
        {
          ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid UTF8 string."));
          break;
        }

        lit_code_point_t cp;
        lit_read_code_point_from_utf8 (octets, bytes_count, &cp);

        if (lit_is_code_point_utf16_high_surrogate (cp)
            || lit_is_code_point_utf16_low_surrogate (cp))
        {
          ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid UTF8 codepoint."));
          break;
        }

        output_char_p += lit_code_point_to_cesu8 (cp, output_char_p);
      }
    }

    if (ecma_is_value_empty (ret_value))
    {
      JERRY_ASSERT (output_start_p + output_size == output_char_p);

      if (lit_is_valid_cesu8_string (output_start_p, output_size))
      {
        ecma_string_t *output_string_p = ecma_new_ecma_string_from_utf8 (output_start_p, output_size);
        ret_value = ecma_make_string_value (output_string_p);
      }
      else
      {
        ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid CESU8 string."));
      }
    }

    JMEM_FINALIZE_LOCAL_ARRAY (output_start_p);
  }

  JMEM_FINALIZE_LOCAL_ARRAY (input_start_p);

  ECMA_FINALIZE (string);
  return ret_value;
} /* ecma_builtin_global_object_decode_uri_helper */

/**
 * The Global object's 'decodeURI' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.3.1
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_decode_uri (ecma_value_t this_arg, /**< this argument */
                                       ecma_value_t encoded_uri) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  return ecma_builtin_global_object_decode_uri_helper (encoded_uri, unescaped_uri_set);
} /* ecma_builtin_global_object_decode_uri */

/**
 * The Global object's 'decodeURIComponent' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.3.2
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_decode_uri_component (ecma_value_t this_arg, /**< this argument */
                                                 ecma_value_t encoded_uri_component) /**< routine's
                                                                                      *   first argument */
{
  JERRY_UNUSED (this_arg);
  return ecma_builtin_global_object_decode_uri_helper (encoded_uri_component, unescaped_uri_component_set);
} /* ecma_builtin_global_object_decode_uri_component */

/**
 * Helper function to encode byte as hexadecimal values.
 */
static void
ecma_builtin_global_object_byte_to_hex (lit_utf8_byte_t *dest_p, /**< destination pointer */
                                        uint32_t byte) /**< value */
{
  JERRY_ASSERT (byte < 256);

  dest_p[0] = LIT_CHAR_PERCENT;
  ecma_char_t hex_digit = (ecma_char_t) (byte >> 4);
  dest_p[1] = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
  hex_digit = (lit_utf8_byte_t) (byte & 0xf);
  dest_p[2] = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
} /* ecma_builtin_global_object_byte_to_hex */

/**
 * Helper function to encode URI.
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argument */
                                              const uint8_t *unescaped_uri_bitset_p) /**< unescaped bitset */
{
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  ECMA_TRY_CATCH (string,
                  ecma_op_to_string (uri),
                  ret_value);

  JERRY_ASSERT (ecma_is_value_string (string));

  ecma_string_t *input_string_p = ecma_get_string_from_value (string);
  lit_utf8_size_t input_size = ecma_string_get_size (input_string_p);

  JMEM_DEFINE_LOCAL_ARRAY (input_start_p,
                           input_size,
                           lit_utf8_byte_t);

  ecma_string_to_utf8_bytes (input_string_p, input_start_p, input_size);

  /*
   * The URI encoding has two major phases: first we validate the input,
   * and compute the length of the output, then we encode the input.
   */

  lit_utf8_byte_t *input_char_p = input_start_p;
  const lit_utf8_byte_t *input_end_p = input_start_p + input_size;
  lit_utf8_size_t output_length = 0;
  lit_code_point_t cp;
  ecma_char_t ch;
  lit_utf8_byte_t octets[LIT_UTF8_MAX_BYTES_IN_CODE_POINT];
  memset (octets, LIT_BYTE_NULL, LIT_UTF8_MAX_BYTES_IN_CODE_POINT);

  while (input_char_p < input_end_p)
  {
    /* Input validation, we need to reject stray surrogates. */
    input_char_p += lit_read_code_unit_from_utf8 (input_char_p, &ch);

    if (lit_is_code_point_utf16_low_surrogate (ch))
    {
      ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Unicode surrogate pair missing."));
      break;
    }

    cp = ch;

    if (lit_is_code_point_utf16_high_surrogate (ch))
    {
      if (input_char_p == input_end_p)
      {
        ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Unicode surrogate pair missing."));
        break;
      }

      ecma_char_t next_ch;
      lit_utf8_size_t read_size = lit_read_code_unit_from_utf8 (input_char_p, &next_ch);

      if (lit_is_code_point_utf16_low_surrogate (next_ch))
      {
        cp = lit_convert_surrogate_pair_to_code_point (ch, next_ch);
        input_char_p += read_size;
      }
      else
      {
        ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Unicode surrogate pair missing."));
        break;
      }
    }

    lit_utf8_size_t utf_size = lit_code_point_to_utf8 (cp, octets);

    if (utf_size == 1)
    {
      if (ecma_builtin_global_object_character_is_in (octets[0], unescaped_uri_bitset_p))
      {
        output_length++;
      }
      else
      {
        output_length += URI_ENCODED_BYTE_SIZE;
      }
    }
    else
    {
      output_length += utf_size * URI_ENCODED_BYTE_SIZE;
    }
  }

  if (ecma_is_value_empty (ret_value))
  {
    JMEM_DEFINE_LOCAL_ARRAY (output_start_p,
                             output_length,
                             lit_utf8_byte_t);

    lit_utf8_byte_t *output_char_p = output_start_p;
    input_char_p = input_start_p;

    while (input_char_p < input_end_p)
    {
      /* Input decode. */
      input_char_p += lit_read_code_unit_from_utf8 (input_char_p, &ch);
      cp = ch;

      if (lit_is_code_point_utf16_high_surrogate (ch))
      {
        ecma_char_t next_ch;
        lit_utf8_size_t read_size = lit_read_code_unit_from_utf8 (input_char_p, &next_ch);

        if (lit_is_code_point_utf16_low_surrogate (next_ch))
        {
          cp = lit_convert_surrogate_pair_to_code_point (ch, next_ch);
          input_char_p += read_size;
        }
      }

      lit_utf8_size_t utf_size = lit_code_point_to_utf8 (cp, octets);

      if (utf_size == 1)
      {
        if (ecma_builtin_global_object_character_is_in (octets[0], unescaped_uri_bitset_p))
        {
          *output_char_p++ = octets[0];
        }
        else
        {
          ecma_builtin_global_object_byte_to_hex (output_char_p, octets[0]);
          output_char_p += URI_ENCODED_BYTE_SIZE;
        }
      }
      else
      {
        for (uint32_t i = 0; i < utf_size; i++)
        {
          ecma_builtin_global_object_byte_to_hex (output_char_p, octets[i]);
          output_char_p += URI_ENCODED_BYTE_SIZE;
        }
      }
    }

    JERRY_ASSERT (output_start_p + output_length == output_char_p);

    ecma_string_t *output_string_p = ecma_new_ecma_string_from_utf8 (output_start_p, output_length);

    ret_value = ecma_make_string_value (output_string_p);

    JMEM_FINALIZE_LOCAL_ARRAY (output_start_p);
  }

  JMEM_FINALIZE_LOCAL_ARRAY (input_start_p);

  ECMA_FINALIZE (string);
  return ret_value;
} /* ecma_builtin_global_object_encode_uri_helper */

/**
 * The Global object's 'encodeURI' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.3.3
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_encode_uri (ecma_value_t this_arg, /**< this argument */
                                       ecma_value_t uri) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  return ecma_builtin_global_object_encode_uri_helper (uri, unescaped_uri_set);
} /* ecma_builtin_global_object_encode_uri */

/**
 * The Global object's 'encodeURIComponent' routine
 *
 * See also:
 *          ECMA-262 v5, 15.1.3.4
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_encode_uri_component (ecma_value_t this_arg, /**< this argument */
                                                 ecma_value_t uri_component) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  return ecma_builtin_global_object_encode_uri_helper (uri_component, unescaped_uri_component_set);
} /* ecma_builtin_global_object_encode_uri_component */

#ifndef CONFIG_DISABLE_ANNEXB_BUILTIN

/**
 * Maximum value of a byte.
 */
#define ECMA_ESCAPE_MAXIMUM_BYTE_VALUE (255)

/**
 * Format is a percent sign followed by lowercase u and four hex digits.
 */
#define ECMA_ESCAPE_ENCODED_UNICODE_CHARACTER_SIZE (6)

/**
 * Escape characters bitset:
 *   One bit for each character between 0 - 127.
 *   Bit is set if the character does not need to be converted to %xx form.
 *   These characters are: a-z A-Z 0-9 @ * _ + - . /
 */
static const uint8_t ecma_escape_set[16] =
{
  0x0, 0x0, 0x0, 0x0, 0x0, 0xec, 0xff, 0x3,
  0xff, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x7
};

/**
 * The Global object's 'escape' routine
 *
 * See also:
 *          ECMA-262 v5, B.2.1
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_escape (ecma_value_t this_arg, /**< this argument */
                                   ecma_value_t arg) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  ECMA_TRY_CATCH (string,
                  ecma_op_to_string (arg),
                  ret_value);

  ecma_string_t *input_string_p = ecma_get_string_from_value (string);
  lit_utf8_size_t input_size = ecma_string_get_size (input_string_p);

  JMEM_DEFINE_LOCAL_ARRAY (input_start_p,
                           input_size,
                           lit_utf8_byte_t);

  ecma_string_to_utf8_bytes (input_string_p, input_start_p, input_size);

  /*
   * The escape routine has two major phases: first we compute
   * the length of the output, then we encode the input.
   */
  const lit_utf8_byte_t *input_curr_p = input_start_p;
  const lit_utf8_byte_t *input_end_p = input_start_p + input_size;
  lit_utf8_size_t output_length = 0;

  while (input_curr_p < input_end_p)
  {
    ecma_char_t chr = lit_utf8_read_next (&input_curr_p);

    if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
    {
      if (ecma_builtin_global_object_character_is_in ((uint32_t) chr, ecma_escape_set))
      {
        output_length++;
      }
      else
      {
        output_length += URI_ENCODED_BYTE_SIZE;
      }
    }
    else if (chr > ECMA_ESCAPE_MAXIMUM_BYTE_VALUE)
    {
      output_length += ECMA_ESCAPE_ENCODED_UNICODE_CHARACTER_SIZE;
    }
    else
    {
      output_length += URI_ENCODED_BYTE_SIZE;
    }
  }

  JMEM_DEFINE_LOCAL_ARRAY (output_start_p,
                           output_length,
                           lit_utf8_byte_t);

  lit_utf8_byte_t *output_char_p = output_start_p;

  input_curr_p = input_start_p;

  while (input_curr_p < input_end_p)
  {
    ecma_char_t chr = lit_utf8_read_next (&input_curr_p);

    if (chr <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
    {
      if (ecma_builtin_global_object_character_is_in ((uint32_t) chr, ecma_escape_set))
      {
        *output_char_p = (lit_utf8_byte_t) chr;
        output_char_p++;
      }
      else
      {
        ecma_builtin_global_object_byte_to_hex (output_char_p, (lit_utf8_byte_t) chr);
        output_char_p += URI_ENCODED_BYTE_SIZE;
      }
    }
    else if (chr > ECMA_ESCAPE_MAXIMUM_BYTE_VALUE)
    {
      /*
       * Although ecma_builtin_global_object_byte_to_hex inserts a percent (%) sign
       * the follow-up changes overwrites it. We call this function twice to
       * produce four hexadecimal characters (%uxxxx format).
       */
      ecma_builtin_global_object_byte_to_hex (output_char_p + 3, (lit_utf8_byte_t) (chr & 0xff));
      ecma_builtin_global_object_byte_to_hex (output_char_p + 1, (lit_utf8_byte_t) (chr >> JERRY_BITSINBYTE));
      output_char_p[0] = LIT_CHAR_PERCENT;
      output_char_p[1] = LIT_CHAR_LOWERCASE_U;
      output_char_p += ECMA_ESCAPE_ENCODED_UNICODE_CHARACTER_SIZE;
    }
    else
    {
      ecma_builtin_global_object_byte_to_hex (output_char_p, (lit_utf8_byte_t) chr);
      output_char_p += URI_ENCODED_BYTE_SIZE;
    }
  }

  JERRY_ASSERT (output_start_p + output_length == output_char_p);

  ecma_string_t *output_string_p = ecma_new_ecma_string_from_utf8 (output_start_p, output_length);

  ret_value = ecma_make_string_value (output_string_p);

  JMEM_FINALIZE_LOCAL_ARRAY (output_start_p);

  JMEM_FINALIZE_LOCAL_ARRAY (input_start_p);

  ECMA_FINALIZE (string);
  return ret_value;
} /* ecma_builtin_global_object_escape */

/**
 * The Global object's 'unescape' routine
 *
 * See also:
 *          ECMA-262 v5, B.2.2
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_global_object_unescape (ecma_value_t this_arg, /**< this argument */
                                     ecma_value_t arg) /**< routine's first argument */
{
  JERRY_UNUSED (this_arg);
  ecma_value_t ret_value = ECMA_VALUE_EMPTY;

  /* 1. */
  ECMA_TRY_CATCH (string, ecma_op_to_string (arg), ret_value);
  ecma_string_t *input_string_p = ecma_get_string_from_value (string);
  /* 2. */
  lit_utf8_size_t input_size = ecma_string_get_size (input_string_p);

  /* 3. */
  JMEM_DEFINE_LOCAL_ARRAY (input_start_p, input_size, lit_utf8_byte_t);
  ecma_string_to_utf8_bytes (input_string_p, input_start_p, input_size);

  const lit_utf8_byte_t *input_curr_p = input_start_p;
  const lit_utf8_byte_t *input_end_p = input_start_p + input_size;
  /* 4. */
  /* The length of input string is always greater than output string
   * so we re-use the input string buffer.
   * The %xx is three byte long, and the maximum encoded value is 0xff,
   * which maximum encoded length is two byte. Similar to this, the maximum
   * encoded length of %uxxxx is four byte. */
  lit_utf8_byte_t *output_char_p = input_start_p;

  /* The state of parsing that tells us where we are in an escape pattern.
   * 0    we are outside of pattern,
   * 1    found '%', start of pattern,
   * 2    found first hex digit of '%xy' pattern
   * 3    found valid '%xy' pattern
   * 4    found 'u', start of '%uwxyz' pattern
   * 5-7  found hex digits of '%uwxyz' pattern
   * 8    found valid '%uwxyz' pattern
   */
  uint8_t status = 0;
  ecma_char_t hex_digits = 0;
  /* 5. */
  while (input_curr_p < input_end_p)
  {
    /* 6. */
    ecma_char_t chr = lit_utf8_read_next (&input_curr_p);

    /* 7-8. */
    if (status == 0 && chr == LIT_CHAR_PERCENT)
    {
      /* Found '%' char, start of escape sequence. */
      status = 1;
    }
    /* 9-10. */
    else if (status == 1 && chr == LIT_CHAR_LOWERCASE_U)
    {
      /* Found 'u' char after '%'. */
      status = 4;
    }
    else if (status > 0 && lit_char_is_hex_digit (chr))
    {
      /* Found hexadecimal digit in escape sequence. */
      hex_digits = (ecma_char_t) (hex_digits * 16 + (ecma_char_t) lit_char_hex_to_int (chr));
      status++;
    }
    else
    {
      /* Previously found hexadecimal digit in escape sequence but it's not valid '%xy' pattern
       * so essentially it was only a simple character. */
      status = 0;
    }

    /* 11-17. Found valid '%uwxyz' or '%xy' escape. */
    if (status == 8 || status == 3)
    {
      output_char_p -= (status == 3) ? 2 : 5;
      status = 0;
      chr = hex_digits;
      hex_digits = 0;
    }

    /* Copying character. */
    lit_utf8_size_t lit_size = lit_code_unit_to_utf8 (chr, output_char_p);
    output_char_p += lit_size;
    JERRY_ASSERT (output_char_p <= input_curr_p);
  }

  lit_utf8_size_t output_length = (lit_utf8_size_t) (output_char_p - input_start_p);
  ecma_string_t *output_string_p = ecma_new_ecma_string_from_utf8 (input_start_p, output_length);
  ret_value = ecma_make_string_value (output_string_p);

  JMEM_FINALIZE_LOCAL_ARRAY (input_start_p);

  ECMA_FINALIZE (string);
  return ret_value;
} /* ecma_builtin_global_object_unescape */

#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */

/**
 * @}
 * @}
 * @}
 */