Reviewers: rossberg,
Description:
Add a cctest for using a C++ FunctionCallback as an Object.observe observer
[email protected]
BUG=v8:3076
Please review this at https://codereview.chromium.org/733483003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+43, -0 lines):
M test/cctest/test-object-observe.cc
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);
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.