Add a cctest for using a C++ FunctionCallback as an Object.observe observer
R=rossberg@chromium.org BUG=v8:3076 LOG=n Review URL: https://codereview.chromium.org/733483003 Cr-Commit-Position: refs/heads/master@{#25384}
This commit is contained in:
parent
d7e3697ddc
commit
58839390c3
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user