-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add instanceof master v8 #48
Closed
gabrielschulhof
wants to merge
5
commits into
nodejs:api-prototype-6.2.0
from
gabrielschulhof:add-instanceof-master-v8
Closed
Add instanceof master v8 #48
gabrielschulhof
wants to merge
5
commits into
nodejs:api-prototype-6.2.0
from
gabrielschulhof:add-instanceof-master-v8
Conversation
This file contains 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
Closed
In napi_instanceof(), GetPrototype() can be used for retrieving the object prototype, but not for retrieving the function prototype. For that, we need to retrieve the "prototype" property.
gabrielschulhof
force-pushed
the
add-instanceof-master-v8
branch
from
January 20, 2017 10:15
b9e3990
to
d137ac0
Compare
LGTM Maybe replace all your tabs with spaces though to avoid mixing and be consistent with the Node.js code style. |
gabrielschulhof
pushed a commit
that referenced
this pull request
Jan 20, 2017
Since FunctionTemplate::HasInstance() is inaccessible, we must implement the Javascript instanceof operator using the public V8 API. This does that, and uses the V8 tests for instanceof to ensure that the semantics of the API are identical to the semantics of the Javascript operator. Closes #48
jasongin
pushed a commit
to jasongin/abi-stable-node
that referenced
this pull request
Jan 26, 2017
Since FunctionTemplate::HasInstance() is inaccessible, we must implement the Javascript instanceof operator using the public V8 API. This does that, and uses the V8 tests for instanceof to ensure that the semantics of the API are identical to the semantics of the Javascript operator. Closes nodejs#48
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.
Implementation of
napi_instanceof()
which uses the"prototype"
property of the constructor and the"__proto__"
property of the object to be examined.It also adds a test to make sure that the result fully implements the semantics of the
instanceof
operator. The test is taken from V8's https://github.com/nodejs/abi-stable-node/blob/api-prototype-6.2.0/deps/v8/test/mjsunit/instanceof.js and https://github.com/nodejs/abi-stable-node/blob/api-prototype-6.2.0/deps/v8/test/mjsunit/instanceof-2.js and modified to replace the JSinstanceof
operator with calls to the addon that exposesnapi_instanceof()
.Note that
napi_instanceof()
is not "linearly independent", in that it can be implemented with calls to existing NAPI APIs (https://gist.github.com/gabrielschulhof/3a8d174b860db0c18a732c0b25c12cbb). Unfortunately this currently means thatnapi_instanceof()
will be less efficient on V8 than the native V8HasInstance()
because we cannot callFunctionTemplate::HasInstance()
, whereas on ChakraCorenapi_instanceof()
will be more efficient than an implementation using other napi APIs, because we can callJsInstanceOf()
.So, adding
napi_instanceof()
will be a net benefit for ChakraCore and a net detriment for V8 - with the benefit that there will be a VM-neutral API for accomplishing this task.Re #47