Invalid regexp literals should throw syntax error in ES11 (#4506)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -27,7 +27,7 @@ JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)
|
||||
*/
|
||||
JERRY_STATIC_ASSERT (CBC_END == 238,
|
||||
number_of_cbc_opcodes_changed);
|
||||
JERRY_STATIC_ASSERT (CBC_EXT_END == 149,
|
||||
JERRY_STATIC_ASSERT (CBC_EXT_END == 148,
|
||||
number_of_cbc_ext_opcodes_changed);
|
||||
|
||||
#if ENABLED (JERRY_PARSER) || ENABLED (JERRY_PARSER_DUMP_BYTE_CODE)
|
||||
|
||||
@@ -610,8 +610,6 @@
|
||||
VM_OC_LINE) \
|
||||
CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, \
|
||||
VM_OC_THROW_REFERENCE_ERROR) \
|
||||
CBC_OPCODE (CBC_EXT_THROW_SYNTAX_ERROR, CBC_HAS_LITERAL_ARG, 1, \
|
||||
VM_OC_THROW_SYNTAX_ERROR | VM_OC_GET_LITERAL) \
|
||||
CBC_OPCODE (CBC_EXT_THROW_ASSIGN_CONST_ERROR, CBC_NO_FLAG, 0, \
|
||||
VM_OC_THROW_CONST_ERROR) \
|
||||
CBC_OPCODE (CBC_EXT_REQUIRE_OBJECT_COERCIBLE, CBC_NO_FLAG, 0, \
|
||||
|
||||
@@ -95,42 +95,6 @@ lexer_hex_to_code_point (const uint8_t *source_p, /**< current source position *
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
|
||||
/**
|
||||
* Find a string literal in the literal pool matching with the given buffer's content
|
||||
*
|
||||
* @return PARSER_INVALID_LITERAL_INDEX - if the literal is not present in the literal pool
|
||||
* literal's index in the pool - otherwise
|
||||
*/
|
||||
static uint16_t
|
||||
parser_find_string_literal (parser_context_t *context_p, /**< context */
|
||||
lexer_literal_t **out_literal_p, /**< [out] found literal */
|
||||
uint8_t *buffer_p, /**< character buffer */
|
||||
lit_utf8_size_t size) /**< buffer's size */
|
||||
{
|
||||
JERRY_ASSERT (out_literal_p != NULL);
|
||||
JERRY_ASSERT (buffer_p != NULL);
|
||||
|
||||
uint16_t literal_index = 0;
|
||||
lexer_literal_t *literal_p;
|
||||
parser_list_iterator_t literal_iterator;
|
||||
parser_list_iterator_init (&context_p->literal_pool, &literal_iterator);
|
||||
|
||||
while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
|
||||
{
|
||||
if (literal_p->type == LEXER_STRING_LITERAL
|
||||
&& literal_p->prop.length == size
|
||||
&& memcmp (literal_p->u.char_p, buffer_p, size) == 0)
|
||||
{
|
||||
*out_literal_p = literal_p;
|
||||
return literal_index;
|
||||
}
|
||||
|
||||
literal_index++;
|
||||
}
|
||||
|
||||
return PARSER_INVALID_LITERAL_INDEX;
|
||||
} /* parser_find_string_literal */
|
||||
|
||||
/**
|
||||
* Parse hexadecimal character sequence enclosed in braces
|
||||
*
|
||||
@@ -3104,56 +3068,14 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */
|
||||
re_compiled_code_t *re_bytecode_p = re_compile_bytecode (pattern_str_p, current_flags);
|
||||
ecma_deref_ecma_string (pattern_str_p);
|
||||
|
||||
lexer_literal_t *literal_p = NULL;
|
||||
uint8_t literal_type = LEXER_REGEXP_LITERAL;
|
||||
|
||||
if (JERRY_UNLIKELY (re_bytecode_p == NULL))
|
||||
{
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
ecma_value_t error = jcontext_take_exception ();
|
||||
ecma_property_t *prop_p = ecma_find_named_property (ecma_get_object_from_value (error),
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE));
|
||||
const char default_msg[] = "Invalid regular expression";
|
||||
lit_utf8_byte_t *buffer_p = (lit_utf8_byte_t *) default_msg;
|
||||
lit_utf8_size_t size = sizeof (buffer_p) - 1;
|
||||
|
||||
if (prop_p != NULL)
|
||||
{
|
||||
ecma_string_t *message_p = ecma_get_string_from_value (ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
|
||||
JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (message_p));
|
||||
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (message_p) == ECMA_STRING_CONTAINER_HEAP_ASCII_STRING);
|
||||
buffer_p = ECMA_ASCII_STRING_GET_BUFFER (message_p);
|
||||
size = ECMA_ASCII_STRING_GET_SIZE (message_p);
|
||||
}
|
||||
|
||||
uint16_t literal_index = parser_find_string_literal (context_p, &literal_p, buffer_p, size);
|
||||
|
||||
if (literal_index != PARSER_INVALID_LITERAL_INDEX)
|
||||
{
|
||||
ecma_free_value (error);
|
||||
context_p->lit_object.literal_p = literal_p;
|
||||
context_p->lit_object.index = literal_index;
|
||||
return;
|
||||
}
|
||||
|
||||
literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool);
|
||||
literal_p->u.char_p = (uint8_t *) jmem_heap_alloc_block (size);
|
||||
memcpy ((uint8_t *) literal_p->u.char_p, buffer_p, size);
|
||||
literal_type = LEXER_STRING_LITERAL;
|
||||
length = size;
|
||||
|
||||
ecma_free_value (error);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
parser_raise_error (context_p, PARSER_ERR_INVALID_REGEXP);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
}
|
||||
else
|
||||
{
|
||||
literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool);
|
||||
literal_p->u.bytecode_p = (ecma_compiled_code_t *) re_bytecode_p;
|
||||
}
|
||||
|
||||
literal_p->type = literal_type;
|
||||
lexer_literal_t *literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool);
|
||||
literal_p->u.bytecode_p = (ecma_compiled_code_t *) re_bytecode_p;
|
||||
literal_p->type = LEXER_REGEXP_LITERAL;
|
||||
literal_p->prop.length = (prop_length_t) length;
|
||||
literal_p->status_flags = 0;
|
||||
|
||||
|
||||
@@ -2177,15 +2177,6 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
case LEXER_ASSIGN_DIVIDE:
|
||||
{
|
||||
lexer_construct_regexp_object (context_p, false);
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (JERRY_UNLIKELY (context_p->lit_object.literal_p->type == LEXER_STRING_LITERAL))
|
||||
{
|
||||
parser_emit_cbc_ext_literal (context_p, CBC_EXT_THROW_SYNTAX_ERROR, context_p->lit_object.index);
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
uint16_t literal_index = (uint16_t) (context_p->literal_count - 1);
|
||||
|
||||
if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL)
|
||||
|
||||
@@ -2832,7 +2832,6 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
|
||||
#if ENABLED (JERRY_ERROR_MESSAGES)
|
||||
ecma_string_t *err_str_p;
|
||||
|
||||
#if !ENABLED (JERRY_ESNEXT)
|
||||
if (parser_error.error == PARSER_ERR_INVALID_REGEXP)
|
||||
{
|
||||
ecma_value_t error = jcontext_take_exception ();
|
||||
@@ -2844,7 +2843,6 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
|
||||
ecma_ref_ecma_string (err_str_p);
|
||||
}
|
||||
else
|
||||
#endif /* !ENABLED (JERRY_ESNEXT) */
|
||||
{
|
||||
const lit_utf8_byte_t *err_bytes_p = (const lit_utf8_byte_t *) parser_error_to_string (parser_error.error);
|
||||
lit_utf8_size_t err_bytes_size = lit_zt_utf8_string_size (err_bytes_p);
|
||||
@@ -2865,12 +2863,12 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
|
||||
ecma_free_value (line_str_val);
|
||||
ecma_deref_ecma_string (err_str_p);
|
||||
#else /* !ENABLED (JERRY_ERROR_MESSAGES) */
|
||||
#if !ENABLED (JERRY_ESNEXT)
|
||||
if (parser_error.error != PARSER_ERR_INVALID_REGEXP)
|
||||
#endif /* !ENABLED (JERRY_ESNEXT) */
|
||||
if (parser_error.error == PARSER_ERR_INVALID_REGEXP)
|
||||
{
|
||||
ecma_raise_syntax_error ("");
|
||||
jcontext_release_exception ();
|
||||
}
|
||||
|
||||
ecma_raise_syntax_error ("");
|
||||
#endif /* ENABLED (JERRY_ERROR_MESSAGES) */
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user