-
Notifications
You must be signed in to change notification settings - Fork 68
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DelSkayn
changed the title
Update rquickjs to the newest version.
Update rquickjs to the newest version of QuickJS
Apr 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 torquickjs::PromiseFuture
and a newPromise
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
orEvaluated
.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 withModule::<Evaluated>::namespace
.