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

Error if there are pending items on the event queue #277

Merged
merged 7 commits into from
Mar 16, 2023

Conversation

jeffcharles
Copy link
Collaborator

We've received feedback that the current behaviour of successfully exiting when items there are items enqueued on to the event loop that will never be executed is unexpected and they would prefer if the execution trapped with a helpful error message instead. This PR:

  • Adds an is_pending to Context to return whether there are pending jobs on the event queue
  • Changes the run bytecode logic to panic if there are pending jobs on the event queue with an exception if we're running the Web Platform Tests suite as the suite enqueues a promise as part of its setup
  • Disables a WPT suite that enqueues events

The check if we're running the WPT suite is done through a WASI environment variable. I opted to use this approach because:

  • I couldn't figure out a reasonable way to change how we run the WPT suite so that it doesn't enqueue the promise
  • we won't have to use a special build of Javy for the WPT suite
  • we don't have to touch the Javy CLI including adding support for additional arguments or env vars and plumbing it through to the core logic

I did take a look at the benchmarks to see if the WASI call to retrieve the env var value would have a performance impact and the results indicated no change in performance between main and this branch.

Copy link
Contributor

@jianghong jianghong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For when we release: Would you consider this a major change?

testFile: "upstream/encoding/replacement-encodings.any.js",
},
// { // FIXME requires the event loop
// testFile: "upstream/encoding/replacement-encodings.any.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear to me why this was needed to be commented out, could you clarify?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually doesn't need to be commented out any more since I disabled the error message with pending jobs. Technically the tests aren't completing properly but I can't figure out a way to have these tests error but have the suite setup to not cause a panic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this does need to continue to be commented out or we get unhandled promise rejections due to Javy not implementing XMLHttpRequest when we run with the event loop enabled. I've updated the comment.

wpt/package.json Outdated
@@ -6,7 +6,7 @@
"scripts": {
"bundle": "rollup -c rollup.config.js runner.js",
"javy": "../target/release/javy compile -o bundle.wasm bundle.js",
"wasmtime": "wasmtime bundle.wasm",
"wasmtime": "wasmtime --env JAVY_WPT=1 bundle.wasm",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about how the wpt stuff is built and ran yet but could we run it with the experimental_event_loop feature turned on? Would that help avoid needing to pass and checking this JAVY_WPT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to address that in #277 (comment). The short answer is yes, but I'd prefer to not do that because WPT would be testing something that doesn't behave like Javy would without the feature enabled.

crates/quickjs-wasm-rs/src/js_binding/context.rs Outdated Show resolved Hide resolved
crates/core/src/execution.rs Outdated Show resolved Hide resolved
@jeffcharles
Copy link
Collaborator Author

For when we release: Would you consider this a major change?

We can bump the minor version since we're 0.x. JS code that was working could stop working if it created pending jobs.

Copy link
Member

@saulecabrera saulecabrera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks for all your patience iterating on this!

@jeffcharles jeffcharles merged commit 48821f8 into main Mar 16, 2023
@jeffcharles jeffcharles deleted the jc.error-if-pending-events branch March 16, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants