Skip to content

Commit ee59c22

Browse files
author
Robert Fancsik
authored
Fix invalid argument reference in Promise.all executor (#4885)
This patch fixes #4871. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent c2eb9ce commit ee59c22

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

jerry-core/ecma/operations/ecma-promise-object.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@ ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, /**<
585585
const ecma_value_t args_p[], /**< argument list */
586586
const uint32_t args_count) /**< argument number */
587587
{
588-
JERRY_UNUSED (args_count);
588+
ecma_value_t arg = args_count > 0 ? args_p[0] : ECMA_VALUE_UNDEFINED;
589+
589590
ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) function_obj_p;
590591
uint8_t promise_type = executor_p->header.u.built_in.u2.routine_flags;
591592

@@ -602,7 +603,7 @@ ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, /**<
602603
/* 8. */
603604
ecma_op_object_put_by_index (ecma_get_object_from_value (executor_p->values),
604605
(uint32_t) (executor_p->index - 1),
605-
args_p[0],
606+
arg,
606607
false);
607608
}
608609
else
@@ -630,12 +631,7 @@ ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, /**<
630631
ecma_get_magic_string (data_propery_name),
631632
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
632633
NULL);
633-
prop_value_p->value = ECMA_VALUE_UNDEFINED;
634-
635-
if (args_count != 0)
636-
{
637-
prop_value_p->value = ecma_copy_value_if_not_object (args_p[0]);
638-
}
634+
prop_value_p->value = ecma_copy_value_if_not_object (arg);
639635

640636
ecma_value_t obj_val = ecma_make_object_value (obj_p);
641637
/* 12. */
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
resolved = false;
16+
17+
function T(p, r, u) {
18+
return Object.assign(p, {
19+
then(onFulfilled, onRejected) {
20+
if (u) {
21+
onFulfilled(r);
22+
} else {
23+
onFulfilled();
24+
}
25+
26+
return Promise.prototype.then.call(this, onFulfilled, onRejected);
27+
}
28+
});
29+
}
30+
31+
var ps = [T(Promise.resolve('success'))];
32+
Promise.all(ps).then(res => {
33+
resolved = true;
34+
}).catch(err => {
35+
assert(false);
36+
});
37+
38+
function __checkAsync() {
39+
assert(resolved);
40+
}

0 commit comments

Comments
 (0)