You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Note that run_queued promise_jobs() only does something when LibJS is running standalone. I.e, that function call does nothing when run as part of LibWeb).
Somehow we need to implement the requirement of only running the promise queue in a manner that meets requirement 9.5 of https://tc39.es/ecma262/#sec-jobs. Ideally, this would also be done in a way that closer unifies the implementation of HTML promise queue with the JS one.
I've also made attempts of changing the pending promise queue to include the relevant script or module, realm, etc (per spec), and run those jobs only when the execution context is empty. But every attempt of that broke a lot of test262 tests. I'm unclear on at what points we actually need to be 'performing a microtask checkpoint' in our pure JS implementation.
One test-js test that I have had trouble with, for example, is:
test("return from async through finally",()=>{lettest=0;letresult=(asyncfunction(){try{return{y: 5};}finally{test=42;}expect.fail("unreachable");})();expect(result).toBeInstanceOf(Promise);expect(test).toBe(42);result.then(value=>{expect(value).toEqual({y: 5});});});
But test-262 catches a whole lot more cases.
The above test does not pass when run in HTML, which does indicate some deeper problems:
The text was updated successfully, but these errors were encountered:
shannonbooth
changed the title
LibJS: Promise queue is evaluated at incorrect timing
LibJS: Promise queue evaluated at incorrect timing / inconsistent with HTML integration
Jan 11, 2025
Example test crashing as a result of this is the following JS:
With an
import.js
of:Which causes an assertion of:
This is a result of running an executable incorrectly running the queued promises:
ladybird/Libraries/LibJS/SourceTextModule.cpp
Line 723 in 19f9747
Resulting in module linking on a module graph which has an incorrect / incomplete state.
This is only a known problem in the pure LibJS implementation due to it's implementation of the host hooks, see:
ladybird/Libraries/LibJS/Runtime/VM.cpp
Line 434 in 19f9747
Currently, we run the queued promise jobs during bytecode evaluation, see:
ladybird/Libraries/LibJS/Bytecode/Interpreter.cpp
Line 271 in 19f9747
ladybird/Libraries/LibJS/Bytecode/Interpreter.cpp
Line 760 in 19f9747
ladybird/Libraries/LibJS/Bytecode/Interpreter.cpp
Line 300 in 19f9747
And also while awaiting a completion:
ladybird/Libraries/LibJS/Runtime/Completion.cpp
Line 116 in 19f9747
(Note that
run_queued promise_jobs()
only does something when LibJS is running standalone. I.e, that function call does nothing when run as part of LibWeb).Somehow we need to implement the requirement of only running the promise queue in a manner that meets requirement 9.5 of https://tc39.es/ecma262/#sec-jobs. Ideally, this would also be done in a way that closer unifies the implementation of HTML promise queue with the JS one.
A hacky fix for the issue above is:
shannonbooth@8a57be5
Which gives the test 262 diff of:
+18 ✅ -18 💥️
An even more ugly change that fixes even more tests is:
shannonbooth@c359084
Which results in:
+31 ✅ -13 ❌ -18 💥
I've also made attempts of changing the pending promise queue to include the relevant script or module, realm, etc (per spec), and run those jobs only when the execution context is empty. But every attempt of that broke a lot of test262 tests. I'm unclear on at what points we actually need to be 'performing a microtask checkpoint' in our pure JS implementation.
One test-js test that I have had trouble with, for example, is:
But test-262 catches a whole lot more cases.
The above test does not pass when run in HTML, which does indicate some deeper problems:
The text was updated successfully, but these errors were encountered: