Skip to content

Commit 1376377

Browse files
romandevaddaleax
authored andcommitted
Make IsObject() allow functions
As discussed in the issue[1], IsObject() should return true for a function. [1] #207 PR-URL: #217 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 673b59d commit 1376377

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

napi-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ inline bool Value::IsTypedArray() const {
329329
}
330330

331331
inline bool Value::IsObject() const {
332-
return Type() == napi_object;
332+
return Type() == napi_object || IsFunction();
333333
}
334334

335335
inline bool Value::IsFunction() const {

test/basic_types/value.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ test(require(`../build/${buildType}/binding.node`));
77
test(require(`../build/${buildType}/binding_noexcept.node`));
88

99
function test(binding) {
10+
function isObject(value) {
11+
return typeof value === 'object' || typeof value === 'function';
12+
}
13+
1014
function detailedTypeOf(value) {
1115
const type = typeof value;
1216
if (type !== 'object')
@@ -57,7 +61,7 @@ function test(binding) {
5761

5862
testValueList.forEach((testValue) => {
5963
if (testValue !== null && expectedType === 'object') {
60-
assert.strictEqual(typeChecker(testValue), typeof testValue === expectedType);
64+
assert.strictEqual(typeChecker(testValue), isObject(testValue));
6165
} else {
6266
assert.strictEqual(typeChecker(testValue), detailedTypeOf(testValue) === expectedType);
6367
}

0 commit comments

Comments
 (0)