Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 99f021d7acc3c2ad85c2ccc753822fb107849f8d..02d1dd58661da485641d03590497ed333f49e9eb 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -6224,6 +6224,63 @@ THREADED_TEST(TypeOf) { |
.FromJust()); |
} |
+THREADED_TEST(InstanceOf) { |
+ LocalContext env; |
+ v8::HandleScope scope(env->GetIsolate()); |
+ CompileRun( |
+ "var A = {};" |
+ "var B = {};" |
+ "var C = {};" |
+ "B.__proto__ = A;" |
+ "C.__proto__ = B;" |
+ "function F() {}" |
+ "F.prototype = A;" |
+ "var G = { [Symbol.hasInstance] : null};" |
+ "var H = { [Symbol.hasInstance] : () => { throw new Error(); } };" |
+ "var J = { [Symbol.hasInstance] : () => true };" |
+ "class K {}" |
+ "var D = new K;" |
+ "class L extends K {}" |
+ "var E = new L"); |
+ |
+ v8::Local<v8::Object> f = v8::Local<v8::Object>::Cast(CompileRun("F")); |
+ v8::Local<v8::Object> g = v8::Local<v8::Object>::Cast(CompileRun("G")); |
+ v8::Local<v8::Object> h = v8::Local<v8::Object>::Cast(CompileRun("H")); |
+ v8::Local<v8::Object> j = v8::Local<v8::Object>::Cast(CompileRun("J")); |
+ v8::Local<v8::Object> k = v8::Local<v8::Object>::Cast(CompileRun("K")); |
+ v8::Local<v8::Object> l = v8::Local<v8::Object>::Cast(CompileRun("L")); |
+ v8::Local<v8::Value> a = v8::Local<v8::Value>::Cast(CompileRun("A")); |
+ v8::Local<v8::Value> b = v8::Local<v8::Value>::Cast(CompileRun("B")); |
+ v8::Local<v8::Value> c = v8::Local<v8::Value>::Cast(CompileRun("C")); |
+ v8::Local<v8::Value> d = v8::Local<v8::Value>::Cast(CompileRun("D")); |
+ v8::Local<v8::Value> e = v8::Local<v8::Value>::Cast(CompileRun("E")); |
+ |
+ v8::TryCatch try_catch(env->GetIsolate()); |
+ CHECK(!a->InstanceOf(env.local(), f).ToChecked()); |
+ CHECK(b->InstanceOf(env.local(), f).ToChecked()); |
+ CHECK(c->InstanceOf(env.local(), f).ToChecked()); |
+ CHECK(!d->InstanceOf(env.local(), f).ToChecked()); |
+ CHECK(!e->InstanceOf(env.local(), f).ToChecked()); |
+ CHECK(!try_catch.HasCaught()); |
+ |
+ CHECK(a->InstanceOf(env.local(), g).IsNothing()); |
+ CHECK(try_catch.HasCaught()); |
+ try_catch.Reset(); |
+ |
+ CHECK(b->InstanceOf(env.local(), h).IsNothing()); |
+ CHECK(try_catch.HasCaught()); |
+ try_catch.Reset(); |
+ |
+ CHECK(v8_num(1)->InstanceOf(env.local(), j).ToChecked()); |
+ CHECK(!try_catch.HasCaught()); |
+ |
+ CHECK(d->InstanceOf(env.local(), k).ToChecked()); |
+ CHECK(e->InstanceOf(env.local(), k).ToChecked()); |
+ CHECK(!d->InstanceOf(env.local(), l).ToChecked()); |
+ CHECK(e->InstanceOf(env.local(), l).ToChecked()); |
+ CHECK(!try_catch.HasCaught()); |
+} |
+ |
THREADED_TEST(MultiRun) { |
LocalContext context; |
v8::HandleScope scope(context->GetIsolate()); |