OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 actual[1000000] = -1; | 75 actual[1000000] = -1; |
76 testArray(); | 76 testArray(); |
77 testArray(); | 77 testArray(); |
78 actual.__defineGetter__('0', function() { return expected[0]; }); | 78 actual.__defineGetter__('0', function() { return expected[0]; }); |
79 expected[0] = 42; | 79 expected[0] = 42; |
80 testArray(); | 80 testArray(); |
81 expected[0] = 111; | 81 expected[0] = 111; |
82 testArray(); | 82 testArray(); |
83 | 83 |
84 // The functionality is not implemented for arrays due to performance issues. | |
85 var a = [ 1 ]; | |
86 a.__defineGetter__('2', function() { return 7; }); | |
87 assertEquals(undefined, a[2]); | |
88 assertEquals(1, a.length); | |
89 var b = 0; | |
90 a.__defineSetter__('5', function(y) { b = y; }); | |
91 assertEquals(1, a.length); | |
92 a[5] = 42; | |
93 assertEquals(0, b); | |
94 assertEquals(42, a[5]); | |
95 assertEquals(6, a.length); | |
96 | |
97 // Using a setter where only a getter is defined throws an exception. | 84 // Using a setter where only a getter is defined throws an exception. |
98 var q = {}; | 85 var q = {}; |
99 q.__defineGetter__('0', function() { return 42; }); | 86 q.__defineGetter__('0', function() { return 42; }); |
100 assertThrows('q[0] = 7'); | 87 assertThrows('q[0] = 7'); |
101 | 88 |
102 // Using a getter where only a setter is defined returns undefined. | 89 // Using a getter where only a setter is defined returns undefined. |
103 var q1 = {}; | 90 var q1 = {}; |
104 q1.__defineSetter__('0', function() {q1.b = 17;}); | 91 q1.__defineSetter__('0', function() {q1.b = 17;}); |
105 assertEquals(q1[0], undefined); | 92 assertEquals(q1[0], undefined); |
106 // Setter works | 93 // Setter works |
107 q1[0] = 3; | 94 q1[0] = 3; |
108 assertEquals(q1[0], undefined); | 95 assertEquals(q1[0], undefined); |
109 assertEquals(q1.b, 17); | 96 assertEquals(q1.b, 17); |
110 | 97 |
111 // Complex case of using an undefined getter. | 98 // Complex case of using an undefined getter. |
112 // From http://code.google.com/p/v8/issues/detail?id=298 | 99 // From http://code.google.com/p/v8/issues/detail?id=298 |
113 // Reported by nth10sd. | 100 // Reported by nth10sd. |
114 | 101 |
115 a = function() {}; | 102 a = function() {}; |
116 __defineSetter__("0", function() {}); | 103 __defineSetter__("0", function() {}); |
117 if (a |= '') {}; | 104 if (a |= '') {}; |
118 assertThrows('this[a].__parent__'); | 105 assertThrows('this[a].__parent__'); |
119 assertEquals(a, 0); | 106 assertEquals(a, 0); |
120 assertEquals(this[a], undefined); | 107 assertEquals(this[a], undefined); |
OLD | NEW |