From 685d8b36755c4a12b09b3203bd05630edc08bd7c Mon Sep 17 00:00:00 2001 From: Robert Fancsik Date: Mon, 17 Sep 2018 18:27:00 +0200 Subject: [PATCH] Fix JERRY_CONTEXT (error_value) handling during ecma_builtin_promise_reject_abrupt (#2519) Fixes #2489. Co-authored-by: Daniel Balla JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu --- .../ecma/builtin-objects/ecma-builtin-promise.c | 5 ++--- tests/jerry/fail/regression-test-issue-2489.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/jerry/fail/regression-test-issue-2489.js diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c b/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c index c33a57322..f9367380a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c @@ -125,6 +125,7 @@ ecma_builtin_promise_reject_or_resolve (ecma_value_t this_arg, /**< "this" argum inline static ecma_value_t ecma_builtin_promise_reject_abrupt (ecma_value_t capability) /**< reject description */ { + ecma_raise_type_error (ECMA_ERR_MSG ("Second argument is not an array.")); ecma_value_t reason = JERRY_CONTEXT (error_value); ecma_string_t *reject_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT); ecma_value_t reject = ecma_op_object_get (ecma_get_object_from_value (capability), reject_str_p); @@ -134,6 +135,7 @@ ecma_builtin_promise_reject_abrupt (ecma_value_t capability) /**< reject descrip &reason, 1); ecma_free_value (reject); + ecma_free_value (reason); if (ECMA_IS_VALUE_ERROR (call_ret)) { @@ -576,11 +578,8 @@ ecma_builtin_promise_race_or_all (ecma_value_t this_arg, /**< 'this' argument */ if (!ecma_is_value_object (array) || ecma_get_object_type (ecma_get_object_from_value (array)) != ECMA_OBJECT_TYPE_ARRAY) { - ecma_raise_type_error (ECMA_ERR_MSG ("Second argument is not an array.")); ret = ecma_builtin_promise_reject_abrupt (capability); - ecma_free_value (JERRY_CONTEXT (error_value)); ecma_free_value (capability); - return ret; } diff --git a/tests/jerry/fail/regression-test-issue-2489.js b/tests/jerry/fail/regression-test-issue-2489.js new file mode 100644 index 000000000..223af7429 --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-2489.js @@ -0,0 +1,16 @@ +// 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. + +Object.defineProperty(Object.prototype, 0, {'get': function() { throw $ }}); +Promise.all();