Skip to content

Commit

Permalink
Make IsObject() allow functions
Browse files Browse the repository at this point in the history
As discussed in the issue[1], IsObject() should return true for a
function.

[1] nodejs/node-addon-api#207

PR-URL: nodejs/node-addon-api#217
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
Marlyfleitas committed Jan 28, 2018
1 parent 43b4da5 commit 9aa647a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ inline bool Value::IsTypedArray() const {
}

inline bool Value::IsObject() const {
return Type() == napi_object;
return Type() == napi_object || IsFunction();
}

inline bool Value::IsFunction() const {
Expand Down
6 changes: 5 additions & 1 deletion test/basic_types/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ test(require(`../build/${buildType}/binding.node`));
test(require(`../build/${buildType}/binding_noexcept.node`));

function test(binding) {
function isObject(value) {
return typeof value === 'object' || typeof value === 'function';
}

function detailedTypeOf(value) {
const type = typeof value;
if (type !== 'object')
Expand Down Expand Up @@ -57,7 +61,7 @@ function test(binding) {

testValueList.forEach((testValue) => {
if (testValue !== null && expectedType === 'object') {
assert.strictEqual(typeChecker(testValue), typeof testValue === expectedType);
assert.strictEqual(typeChecker(testValue), isObject(testValue));
} else {
assert.strictEqual(typeChecker(testValue), detailedTypeOf(testValue) === expectedType);
}
Expand Down

0 comments on commit 9aa647a

Please sign in to comment.