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

InstanceOf 6.2.0 #47

Closed
wants to merge 1 commit into from
Closed

Conversation

jasongin
Copy link
Member

Adding a napi_instanceof API that checks whether a napi_value object is an instance created by a napi_value constructor function.

The V8 implementation isn't entirely trivial: V8 code would normally use FunctionTemplate::HasInstance(), except here we don't have the FunctionTemplate available because (as a V8-only concept) it is not exposed via NAPI. So instead we can implement the instance-of logic in a slightly less efficient way by looking through the prototype chain. (The JSRT implementation can simply call JsInstanceOf().)

I started porting the canvas package and found it makes frequent use of FunctionTemplate::HasInstance() checks to support sort of polymorphic behavior for drawing different kinds of things on the canvas. The sqlite3 package use the API in one place, just for a simple argument check. Based on my previous scans, not very many other packages use it.

@gabrielschulhof
Copy link
Collaborator

gabrielschulhof commented Jan 16, 2017 via email

gabrielschulhof

This comment was marked as off-topic.

@gabrielschulhof
Copy link
Collaborator

@jasongin if you only need instanceof because of canvas and sqlite then perhaps we need not add it to NAPI because it can be implemented using existing NAPI APIs (https://github.com/gabrielschulhof/abi-stable-node/blob/test-instanceof-master/test/addons-abi/test_instanceof/test_instanceof.cc#L15).

If we do add it to NAPI, we should make sure that it passes the test from my PR.

@gabrielschulhof
Copy link
Collaborator

gabrielschulhof commented Jan 16, 2017

Hmmm, given that we currently have canvas, sqlite, and even iotivity-node that need this, maybe we should have an implementation of this in NAPI after all.

@jasongin
Copy link
Member Author

I think people would expect it to be part of the API. This PR worked in my limited testing, enough to unblock canvas, but it looks like you've done a lot more extensive testing than I did.

@jasongin
Copy link
Member Author

Closing this in favor of @gabrielschulhof's more complete PR.

@jasongin jasongin closed this Jan 19, 2017
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

Successfully merging this pull request may close these issues.

2 participants