Skip to content

Commit

Permalink
Add test for Object::InstanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseExposito committed Mar 5, 2021
1 parent 47fcf4a commit cdd5c9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/object/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ Value CreateObjectUsingMagic(const CallbackInfo& info) {
return obj;
}

Value InstanceOf(const CallbackInfo& info) {
Object obj = info[0].As<Object>();
Function constructor = info[1].As<Function>();
return Boolean::New(info.Env(), obj.InstanceOf(constructor));
}

Object InitObject(Env env) {
Object exports = Object::New(env);

Expand Down Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions test/object/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit cdd5c9f

Please sign in to comment.