From be95aa33b4f9c971484632c3b2b3b1b93fa6ba93 Mon Sep 17 00:00:00 2001 From: Robert Fancsik Date: Thu, 14 Nov 2019 13:53:52 +0100 Subject: [PATCH] Improve delete property with undefined base (#3312) This patch finally resolves #2891 also the removes the related bytecode since it has become unnecessary. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu --- jerry-core/parser/js/byte-code.h | 6 ++--- jerry-core/parser/js/js-parser-expr.c | 10 +++++-- jerry-core/vm/opcodes.c | 2 ++ jerry-core/vm/vm.c | 7 ----- jerry-core/vm/vm.h | 1 - .../es2015/regression-test-issue-2891.js | 26 +++++++++++++++++++ 6 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 tests/jerry/es2015/regression-test-issue-2891.js diff --git a/jerry-core/parser/js/byte-code.h b/jerry-core/parser/js/byte-code.h index 853dbb248..85404cec6 100644 --- a/jerry-core/parser/js/byte-code.h +++ b/jerry-core/parser/js/byte-code.h @@ -528,8 +528,8 @@ VM_OC_BLOCK_CREATE_CONTEXT) \ CBC_FORWARD_BRANCH (CBC_EXT_CATCH, 1, \ VM_OC_CATCH) \ - CBC_OPCODE (CBC_EXT_PUSH_UNDEFINED_BASE, CBC_NO_FLAG, 1, \ - VM_OC_PUSH_UNDEFINED_BASE | VM_OC_PUT_STACK) \ + CBC_OPCODE (CBC_EXT_RESOLVE_BASE, CBC_NO_FLAG, 0, \ + VM_OC_RESOLVE_BASE_FOR_CALL) \ CBC_FORWARD_BRANCH (CBC_EXT_FINALLY, 0, \ VM_OC_FINALLY) \ CBC_OPCODE (CBC_EXT_CLASS_EXPR_CONTEXT_END, CBC_NO_FLAG, 0, \ @@ -576,8 +576,6 @@ VM_OC_SET_GETTER | VM_OC_GET_STACK_LITERAL) \ CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_SETTER, CBC_HAS_LITERAL_ARG, -1, \ VM_OC_SET_SETTER | VM_OC_GET_STACK_LITERAL) \ - CBC_OPCODE (CBC_EXT_RESOLVE_BASE, CBC_NO_FLAG, 0, \ - VM_OC_RESOLVE_BASE_FOR_CALL) \ CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, \ VM_OC_THROW_REFERENCE_ERROR) \ \ diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c index e3c677bd1..255c375f2 100644 --- a/jerry-core/parser/js/js-parser-expr.c +++ b/jerry-core/parser/js/js-parser-expr.c @@ -201,8 +201,14 @@ parser_emit_unary_lvalue_opcode (parser_context_t *context_p, /**< context */ else { /* Invalid LeftHandSide expression. */ - parser_emit_cbc_ext (context_p, (opcode == CBC_DELETE_PUSH_RESULT) ? CBC_EXT_PUSH_UNDEFINED_BASE - : CBC_EXT_THROW_REFERENCE_ERROR); + if (opcode == CBC_DELETE_PUSH_RESULT) + { + parser_emit_cbc (context_p, CBC_POP); + parser_emit_cbc (context_p, CBC_PUSH_TRUE); + return; + } + + parser_emit_cbc_ext (context_p, CBC_EXT_THROW_REFERENCE_ERROR); } parser_emit_cbc (context_p, (uint16_t) opcode); diff --git a/jerry-core/vm/opcodes.c b/jerry-core/vm/opcodes.c index f551481c2..8d2d07cca 100644 --- a/jerry-core/vm/opcodes.c +++ b/jerry-core/vm/opcodes.c @@ -176,10 +176,12 @@ vm_op_delete_prop (ecma_value_t object, /**< base object */ ecma_value_t property, /**< property name */ bool is_strict) /**< strict mode */ { +#if !ENABLED (JERRY_ES2015) if (ecma_is_value_undefined (object)) { return ECMA_VALUE_TRUE; } +#endif /* !ENABLED (JERRY_ES2015) */ ecma_value_t check_coercible = ecma_op_check_object_coercible (object); if (ECMA_IS_VALUE_ERROR (check_coercible)) diff --git a/jerry-core/vm/vm.c b/jerry-core/vm/vm.c index 0a5f7ada6..7ad2663b7 100644 --- a/jerry-core/vm/vm.c +++ b/jerry-core/vm/vm.c @@ -1917,13 +1917,6 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ #endif /* ENABLED (JERRY_ES2015) */ continue; } - case VM_OC_PUSH_UNDEFINED_BASE: - { - stack_top_p[0] = stack_top_p[-1]; - stack_top_p[-1] = ECMA_VALUE_UNDEFINED; - stack_top_p++; - continue; - } case VM_OC_IDENT_REFERENCE: { uint16_t literal_index; diff --git a/jerry-core/vm/vm.h b/jerry-core/vm/vm.h index 08a7b9bb2..b9ba0aa27 100644 --- a/jerry-core/vm/vm.h +++ b/jerry-core/vm/vm.h @@ -125,7 +125,6 @@ typedef enum VM_OC_SET_GETTER, /**< set getter */ VM_OC_SET_SETTER, /**< set setter */ - VM_OC_PUSH_UNDEFINED_BASE, /**< push undefined base */ VM_OC_PUSH_ARRAY, /**< push array */ VM_OC_PUSH_ELISON, /**< push elison */ VM_OC_APPEND_ARRAY, /**< append array */ diff --git a/tests/jerry/es2015/regression-test-issue-2891.js b/tests/jerry/es2015/regression-test-issue-2891.js new file mode 100644 index 000000000..c63d25130 --- /dev/null +++ b/tests/jerry/es2015/regression-test-issue-2891.js @@ -0,0 +1,26 @@ +// 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. + + +function f (name){ + delete this.keywords[name]; + assert (false); +} + +try { + f ("jerry"); + assert (false); +} catch (e) { + assert (e instanceof TypeError); +}