You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 15, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 15, 2020. It is now read-only.
Fix napi_create_reference to work correctly with integers #380
The N-API implementation of napi_create_reference uses JsCreateWeakReference. If a reference is created for an integer then there is an access violation during the GC update of the weak reference map. I proposed a possible fix in chakra-core/ChakraCore#3591, but once an approved fix is found we'll need to re-enable test_general/test.
It looks like test_general/test has continued to evolve and is broken for an additional reason now: It attempts to create an object, wrap it, lose the JS reference to the object, force a GC, and ensure that the finalizer passed when wrapping was called. At the moment it looks like we might be mid-gc when the JS tries to force a gc, and so we complete that GC but it doesn't delete the only-just-now-created object.
Other than that, there is some discussion about whether it makes sense to create references to primitive values at nodejs/node-addon-api#131
Honestly, I would prefer that ChakraCore be able to create references to
primitive values, if only because there might be some obscure case out
there in the wild where this is happening.
Yet, if it's not feasible, I can submit a PR that modifies test_general to
not attempt to create references to primitives. After all, that is not the
purpose of that test. The reference to the primitive is used only as a test
payload for the object wrap.
On Thu, Sep 7, 2017 at 9:30 PM, Jimmy Thomson ***@***.***> wrote:
It looks like test_general/test has continued to evolve and is broken for
an additional reason now: It attempts to create an object, wrap it, lose
the JS reference to the object, force a GC, and ensure that the finalizer
passed when wrapping was called. At the moment it looks like we might be
mid-gc when the JS tries to force a gc, and so we complete that GC but it
doesn't delete the only-just-now-created object.
Other than that, there is some discussion about whether it makes sense to
create references to primitive values at nodejs/node-addon-api#131
<nodejs/node-addon-api#131>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#380 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA7k0cZ3HoGrA4_-UfTEj4Ai-L-pNU8Fks5sgDZCgaJpZM4PDVIA>
.
@gabrielschulhof semantically, what does a reference to a primitive mean if a primitive is not heap allocated? ChakraCore's JSRT returns JsValueRefs that are opaque (can be either pointers to heap allocated objects or primitive values)- are you suggesting in the case of primitive values, we always return boxed (heap allocated) values? That seems to be a rather expensive perf cost for supporting obscure cases, no? Alternatively, if you're not suggesting that, then when you say that we create references to primitive values, are you suggesting that we box the value as part of the CreateWeakReference api? That also seems fraught since that value would get collected at the next GC since no one would have a strong handle to that, just a weak one.
So it's unclear what the desired behavior should be. My instinct is that if napi has a chance to define this behavior more concretely right now, we should just say that napi_create_weakreference can return an error if the napi_value passed in can't be weakly referenced- that exposes some concept of VM internals but then again, so does napi_create_weakreference, and this approach allows VM vendors to not be "boxed in" 😄
I think it's pretty safe to return napi_invalid_arg for values that cannot be referenced. Any engine worth its salt should be able to provide persistent references to objects and functions. V8 is known to have features that are redundant, or have been rendered redundant by its evolution.
We might even go so far as to document that only objects and functions can be retained as napi_refs. After all, primitive values are better stored as their native equivalents.
In fact, we document that the napi_value to which a reference is created must be an object. So, I was basically abusing the napi_create_reference() mechanism. My bad.
Activity
test: fixing new test issues
MSLaguana commentedon Sep 7, 2017
It looks like test_general/test has continued to evolve and is broken for an additional reason now: It attempts to create an object, wrap it, lose the JS reference to the object, force a GC, and ensure that the finalizer passed when wrapping was called. At the moment it looks like we might be mid-gc when the JS tries to force a gc, and so we complete that GC but it doesn't delete the only-just-now-created object.
Other than that, there is some discussion about whether it makes sense to create references to primitive values at nodejs/node-addon-api#131
gabrielschulhof commentedon Sep 7, 2017
digitalinfinity commentedon Sep 8, 2017
@gabrielschulhof semantically, what does a reference to a primitive mean if a primitive is not heap allocated? ChakraCore's JSRT returns JsValueRefs that are opaque (can be either pointers to heap allocated objects or primitive values)- are you suggesting in the case of primitive values, we always return boxed (heap allocated) values? That seems to be a rather expensive perf cost for supporting obscure cases, no? Alternatively, if you're not suggesting that, then when you say that we create references to primitive values, are you suggesting that we box the value as part of the CreateWeakReference api? That also seems fraught since that value would get collected at the next GC since no one would have a strong handle to that, just a weak one.
So it's unclear what the desired behavior should be. My instinct is that if napi has a chance to define this behavior more concretely right now, we should just say that
napi_create_weakreferencecan return an error if thenapi_valuepassed in can't be weakly referenced- that exposes some concept of VM internals but then again, so doesnapi_create_weakreference, and this approach allows VM vendors to not be "boxed in" 😄gabrielschulhof commentedon Sep 9, 2017
I think it's pretty safe to return
napi_invalid_argfor values that cannot be referenced. Any engine worth its salt should be able to provide persistent references to objects and functions. V8 is known to have features that are redundant, or have been rendered redundant by its evolution.We might even go so far as to document that only objects and functions can be retained as
napi_refs. After all, primitive values are better stored as their native equivalents.gabrielschulhof commentedon Sep 9, 2017
In fact, we document that the
napi_valueto which a reference is created must be an object. So, I was basically abusing thenapi_create_reference()mechanism. My bad.n-api: stop creating references to primitives
n-api: stop creating references to primitives
n-api: stop creating references to primitives
n-api: stop creating references to primitives
n-api: stop creating references to primitives