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

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

Issue 11598014: Object.observe: test mutating an object via the API (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« test/cctest/test-api.cc ('K') | « test/cctest/test-api.cc ('k') | 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 25e5557a89913d9b5c2895d06e6e69d885d7cec0..4b65293fcb2639ac887f1218b1fb88bbaadf61be 100644
--- a/test/cctest/test-object-observe.cc
+++ b/test/cctest/test-object-observe.cc
@@ -278,3 +278,50 @@ TEST(GlobalObjectObservation) {
}
CHECK_EQ(3, CompileRun("records.length")->Int32Value());
}
+
+TEST(APITestBasicMutation) {
+ HarmonyIsolate isolate;
+ HandleScope scope;
+ LocalContext context;
+ Handle<Object> obj = Handle<Object>::Cast(CompileRun(
+ "var records = [];"
+ "var obj = {};"
+ "function observer(r) { [].push.apply(records, r); };"
+ "Object.observe(obj, observer);"
+ "obj"));
+ obj->Set(String::New("foo"), Number::New(1));
+ obj->Set(1, Number::New(2));
+ // ForceSet should work just as well as Set
+ obj->ForceSet(String::New("foo"), Number::New(3));
+ obj->ForceSet(Number::New(1), Number::New(4));
+ // Setting an indexed element via the property setting method
+ obj->Set(Number::New(1), Number::New(5));
+ // Setting with a non-String, non-uint32 key
+ obj->Set(Number::New(1.1), Number::New(6), DontDelete);
+ obj->Delete(String::New("foo"));
+ obj->Delete(1);
+ obj->ForceDelete(Number::New(1.1));
+
+ // Force delivery
+ // TODO(adamk): Should the above set methods trigger delivery themselves?
+ CompileRun("void 0");
+ CHECK_EQ(9, CompileRun("records.length")->Int32Value());
+ ExpectString("records[0].type", "new");
rossberg 2012/12/18 13:35:58 Can you check object and oldValue as well? Perhaps
adamk 2012/12/18 17:26:10 Added a helper. Will do a cleanup in a future chan
+ ExpectString("records[0].name", "foo");
+ ExpectString("records[1].type", "new");
+ ExpectString("records[1].name", "1");
+ ExpectString("records[2].type", "updated");
+ ExpectString("records[2].name", "foo");
+ ExpectString("records[3].type", "updated");
+ ExpectString("records[3].name", "1");
+ ExpectString("records[4].type", "updated");
+ ExpectString("records[4].name", "1");
+ ExpectString("records[5].type", "new");
+ ExpectString("records[5].name", "1.1");
+ ExpectString("records[6].type", "deleted");
+ ExpectString("records[6].name", "foo");
+ ExpectString("records[7].type", "deleted");
+ ExpectString("records[7].name", "1");
+ ExpectString("records[8].type", "deleted");
+ ExpectString("records[8].name", "1.1");
+}
« test/cctest/test-api.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698