Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PromiseLike bug: sync with Turbowarp #3

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/compiler/jsexecute.js
Original file line number Diff line number Diff line change
@@ -116,19 +116,20 @@ const waitPromise = function*(promise) {
const thread = globalState.thread;
let returnValue;

// enter STATUS_PROMISE_WAIT and yield
// this will stop script execution until the promise handlers reset the thread status
// because promise handlers might execute immediately, configure thread.status here
thread.status = 1; // STATUS_PROMISE_WAIT

promise
.then(value => {
returnValue = value;
thread.status = 0; // STATUS_RUNNING
})
.catch(error => {
}, error => {
thread.status = 0; // STATUS_RUNNING
globalState.log.warn('Promise rejected in compiled script:', error);
});

// enter STATUS_PROMISE_WAIT and yield
// this will stop script execution until the promise handlers reset the thread status
thread.status = 1; // STATUS_PROMISE_WAIT
yield;

return returnValue;