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
This commit is contained in:
Szilagyi Adam 2020-07-02 11:46:07 +02:00 committed by GitHub
parent 55d6637da5
commit cd1e067671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 35 deletions

View File

@ -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)

View File

@ -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) \

View File

@ -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);

View File

@ -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);

View File

@ -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([]);