Add JS_NewObjectFrom and JS_NewObjectFromStr#871
Merged
bnoordhuis merged 6 commits intoquickjs-ng:masterfrom Feb 2, 2025
Merged
Add JS_NewObjectFrom and JS_NewObjectFromStr#871bnoordhuis merged 6 commits intoquickjs-ng:masterfrom
bnoordhuis merged 6 commits intoquickjs-ng:masterfrom
Conversation
bnoordhuis
commented
Feb 1, 2025
saghul
approved these changes
Feb 1, 2025
Contributor
saghul
left a comment
There was a problem hiding this comment.
At a quick glance there are a couple of places in txiki.js where I could use this. Not any hot path but still.
Contributor
|
I can see a couple of places where it can be useful. Have you considered the interface like this JSValue JS_NewObjectFrom(JSContext *ctx, ...) via va_arg() macro? The usage: obj = JS_NewObjectFrom(ctx, prop1, val1, prop2, val2, NULL); |
Contributor
Author
|
Yes, I considered that but rejected it because:
|
This file contains hidden or 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
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.
I did it as a sequence of commits that iteratively refine the logic so you can see how it builds up from the naive version to the final version.
The final version is definitely quite a bit faster vs. JS_NewObject + JS_SetProperty because we can make some assumptions about the object shape and skip a lot of repeated busywork.
I do wonder though how often I, as a quickjs user, would actually use these functions. I couldn't find many places in qjs.c or run-test262.c where it made sense. The change I made to the latter is admittedly somewhat contrived, so... WDYT?