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

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

Issue 11414094: Make Object.observe on the global object functional (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Test with reattaching to a different context Created 8 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 | « src/runtime.cc ('k') | test/mjsunit/harmony/object-observe.js » ('j') | 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 9decf1768f30904c1a9c5f03cdd977e39af68c62..a8e4acad7da67b26281ab2b2547df04f77eb6fae 100644
--- a/test/cctest/test-object-observe.cc
+++ b/test/cctest/test-object-observe.cc
@@ -218,3 +218,50 @@ TEST(ObjectHashTableGrowth) {
CompileRun("obj.foo = 'bar'");
CHECK(CompileRun("ran")->BooleanValue());
}
+
+TEST(GlobalObjectObservation) {
+ HarmonyIsolate isolate;
+ HandleScope scope;
+ LocalContext context;
+ Handle<Object> global_proxy = context->Global();
+ Handle<Object> inner_global = global_proxy->GetPrototype().As<Object>();
+ CompileRun(
+ "var records = [];"
+ "var global = this;"
+ "Object.observe(global, function(r) { [].push.apply(records, r) });"
+ "global.foo = 'hello';");
+ CHECK_EQ(1, CompileRun("records.length")->Int32Value());
+ CHECK(global_proxy->StrictEquals(CompileRun("records[0].object")));
+
+ // Detached, mutating the proxy has no effect.
+ context->DetachGlobal();
+ CompileRun("global.bar = 'goodbye';");
+ CHECK_EQ(1, CompileRun("records.length")->Int32Value());
+
+ // Mutating the global object directly still has an effect...
+ CompileRun("this.bar = 'goodbye';");
+ CHECK_EQ(2, CompileRun("records.length")->Int32Value());
+ CHECK(inner_global->StrictEquals(CompileRun("records[1].object")));
abarth-chromium 2012/11/26 22:53:08 So, records[1].object no longer points to the glob
+
+ // Reattached, back to global proxy.
+ context->ReattachGlobal(global_proxy);
+ CompileRun("global.baz = 'again';");
+ CHECK_EQ(3, CompileRun("records.length")->Int32Value());
+ CHECK(global_proxy->StrictEquals(CompileRun("records[2].object")));
abarth-chromium 2012/11/26 22:53:08 What would happen if you grabbed a reference to re
+
+ // Attached to a different context, should not leak mutations
+ // to the old context.
+ context->DetachGlobal();
+ {
+ LocalContext context2;
+ context2->DetachGlobal();
+ context2->ReattachGlobal(global_proxy);
rossberg 2012/12/03 13:26:18 Is this equivalent to calling Context::New with a
adamk 2012/12/03 19:23:20 Added an explicit test for that codepath as it's a
+ CompileRun(
+ "var records2 = [];"
+ "Object.observe(this, function(r) { [].push.apply(records2, r) });"
+ "this.bat = 'context2';");
+ CHECK_EQ(1, CompileRun("records2.length")->Int32Value());
+ CHECK(global_proxy->StrictEquals(CompileRun("records2[0].object")));
+ }
+ CHECK_EQ(3, CompileRun("records.length")->Int32Value());
+}
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698