From cdd5c9f7495cb7e5713ca62f525cc5cb9810ba6b Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Fri, 5 Mar 2021 18:49:17 +0100 Subject: [PATCH] Add test for Object::InstanceOf --- test/object/object.cc | 8 ++++++++ test/object/object.js | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/test/object/object.cc b/test/object/object.cc index 2c0ce420b..2a2bd2e51 100644 --- a/test/object/object.cc +++ b/test/object/object.cc @@ -228,6 +228,12 @@ Value CreateObjectUsingMagic(const CallbackInfo& info) { return obj; } +Value InstanceOf(const CallbackInfo& info) { + Object obj = info[0].As(); + Function constructor = info[1].As(); + return Boolean::New(info.Env(), obj.InstanceOf(constructor)); +} + Object InitObject(Env env) { Object exports = Object::New(env); @@ -265,5 +271,7 @@ Object InitObject(Env env) { exports["addFinalizer"] = Function::New(env, AddFinalizer); exports["addFinalizerWithHint"] = Function::New(env, AddFinalizerWithHint); + exports["instanceOf"] = Function::New(env, InstanceOf); + return exports; } diff --git a/test/object/object.js b/test/object/object.js index b9036560f..52646cb8c 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -137,4 +137,13 @@ function test(binding) { circular2: magicObject }); } + + { + function Ctor() {}; + + assert.strictEqual(binding.object.instanceOf(new Ctor(), Ctor), true); + assert.strictEqual(binding.object.instanceOf(new Ctor(), Object), true); + assert.strictEqual(binding.object.instanceOf({}, Ctor), false); + assert.strictEqual(binding.object.instanceOf(null, Ctor), false); + } }