Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(599)

Unified Diff: test/cctest/test-api.cc

Side-by-side diff isn't available for this file because of its large size.
Issue 2812613002: [api] Expose instanceof through v8::Value::InstanceOf. (Closed)
Patch Set: test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
Download patch
« no previous file with comments | « src/counters.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « src/counters.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698