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 try { |
60 print(i, JSON.stringify(this.records[i]), JSON.stringify(recs[i])); | |
61 } catch (e) { } | |
rossberg
2012/11/21 12:43:17
Can you factor this out into a helper function tha
adamk
2012/11/21 17:02:57
Done.
| |
60 assertSame(this.records[i].object, recs[i].object); | 62 assertSame(this.records[i].object, recs[i].object); |
61 assertEquals('string', typeof recs[i].type); | 63 assertEquals('string', typeof recs[i].type); |
62 assertPropertiesEqual(this.records[i], recs[i]); | 64 assertPropertiesEqual(this.records[i], recs[i]); |
63 } | 65 } |
64 } | 66 } |
65 }; | 67 }; |
66 | 68 |
67 observer.callback = function(r) { | 69 observer.callback = function(r) { |
68 assertEquals(undefined, this); | 70 assertEquals(undefined, this); |
69 assertEquals('object', typeof r); | 71 assertEquals('object', typeof r); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 delete: function(k) { | 457 delete: function(k) { |
456 var x = delete this.target[k]; | 458 var x = delete this.target[k]; |
457 Object.deliverChangeRecords(this.callback); | 459 Object.deliverChangeRecords(this.callback); |
458 return x; | 460 return x; |
459 }, | 461 }, |
460 getPropertyNames: function() { | 462 getPropertyNames: function() { |
461 return Object.getOwnPropertyNames(this.target); | 463 return Object.getOwnPropertyNames(this.target); |
462 }, | 464 }, |
463 target: {isProxy: true}, | 465 target: {isProxy: true}, |
464 callback: function(changeRecords) { | 466 callback: function(changeRecords) { |
465 print("callback", JSON.stringify(handler.proxy), JSON.stringify(got)); | 467 try { |
468 print("callback", JSON.stringify(handler.proxy), JSON.stringify(got)); | |
469 } catch (e) { } | |
466 for (var i in changeRecords) { | 470 for (var i in changeRecords) { |
467 var got = changeRecords[i]; | 471 var got = changeRecords[i]; |
468 var change = {object: handler.proxy, name: got.name, type: got.type}; | 472 var change = {object: handler.proxy, name: got.name, type: got.type}; |
469 if ("oldValue" in got) change.oldValue = got.oldValue; | 473 if ("oldValue" in got) change.oldValue = got.oldValue; |
470 Object.getNotifier(handler.proxy).notify(change); | 474 Object.getNotifier(handler.proxy).notify(change); |
471 } | 475 } |
472 }, | 476 }, |
473 }; | 477 }; |
474 Object.observe(handler.target, handler.callback); | 478 Object.observe(handler.target, handler.callback); |
475 return handler.proxy = create(handler, x); | 479 return handler.proxy = create(handler, x); |
(...skipping 20 matching lines...) Expand all Loading... | |
496 // TODO(observe): ...or don't work yet. | 500 // TODO(observe): ...or don't work yet. |
497 function blacklisted(obj, prop) { | 501 function blacklisted(obj, prop) { |
498 return (obj instanceof Array && prop == 1) || | 502 return (obj instanceof Array && prop == 1) || |
499 (obj instanceof Int32Array && prop == 1) || | 503 (obj instanceof Int32Array && prop == 1) || |
500 (obj instanceof Int32Array && prop === "length") || | 504 (obj instanceof Int32Array && prop === "length") || |
501 // TODO(observe): oldValue when deleting/reconfiguring indexed accessor | 505 // TODO(observe): oldValue when deleting/reconfiguring indexed accessor |
502 prop == 1 || | 506 prop == 1 || |
503 // TODO(observe): oldValue when reconfiguring array length | 507 // TODO(observe): oldValue when reconfiguring array length |
504 (obj instanceof Array && prop === "length") || | 508 (obj instanceof Array && prop === "length") || |
505 // TODO(observe): prototype property on functions | 509 // TODO(observe): prototype property on functions |
506 (obj instanceof Function && prop === "prototype") || | 510 (obj instanceof Function && prop === "prototype") |
507 // TODO(observe): global object | |
508 obj === this; | |
509 } | 511 } |
510 | 512 |
511 for (var i in objects) for (var j in properties) { | 513 for (var i in objects) for (var j in properties) { |
512 var obj = objects[i]; | 514 var obj = objects[i]; |
513 var prop = properties[j]; | 515 var prop = properties[j]; |
514 if (blacklisted(obj, prop)) continue; | 516 if (blacklisted(obj, prop)) continue; |
515 var desc = Object.getOwnPropertyDescriptor(obj, prop); | 517 var desc = Object.getOwnPropertyDescriptor(obj, prop); |
516 print("***", typeof obj, JSON.stringify(obj), prop); | 518 try { print("***", typeof obj, JSON.stringify(obj), prop) } catch (e) { }; |
517 if (!desc || desc.configurable) | 519 if (!desc || desc.configurable) |
518 TestObserveConfigurable(obj, prop); | 520 TestObserveConfigurable(obj, prop); |
519 else if (desc.writable) | 521 else if (desc.writable) |
520 TestObserveNonConfigurable(obj, prop); | 522 TestObserveNonConfigurable(obj, prop); |
521 } | 523 } |
522 | 524 |
523 | 525 |
524 // Observing array length (including truncation) | 526 // Observing array length (including truncation) |
525 reset(); | 527 reset(); |
526 var arr = ['a', 'b', 'c', 'd']; | 528 var arr = ['a', 'b', 'c', 'd']; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 Object.observe(dummy, observer.callback); | 771 Object.observe(dummy, observer.callback); |
770 Object.unobserve(dummy, observer.callback); | 772 Object.unobserve(dummy, observer.callback); |
771 var array = [0]; | 773 var array = [0]; |
772 Object.observe(array, observer.callback); | 774 Object.observe(array, observer.callback); |
773 array.splice(0, 1); | 775 array.splice(0, 1); |
774 Object.deliverChangeRecords(observer.callback); | 776 Object.deliverChangeRecords(observer.callback); |
775 observer.assertCallbackRecords([ | 777 observer.assertCallbackRecords([ |
776 { object: array, name: '0', type: 'deleted', oldValue: 0 }, | 778 { object: array, name: '0', type: 'deleted', oldValue: 0 }, |
777 { object: array, name: 'length', type: 'updated', oldValue: 1}, | 779 { object: array, name: 'length', type: 'updated', oldValue: 1}, |
778 ]); | 780 ]); |
OLD | NEW |