Open p51lee opened 1 year ago
Let me explain what is going on here. The provided async
function is invoked to obtain the iterator. There is no special handling for async functions here. So, the returned Promise
(that corresponds to the body of the async function) is being interpreted as the iterator. The promise does not have next
method. Hence, TypeError
occurs (when next
is invoked). Unfortunately, there is still the infinite promise job trying to resolve the promise.
In fact, graal-js
throws the TypeError
but for some technical reasons the js
launcher postpones the output of this error into the console until the promise job queue is empty. This never happens in this case.
You can verify that graal-js
throws the TypeError
if you replace the last line of your test-case by
try {
for ( { } of obj );
} catch (e) {
console.log(e);
}
So, the described behaviour can be considered as a confusing behaviour of js
launcher but it cannot be considered as non-compliant behaviour with respect to ECMAScript specification. The specification does not cover how and when the user is informed about the abrupt completion of the top-level script.
Thank you for your detailed explanation!
Hello,
I think the input code should throw
TypeError
and thewhile (true)
loop underawait 0
should not be executed:but running it using GraalJS results in infinite loop:
Interestingly, V8 has a similar bug:
but NodeJS terminates well: