Reviewers: rossberg,

Description:
Basic test for interaction of Object.observe and hidden prototypes

The test simply shows the current behavior, not necessarily what we
want the behavior to be.


Please review this at https://codereview.chromium.org/11635033/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  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 abd10117dd49ea4fa5c8f7191dc66ddb42f6fed9..539db4f68ef13a8a9e07f8deb193c1f8321ca393 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,35 @@ 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;"
+      "Object.observe(obj, function(r) { records = r });"
+      "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);
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to