Skip to content

Commit bfc1121

Browse files
author
Robert Fancsik
authored
Fix AsyncGeneratorPrototype routines 'this' argument validation (#4811)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent af297bc commit bfc1121

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-async-generator-prototype.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,18 @@ ecma_builtin_async_generator_prototype_dispatch_routine (uint8_t builtin_routine
111111

112112
if (executable_object_p == NULL)
113113
{
114-
return ecma_raise_type_error (ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR);
114+
const lit_utf8_byte_t *msg_p = ecma_get_error_utf8 (ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR);
115+
lit_utf8_size_t msg_size = ecma_get_error_size (ECMA_ERR_ARGUMENT_THIS_NOT_ASYNC_GENERATOR);
116+
ecma_string_t *error_msg_p = ecma_new_ecma_string_from_ascii (msg_p, msg_size);
117+
118+
ecma_object_t *type_error_obj_p = ecma_new_standard_error (JERRY_ERROR_TYPE, error_msg_p);
119+
ecma_deref_ecma_string (error_msg_p);
120+
121+
ecma_value_t promise = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL);
122+
ecma_reject_promise (promise, ecma_make_object_value (type_error_obj_p));
123+
ecma_deref_object (type_error_obj_p);
124+
125+
return promise;
115126
}
116127

117128
if (executable_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_COMPLETED)

tests/jerry/es.next/function-async-gen1.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ function check_rejected(p, value)
3939
})
4040
}
4141

42+
43+
function check_type_error(p)
44+
{
45+
assert(p instanceof Promise)
46+
47+
p.then(function(v) {
48+
assert(false)
49+
}, function(v) {
50+
assert(v instanceof TypeError);
51+
successCount++
52+
})
53+
}
54+
4255
// Test 1
4356

4457
var gen, r, o
@@ -65,6 +78,9 @@ check_fulfilled(gen.next("Test2"), 1.5, false)
6578
check_fulfilled(gen.next(2.5), o, true)
6679
check_fulfilled(gen.next(), undefined, true)
6780
check_fulfilled(gen.next(), undefined, true)
81+
check_type_error(gen.next.call(undefined))
82+
check_type_error(gen.throw.call(undefined))
83+
check_type_error(gen.return.call(undefined))
6884

6985
r(1)
7086

@@ -220,7 +236,7 @@ check_fulfilled(gen.next(), undefined, true)
220236
// END
221237

222238
function __checkAsync() {
223-
assert(successCount === 29)
239+
assert(successCount === 32)
224240
assert(state === 4)
225241
assert(state2 === 4)
226242
}

tests/test262-esnext-excludelist.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3112,15 +3112,9 @@
31123112
<test id="built-ins/AsyncGeneratorFunction/instance-yield-expr-in-param.js"><reason></reason></test>
31133113
<test id="built-ins/AsyncGeneratorPrototype/next/request-queue-await-order.js"><reason></reason></test>
31143114
<test id="built-ins/AsyncGeneratorPrototype/next/request-queue-promise-resolve-order.js"><reason></reason></test>
3115-
<test id="built-ins/AsyncGeneratorPrototype/next/this-val-not-async-generator.js"><reason></reason></test>
3116-
<test id="built-ins/AsyncGeneratorPrototype/next/this-val-not-object.js"><reason></reason></test>
31173115
<test id="built-ins/AsyncGeneratorPrototype/return/return-state-completed.js"><reason></reason></test>
31183116
<test id="built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.js"><reason></reason></test>
31193117
<test id="built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js"><reason></reason></test>
3120-
<test id="built-ins/AsyncGeneratorPrototype/return/this-val-not-async-generator.js"><reason></reason></test>
3121-
<test id="built-ins/AsyncGeneratorPrototype/return/this-val-not-object.js"><reason></reason></test>
3122-
<test id="built-ins/AsyncGeneratorPrototype/throw/this-val-not-async-generator.js"><reason></reason></test>
3123-
<test id="built-ins/AsyncGeneratorPrototype/throw/this-val-not-object.js"><reason></reason></test>
31243118
<test id="built-ins/FinalizationRegistry/prototype/cleanupSome/return-undefined-with-gc.js"><reason></reason></test>
31253119
<test id="built-ins/FinalizationRegistry/prototype/cleanupSome/return-undefined.js"><reason></reason></test>
31263120
<test id="language/block-scope/syntax/redeclaration/async-function-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>

0 commit comments

Comments
 (0)