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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // TODO(observe): oldValue should not be present below. | 326 // TODO(observe): oldValue should not be present below. |
327 { object: obj, name: "1", type: "deleted", oldValue: undefined }, | 327 { object: obj, name: "1", type: "deleted", oldValue: undefined }, |
328 { object: obj, name: "1", type: "new" }, | 328 { object: obj, name: "1", type: "new" }, |
329 // TODO(observe): oldValue should be absent below, and type = "reconfigured". | 329 // TODO(observe): oldValue should be absent below, and type = "reconfigured". |
330 { object: obj, name: "1", type: "updated", oldValue: undefined }, | 330 { object: obj, name: "1", type: "updated", oldValue: undefined }, |
331 { object: obj, name: "1", type: "updated", oldValue: 9 }, | 331 { object: obj, name: "1", type: "updated", oldValue: 9 }, |
332 { object: obj, name: "1", type: "deleted", oldValue: 10 }, | 332 { object: obj, name: "1", type: "deleted", oldValue: 10 }, |
333 { object: obj, name: "1", type: "new" }, | 333 { object: obj, name: "1", type: "new" }, |
334 ]); | 334 ]); |
335 | 335 |
| 336 // Observing array length (including truncation) |
| 337 reset(); |
| 338 var arr = ['a', 'b', 'c', 'd']; |
| 339 var arr2 = ['alpha', 'beta']; |
| 340 Object.defineProperty(arr, '0', {configurable: false}); |
| 341 Object.defineProperty(arr, '2', {get: function(){}}); |
| 342 Object.defineProperty(arr2, '0', {get: function(){}, configurable: false}); |
| 343 Object.observe(arr, observer.callback); |
| 344 Object.observe(arr2, observer.callback); |
| 345 arr.length = 2; |
| 346 arr.length = 0; |
| 347 arr.length = 10; |
| 348 arr2.length = 0; |
| 349 arr2.length = 1; // no change expected |
| 350 Object.deliverChangeRecords(observer.callback); |
| 351 observer.assertCallbackRecords([ |
| 352 { object: arr, name: '3', type: 'deleted', oldValue: 'd' }, |
| 353 // TODO(adamk): oldValue should not be present below |
| 354 { object: arr, name: '2', type: 'deleted', oldValue: undefined }, |
| 355 { object: arr, name: 'length', type: 'updated', oldValue: 4 }, |
| 356 { object: arr, name: '1', type: 'deleted', oldValue: 'b' }, |
| 357 { object: arr, name: 'length', type: 'updated', oldValue: 2 }, |
| 358 { object: arr, name: 'length', type: 'updated', oldValue: 1 }, |
| 359 { object: arr2, name: '1', type: 'deleted', oldValue: 'beta' }, |
| 360 { object: arr2, name: 'length', type: 'updated', oldValue: 2 }, |
| 361 ]); |
336 | 362 |
337 // Assignments in loops (checking different IC states). | 363 // Assignments in loops (checking different IC states). |
338 reset(); | 364 reset(); |
339 var obj = {}; | 365 var obj = {}; |
340 Object.observe(obj, observer.callback); | 366 Object.observe(obj, observer.callback); |
341 for (var i = 0; i < 5; i++) { | 367 for (var i = 0; i < 5; i++) { |
342 obj["a" + i] = i; | 368 obj["a" + i] = i; |
343 } | 369 } |
344 Object.deliverChangeRecords(observer.callback); | 370 Object.deliverChangeRecords(observer.callback); |
345 observer.assertCallbackRecords([ | 371 observer.assertCallbackRecords([ |
(...skipping 11 matching lines...) Expand all Loading... |
357 obj[i] = i; | 383 obj[i] = i; |
358 } | 384 } |
359 Object.deliverChangeRecords(observer.callback); | 385 Object.deliverChangeRecords(observer.callback); |
360 observer.assertCallbackRecords([ | 386 observer.assertCallbackRecords([ |
361 { object: obj, name: "0", type: "new" }, | 387 { object: obj, name: "0", type: "new" }, |
362 { object: obj, name: "1", type: "new" }, | 388 { object: obj, name: "1", type: "new" }, |
363 { object: obj, name: "2", type: "new" }, | 389 { object: obj, name: "2", type: "new" }, |
364 { object: obj, name: "3", type: "new" }, | 390 { object: obj, name: "3", type: "new" }, |
365 { object: obj, name: "4", type: "new" }, | 391 { object: obj, name: "4", type: "new" }, |
366 ]); | 392 ]); |
OLD | NEW |