-
Notifications
You must be signed in to change notification settings - Fork 285
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
Plain data objects #493
Plain data objects #493
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! This is really exciting. I just asked for a couple of clarifying comments in some of the subtler bits of the implementation.
Test failure is because Node.js 10 appears to return a Number in a mixed
|
There was another complication:
I tried the first approach using I did work on a test for it too, but it requires a way to call into Rust functions from JS, which isn't yet implemented in this PR. I rebased #507 and added a test there. One final thing to check: does |
I thought I could be clever and micro-optimize this a bit, but `has_own_property` really does require a string argument, so we have to do the conversion first.
@goto-bus-stop I'll review more closely in a bit, thanks for updating! Technically, the semantics of
|
|
@goto-bus-stop Oh, wait! Twitter came to the rescue and explained that |
Riiight Proxies…I really should've read the spec instead of guessing! I wanted to use |
Oh lol—the backport was released in |
|
I guess tests won't pass on Node 12 until a new minor is released. Should we in the mean time just rely on my buggy implementation, and file a follow-up issue to upgrade as soon as a Node.js 12.x with the backport is available? |
@goto-bus-stop Thanks for all this detective work! I think your workaround is totally fine for now until the new API is backported to 12. Do you mind also filing a followup issue so we can replace the workaround once 12 is ready? |
filed follow up in #511 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks so much for all the investigations and revisions you've done.
Implements these 'plain object' operations:
And the required tag checks to make that work, and the required array methods to make
get_own_property_names
usable.Most of it is quite straightforward, just calling napi functions. The remaining changes are about passing
Env
values to functions that need it under n-api, but did not need it under nan. The test for the object code uses downcasting, and the downcasting and typecheck code did not previously receive a reference to theEnv
. Thejs_array.len()
function also did not receive a reference to theEnv
, but needs one to eventually call the napi function.For the
js_array.len()
function, which is used by other methods on the impl, I added a privatelen_inner()
function with a consistent API to save some feature flag checks. It could be removed if the nan implementation is removed later.