forked from nodejs/abi-stable-node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "test_instanceof", | ||
"sources": [ "test_instanceof.cc" ] | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var fs = require( 'fs' ); | ||
|
||
require('../../common'); | ||
var assert = require('assert'); | ||
var addon = require('./build/Release/test_instanceof'); | ||
var path = require( 'path' ); | ||
|
||
function assertTrue(assertion) { | ||
return assert.strictEqual(true, assertion); | ||
} | ||
|
||
function assertFalse(assertion) { | ||
assert.strictEqual(false, assertion); | ||
} | ||
|
||
function assertEquals(leftHandSide, rightHandSide) { | ||
assert.equal(leftHandSide, rightHandSide); | ||
} | ||
|
||
function assertThrows(statement) { | ||
assert.throws(function() { | ||
eval(statement); | ||
}, Error); | ||
} | ||
|
||
function testFile( fileName ) { | ||
eval( fs.readFileSync( fileName, { encoding: 'utf8' } ) | ||
.replace( /[(]([^\s(]+)\s+instanceof\s+([^)]+)[)]/g, | ||
'( addon.doInstanceOf( $1, $2 ) )' ) ); | ||
} | ||
|
||
testFile( | ||
path.join( path.resolve( __dirname, '..', '..', '..', 'deps', 'v8', 'test', 'mjsunit' ), | ||
'instanceof.js' ) ); | ||
testFile( | ||
path.join( path.resolve( __dirname, '..', '..', '..', 'deps', 'v8', 'test', 'mjsunit' ), | ||
'instanceof-2.js' ) ); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <node_jsvmapi.h> | ||
#include <stdio.h> | ||
|
||
void doInstanceOf(napi_env env, napi_func_cb_info info) { | ||
napi_value arguments[2]; | ||
|
||
napi_get_cb_args(env, info, arguments, 2); | ||
|
||
napi_set_return_value(env, info, | ||
napi_create_boolean(env, napi_instanceof(env, arguments[0], arguments[1]))); | ||
} | ||
|
||
void Init(napi_env env, napi_value exports, napi_value module) { | ||
napi_set_property(env, exports, | ||
napi_property_name(env, "doInstanceOf"), | ||
napi_create_function(env, doInstanceOf)); | ||
} | ||
|
||
NODE_MODULE_ABI(addon, Init) |