From 1b38121bc9090792a85783bfaec264004f83f6a4 Mon Sep 17 00:00:00 2001 From: Roy Wright Date: Sun, 28 Jan 2018 09:23:17 +0900 Subject: [PATCH] Make IsObject() allow functions As discussed in the issue[1], IsObject() should return true for a function. [1] https://github.com/nodejs/node-addon-api/issues/207 PR-URL: https://github.com/nodejs/node-addon-api/pull/217 Reviewed-By: Anna Henningsen --- napi-inl.h | 2 +- test/basic_types/value.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/napi-inl.h b/napi-inl.h index e84ca78..f34ed7a 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -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 { diff --git a/test/basic_types/value.js b/test/basic_types/value.js index 36fc351..0d67e75 100644 --- a/test/basic_types/value.js +++ b/test/basic_types/value.js @@ -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') @@ -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); }