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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 assertCalled: function() { | 49 assertCalled: function() { |
50 assertEquals(1, this.callbackCount); | 50 assertEquals(1, this.callbackCount); |
51 }, | 51 }, |
52 assertRecordCount: function(count) { | 52 assertRecordCount: function(count) { |
53 this.assertCalled(); | 53 this.assertCalled(); |
54 assertEquals(count, this.records.length); | 54 assertEquals(count, this.records.length); |
55 }, | 55 }, |
56 assertCallbackRecords: function(recs) { | 56 assertCallbackRecords: function(recs) { |
57 this.assertRecordCount(recs.length); | 57 this.assertRecordCount(recs.length); |
58 for (var i = 0; i < recs.length; i++) { | 58 for (var i = 0; i < recs.length; i++) { |
| 59 print(i, JSON.stringify(this.records[i]), JSON.stringify(recs[i])) |
59 assertSame(this.records[i].object, recs[i].object); | 60 assertSame(this.records[i].object, recs[i].object); |
60 assertEquals('string', typeof recs[i].type); | 61 assertEquals('string', typeof recs[i].type); |
61 assertPropertiesEqual(this.records[i], recs[i]); | 62 assertPropertiesEqual(this.records[i], recs[i]); |
62 } | 63 } |
63 } | 64 } |
64 }; | 65 }; |
65 | 66 |
66 observer.callback = function(r) { | 67 observer.callback = function(r) { |
67 assertEquals(undefined, this); | 68 assertEquals(undefined, this); |
68 assertEquals('object', typeof r); | 69 assertEquals('object', typeof r); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 delete obj[1]; | 314 delete obj[1]; |
314 obj[1] = 4; | 315 obj[1] = 4; |
315 obj[1] = 4; // ignored | 316 obj[1] = 4; // ignored |
316 obj[1] = 5; | 317 obj[1] = 5; |
317 Object.defineProperty(obj, "1", {value: 6}); | 318 Object.defineProperty(obj, "1", {value: 6}); |
318 Object.defineProperty(obj, "1", {writable: false}); | 319 Object.defineProperty(obj, "1", {writable: false}); |
319 obj[1] = 7; // ignored | 320 obj[1] = 7; // ignored |
320 Object.defineProperty(obj, "1", {value: 8}); | 321 Object.defineProperty(obj, "1", {value: 8}); |
321 Object.defineProperty(obj, "1", {value: 7, writable: true}); | 322 Object.defineProperty(obj, "1", {value: 7, writable: true}); |
322 Object.defineProperty(obj, "1", {get: function() {}}); | 323 Object.defineProperty(obj, "1", {get: function() {}}); |
| 324 Object.defineProperty(obj, "1", {get: function() {}}); |
323 delete obj[1]; | 325 delete obj[1]; |
324 delete obj[1]; | 326 delete obj[1]; |
325 Object.defineProperty(obj, "1", {get: function() {}, configurable: true}); | 327 Object.defineProperty(obj, "1", {get: function() {}, configurable: true}); |
326 Object.defineProperty(obj, "1", {value: 9, writable: true}); | 328 Object.defineProperty(obj, "1", {value: 9, writable: true}); |
327 obj[1] = 10; | 329 obj[1] = 10; |
328 delete obj[1]; | 330 delete obj[1]; |
329 Object.defineProperty(obj, "1", {value: 11, configurable: true}); | 331 Object.defineProperty(obj, "1", {value: 11, configurable: true}); |
330 Object.deliverChangeRecords(observer.callback); | 332 Object.deliverChangeRecords(observer.callback); |
331 observer.assertCallbackRecords([ | 333 observer.assertCallbackRecords([ |
332 { object: obj, name: "1", type: "updated", oldValue: 1 }, | 334 { object: obj, name: "1", type: "updated", oldValue: 1 }, |
333 { object: obj, name: "1", type: "updated", oldValue: 2 }, | 335 { object: obj, name: "1", type: "updated", oldValue: 2 }, |
334 { object: obj, name: "1", type: "deleted", oldValue: 3 }, | 336 { object: obj, name: "1", type: "deleted", oldValue: 3 }, |
335 { object: obj, name: "1", type: "new" }, | 337 { object: obj, name: "1", type: "new" }, |
336 { object: obj, name: "1", type: "updated", oldValue: 4 }, | 338 { object: obj, name: "1", type: "updated", oldValue: 4 }, |
337 { object: obj, name: "1", type: "updated", oldValue: 5 }, | 339 { object: obj, name: "1", type: "updated", oldValue: 5 }, |
338 { object: obj, name: "1", type: "reconfigured", oldValue: 6 }, | 340 { object: obj, name: "1", type: "reconfigured", oldValue: 6 }, |
339 { object: obj, name: "1", type: "updated", oldValue: 6 }, | 341 { object: obj, name: "1", type: "updated", oldValue: 6 }, |
340 { object: obj, name: "1", type: "reconfigured", oldValue: 8 }, | 342 { object: obj, name: "1", type: "reconfigured", oldValue: 8 }, |
341 { object: obj, name: "1", type: "reconfigured", oldValue: 7 }, | 343 { object: obj, name: "1", type: "reconfigured", oldValue: 7 }, |
342 // TODO(observe): oldValue should not be present below. | 344 { object: obj, name: "1", type: "reconfigured" }, |
343 { object: obj, name: "1", type: "deleted", oldValue: undefined }, | 345 { object: obj, name: "1", type: "deleted" }, |
344 { object: obj, name: "1", type: "new" }, | 346 { object: obj, name: "1", type: "new" }, |
345 // TODO(observe): oldValue should be absent below, and type = "reconfigured". | 347 { object: obj, name: "1", type: "reconfigured" }, |
346 { object: obj, name: "1", type: "updated", oldValue: undefined }, | |
347 { object: obj, name: "1", type: "updated", oldValue: 9 }, | 348 { object: obj, name: "1", type: "updated", oldValue: 9 }, |
348 { object: obj, name: "1", type: "deleted", oldValue: 10 }, | 349 { object: obj, name: "1", type: "deleted", oldValue: 10 }, |
349 { object: obj, name: "1", type: "new" }, | 350 { object: obj, name: "1", type: "new" }, |
350 ]); | 351 ]); |
351 | 352 |
352 // Observing array length (including truncation) | 353 // Observing array length (including truncation) |
353 reset(); | 354 reset(); |
354 var arr = ['a', 'b', 'c', 'd']; | 355 var arr = ['a', 'b', 'c', 'd']; |
355 var arr2 = ['alpha', 'beta']; | 356 var arr2 = ['alpha', 'beta']; |
356 var arr3 = ['hello']; | 357 var arr3 = ['hello']; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 var array = {0: 1, 1: 2, 2: 3, length: 3}; | 584 var array = {0: 1, 1: 2, 2: 3, length: 3}; |
584 Object.observe(array, observer.callback); | 585 Object.observe(array, observer.callback); |
585 Array.prototype.splice.call(array, 1, 1, 4, 5); | 586 Array.prototype.splice.call(array, 1, 1, 4, 5); |
586 Object.deliverChangeRecords(observer.callback); | 587 Object.deliverChangeRecords(observer.callback); |
587 observer.assertCallbackRecords([ | 588 observer.assertCallbackRecords([ |
588 { object: array, name: '3', type: 'new' }, | 589 { object: array, name: '3', type: 'new' }, |
589 { object: array, name: '1', type: 'updated', oldValue: 2 }, | 590 { object: array, name: '1', type: 'updated', oldValue: 2 }, |
590 { object: array, name: '2', type: 'updated', oldValue: 3 }, | 591 { object: array, name: '2', type: 'updated', oldValue: 3 }, |
591 { object: array, name: 'length', type: 'updated', oldValue: 3 }, | 592 { object: array, name: 'length', type: 'updated', oldValue: 3 }, |
592 ]); | 593 ]); |
OLD | NEW |