From 1523ca3b26cd1835c1af51ace2a6d1024e43057d Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Fri, 3 Sep 2021 12:15:06 +0200 Subject: [PATCH] Fix prototype of the values returned by Promise.allSettled (#4758) JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com --- .../ecma/operations/ecma-promise-object.c | 6 +++-- tests/jerry/es.next/promise-all-settled.js | 22 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/jerry-core/ecma/operations/ecma-promise-object.c b/jerry-core/ecma/operations/ecma-promise-object.c index 4404278ad..ed96717a4 100644 --- a/jerry-core/ecma/operations/ecma-promise-object.c +++ b/jerry-core/ecma/operations/ecma-promise-object.c @@ -630,11 +630,13 @@ ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, /**< if (promise_type == ECMA_PROMISE_ALLSETTLED_RESOLVE) { - status_property_val = LIT_MAGIC_STRING_FULFILLED; + status_property_val = LIT_MAGIC_STRING_FULFILLED; data_propery_name = LIT_MAGIC_STRING_VALUE; } - ecma_object_t *obj_p = ecma_create_object (NULL, 0, ECMA_OBJECT_TYPE_GENERAL); + ecma_object_t *obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE), + 0, + ECMA_OBJECT_TYPE_GENERAL); ecma_property_value_t *prop_value_p; prop_value_p = ecma_create_named_data_property (obj_p, ecma_get_magic_string (LIT_MAGIC_STRING_STATUS), diff --git a/tests/jerry/es.next/promise-all-settled.js b/tests/jerry/es.next/promise-all-settled.js index 05133baad..1ad71012c 100644 --- a/tests/jerry/es.next/promise-all-settled.js +++ b/tests/jerry/es.next/promise-all-settled.js @@ -76,8 +76,26 @@ var rejects = Promise.allSettled(createIterable([ new Promise((_, reject) => { reject("qux"); }), ])); -fulfills.then(result => { assert (result + "" === "foo,bar"); }); -rejects.catch(result => { assert (result === "baz"); }); +fulfills.then(result => { + assert(Object.getPrototypeOf(result) === Array.prototype); + assert(result.length === 2) + assert(Object.getPrototypeOf(result[0]) === Object.prototype); + assert(result[0].status === "fulfilled"); + assert(result[0].value === "foo"); + assert(Object.getPrototypeOf(result[1]) === Object.prototype); + assert(result[1].status === "fulfilled"); + assert(result[1].value === "bar"); +}); +rejects.then(result => { + assert(Object.getPrototypeOf(result) === Array.prototype); + assert(result.length === 2) + assert(Object.getPrototypeOf(result[0]) === Object.prototype); + assert(result[0].status === "rejected"); + assert(result[0].reason === "baz"); + assert(Object.getPrototypeOf(result[1]) === Object.prototype); + assert(result[1].status === "rejected"); + assert(result[1].reason === "qux"); +}); var closed = true; delete Promise.resolve;