OLD | NEW |
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 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 assertEquals(3, array[2]); | 1226 assertEquals(3, array[2]); |
1227 Object.deliverChangeRecords(observer.callback); | 1227 Object.deliverChangeRecords(observer.callback); |
1228 observer.assertCallbackRecords([ | 1228 observer.assertCallbackRecords([ |
1229 { object: array, name: '1', type: 'updated', oldValue: 2 }, | 1229 { object: array, name: '1', type: 'updated', oldValue: 2 }, |
1230 { object: array, name: '0', type: 'updated', oldValue: 3 }, | 1230 { object: array, name: '0', type: 'updated', oldValue: 3 }, |
1231 { object: array, name: '2', type: 'updated', oldValue: 1 }, | 1231 { object: array, name: '2', type: 'updated', oldValue: 1 }, |
1232 { object: array, name: '1', type: 'updated', oldValue: 3 }, | 1232 { object: array, name: '1', type: 'updated', oldValue: 3 }, |
1233 { object: array, name: '0', type: 'updated', oldValue: 2 }, | 1233 { object: array, name: '0', type: 'updated', oldValue: 2 }, |
1234 ]); | 1234 ]); |
1235 | 1235 |
| 1236 // Splice emitted after Array mutation methods |
| 1237 function MockArray(initial, observer) { |
| 1238 for (var i = 0; i < initial.length; i++) |
| 1239 this[i] = initial[i]; |
| 1240 |
| 1241 this.length_ = initial.length; |
| 1242 this.observer = observer; |
| 1243 } |
| 1244 MockArray.prototype = { |
| 1245 set length(length) { |
| 1246 Object.getNotifier(this).notify({ type: 'lengthChange' }); |
| 1247 this.length_ = length; |
| 1248 Object.observe(this, this.observer.callback, ['splice']); |
| 1249 }, |
| 1250 get length() { |
| 1251 return this.length_; |
| 1252 } |
| 1253 } |
| 1254 |
| 1255 reset(); |
| 1256 var array = new MockArray([], observer); |
| 1257 Object.observe(array, observer.callback, ['lengthChange']); |
| 1258 Array.prototype.push.call(array, 1); |
| 1259 Object.deliverChangeRecords(observer.callback); |
| 1260 observer.assertCallbackRecords([ |
| 1261 { object: array, type: 'lengthChange' }, |
| 1262 { object: array, type: 'splice', index: 0, removed: [], addedCount: 1 }, |
| 1263 ]); |
| 1264 |
| 1265 reset(); |
| 1266 var array = new MockArray([1], observer); |
| 1267 Object.observe(array, observer.callback, ['lengthChange']); |
| 1268 Array.prototype.pop.call(array); |
| 1269 Object.deliverChangeRecords(observer.callback); |
| 1270 observer.assertCallbackRecords([ |
| 1271 { object: array, type: 'lengthChange' }, |
| 1272 { object: array, type: 'splice', index: 0, removed: [1], addedCount: 0 }, |
| 1273 ]); |
| 1274 |
| 1275 reset(); |
| 1276 var array = new MockArray([1], observer); |
| 1277 Object.observe(array, observer.callback, ['lengthChange']); |
| 1278 Array.prototype.shift.call(array); |
| 1279 Object.deliverChangeRecords(observer.callback); |
| 1280 observer.assertCallbackRecords([ |
| 1281 { object: array, type: 'lengthChange' }, |
| 1282 { object: array, type: 'splice', index: 0, removed: [1], addedCount: 0 }, |
| 1283 ]); |
| 1284 |
| 1285 reset(); |
| 1286 var array = new MockArray([], observer); |
| 1287 Object.observe(array, observer.callback, ['lengthChange']); |
| 1288 Array.prototype.unshift.call(array, 1); |
| 1289 Object.deliverChangeRecords(observer.callback); |
| 1290 observer.assertCallbackRecords([ |
| 1291 { object: array, type: 'lengthChange' }, |
| 1292 { object: array, type: 'splice', index: 0, removed: [], addedCount: 1 }, |
| 1293 ]); |
| 1294 |
| 1295 reset(); |
| 1296 var array = new MockArray([0, 1, 2], observer); |
| 1297 Object.observe(array, observer.callback, ['lengthChange']); |
| 1298 Array.prototype.splice.call(array, 1, 1); |
| 1299 Object.deliverChangeRecords(observer.callback); |
| 1300 observer.assertCallbackRecords([ |
| 1301 { object: array, type: 'lengthChange' }, |
| 1302 { object: array, type: 'splice', index: 1, removed: [1], addedCount: 0 }, |
| 1303 ]); |
| 1304 |
1236 // | 1305 // |
1237 // === PLAIN OBJECTS === | 1306 // === PLAIN OBJECTS === |
1238 // | 1307 // |
1239 // Push | 1308 // Push |
1240 reset() | 1309 reset() |
1241 var array = {0: 1, 1: 2, length: 2} | 1310 var array = {0: 1, 1: 2, length: 2} |
1242 Object.observe(array, observer.callback); | 1311 Object.observe(array, observer.callback); |
1243 Array.prototype.push.call(array, 3, 4); | 1312 Array.prototype.push.call(array, 3, 4); |
1244 Object.deliverChangeRecords(observer.callback); | 1313 Object.deliverChangeRecords(observer.callback); |
1245 observer.assertCallbackRecords([ | 1314 observer.assertCallbackRecords([ |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 for (var n1 = 0; n1 < 3; ++n1) | 1594 for (var n1 = 0; n1 < 3; ++n1) |
1526 for (var n2 = 0; n2 < 3; ++n2) | 1595 for (var n2 = 0; n2 < 3; ++n2) |
1527 for (var i in mutation) | 1596 for (var i in mutation) |
1528 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 1597 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); |
1529 | 1598 |
1530 for (var b1 = 0; b1 < 2; ++b1) | 1599 for (var b1 = 0; b1 < 2; ++b1) |
1531 for (var b2 = 0; b2 < 2; ++b2) | 1600 for (var b2 = 0; b2 < 2; ++b2) |
1532 for (var n = 0; n < 3; ++n) | 1601 for (var n = 0; n < 3; ++n) |
1533 for (var i in mutationByIncr) | 1602 for (var i in mutationByIncr) |
1534 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 1603 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); |
OLD | NEW |