From cd1e06767167db365f7b8830c8e5989e043048aa Mon Sep 17 00:00:00 2001 From: Szilagyi Adam Date: Thu, 2 Jul 2020 11:46:07 +0200 Subject: [PATCH] Update Promise.race and Promise.all to ES11 (#3954) Changes based on ECMA-262 v11, 25.6.4.4 and 26.6.4.1 step 3 JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu --- .../builtin-objects/ecma-builtin-promise.c | 30 ++----------------- jerry-core/lit/lit-magic-strings.inc.h | 3 +- tests/jerry/es.next/promise-all-iterator.js | 4 +++ tests/jerry/es.next/promise-race-iterator.js | 4 +++ .../es.next/regression-test-issue-3478.js | 7 +---- 5 files changed, 13 insertions(+), 35 deletions(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c b/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c index 49fa3376c..eb4c06f4f 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c @@ -501,31 +501,10 @@ ecma_builtin_promise_race_or_all (ecma_value_t this_arg, /**< 'this' argument */ return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not an object.")); } - ecma_object_t *this_obj_p = ecma_get_object_from_value (this_arg); - ecma_value_t species_symbol = ecma_op_object_get_by_magic_id (this_obj_p, - LIT_MAGIC_STRING_SYMBOL); - - if (ECMA_IS_VALUE_ERROR (species_symbol)) - { - return species_symbol; - } - - ecma_value_t constructor_value = this_arg; - - if (!ecma_is_value_null (species_symbol) && !ecma_is_value_undefined (species_symbol)) - { - constructor_value = species_symbol; - } - else - { - ecma_ref_object (this_obj_p); - } - - ecma_value_t capability = ecma_promise_new_capability (constructor_value); + ecma_value_t capability = ecma_promise_new_capability (this_arg); if (ECMA_IS_VALUE_ERROR (capability)) { - ecma_free_value (constructor_value); return capability; } @@ -535,7 +514,6 @@ ecma_builtin_promise_race_or_all (ecma_value_t this_arg, /**< 'this' argument */ if (ECMA_IS_VALUE_ERROR (iterator)) { - ecma_free_value (constructor_value); ecma_free_value (capability); return iterator; } @@ -545,15 +523,13 @@ ecma_builtin_promise_race_or_all (ecma_value_t this_arg, /**< 'this' argument */ if (is_race) { - ret = ecma_builtin_promise_perform_race (iterator, next_method, capability, constructor_value, &is_done); + ret = ecma_builtin_promise_perform_race (iterator, next_method, capability, this_arg, &is_done); } else { - ret = ecma_builtin_promise_perform_all (iterator, next_method, capability, constructor_value, &is_done); + ret = ecma_builtin_promise_perform_all (iterator, next_method, capability, this_arg, &is_done); } - ecma_free_value (constructor_value); - if (ECMA_IS_VALUE_ERROR (ret)) { if (!is_done) diff --git a/jerry-core/lit/lit-magic-strings.inc.h b/jerry-core/lit/lit-magic-strings.inc.h index 93da94331..a024b740e 100644 --- a/jerry-core/lit/lit-magic-strings.inc.h +++ b/jerry-core/lit/lit-magic-strings.inc.h @@ -405,8 +405,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STRING, "string") #if ENABLED (JERRY_BUILTIN_ANNEXB) && ENABLED (JERRY_BUILTIN_STRING) LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SUBSTR, "substr") #endif -#if ENABLED (JERRY_BUILTIN_PROMISE) \ -|| ENABLED (JERRY_ESNEXT) +#if ENABLED (JERRY_ESNEXT) LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SYMBOL, "symbol") #endif #if ENABLED (JERRY_BUILTIN_DATE) \ diff --git a/tests/jerry/es.next/promise-all-iterator.js b/tests/jerry/es.next/promise-all-iterator.js index 4c53cf3c0..725f616ad 100644 --- a/tests/jerry/es.next/promise-all-iterator.js +++ b/tests/jerry/es.next/promise-all-iterator.js @@ -79,3 +79,7 @@ var closed = false; delete Promise.resolve; Promise.all(createIterable([1,2,3], {'return': function () { closed = true; }})); assert (closed); + +var arr = []; +Object.defineProperty(arr, Symbol.species, { get: function () { assert(false) }}); +Promise.all(arr); diff --git a/tests/jerry/es.next/promise-race-iterator.js b/tests/jerry/es.next/promise-race-iterator.js index e225d5482..e343a79f6 100644 --- a/tests/jerry/es.next/promise-race-iterator.js +++ b/tests/jerry/es.next/promise-race-iterator.js @@ -67,3 +67,7 @@ var closed = false; delete Promise.resolve; Promise.race(createIterable([1,2,3], {'return': function () { closed = true; }})); assert (closed); + +var arr = []; +Object.defineProperty(arr, Symbol.species, { get: function () { assert(false) }}); +Promise.race(arr); diff --git a/tests/jerry/es.next/regression-test-issue-3478.js b/tests/jerry/es.next/regression-test-issue-3478.js index 1e224143c..2270de270 100644 --- a/tests/jerry/es.next/regression-test-issue-3478.js +++ b/tests/jerry/es.next/regression-test-issue-3478.js @@ -13,9 +13,4 @@ // limitations under the License. Object.prototype["symbol"] = 0; -try { - Promise.race([]); - assert(false); -} catch(e) { - assert(e instanceof TypeError); -} +Promise.race([]);