Skip to content

Commit

Permalink
napi: eslint the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Mar 22, 2017
1 parent 18d7b73 commit 09a127c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
21 changes: 11 additions & 10 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2053,38 +2053,39 @@ napi_status napi_instanceof(napi_env e,
return napi_set_last_error(napi_function_expected);
}

napi_value value, jsRes;
napi_value value, js_result;
napi_status status;
napi_valuetype valueType;
napi_valuetype value_type;

// Get "Symbol" from the global object
status = napi_get_global(e, &value);
if (status != napi_ok) return status;
status = napi_get_named_property(e, value, "Symbol", &value);
if (status != napi_ok) return status;
status = napi_get_type_of_value(e, value, &valueType);
status = napi_get_type_of_value(e, value, &value_type);
if (status != napi_ok) return status;

// Get "hasInstance" from Symbol
if (valueType == napi_function) {
if (value_type == napi_function) {
status = napi_get_named_property(e, value, "hasInstance", &value);
if (status != napi_ok) return status;
status = napi_get_type_of_value(e, value, &valueType);
status = napi_get_type_of_value(e, value, &value_type);
if (status != napi_ok) return status;

// Retrieve the function at the Symbol(hasInstance) key of the constructor
if (valueType == napi_symbol) {
if (value_type == napi_symbol) {
status = napi_get_property(e, constructor, value, &value);
if (status != napi_ok) return status;
status = napi_get_type_of_value(e, value, &valueType);
status = napi_get_type_of_value(e, value, &value_type);
if (status != napi_ok) return status;

// Call the function to determine whether the object is an instance of the
// constructor
if (valueType == napi_function) {
status = napi_call_function(e, constructor, value, 1, &object, &jsRes);
if (value_type == napi_function) {
status = napi_call_function(e, constructor, value, 1, &object,
&js_result);
if (status != napi_ok) return status;
return napi_get_value_bool(e, jsRes, result);
return napi_get_value_bool(e, js_result, result);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions test/addons-napi/test_instanceof/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ testFile(
if (typeof Symbol !== 'undefined' && 'hasInstance' in Symbol &&
typeof Symbol.hasInstance === 'symbol') {

function compareToNative( object, constructor ) {
return (addon.doInstanceOf( object, constructor) ===
(object instanceof constructor ));
function compareToNative(object, constructor) {
return (addon.doInstanceOf(object, constructor) ===
(object instanceof constructor));
}

var MyClass = function MyClass() {}
const MyClass = function MyClass() {};
Object.defineProperty(MyClass, Symbol.hasInstance, {
value: function( candidate ) {
value: function(candidate) {
return 'mark' in candidate;
}
} );
});

var MySubClass = function MySubClass() {}
const MySubClass = function MySubClass() {};
MySubClass.prototype = new MyClass();

var x = new MySubClass();
var y = new MySubClass();
let x = new MySubClass();
let y = new MySubClass();
x.mark = true;

compareToNative(x, MySubClass);
Expand Down

0 comments on commit 09a127c

Please sign in to comment.