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

Unified Diff: test/cctest/test-object-observe.cc

Issue 733483003: Add a cctest for using a C++ FunctionCallback as an Object.observe observer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-object-observe.cc
diff --git a/test/cctest/test-object-observe.cc b/test/cctest/test-object-observe.cc
index 8851d888933947143bd66f3850dd683a37d40de8..7e9992c19d277c658566dd9f682ca852cc18fe08 100644
--- a/test/cctest/test-object-observe.cc
+++ b/test/cctest/test-object-observe.cc
@@ -762,3 +762,46 @@ TEST(DontLeakContextOnNotifierPerformChange) {
CcTest::isolate()->ContextDisposedNotification();
CheckSurvivingGlobalObjectsCount(1);
}
+
+
+static void ObserverCallback(const FunctionCallbackInfo<Value>& args) {
+ *static_cast<int*>(Handle<External>::Cast(args.Data())->Value()) =
+ Handle<Array>::Cast(args[0])->Length();
+}
+
+
+TEST(ObjectObserveCallsCppFunction) {
+ Isolate* isolate = CcTest::isolate();
+ HandleScope scope(isolate);
+ LocalContext context(isolate);
+ int numRecordsSent = 0;
+ Handle<Function> observer =
+ Function::New(CcTest::isolate(), ObserverCallback,
+ External::New(isolate, &numRecordsSent));
+ context->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "observer"),
+ observer);
+ CompileRun(
+ "var obj = {};"
+ "Object.observe(obj, observer);"
+ "obj.foo = 1;"
+ "obj.bar = 2;");
+ CHECK_EQ(2, numRecordsSent);
+}
+
+
+TEST(ObjectObserveCallsFunctionTemplateInstance) {
+ Isolate* isolate = CcTest::isolate();
+ HandleScope scope(isolate);
+ LocalContext context(isolate);
+ int numRecordsSent = 0;
+ Handle<FunctionTemplate> tmpl = FunctionTemplate::New(
+ isolate, ObserverCallback, External::New(isolate, &numRecordsSent));
+ context->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "observer"),
+ tmpl->GetFunction());
+ CompileRun(
+ "var obj = {};"
+ "Object.observe(obj, observer);"
+ "obj.foo = 1;"
+ "obj.bar = 2;");
+ CHECK_EQ(2, numRecordsSent);
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698