OLD | NEW |
---|---|
1 // Flags: --harmony-proxies | 1 // Flags: --harmony-proxies |
2 | 2 |
3 // Copyright 2008 the V8 project authors. All rights reserved. | 3 // Copyright 2008 the V8 project authors. All rights reserved. |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 }) | 142 }) |
143 | 143 |
144 TestSet(Proxy.create({ | 144 TestSet(Proxy.create({ |
145 get: function(pr, pk) { | 145 get: function(pr, pk) { |
146 return function(r, k, v) { key = k; val = v; return true } | 146 return function(r, k, v) { key = k; val = v; return true } |
147 } | 147 } |
148 })) | 148 })) |
149 | 149 |
150 | 150 |
151 | 151 |
152 // Property definition (Object.defineProperty). | |
153 | |
154 var key | |
155 var desc | |
156 function TestDefine(handler) { | |
157 var o = Proxy.create(handler) | |
158 assertEquals(o, Object.defineProperty(o, "a", {value: 44})) | |
159 assertEquals("a", key) | |
160 assertEquals(1, Object.getOwnPropertyNames(desc).length) | |
161 assertEquals(44, desc.value) | |
162 | |
163 assertEquals(o, Object.defineProperty(o, "b", {value: 45, writable: false})) | |
164 assertEquals("b", key) | |
165 assertEquals(2, Object.getOwnPropertyNames(desc).length) | |
166 assertEquals(45, desc.value) | |
167 assertEquals(false, desc.writable) | |
168 | |
169 assertEquals(o, Object.defineProperty(o, "c", {value: 46, enumerable: false})) | |
170 assertEquals("c", key) | |
171 assertEquals(2, Object.getOwnPropertyNames(desc).length) | |
172 assertEquals(46, desc.value) | |
173 assertEquals(false, desc.enumerable) | |
174 | |
175 var attributes = {configurable: true, mine: 66, minetoo: 23} | |
176 assertEquals(o, Object.defineProperty(o, "d", attributes)) | |
177 assertEquals("d", key) | |
178 // Modifying the attributes object after the fact should have no effect. | |
179 attributes.configurable = false | |
180 attributes.mine = 77 | |
181 delete attributes.midetoo | |
Kevin Millikin (Chromium)
2011/07/07 08:12:02
midetoo => minetoo
rossberg
2011/07/07 09:19:32
Done.
| |
182 assertEquals(3, Object.getOwnPropertyNames(desc).length) | |
183 assertEquals(true, desc.configurable) | |
184 assertEquals(66, desc.mine) | |
185 assertEquals(23, desc.minetoo) | |
186 | |
187 assertEquals(o, Object.defineProperty(o, "e", {get: function(){ return 5 }})) | |
188 assertEquals("e", key) | |
189 assertEquals(1, Object.getOwnPropertyNames(desc).length) | |
190 assertEquals(5, desc.get()) | |
191 | |
192 assertEquals(o, Object.defineProperty(o, "zzz", {})) | |
193 assertEquals("zzz", key) | |
194 assertEquals(0, Object.getOwnPropertyNames(desc).length) | |
195 | |
196 // This test requires [s in proxy] to be implemented first. | |
197 // var d = Proxy.create({ | |
198 // get: function(r, k) { return (k === "value") ? 77 : void 0 }, | |
199 // getOwnPropertyNames: function() { return ["value"] } | |
200 // }) | |
201 // assertEquals(1, Object.getOwnPropertyNames(d).length) | |
202 // assertEquals(77, d.value) | |
203 // assertEquals(o, Object.defineProperty(o, "p", d)) | |
204 // assertEquals("p", key) | |
205 // assertEquals(1, Object.getOwnPropertyNames(desc).length) | |
206 // assertEquals(77, desc.value) | |
207 } | |
208 | |
209 TestDefine({ | |
210 defineProperty: function(k, d) { key = k; desc = d; return true } | |
211 }) | |
212 TestDefine({ | |
213 defineProperty: function(k, d) { return this.defineProperty2(k, d) }, | |
214 defineProperty2: function(k, d) { key = k; desc = d; return true } | |
215 }) | |
216 TestDefine(Proxy.create({ | |
217 get: function(pr, pk) { | |
218 return function(k, d) { key = k; desc = d; return true } | |
219 } | |
220 })) | |
221 | |
222 | |
223 | |
152 // Comparison. | 224 // Comparison. |
153 | 225 |
154 function TestComparison(eq) { | 226 function TestComparison(eq) { |
155 var o1 = Proxy.create({}) | 227 var o1 = Proxy.create({}) |
156 var o2 = Proxy.create({}) | 228 var o2 = Proxy.create({}) |
157 | 229 |
158 assertTrue(eq(o1, o1)) | 230 assertTrue(eq(o1, o1)) |
159 assertTrue(eq(o2, o2)) | 231 assertTrue(eq(o2, o2)) |
160 assertTrue(!eq(o1, o2)) | 232 assertTrue(!eq(o1, o2)) |
161 assertTrue(!eq(o1, {})) | 233 assertTrue(!eq(o1, {})) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 }) | 324 }) |
253 TestPropertyNames(["throw", "function "], { | 325 TestPropertyNames(["throw", "function "], { |
254 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 326 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, |
255 getOwnPropertyNames2: function() { return ["throw", "function "] } | 327 getOwnPropertyNames2: function() { return ["throw", "function "] } |
256 }) | 328 }) |
257 TestPropertyNames(["[object Object]"], { | 329 TestPropertyNames(["[object Object]"], { |
258 get getOwnPropertyNames() { | 330 get getOwnPropertyNames() { |
259 return function() { return [{}] } | 331 return function() { return [{}] } |
260 } | 332 } |
261 }) | 333 }) |
OLD | NEW |