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

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

Issue 11635033: Basic test for interaction of Object.observe and hidden prototypes (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Observe proto Created 8 years 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 abd10117dd49ea4fa5c8f7191dc66ddb42f6fed9..07db3a3916e977b1cf29f040757e3544c5af6f5c 100644
--- a/test/cctest/test-object-observe.cc
+++ b/test/cctest/test-object-observe.cc
@@ -279,6 +279,7 @@ TEST(GlobalObjectObservation) {
CHECK_EQ(3, CompileRun("records.length")->Int32Value());
}
+
struct RecordExpectation {
Handle<Value> object;
const char* type;
@@ -310,6 +311,9 @@ static void ExpectRecords(Handle<Value> records,
}
}
+#define EXPECT_RECORDS(records, expectations) \
+ ExpectRecords(records, expectations, ARRAY_SIZE(expectations))
+
TEST(APITestBasicMutation) {
HarmonyIsolate isolate;
HandleScope scope;
@@ -348,7 +352,50 @@ TEST(APITestBasicMutation) {
{ obj, "deleted", "1", Number::New(5) },
{ obj, "deleted", "1.1", Number::New(6) }
};
- ExpectRecords(CompileRun("records"),
- expected_records,
- ARRAY_SIZE(expected_records));
+ EXPECT_RECORDS(CompileRun("records"), expected_records);
+}
+
+TEST(HiddenPrototypeObservation) {
+ HarmonyIsolate isolate;
+ HandleScope scope;
+ LocalContext context;
+ Handle<FunctionTemplate> tmpl = FunctionTemplate::New();
+ tmpl->SetHiddenPrototype(true);
+ tmpl->InstanceTemplate()->Set(String::New("foo"), Number::New(75));
+ Handle<Object> proto = tmpl->GetFunction()->NewInstance();
+ Handle<Object> obj = Object::New();
+ obj->SetPrototype(proto);
+ context->Global()->Set(String::New("obj"), obj);
+ context->Global()->Set(String::New("proto"), proto);
+ CompileRun(
+ "var records;"
+ "function observer(r) { records = r; };"
+ "Object.observe(obj, observer);"
+ "obj.foo = 41;" // triggers a notification
+ "proto.foo = 42;" // does not trigger a notification
+ );
+ const RecordExpectation expected_records[] = {
+ { obj, "updated", "foo", Number::New(75) }
+ };
+ EXPECT_RECORDS(CompileRun("records"), expected_records);
+ obj->SetPrototype(Null());
+ CompileRun("obj.foo = 43");
+ const RecordExpectation expected_records2[] = {
+ { obj, "new", "foo", Handle<Value>() }
+ };
+ EXPECT_RECORDS(CompileRun("records"), expected_records2);
+ obj->SetPrototype(proto);
+ CompileRun(
+ "Object.observe(proto, observer);"
+ "proto.bar = 1;"
+ "Object.unobserve(obj, observer);"
+ "obj.foo = 44;"
+ );
+ const RecordExpectation expected_records3[] = {
+ { proto, "new", "bar", Handle<Value>() }
+ // TODO(adamk): The below record should be emitted since proto is observed
+ // and has been modified. Not clear if this happens in practice.
+ // { proto, "updated", "foo", Number::New(43) }
+ };
+ EXPECT_RECORDS(CompileRun("records"), expected_records3);
}
« 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