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

WeakMap support #312

Closed
gabrielschulhof opened this issue Apr 28, 2018 · 5 comments
Closed

WeakMap support #312

gabrielschulhof opened this issue Apr 28, 2018 · 5 comments

Comments

@gabrielschulhof
Copy link
Collaborator

N-API can already create and manipulate a Array, but there is no support
to create and manipulate a WeakMap, which may sometimes be useful for
internally attaching extra data to arbitrary objects.

(You might be able to define your own finalizer callbacks also using a
WeakMap anyways, by giving a key for the object to check, and the value
being a external value with a finalizer callback defined, so that it will
be called when the key object is finalized; I don't know whether or not it
will work, but it seems like it is allowed to work, at least.)

@gabrielschulhof
Copy link
Collaborator Author

Re: nodejs/node#14256

@bnoordhuis
Copy link
Member

but there is no support to create and manipulate a WeakMap

There's no support for that in the V8 C++ API either.

@gabrielschulhof
Copy link
Collaborator Author

There is always the roundabout way of obtaining the JS API using napi_get_global() and napi_get_named_property().

@bnoordhuis
Copy link
Member

Sure, but why would you want to? At that point you're just adding API sugar.

@gabrielschulhof
Copy link
Collaborator Author

Oh, definitely. There's not even a performance benefit, since you're not saving yourself a trip into JS by using a native API, because, as you pointed out, the native API does not exist. Of course, other engines may have such an API, but I guess when we're faced with that, we can reconsider this issue. I guess we can close this issue.

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

No branches or pull requests

2 participants