Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: test/mjsunit/harmony/proxies-function.js

Issue 8404030: Version 3.7.1 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/harmony/proxies-for.js ('k') | test/mjsunit/harmony/proxies-hash.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 20 matching lines...) Expand all
31 // Helper. 31 // Helper.
32 32
33 function CreateFrozen(handler, callTrap, constructTrap) { 33 function CreateFrozen(handler, callTrap, constructTrap) {
34 if (handler.fix === undefined) handler.fix = function() { return {} } 34 if (handler.fix === undefined) handler.fix = function() { return {} }
35 var f = Proxy.createFunction(handler, callTrap, constructTrap) 35 var f = Proxy.createFunction(handler, callTrap, constructTrap)
36 Object.freeze(f) 36 Object.freeze(f)
37 return f 37 return f
38 } 38 }
39 39
40 40
41 // Ensures that checking the "length" property of a function proxy doesn't
42 // crash due to lack of a [[Get]] method.
43 var handler = {
44 get : function(r, n) { return n == "length" ? 2 : undefined }
45 }
46
47
41 // Calling (call, Function.prototype.call, Function.prototype.apply, 48 // Calling (call, Function.prototype.call, Function.prototype.apply,
42 // Function.prototype.bind). 49 // Function.prototype.bind).
43 50
44 var global_object = this 51 var global_object = this
45 var receiver 52 var receiver
46 53
47 function TestCall(isStrict, callTrap) { 54 function TestCall(isStrict, callTrap) {
48 assertEquals(42, callTrap(5, 37)) 55 assertEquals(42, callTrap(5, 37))
49 // TODO(rossberg): unrelated bug: this does not succeed for optimized code: 56 assertEquals(isStrict ? undefined : global_object, receiver)
50 // assertEquals(isStrict ? undefined : global_object, receiver)
51 57
52 var f = Proxy.createFunction({}, callTrap) 58 var handler = {
59 get: function(r, k) {
60 return k == "length" ? 2 : Function.prototype[k]
61 }
62 }
63 var f = Proxy.createFunction(handler, callTrap)
64
53 receiver = 333 65 receiver = 333
54 assertEquals(42, f(11, 31)) 66 assertEquals(42, f(11, 31))
55 assertEquals(isStrict ? undefined : global_object, receiver) 67 assertEquals(isStrict ? undefined : global_object, receiver)
56 var o = {} 68 var o = {f: f}
69 receiver = 333
70 assertEquals(42, o.f(10, 32))
71 assertSame(o, receiver)
72 receiver = 333
73 assertEquals(42, o["f"](9, 33))
74 assertSame(o, receiver)
75 receiver = 333
76 assertEquals(42, (1, o).f(8, 34))
77 assertSame(o, receiver)
78 receiver = 333
79 assertEquals(42, (1, o)["f"](7, 35))
80 assertSame(o, receiver)
81 receiver = 333
82 assertEquals(42, f.call(o, 32, 10))
83 assertSame(o, receiver)
84 receiver = 333
85 assertEquals(42, f.call(null, 33, 9))
86 assertSame(isStrict ? null : global_object, receiver)
87 receiver = 333
88 assertEquals(44, f.call(2, 21, 23))
89 assertSame(2, receiver.valueOf())
90 receiver = 333
57 assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) 91 assertEquals(42, Function.prototype.call.call(f, o, 20, 22))
58 assertEquals(o, receiver) 92 assertSame(o, receiver)
93 receiver = 333
59 assertEquals(43, Function.prototype.call.call(f, null, 20, 23)) 94 assertEquals(43, Function.prototype.call.call(f, null, 20, 23))
60 assertEquals(isStrict ? null : global_object, receiver) 95 assertSame(isStrict ? null : global_object, receiver)
61 assertEquals(44, Function.prototype.call.call(f, 2, 21, 23)) 96 assertEquals(44, Function.prototype.call.call(f, 2, 21, 23))
62 assertEquals(2, receiver.valueOf()) 97 assertEquals(2, receiver.valueOf())
63 receiver = 333 98 receiver = 333
99 assertEquals(32, f.apply(o, [16, 16]))
100 assertSame(o, receiver)
101 receiver = 333
64 assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) 102 assertEquals(32, Function.prototype.apply.call(f, o, [17, 15]))
65 assertEquals(o, receiver) 103 assertSame(o, receiver)
104
66 var ff = Function.prototype.bind.call(f, o, 12) 105 var ff = Function.prototype.bind.call(f, o, 12)
106 assertTrue(ff.length <= 1) // TODO(rossberg): Not spec'ed yet, be lax.
67 receiver = 333 107 receiver = 333
68 assertEquals(42, ff(30)) 108 assertEquals(42, ff(30))
69 assertEquals(o, receiver) 109 assertSame(o, receiver)
70 receiver = 333 110 receiver = 333
71 assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) 111 assertEquals(32, Function.prototype.apply.call(ff, {}, [20]))
72 assertEquals(o, receiver) 112 assertSame(o, receiver)
113
114 var fff = Function.prototype.bind.call(ff, o, 30)
115 assertEquals(0, fff.length)
116 receiver = 333
117 assertEquals(42, fff())
118 assertSame(o, receiver)
119 receiver = 333
120 assertEquals(42, Function.prototype.call.call(fff, {}))
121 assertSame(o, receiver)
73 122
74 var f = CreateFrozen({}, callTrap) 123 var f = CreateFrozen({}, callTrap)
75 receiver = 333 124 receiver = 333
76 assertEquals(42, f(11, 31)) 125 assertEquals(42, f(11, 31))
77 // TODO(rossberg): unrelated bug: this does not succeed for optimized code. 126 assertSame(isStrict ? undefined : global_object, receiver)
78 // assertEquals(isStrict ? undefined : global, receiver) 127 var o = {f: f}
128 receiver = 333
129 assertEquals(42, o.f(10, 32))
130 assertSame(o, receiver)
131 receiver = 333
132 assertEquals(42, o["f"](9, 33))
133 assertSame(o, receiver)
134 receiver = 333
135 assertEquals(42, (1, o).f(8, 34))
136 assertSame(o, receiver)
137 receiver = 333
138 assertEquals(42, (1, o)["f"](7, 35))
139 assertSame(o, receiver)
79 receiver = 333 140 receiver = 333
80 assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) 141 assertEquals(42, Function.prototype.call.call(f, o, 20, 22))
81 assertEquals(o, receiver) 142 assertSame(o, receiver)
82 receiver = 333 143 receiver = 333
83 assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) 144 assertEquals(32, Function.prototype.apply.call(f, o, [17, 15]))
84 assertEquals(o, receiver) 145 assertSame(o, receiver)
85 receiver = 333 146 receiver = 333
86 assertEquals(42, ff(30)) 147 assertEquals(42, ff(30))
87 assertEquals(o, receiver) 148 assertSame(o, receiver)
88 receiver = 333 149 receiver = 333
89 assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) 150 assertEquals(32, Function.prototype.apply.call(ff, {}, [20]))
90 assertEquals(o, receiver) 151 assertSame(o, receiver)
91 } 152 }
92 153
93 TestCall(false, function(x, y) { 154 TestCall(false, function(x, y) {
94 receiver = this; return x + y 155 receiver = this
156 return x + y
95 }) 157 })
96 158
97 TestCall(true, function(x, y) { 159 TestCall(true, function(x, y) {
98 "use strict"; 160 "use strict"
99 receiver = this; return x + y 161 receiver = this
162 return x + y
100 }) 163 })
101 164
102 TestCall(false, Proxy.createFunction({}, function(x, y) { 165 TestCall(false, function() {
103 receiver = this; return x + y 166 receiver = this; return arguments[0] + arguments[1]
167 })
168
169 TestCall(false, Proxy.createFunction(handler, function(x, y) {
170 receiver = this
171 return x + y
104 })) 172 }))
105 173
106 TestCall(true, Proxy.createFunction({}, function(x, y) { 174 TestCall(true, Proxy.createFunction(handler, function(x, y) {
107 "use strict"; 175 "use strict"
108 receiver = this; return x + y 176 receiver = this
177 return x + y
109 })) 178 }))
110 179
111 TestCall(false, CreateFrozen({}, function(x, y) { 180 TestCall(false, CreateFrozen(handler, function(x, y) {
112 receiver = this; return x + y 181 receiver = this
182 return x + y
113 })) 183 }))
114 184
115 185
186
187 // Using intrinsics as call traps.
188
189 function TestCallIntrinsic(type, callTrap) {
190 var f = Proxy.createFunction({}, callTrap)
191 var x = f()
192 assertTrue(typeof x == type)
193 }
194
195 TestCallIntrinsic("boolean", Boolean)
196 TestCallIntrinsic("number", Number)
197 TestCallIntrinsic("string", String)
198 TestCallIntrinsic("object", Object)
199 TestCallIntrinsic("function", Function)
200
201
202
203 // Throwing from call trap.
204
116 function TestCallThrow(callTrap) { 205 function TestCallThrow(callTrap) {
117 var f = Proxy.createFunction({}, callTrap) 206 var f = Proxy.createFunction({}, callTrap)
118 assertThrows(function(){ f(11) }, "myexn") 207 assertThrows(function(){ f(11) }, "myexn")
208 assertThrows(function(){ ({x: f}).x(11) }, "myexn")
209 assertThrows(function(){ ({x: f})["x"](11) }, "myexn")
119 assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") 210 assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn")
120 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") 211 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn")
121 212
122 var f = CreateFrozen({}, callTrap) 213 var f = CreateFrozen({}, callTrap)
123 assertThrows(function(){ f(11) }, "myexn") 214 assertThrows(function(){ f(11) }, "myexn")
215 assertThrows(function(){ ({x: f}).x(11) }, "myexn")
216 assertThrows(function(){ ({x: f})["x"](11) }, "myexn")
124 assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") 217 assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn")
125 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") 218 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn")
126 } 219 }
127 220
128 TestCallThrow(function() { throw "myexn" }) 221 TestCallThrow(function() { throw "myexn" })
129 TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" })) 222 TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" }))
130 TestCallThrow(CreateFrozen({}, function() { throw "myexn" })) 223 TestCallThrow(CreateFrozen({}, function() { throw "myexn" }))
131 224
132 225
133 226
134 // Construction (new). 227 // Construction (new).
135 228
136 var prototype = {} 229 var prototype = {}
137 var receiver 230 var receiver
138 231
139 var handlerWithPrototype = { 232 var handlerWithPrototype = {
140 fix: function() { return {prototype: prototype} }, 233 fix: function() { return { prototype: { value: prototype } }; },
141 get: function(r, n) { assertEquals("prototype", n); return prototype } 234 get: function(r, n) {
235 if (n == "length") return 2;
236 assertEquals("prototype", n);
237 return prototype;
238 }
142 } 239 }
143 240
144 var handlerSansPrototype = { 241 var handlerSansPrototype = {
145 fix: function() { return {} }, 242 fix: function() { return { length: { value: 2 } } },
146 get: function(r, n) { assertEquals("prototype", n); return undefined } 243 get: function(r, n) {
244 if (n == "length") return 2;
245 assertEquals("prototype", n);
246 return undefined;
247 }
147 } 248 }
148 249
149 function ReturnUndef(x, y) { "use strict"; receiver = this; this.sum = x + y } 250 function ReturnUndef(x, y) {
150 function ReturnThis(x, y) { "use strict"; receiver = this; this.sum = x + y; ret urn this } 251 "use strict";
151 function ReturnNew(x, y) { "use strict"; receiver = this; return {sum: x + y} } 252 receiver = this;
253 this.sum = x + y;
254 }
255
256 function ReturnThis(x, y) {
257 "use strict";
258 receiver = this;
259 this.sum = x + y;
260 return this;
261 }
262
263 function ReturnNew(x, y) {
264 "use strict";
265 receiver = this;
266 return {sum: x + y};
267 }
268
152 function ReturnNewWithProto(x, y) { 269 function ReturnNewWithProto(x, y) {
153 "use strict"; 270 "use strict";
154 receiver = this; 271 receiver = this;
155 var result = Object.create(prototype) 272 var result = Object.create(prototype);
156 result.sum = x + y 273 result.sum = x + y;
157 return result 274 return result;
158 } 275 }
159 276
160 function TestConstruct(proto, constructTrap) { 277 function TestConstruct(proto, constructTrap) {
161 TestConstruct2(proto, constructTrap, handlerWithPrototype) 278 TestConstruct2(proto, constructTrap, handlerWithPrototype)
162 TestConstruct2(proto, constructTrap, handlerSansPrototype) 279 TestConstruct2(proto, constructTrap, handlerSansPrototype)
163 } 280 }
164 281
165 function TestConstruct2(proto, constructTrap, handler) { 282 function TestConstruct2(proto, constructTrap, handler) {
166 var f = Proxy.createFunction(handler, function() {}, constructTrap) 283 var f = Proxy.createFunction(handler, function() {}, constructTrap)
167 var o = new f(11, 31) 284 var o = new f(11, 31)
168 // TODO(rossberg): doesn't hold, due to unrelated bug. 285 assertEquals(undefined, receiver)
169 // assertEquals(undefined, receiver)
170 assertEquals(42, o.sum) 286 assertEquals(42, o.sum)
171 assertSame(proto, Object.getPrototypeOf(o)) 287 assertSame(proto, Object.getPrototypeOf(o))
172 288
173 var f = CreateFrozen(handler, function() {}, constructTrap) 289 var f = CreateFrozen(handler, function() {}, constructTrap)
174 var o = new f(11, 32) 290 var o = new f(11, 32)
175 // TODO(rossberg): doesn't hold, due to unrelated bug. 291 assertEquals(undefined, receiver)
176 // assertEquals(undefined, receiver)
177 assertEquals(43, o.sum) 292 assertEquals(43, o.sum)
178 assertSame(proto, Object.getPrototypeOf(o)) 293 assertSame(proto, Object.getPrototypeOf(o))
179 } 294 }
180 295
181 TestConstruct(Object.prototype, ReturnNew) 296 TestConstruct(Object.prototype, ReturnNew)
182 TestConstruct(prototype, ReturnNewWithProto) 297 TestConstruct(prototype, ReturnNewWithProto)
183 298
184 TestConstruct(Object.prototype, Proxy.createFunction({}, ReturnNew)) 299 TestConstruct(Object.prototype, Proxy.createFunction(handler, ReturnNew))
185 TestConstruct(prototype, Proxy.createFunction({}, ReturnNewWithProto)) 300 TestConstruct(prototype, Proxy.createFunction(handler, ReturnNewWithProto))
186 301
187 TestConstruct(Object.prototype, CreateFrozen({}, ReturnNew)) 302 TestConstruct(Object.prototype, CreateFrozen(handler, ReturnNew))
188 TestConstruct(prototype, CreateFrozen({}, ReturnNewWithProto)) 303 TestConstruct(prototype, CreateFrozen(handler, ReturnNewWithProto))
189 304
190 305
306
307 // Construction with derived construct trap.
308
191 function TestConstructFromCall(proto, returnsThis, callTrap) { 309 function TestConstructFromCall(proto, returnsThis, callTrap) {
192 TestConstructFromCall2(proto, returnsThis, callTrap, handlerWithPrototype) 310 TestConstructFromCall2(proto, returnsThis, callTrap, handlerWithPrototype)
193 TestConstructFromCall2(proto, returnsThis, callTrap, handlerSansPrototype) 311 TestConstructFromCall2(proto, returnsThis, callTrap, handlerSansPrototype)
194 } 312 }
195 313
196 function TestConstructFromCall2(proto, returnsThis, callTrap, handler) { 314 function TestConstructFromCall2(proto, returnsThis, callTrap, handler) {
197 var f = Proxy.createFunction(handler, callTrap) 315 var f = Proxy.createFunction(handler, callTrap)
198 var o = new f(11, 31) 316 var o = new f(11, 31)
199 if (returnsThis) assertEquals(o, receiver) 317 if (returnsThis) assertEquals(o, receiver)
200 assertEquals(42, o.sum) 318 assertEquals(42, o.sum)
201 assertSame(proto, Object.getPrototypeOf(o)) 319 assertSame(proto, Object.getPrototypeOf(o))
202 320
203 var f = CreateFrozen(handler, callTrap) 321 var f = CreateFrozen(handler, callTrap)
204 var o = new f(11, 32) 322 var o = new f(11, 32)
205 if (returnsThis) assertEquals(o, receiver) 323 if (returnsThis) assertEquals(o, receiver)
206 assertEquals(43, o.sum) 324 assertEquals(43, o.sum)
207 assertSame(proto, Object.getPrototypeOf(o)) 325 assertSame(proto, Object.getPrototypeOf(o))
208 } 326 }
209 327
210 TestConstructFromCall(Object.prototype, true, ReturnUndef) 328 TestConstructFromCall(Object.prototype, true, ReturnUndef)
211 TestConstructFromCall(Object.prototype, true, ReturnThis) 329 TestConstructFromCall(Object.prototype, true, ReturnThis)
212 TestConstructFromCall(Object.prototype, false, ReturnNew) 330 TestConstructFromCall(Object.prototype, false, ReturnNew)
213 TestConstructFromCall(prototype, false, ReturnNewWithProto) 331 TestConstructFromCall(prototype, false, ReturnNewWithProto)
214 332
215 TestConstructFromCall(Object.prototype, true, Proxy.createFunction({}, ReturnUnd ef)) 333 TestConstructFromCall(Object.prototype, true,
216 TestConstructFromCall(Object.prototype, true, Proxy.createFunction({}, ReturnThi s)) 334 Proxy.createFunction(handler, ReturnUndef))
217 TestConstructFromCall(Object.prototype, false, Proxy.createFunction({}, ReturnNe w)) 335 TestConstructFromCall(Object.prototype, true,
218 TestConstructFromCall(prototype, false, Proxy.createFunction({}, ReturnNewWithPr oto)) 336 Proxy.createFunction(handler, ReturnThis))
337 TestConstructFromCall(Object.prototype, false,
338 Proxy.createFunction(handler, ReturnNew))
339 TestConstructFromCall(prototype, false,
340 Proxy.createFunction(handler, ReturnNewWithProto))
219 341
220 TestConstructFromCall(Object.prototype, true, CreateFrozen({}, ReturnUndef)) 342 TestConstructFromCall(Object.prototype, true, CreateFrozen({}, ReturnUndef))
221 TestConstructFromCall(Object.prototype, true, CreateFrozen({}, ReturnThis)) 343 TestConstructFromCall(Object.prototype, true, CreateFrozen({}, ReturnThis))
222 TestConstructFromCall(Object.prototype, false, CreateFrozen({}, ReturnNew)) 344 TestConstructFromCall(Object.prototype, false, CreateFrozen({}, ReturnNew))
223 TestConstructFromCall(prototype, false, CreateFrozen({}, ReturnNewWithProto)) 345 TestConstructFromCall(prototype, false, CreateFrozen({}, ReturnNewWithProto))
224 346
225 ReturnUndef.prototype = prototype 347 ReturnUndef.prototype = prototype
226 ReturnThis.prototype = prototype 348 ReturnThis.prototype = prototype
227 ReturnNew.prototype = prototype 349 ReturnNew.prototype = prototype
228 ReturnNewWithProto.prototype = prototype 350 ReturnNewWithProto.prototype = prototype
229 351
230 TestConstructFromCall(prototype, true, ReturnUndef) 352 TestConstructFromCall(prototype, true, ReturnUndef)
231 TestConstructFromCall(prototype, true, ReturnThis) 353 TestConstructFromCall(prototype, true, ReturnThis)
232 TestConstructFromCall(Object.prototype, false, ReturnNew) 354 TestConstructFromCall(Object.prototype, false, ReturnNew)
233 TestConstructFromCall(prototype, false, ReturnNewWithProto) 355 TestConstructFromCall(prototype, false, ReturnNewWithProto)
234 356
235 TestConstructFromCall(Object.prototype, true, Proxy.createFunction({}, ReturnUnd ef)) 357 TestConstructFromCall(Object.prototype, true,
236 TestConstructFromCall(Object.prototype, true, Proxy.createFunction({}, ReturnThi s)) 358 Proxy.createFunction(handler, ReturnUndef))
237 TestConstructFromCall(Object.prototype, false, Proxy.createFunction({}, ReturnNe w)) 359 TestConstructFromCall(Object.prototype, true,
238 TestConstructFromCall(prototype, false, Proxy.createFunction({}, ReturnNewWithPr oto)) 360 Proxy.createFunction(handler, ReturnThis))
361 TestConstructFromCall(Object.prototype, false,
362 Proxy.createFunction(handler, ReturnNew))
363 TestConstructFromCall(prototype, false,
364 Proxy.createFunction(handler, ReturnNewWithProto))
239 365
240 TestConstructFromCall(prototype, true, Proxy.createFunction(handlerWithPrototype , ReturnUndef)) 366 TestConstructFromCall(prototype, true,
241 TestConstructFromCall(prototype, true, Proxy.createFunction(handlerWithPrototype , ReturnThis)) 367 Proxy.createFunction(handlerWithPrototype, ReturnUndef))
242 TestConstructFromCall(Object.prototype, false, Proxy.createFunction(handlerWithP rototype, ReturnNew)) 368 TestConstructFromCall(prototype, true,
243 TestConstructFromCall(prototype, false, Proxy.createFunction(handlerWithPrototyp e, ReturnNewWithProto)) 369 Proxy.createFunction(handlerWithPrototype, ReturnThis))
370 TestConstructFromCall(Object.prototype, false,
371 Proxy.createFunction(handlerWithPrototype, ReturnNew))
372 TestConstructFromCall(prototype, false,
373 Proxy.createFunction(handlerWithPrototype,
374 ReturnNewWithProto))
244 375
245 TestConstructFromCall(prototype, true, CreateFrozen(handlerWithPrototype, Return Undef)) 376 TestConstructFromCall(prototype, true,
246 TestConstructFromCall(prototype, true, CreateFrozen(handlerWithPrototype, Return This)) 377 CreateFrozen(handlerWithPrototype, ReturnUndef))
247 TestConstructFromCall(Object.prototype, false, CreateFrozen(handlerWithPrototype , ReturnNew)) 378 TestConstructFromCall(prototype, true,
248 TestConstructFromCall(prototype, false, CreateFrozen(handlerWithPrototype, Retur nNewWithProto)) 379 CreateFrozen(handlerWithPrototype, ReturnThis))
380 TestConstructFromCall(Object.prototype, false,
381 CreateFrozen(handlerWithPrototype, ReturnNew))
382 TestConstructFromCall(prototype, false,
383 CreateFrozen(handlerWithPrototype, ReturnNewWithProto))
249 384
250 385
386
387 // Throwing from the construct trap.
388
251 function TestConstructThrow(trap) { 389 function TestConstructThrow(trap) {
252 TestConstructThrow2(Proxy.createFunction({fix: function() {return {}}}, trap)) 390 TestConstructThrow2(Proxy.createFunction({ fix: function() {return {};} },
253 TestConstructThrow2(Proxy.createFunction({fix: function() {return {}}}, 391 trap))
254 function() {}, trap)) 392 TestConstructThrow2(Proxy.createFunction({ fix: function() {return {};} },
393 function() {},
394 trap))
255 } 395 }
256 396
257 function TestConstructThrow2(f) { 397 function TestConstructThrow2(f) {
258 assertThrows(function(){ new f(11) }, "myexn") 398 assertThrows(function(){ new f(11) }, "myexn")
259 Object.freeze(f) 399 Object.freeze(f)
260 assertThrows(function(){ new f(11) }, "myexn") 400 assertThrows(function(){ new f(11) }, "myexn")
261 } 401 }
262 402
263 TestConstructThrow(function() { throw "myexn" }) 403 TestConstructThrow(function() { throw "myexn" })
264 TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" })) 404 TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" }))
265 TestConstructThrow(CreateFrozen({}, function() { throw "myexn" })) 405 TestConstructThrow(CreateFrozen({}, function() { throw "myexn" }))
266 406
267 407
268 408
269 // Getters and setters. 409 // Using function proxies as getters and setters.
270 410
271 var value 411 var value
272 var receiver 412 var receiver
273 413
274 function TestAccessorCall(getterCallTrap, setterCallTrap) { 414 function TestAccessorCall(getterCallTrap, setterCallTrap) {
275 var handler = {fix: function() { return {} }} 415 var handler = { fix: function() { return {} } }
276 var pgetter = Proxy.createFunction(handler, getterCallTrap) 416 var pgetter = Proxy.createFunction(handler, getterCallTrap)
277 var psetter = Proxy.createFunction(handler, setterCallTrap) 417 var psetter = Proxy.createFunction(handler, setterCallTrap)
278 418
279 var o = {} 419 var o = {}
280 var oo = Object.create(o) 420 var oo = Object.create(o)
281 Object.defineProperty(o, "a", {get: pgetter, set: psetter}) 421 Object.defineProperty(o, "a", {get: pgetter, set: psetter})
282 Object.defineProperty(o, "b", {get: pgetter}) 422 Object.defineProperty(o, "b", {get: pgetter})
283 Object.defineProperty(o, "c", {set: psetter}) 423 Object.defineProperty(o, "c", {set: psetter})
284 Object.defineProperty(o, "3", {get: pgetter, set: psetter}) 424 Object.defineProperty(o, "3", {get: pgetter, set: psetter})
285 Object.defineProperty(oo, "a", {value: 43}) 425 Object.defineProperty(oo, "a", {value: 43})
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 513
374 TestAccessorCall( 514 TestAccessorCall(
375 Proxy.createFunction({}, function() { receiver = this; return 42 }), 515 Proxy.createFunction({}, function() { receiver = this; return 42 }),
376 Proxy.createFunction({}, function(x) { receiver = this; value = x }) 516 Proxy.createFunction({}, function(x) { receiver = this; value = x })
377 ) 517 )
378 518
379 TestAccessorCall( 519 TestAccessorCall(
380 CreateFrozen({}, function() { receiver = this; return 42 }), 520 CreateFrozen({}, function() { receiver = this; return 42 }),
381 CreateFrozen({}, function(x) { receiver = this; value = x }) 521 CreateFrozen({}, function(x) { receiver = this; value = x })
382 ) 522 )
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/proxies-for.js ('k') | test/mjsunit/harmony/proxies-hash.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698