diff --git a/jerry-core/vm/vm.c b/jerry-core/vm/vm.c index f9e3850a0..578b6f7e4 100644 --- a/jerry-core/vm/vm.c +++ b/jerry-core/vm/vm.c @@ -364,7 +364,13 @@ opfunc_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ { this_value = stack_top_p[-3]; - if (vm_get_implicit_this_value (&this_value)) + if (this_value == ecma_make_simple_value (ECMA_SIMPLE_VALUE_REGISTER_REF)) + { + /* Lexical environment cannot be 'this' value. */ + stack_top_p[-2] = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); + this_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); + } + else if (vm_get_implicit_this_value (&this_value)) { ecma_free_value (stack_top_p[-3]); stack_top_p[-3] = this_value; diff --git a/tests/jerry/fail/1/regression-test-issue-1624.js b/tests/jerry/fail/1/regression-test-issue-1624.js new file mode 100644 index 000000000..1c12273d1 --- /dev/null +++ b/tests/jerry/fail/1/regression-test-issue-1624.js @@ -0,0 +1,22 @@ +// 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. + +with ({}) { + a = function (b) + { + var init; + init(); + } +} +a();