diff --git a/jerry-core/include/jerryscript-snapshot.h b/jerry-core/include/jerryscript-snapshot.h index 57f867846..831f86417 100644 --- a/jerry-core/include/jerryscript-snapshot.h +++ b/jerry-core/include/jerryscript-snapshot.h @@ -30,7 +30,7 @@ extern "C" /** * Jerry snapshot format version. */ -#define JERRY_SNAPSHOT_VERSION (39u) +#define JERRY_SNAPSHOT_VERSION (40u) /** * Flags for jerry_generate_snapshot and jerry_generate_function_snapshot. diff --git a/jerry-core/parser/js/byte-code.h b/jerry-core/parser/js/byte-code.h index 4ee13c446..1bea29ff0 100644 --- a/jerry-core/parser/js/byte-code.h +++ b/jerry-core/parser/js/byte-code.h @@ -576,6 +576,8 @@ VM_OC_ERROR) \ CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, \ 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. */ \ CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY, CBC_NO_FLAG, -2, \ diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c index 5179e160d..9b171d714 100644 --- a/jerry-core/parser/js/js-parser-expr.c +++ b/jerry-core/parser/js/js-parser-expr.c @@ -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); + /* 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) { lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_OBJECT_PATTERN); diff --git a/jerry-core/vm/vm.c b/jerry-core/vm/vm.c index 17310cb4e..b627bcfd1 100644 --- a/jerry-core/vm/vm.c +++ b/jerry-core/vm/vm.c @@ -2229,6 +2229,16 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ } 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) */ case VM_OC_PUSH_ELISON: { diff --git a/jerry-core/vm/vm.h b/jerry-core/vm/vm.h index ef3291b50..cc5a88ec7 100644 --- a/jerry-core/vm/vm.h +++ b/jerry-core/vm/vm.h @@ -268,6 +268,7 @@ typedef enum VM_OC_STRING_CONCAT, /**< string concatenation */ VM_OC_GET_TEMPLATE_OBJECT, /**< GetTemplateObject operation */ VM_OC_PUSH_NEW_TARGET, /**< push new.target onto the stack */ + VM_OC_REQUIRE_OBJECT_COERCIBLE,/**< RequireObjectCoercible opretaion */ #endif /* ENABLED (JERRY_ES2015) */ VM_OC_NONE, /**< a special opcode for unsupported byte codes */ } vm_oc_types; @@ -327,6 +328,7 @@ typedef enum VM_OC_STRING_CONCAT = VM_OC_NONE, /**< string concatenation */ 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_REQUIRE_OBJECT_COERCIBLE = VM_OC_NONE,/**< RequireObjectCoercible opretaion */ #endif /* !ENABLED (JERRY_ES2015) */ VM_OC_UNUSED = VM_OC_NONE /**< placeholder if the list is empty */ diff --git a/tests/jerry/es2015/object-pattern.js b/tests/jerry/es2015/object-pattern.js index 73f32cf18..420dc8a16 100644 --- a/tests/jerry/es2015/object-pattern.js +++ b/tests/jerry/es2015/object-pattern.js @@ -54,6 +54,8 @@ checkSyntax ("let {a:(a)} = {a:1}"); mustThrow ("var {a} = null"); 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 diff --git a/tests/unit-core/test-snapshot.c b/tests/unit-core/test-snapshot.c index 7d3dc4c49..ae1706921 100644 --- a/tests/unit-core/test-snapshot.c +++ b/tests/unit-core/test-snapshot.c @@ -223,7 +223,7 @@ main (void) /* Check the snapshot data. Unused bytes should be filled with zeroes */ 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, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x41, 0x00, 0x01, 0x00,