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

Side by Side Diff: test/cctest/test-object-observe.cc

Issue 11410046: Object.deliverChangeRecords should remove the observer from activeObservers (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rename activeObservers to pendingObservers 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/object-observe.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 CHECK_EQ(5, CompileRun("ordering.length")->Int32Value()); 159 CHECK_EQ(5, CompileRun("ordering.length")->Int32Value());
160 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); 160 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value());
161 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); 161 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value());
162 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); 162 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value());
163 // Note that we re-deliver to observers 1 and 2, while observer3 163 // Note that we re-deliver to observers 1 and 2, while observer3
164 // already received the second record during the first round. 164 // already received the second record during the first round.
165 CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value()); 165 CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value());
166 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); 166 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value());
167 } 167 }
168 168
169 TEST(DeliveryOrderingDeliverChangeRecords) {
170 HarmonyIsolate isolate;
171 HandleScope scope;
172 LocalContext context;
173 CompileRun(
174 "var obj = {};"
175 "var ordering = [];"
176 "function observer1() { ordering.push(1); if (!obj.b) obj.b = true };"
177 "function observer2() { ordering.push(2); };"
178 "Object.observe(obj, observer1);"
179 "Object.observe(obj, observer2);"
180 "obj.a = 1;"
181 "Object.deliverChangeRecords(observer2);");
182 CHECK_EQ(4, CompileRun("ordering.length")->Int32Value());
183 // First, observer2 is called due to deliverChangeRecords
184 CHECK_EQ(2, CompileRun("ordering[0]")->Int32Value());
185 // Then, observer1 is called when the stack unwinds
186 CHECK_EQ(1, CompileRun("ordering[1]")->Int32Value());
187 // observer1's mutation causes both 1 and 2 to be reactivated,
188 // with 1 having priority.
189 CHECK_EQ(1, CompileRun("ordering[2]")->Int32Value());
190 CHECK_EQ(2, CompileRun("ordering[3]")->Int32Value());
191 }
192
169 TEST(ObjectHashTableGrowth) { 193 TEST(ObjectHashTableGrowth) {
170 HarmonyIsolate isolate; 194 HarmonyIsolate isolate;
171 HandleScope scope; 195 HandleScope scope;
172 // Initializing this context sets up initial hash tables. 196 // Initializing this context sets up initial hash tables.
173 LocalContext context; 197 LocalContext context;
174 Handle<Value> obj = CompileRun("obj = {};"); 198 Handle<Value> obj = CompileRun("obj = {};");
175 Handle<Value> observer = CompileRun( 199 Handle<Value> observer = CompileRun(
176 "var ran = false;" 200 "var ran = false;"
177 "(function() { ran = true })"); 201 "(function() { ran = true })");
178 { 202 {
179 // As does initializing this context. 203 // As does initializing this context.
180 LocalContext context2; 204 LocalContext context2;
181 context2->Global()->Set(String::New("obj"), obj); 205 context2->Global()->Set(String::New("obj"), obj);
182 context2->Global()->Set(String::New("observer"), observer); 206 context2->Global()->Set(String::New("observer"), observer);
183 CompileRun( 207 CompileRun(
184 "var objArr = [];" 208 "var objArr = [];"
185 // 100 objects should be enough to make the hash table grow 209 // 100 objects should be enough to make the hash table grow
186 // (and thus relocate). 210 // (and thus relocate).
187 "for (var i = 0; i < 100; ++i) {" 211 "for (var i = 0; i < 100; ++i) {"
188 " objArr.push({});" 212 " objArr.push({});"
189 " Object.observe(objArr[objArr.length-1], function(){});" 213 " Object.observe(objArr[objArr.length-1], function(){});"
190 "}" 214 "}"
191 "Object.observe(obj, observer);"); 215 "Object.observe(obj, observer);");
192 } 216 }
193 // obj is now marked "is_observed", but our map has moved. 217 // obj is now marked "is_observed", but our map has moved.
194 CompileRun("obj.foo = 'bar'"); 218 CompileRun("obj.foo = 'bar'");
195 CHECK(CompileRun("ran")->BooleanValue()); 219 CHECK(CompileRun("ran")->BooleanValue());
196 } 220 }
OLDNEW
« no previous file with comments | « src/object-observe.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698