@@ -150,7 +150,8 @@ lexer_hex_in_braces_to_code_point (const uint8_t *source_p, /**< current source
150
150
* @return character value
151
151
*/
152
152
static lit_code_point_t
153
- lexer_unchecked_hex_to_character (const uint8_t * * source_p ) /**< [in, out] current source position */
153
+ lexer_unchecked_hex_to_character (parser_context_t * context_p , /**< context */
154
+ const uint8_t * * source_p ) /**< [in, out] current source position */
154
155
{
155
156
lit_code_point_t result = 0 ;
156
157
const uint8_t * char_p = * source_p ;
@@ -174,13 +175,19 @@ lexer_unchecked_hex_to_character (const uint8_t **source_p) /**< [in, out] curre
174
175
}
175
176
else
176
177
{
177
- JERRY_ASSERT ((byte >= LIT_CHAR_LOWERCASE_A && byte <= LIT_CHAR_LOWERCASE_F )
178
- || (byte >= LIT_CHAR_UPPERCASE_A && byte <= LIT_CHAR_UPPERCASE_F ));
178
+ if (!((byte >= LIT_CHAR_LOWERCASE_A && byte <= LIT_CHAR_LOWERCASE_F )
179
+ || (byte >= LIT_CHAR_UPPERCASE_A && byte <= LIT_CHAR_UPPERCASE_F )))
180
+ {
181
+ parser_raise_error (context_p , PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE );
182
+ }
179
183
180
184
result += LEXER_TO_ASCII_LOWERCASE (byte ) - (LIT_CHAR_LOWERCASE_A - 10 );
181
185
}
182
186
183
- JERRY_ASSERT (result <= LIT_UNICODE_CODE_POINT_MAX );
187
+ if (result > LIT_UNICODE_CODE_POINT_MAX )
188
+ {
189
+ parser_raise_error (context_p , PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE );
190
+ }
184
191
185
192
if (length == 0 )
186
193
{
@@ -713,7 +720,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */
713
720
714
721
if (JERRY_UNLIKELY (context_p -> token .lit_location .status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE ))
715
722
{
716
- lexer_convert_ident_to_cesu8 (buffer_p , ident_start_p , (prop_length_t ) length );
723
+ lexer_convert_ident_to_cesu8 (context_p , buffer_p , ident_start_p , (prop_length_t ) length );
717
724
ident_start_p = buffer_p ;
718
725
}
719
726
@@ -2070,7 +2077,8 @@ lexer_scan_private_identifier (parser_context_t *context_p) /**< context */
2070
2077
* Convert an ident with escapes to a utf8 string.
2071
2078
*/
2072
2079
void
2073
- lexer_convert_ident_to_cesu8 (uint8_t * destination_p , /**< destination string */
2080
+ lexer_convert_ident_to_cesu8 (parser_context_t * context_p , /**< context */
2081
+ uint8_t * destination_p , /**< destination string */
2074
2082
const uint8_t * source_p , /**< source string */
2075
2083
prop_length_t length ) /**< length of destination string */
2076
2084
{
@@ -2083,7 +2091,8 @@ lexer_convert_ident_to_cesu8 (uint8_t *destination_p, /**< destination string */
2083
2091
if (* source_p == LIT_CHAR_BACKSLASH )
2084
2092
{
2085
2093
source_p += 2 ;
2086
- destination_p += lit_code_point_to_cesu8_bytes (destination_p , lexer_unchecked_hex_to_character (& source_p ));
2094
+ destination_p +=
2095
+ lit_code_point_to_cesu8_bytes (destination_p , lexer_unchecked_hex_to_character (context_p , & source_p ));
2087
2096
continue ;
2088
2097
}
2089
2098
@@ -2130,7 +2139,7 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */
2130
2139
2131
2140
if (literal_p -> type == LEXER_IDENT_LITERAL )
2132
2141
{
2133
- lexer_convert_ident_to_cesu8 (destination_start_p , literal_p -> char_p , literal_p -> length );
2142
+ lexer_convert_ident_to_cesu8 (context_p , destination_start_p , literal_p -> char_p , literal_p -> length );
2134
2143
return destination_start_p ;
2135
2144
}
2136
2145
@@ -2229,7 +2238,8 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */
2229
2238
if (* source_p == LIT_CHAR_LOWERCASE_X || * source_p == LIT_CHAR_LOWERCASE_U )
2230
2239
{
2231
2240
source_p ++ ;
2232
- destination_p += lit_code_point_to_cesu8_bytes (destination_p , lexer_unchecked_hex_to_character (& source_p ));
2241
+ destination_p +=
2242
+ lit_code_point_to_cesu8_bytes (destination_p , lexer_unchecked_hex_to_character (context_p , & source_p ));
2233
2243
continue ;
2234
2244
}
2235
2245
@@ -3286,7 +3296,8 @@ lexer_check_property_modifier (parser_context_t *context_p) /**< context */
3286
3296
* @return true if the two identifiers are the same
3287
3297
*/
3288
3298
static bool
3289
- lexer_compare_identifier_to_chars (const uint8_t * left_p , /**< left identifier */
3299
+ lexer_compare_identifier_to_chars (parser_context_t * context_p , /**< context */
3300
+ const uint8_t * left_p , /**< left identifier */
3290
3301
const uint8_t * right_p , /**< right identifier string */
3291
3302
size_t size ) /**< byte size of the two identifiers */
3292
3303
{
@@ -3307,7 +3318,7 @@ lexer_compare_identifier_to_chars (const uint8_t *left_p, /**< left identifier *
3307
3318
if (* left_p == LIT_CHAR_BACKSLASH )
3308
3319
{
3309
3320
left_p += 2 ;
3310
- lit_code_point_t code_point = lexer_unchecked_hex_to_character (& left_p );
3321
+ lit_code_point_t code_point = lexer_unchecked_hex_to_character (context_p , & left_p );
3311
3322
3312
3323
escape_size = lit_code_point_to_cesu8_bytes (utf8_buf , code_point );
3313
3324
}
@@ -3346,7 +3357,8 @@ lexer_compare_identifier_to_chars (const uint8_t *left_p, /**< left identifier *
3346
3357
* @return true if the identifier equals to string
3347
3358
*/
3348
3359
bool
3349
- lexer_compare_identifier_to_string (const lexer_lit_location_t * left_p , /**< left literal */
3360
+ lexer_compare_identifier_to_string (parser_context_t * context_p , /**< context */
3361
+ const lexer_lit_location_t * left_p , /**< left literal */
3350
3362
const uint8_t * right_p , /**< right identifier string */
3351
3363
size_t size ) /**< byte size of the right identifier */
3352
3364
{
@@ -3360,7 +3372,7 @@ lexer_compare_identifier_to_string (const lexer_lit_location_t *left_p, /**< lef
3360
3372
return memcmp (left_p -> char_p , right_p , size ) == 0 ;
3361
3373
}
3362
3374
3363
- return lexer_compare_identifier_to_chars (left_p -> char_p , right_p , size );
3375
+ return lexer_compare_identifier_to_chars (context_p , left_p -> char_p , right_p , size );
3364
3376
} /* lexer_compare_identifier_to_string */
3365
3377
3366
3378
/**
@@ -3385,25 +3397,25 @@ lexer_compare_identifiers (parser_context_t *context_p, /**< context */
3385
3397
3386
3398
if (!(left_p -> status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE ))
3387
3399
{
3388
- return lexer_compare_identifier_to_chars (right_p -> char_p , left_p -> char_p , length );
3400
+ return lexer_compare_identifier_to_chars (context_p , right_p -> char_p , left_p -> char_p , length );
3389
3401
}
3390
3402
3391
3403
if (!(right_p -> status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE ))
3392
3404
{
3393
- return lexer_compare_identifier_to_chars (left_p -> char_p , right_p -> char_p , length );
3405
+ return lexer_compare_identifier_to_chars (context_p , left_p -> char_p , right_p -> char_p , length );
3394
3406
}
3395
3407
3396
3408
if (length <= 64 )
3397
3409
{
3398
3410
uint8_t buf_p [64 ];
3399
- lexer_convert_ident_to_cesu8 (buf_p , left_p -> char_p , length );
3400
- return lexer_compare_identifier_to_chars (right_p -> char_p , buf_p , length );
3411
+ lexer_convert_ident_to_cesu8 (context_p , buf_p , left_p -> char_p , length );
3412
+ return lexer_compare_identifier_to_chars (context_p , right_p -> char_p , buf_p , length );
3401
3413
}
3402
3414
3403
3415
uint8_t * dynamic_buf_p = parser_malloc (context_p , length );
3404
3416
3405
- lexer_convert_ident_to_cesu8 (dynamic_buf_p , left_p -> char_p , length );
3406
- bool result = lexer_compare_identifier_to_chars (right_p -> char_p , dynamic_buf_p , length );
3417
+ lexer_convert_ident_to_cesu8 (context_p , dynamic_buf_p , left_p -> char_p , length );
3418
+ bool result = lexer_compare_identifier_to_chars (context_p , right_p -> char_p , dynamic_buf_p , length );
3407
3419
parser_free (dynamic_buf_p , length );
3408
3420
3409
3421
return result ;
0 commit comments