Skip to content

Commit

Permalink
Fix AsyncGeneratorPrototype routines 'this' argument validation
Browse files Browse the repository at this point in the history
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
  • Loading branch information
Robert Fancsik committed Oct 29, 2021
1 parent 3c742be commit 8ce832b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,26 @@ ecma_builtin_async_generator_prototype_dispatch_routine (uint8_t builtin_routine

if (executable_object_p == NULL)
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an async generator object"));
#if JERRY_ERROR_MESSAGES
const lit_utf8_byte_t *msg_p = (const lit_utf8_byte_t *) "Argument 'this' is not an async generator object";
lit_utf8_size_t msg_size = (lit_utf8_size_t) 48;
JERRY_ASSERT (lit_zt_utf8_string_size (msg_p) == msg_size);
ecma_string_t *error_msg_p = ecma_new_ecma_string_from_ascii (msg_p, msg_size);
#else /* !JERRY_ERROR_MESSAGES */
ecma_string_t *error_msg_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
#endif /* JERRY_ERROR_MESSAGES */

ecma_object_t *type_error_obj_p = ecma_new_standard_error (JERRY_ERROR_TYPE, error_msg_p);

#if JERRY_ERROR_MESSAGES
ecma_deref_ecma_string (error_msg_p);
#endif /* JERRY_ERROR_MESSAGES */

ecma_value_t promise = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL);
ecma_reject_promise (promise, ecma_make_object_value (type_error_obj_p));
ecma_deref_object (type_error_obj_p);

return promise;
}

if (executable_object_p->extended_object.u.cls.u2.executable_obj_flags & ECMA_EXECUTABLE_OBJECT_COMPLETED)
Expand Down
18 changes: 17 additions & 1 deletion tests/jerry/es.next/function-async-gen1.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ function check_rejected(p, value)
})
}


function check_type_error(p)
{
assert(p instanceof Promise)

p.then(function(v) {
assert(false)
}, function(v) {
assert(v instanceof TypeError);
successCount++
})
}

// Test 1

var gen, r, o
Expand All @@ -65,6 +78,9 @@ check_fulfilled(gen.next("Test2"), 1.5, false)
check_fulfilled(gen.next(2.5), o, true)
check_fulfilled(gen.next(), undefined, true)
check_fulfilled(gen.next(), undefined, true)
check_type_error(gen.next.call(undefined))
check_type_error(gen.throw.call(undefined))
check_type_error(gen.return.call(undefined))

r(1)

Expand Down Expand Up @@ -220,7 +236,7 @@ check_fulfilled(gen.next(), undefined, true)
// END

function __checkAsync() {
assert(successCount === 29)
assert(successCount === 32)
assert(state === 4)
assert(state2 === 4)
}
6 changes: 0 additions & 6 deletions tests/test262-esnext-excludelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6480,15 +6480,9 @@
<test id="built-ins/AsyncGeneratorFunction/instance-yield-expr-in-param.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/next/request-queue-await-order.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/next/request-queue-promise-resolve-order.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/next/this-val-not-async-generator.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/next/this-val-not-object.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/return/return-state-completed.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/return/this-val-not-async-generator.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/return/this-val-not-object.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/throw/this-val-not-async-generator.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/throw/this-val-not-object.js"><reason></reason></test>
<test id="built-ins/FinalizationRegistry/prototype/cleanupSome/return-undefined-with-gc.js"><reason></reason></test>
<test id="built-ins/FinalizationRegistry/prototype/cleanupSome/return-undefined.js"><reason></reason></test>
<test id="language/arguments-object/cls-decl-async-private-gen-meth-args-trailing-comma-multiple.js"><reason></reason></test>
Expand Down

0 comments on commit 8ce832b

Please sign in to comment.