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

Update rquickjs to the newest version of QuickJS #293

Merged
merged 22 commits into from
Apr 25, 2024
Merged

Conversation

DelSkayn
Copy link
Owner

@DelSkayn DelSkayn commented Apr 18, 2024

This PR updates the version of QuickJS used by rquickjs to the newest version.
QuickJS has some rather significant changes since the last release which impact rquickjs.
As a result rquickjs will have to introduce some breaking changes.

Changes

Promise

rquickjs::Promise is renamed to rquickjs::PromiseFuture and a new Promise struct is introduced.
Unlike the previous promise struct the new one isn't a future by default, allowing it to be used by non-async code.
You can turn the promise into a future if desired and future feature is enabled. You can also manually access the state and result of a promise allowing you to implement polling methods on the promises yourself if required.

Modules

A lot of the current design for modules was made to work around the problem of QuickJS freeing modules which were not evaluated if any module returned an error during evaluation.
This is no longer the case.
Unfortunately there are some functions which will segfault if they are called on an unevaluated module so we still need some safety system to avoid calling those functions.
Furthermore with the introduction of top level await support in QuickJS the evaluation of a module now returns a promise.
This means I needed to redesign the module API to support this.

Modules are now, once again, safe to hold onto once declared.
Ctx::compile is removed, it didn't make sense since evaluating a module no longer returns the module but a promise which itself also doesn't return the module.
If you want or replicate the behaviour of Ctx::compile you will have to first declare a module and then call eval on that module and make sure the promise is resolved.
Further more modules are now tagged with a marker type: either Declared or Evaluated.
There are some functions which you are only able to call after you make sure that the module is evaluated which is what these marker types are used for.

Most of the functions dealing with retrieving modules exports have been removed in favor of an approach based of the new QuickJS function JS_GetModuleNamespace which returns an object with all the exports of the module. This function can no be safely called with Module::<Evaluated>::namespace.

@DelSkayn DelSkayn marked this pull request as ready for review April 23, 2024 13:47
@DelSkayn DelSkayn changed the title Update rquickjs to the newest version. Update rquickjs to the newest version of QuickJS Apr 24, 2024
@DelSkayn DelSkayn merged commit 377f9ed into master Apr 25, 2024
54 checks passed
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.

1 participant