diff --git a/jerry-core/ecma/operations/ecma-function-object.c b/jerry-core/ecma/operations/ecma-function-object.c index bdbaf31c1..52b4115b6 100644 --- a/jerry-core/ecma/operations/ecma-function-object.c +++ b/jerry-core/ecma/operations/ecma-function-object.c @@ -1336,10 +1336,6 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */ return ecma_raise_type_error (message_p); } - /* 6. */ - ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target); - JERRY_CONTEXT (current_new_target) = new_target_p; - /* 5. */ if (!ECMA_GET_THIRD_BIT_FROM_POINTER_TAG (ext_func_obj_p->u.function.scope_cp)) { @@ -1362,6 +1358,10 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */ { this_arg = ECMA_VALUE_UNDEFINED; } + + /* 6. */ + ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target); + JERRY_CONTEXT (current_new_target) = new_target_p; #endif /* ENABLED (JERRY_ESNEXT) */ ecma_value_t ret_value = ecma_op_function_call_simple (func_obj_p, this_arg, arguments_list_p, arguments_list_len); diff --git a/tests/jerry/es.next/regression-test-issue-4059.js b/tests/jerry/es.next/regression-test-issue-4059.js new file mode 100644 index 000000000..6311de4aa --- /dev/null +++ b/tests/jerry/es.next/regression-test-issue-4059.js @@ -0,0 +1,20 @@ +// 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. + +try { + new new Proxy(Function(), { get:String.fromCharCode }) + assert(false); +} catch (e) { + assert(e instanceof TypeError); +}