Fix object destructuring for empty pattern (#3571)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -30,7 +30,7 @@ extern "C"
|
|||||||
/**
|
/**
|
||||||
* Jerry snapshot format version.
|
* Jerry snapshot format version.
|
||||||
*/
|
*/
|
||||||
#define JERRY_SNAPSHOT_VERSION (39u)
|
#define JERRY_SNAPSHOT_VERSION (40u)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flags for jerry_generate_snapshot and jerry_generate_function_snapshot.
|
* Flags for jerry_generate_snapshot and jerry_generate_function_snapshot.
|
||||||
|
|||||||
@@ -576,6 +576,8 @@
|
|||||||
VM_OC_ERROR) \
|
VM_OC_ERROR) \
|
||||||
CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, \
|
CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, \
|
||||||
VM_OC_THROW_REFERENCE_ERROR) \
|
VM_OC_THROW_REFERENCE_ERROR) \
|
||||||
|
CBC_OPCODE (CBC_EXT_REQUIRE_OBJECT_COERCIBLE, CBC_NO_FLAG, 0, \
|
||||||
|
VM_OC_REQUIRE_OBJECT_COERCIBLE) \
|
||||||
\
|
\
|
||||||
/* Computed / class property related opcodes. */ \
|
/* Computed / class property related opcodes. */ \
|
||||||
CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY, CBC_NO_FLAG, -2, \
|
CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY, CBC_NO_FLAG, -2, \
|
||||||
|
|||||||
@@ -2798,6 +2798,15 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */
|
|||||||
{
|
{
|
||||||
parser_pattern_end_marker_t end_pos = parser_pattern_get_target (context_p, flags);
|
parser_pattern_end_marker_t end_pos = parser_pattern_get_target (context_p, flags);
|
||||||
|
|
||||||
|
/* 12.14.5.2: ObjectAssignmentPattern : { } */
|
||||||
|
if (lexer_check_next_character (context_p, LIT_CHAR_RIGHT_BRACE))
|
||||||
|
{
|
||||||
|
parser_emit_cbc_ext (context_p, CBC_EXT_REQUIRE_OBJECT_COERCIBLE);
|
||||||
|
lexer_consume_next_character (context_p);
|
||||||
|
parser_pattern_finalize (context_p, flags, &end_pos);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_OBJECT_PATTERN);
|
lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_OBJECT_PATTERN);
|
||||||
|
|||||||
@@ -2229,6 +2229,16 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
case VM_OC_REQUIRE_OBJECT_COERCIBLE:
|
||||||
|
{
|
||||||
|
result = ecma_op_check_object_coercible (stack_top_p[-1]);
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (result))
|
||||||
|
{
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
case VM_OC_PUSH_ELISON:
|
case VM_OC_PUSH_ELISON:
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -268,6 +268,7 @@ typedef enum
|
|||||||
VM_OC_STRING_CONCAT, /**< string concatenation */
|
VM_OC_STRING_CONCAT, /**< string concatenation */
|
||||||
VM_OC_GET_TEMPLATE_OBJECT, /**< GetTemplateObject operation */
|
VM_OC_GET_TEMPLATE_OBJECT, /**< GetTemplateObject operation */
|
||||||
VM_OC_PUSH_NEW_TARGET, /**< push new.target onto the stack */
|
VM_OC_PUSH_NEW_TARGET, /**< push new.target onto the stack */
|
||||||
|
VM_OC_REQUIRE_OBJECT_COERCIBLE,/**< RequireObjectCoercible opretaion */
|
||||||
#endif /* ENABLED (JERRY_ES2015) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
VM_OC_NONE, /**< a special opcode for unsupported byte codes */
|
VM_OC_NONE, /**< a special opcode for unsupported byte codes */
|
||||||
} vm_oc_types;
|
} vm_oc_types;
|
||||||
@@ -327,6 +328,7 @@ typedef enum
|
|||||||
VM_OC_STRING_CONCAT = VM_OC_NONE, /**< string concatenation */
|
VM_OC_STRING_CONCAT = VM_OC_NONE, /**< string concatenation */
|
||||||
VM_OC_GET_TEMPLATE_OBJECT = VM_OC_NONE, /**< GetTemplateObject operation */
|
VM_OC_GET_TEMPLATE_OBJECT = VM_OC_NONE, /**< GetTemplateObject operation */
|
||||||
VM_OC_PUSH_NEW_TARGET = VM_OC_NONE, /**< push new.target onto the stack */
|
VM_OC_PUSH_NEW_TARGET = VM_OC_NONE, /**< push new.target onto the stack */
|
||||||
|
VM_OC_REQUIRE_OBJECT_COERCIBLE = VM_OC_NONE,/**< RequireObjectCoercible opretaion */
|
||||||
#endif /* !ENABLED (JERRY_ES2015) */
|
#endif /* !ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
VM_OC_UNUSED = VM_OC_NONE /**< placeholder if the list is empty */
|
VM_OC_UNUSED = VM_OC_NONE /**< placeholder if the list is empty */
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ checkSyntax ("let {a:(a)} = {a:1}");
|
|||||||
|
|
||||||
mustThrow ("var {a} = null");
|
mustThrow ("var {a} = null");
|
||||||
mustThrow ("var {a} = undefined");
|
mustThrow ("var {a} = undefined");
|
||||||
|
mustThrow ("function f ({a : {}}) {}; f({});");
|
||||||
|
mustThrow ("function f ({}) {}; f();");
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
|
||||||
|
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ main (void)
|
|||||||
/* Check the snapshot data. Unused bytes should be filled with zeroes */
|
/* Check the snapshot data. Unused bytes should be filled with zeroes */
|
||||||
const uint8_t expected_data[] =
|
const uint8_t expected_data[] =
|
||||||
{
|
{
|
||||||
0x4A, 0x52, 0x52, 0x59, 0x27, 0x00, 0x00, 0x00,
|
0x4A, 0x52, 0x52, 0x59, 0x28, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
|
||||||
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
|
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
|
||||||
0x03, 0x00, 0x01, 0x00, 0x41, 0x00, 0x01, 0x00,
|
0x03, 0x00, 0x01, 0x00, 0x41, 0x00, 0x01, 0x00,
|
||||||
|
|||||||
Reference in New Issue
Block a user