OLD | NEW |
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 assertSame(isStrict ? null : global_object, receiver) | 99 assertSame(isStrict ? null : global_object, receiver) |
100 assertEquals(44, Function.prototype.call.call(f, 2, 21, 23)) | 100 assertEquals(44, Function.prototype.call.call(f, 2, 21, 23)) |
101 assertEquals(2, receiver.valueOf()) | 101 assertEquals(2, receiver.valueOf()) |
102 receiver = 333 | 102 receiver = 333 |
103 assertEquals(32, f.apply(o, [16, 16])) | 103 assertEquals(32, f.apply(o, [16, 16])) |
104 assertSame(o, receiver) | 104 assertSame(o, receiver) |
105 receiver = 333 | 105 receiver = 333 |
106 assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) | 106 assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) |
107 assertSame(o, receiver) | 107 assertSame(o, receiver) |
108 receiver = 333 | 108 receiver = 333 |
109 assertEquals(42, %Call(o, 11, 31, f)) | 109 assertEquals(42, %Call(f, o, 11, 31)); |
110 assertSame(o, receiver) | 110 assertSame(o, receiver) |
111 receiver = 333 | 111 receiver = 333 |
112 assertEquals(42, %Call(null, 11, 31, f)) | 112 assertEquals(42, %Call(f, null, 11, 31)); |
113 assertSame(isStrict ? null : global_object, receiver) | 113 assertSame(isStrict ? null : global_object, receiver) |
114 receiver = 333 | 114 receiver = 333 |
115 assertEquals(42, %Apply(f, o, [11, 31], 0, 2)) | 115 assertEquals(42, %Apply(f, o, [11, 31], 0, 2)) |
116 assertSame(o, receiver) | 116 assertSame(o, receiver) |
117 receiver = 333 | 117 receiver = 333 |
118 assertEquals(42, %Apply(f, null, [11, 31], 0, 2)) | 118 assertEquals(42, %Apply(f, null, [11, 31], 0, 2)) |
119 assertSame(isStrict ? null : global_object, receiver) | 119 assertSame(isStrict ? null : global_object, receiver) |
120 receiver = 333 | 120 receiver = 333 |
121 assertEquals(42, %_CallFunction(o, 11, 31, f)) | 121 assertEquals(42, %_CallFunction(o, 11, 31, f)) |
122 assertSame(o, receiver) | 122 assertSame(o, receiver) |
123 receiver = 333 | 123 receiver = 333 |
124 assertEquals(42, %_CallFunction(null, 11, 31, f)) | 124 assertEquals(42, %_CallFunction(null, 11, 31, f)) |
125 assertSame(isStrict ? null : global_object, receiver) | 125 assertSame(isStrict ? null : global_object, receiver) |
126 | 126 |
127 var ff = Function.prototype.bind.call(f, o, 12) | 127 var ff = Function.prototype.bind.call(f, o, 12) |
128 assertTrue(ff.length <= 1) // TODO(rossberg): Not spec'ed yet, be lax. | 128 assertTrue(ff.length <= 1) // TODO(rossberg): Not spec'ed yet, be lax. |
129 receiver = 333 | 129 receiver = 333 |
130 assertEquals(42, ff(30)) | 130 assertEquals(42, ff(30)) |
131 assertSame(o, receiver) | 131 assertSame(o, receiver) |
132 receiver = 333 | 132 receiver = 333 |
133 assertEquals(33, Function.prototype.call.call(ff, {}, 21)) | 133 assertEquals(33, Function.prototype.call.call(ff, {}, 21)) |
134 assertSame(o, receiver) | 134 assertSame(o, receiver) |
135 receiver = 333 | 135 receiver = 333 |
136 assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) | 136 assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) |
137 assertSame(o, receiver) | 137 assertSame(o, receiver) |
138 receiver = 333 | 138 receiver = 333 |
139 assertEquals(23, %Call({}, 11, ff)) | 139 assertEquals(23, %Call(ff, {}, 11)); |
140 assertSame(o, receiver) | 140 assertSame(o, receiver) |
141 receiver = 333 | 141 receiver = 333 |
142 assertEquals(23, %Call({}, 11, 3, ff)) | 142 assertEquals(23, %Call(ff, {}, 11, 3)); |
143 assertSame(o, receiver) | 143 assertSame(o, receiver) |
144 receiver = 333 | 144 receiver = 333 |
145 assertEquals(24, %Apply(ff, {}, [12, 13], 0, 1)) | 145 assertEquals(24, %Apply(ff, {}, [12, 13], 0, 1)) |
146 assertSame(o, receiver) | 146 assertSame(o, receiver) |
147 receiver = 333 | 147 receiver = 333 |
148 assertEquals(24, %Apply(ff, {}, [12, 13], 0, 2)) | 148 assertEquals(24, %Apply(ff, {}, [12, 13], 0, 2)) |
149 assertSame(o, receiver) | 149 assertSame(o, receiver) |
150 receiver = 333 | 150 receiver = 333 |
151 assertEquals(34, %_CallFunction({}, 22, ff)) | 151 assertEquals(34, %_CallFunction({}, 22, ff)) |
152 assertSame(o, receiver) | 152 assertSame(o, receiver) |
153 receiver = 333 | 153 receiver = 333 |
154 assertEquals(34, %_CallFunction({}, 22, 3, ff)) | 154 assertEquals(34, %_CallFunction({}, 22, 3, ff)) |
155 assertSame(o, receiver) | 155 assertSame(o, receiver) |
156 | 156 |
157 var fff = Function.prototype.bind.call(ff, o, 30) | 157 var fff = Function.prototype.bind.call(ff, o, 30) |
158 assertEquals(0, fff.length) | 158 assertEquals(0, fff.length) |
159 receiver = 333 | 159 receiver = 333 |
160 assertEquals(42, fff()) | 160 assertEquals(42, fff()) |
161 assertSame(o, receiver) | 161 assertSame(o, receiver) |
162 receiver = 333 | 162 receiver = 333 |
163 assertEquals(42, Function.prototype.call.call(fff, {})) | 163 assertEquals(42, Function.prototype.call.call(fff, {})) |
164 assertSame(o, receiver) | 164 assertSame(o, receiver) |
165 receiver = 333 | 165 receiver = 333 |
166 assertEquals(42, Function.prototype.apply.call(fff, {})) | 166 assertEquals(42, Function.prototype.apply.call(fff, {})) |
167 assertSame(o, receiver) | 167 assertSame(o, receiver) |
168 receiver = 333 | 168 receiver = 333 |
169 assertEquals(42, %Call({}, fff)) | 169 assertEquals(42, %Call(fff, {})); |
170 assertSame(o, receiver) | 170 assertSame(o, receiver) |
171 receiver = 333 | 171 receiver = 333 |
172 assertEquals(42, %Call({}, 11, 3, fff)) | 172 assertEquals(42, %Call(fff, {}, 11, 3)) |
173 assertSame(o, receiver) | 173 assertSame(o, receiver) |
174 receiver = 333 | 174 receiver = 333 |
175 assertEquals(42, %Apply(fff, {}, [], 0, 0)) | 175 assertEquals(42, %Apply(fff, {}, [], 0, 0)) |
176 assertSame(o, receiver) | 176 assertSame(o, receiver) |
177 receiver = 333 | 177 receiver = 333 |
178 assertEquals(42, %Apply(fff, {}, [12, 13], 0, 0)) | 178 assertEquals(42, %Apply(fff, {}, [12, 13], 0, 0)) |
179 assertSame(o, receiver) | 179 assertSame(o, receiver) |
180 receiver = 333 | 180 receiver = 333 |
181 assertEquals(42, %Apply(fff, {}, [12, 13], 0, 2)) | 181 assertEquals(42, %Apply(fff, {}, [12, 13], 0, 2)) |
182 assertSame(o, receiver) | 182 assertSame(o, receiver) |
(...skipping 21 matching lines...) Expand all Loading... |
204 receiver = 333 | 204 receiver = 333 |
205 assertEquals(42, (1, o)["f"](7, 35)) | 205 assertEquals(42, (1, o)["f"](7, 35)) |
206 assertSame(o, receiver) | 206 assertSame(o, receiver) |
207 receiver = 333 | 207 receiver = 333 |
208 assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) | 208 assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) |
209 assertSame(o, receiver) | 209 assertSame(o, receiver) |
210 receiver = 333 | 210 receiver = 333 |
211 assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) | 211 assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) |
212 assertSame(o, receiver) | 212 assertSame(o, receiver) |
213 receiver = 333 | 213 receiver = 333 |
214 assertEquals(23, %Call(o, 11, 12, f)) | 214 assertEquals(23, %Call(f, o, 11, 12)) |
215 assertSame(o, receiver) | 215 assertSame(o, receiver) |
216 receiver = 333 | 216 receiver = 333 |
217 assertEquals(27, %Apply(f, o, [12, 13, 14], 1, 2)) | 217 assertEquals(27, %Apply(f, o, [12, 13, 14], 1, 2)) |
218 assertSame(o, receiver) | 218 assertSame(o, receiver) |
219 receiver = 333 | 219 receiver = 333 |
220 assertEquals(42, %_CallFunction(o, 18, 24, f)) | 220 assertEquals(42, %_CallFunction(o, 18, 24, f)) |
221 assertSame(o, receiver) | 221 assertSame(o, receiver) |
222 } | 222 } |
223 | 223 |
224 TestCall(false, function(x, y) { | 224 TestCall(false, function(x, y) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 // Throwing from call trap. | 274 // Throwing from call trap. |
275 | 275 |
276 function TestCallThrow(callTrap) { | 276 function TestCallThrow(callTrap) { |
277 var f = Proxy.createFunction({}, callTrap) | 277 var f = Proxy.createFunction({}, callTrap) |
278 assertThrows(function(){ f(11) }, "myexn") | 278 assertThrows(function(){ f(11) }, "myexn") |
279 assertThrows(function(){ ({x: f}).x(11) }, "myexn") | 279 assertThrows(function(){ ({x: f}).x(11) }, "myexn") |
280 assertThrows(function(){ ({x: f})["x"](11) }, "myexn") | 280 assertThrows(function(){ ({x: f})["x"](11) }, "myexn") |
281 assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") | 281 assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") |
282 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") | 282 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") |
283 assertThrows(function(){ %Call({}, f) }, "myexn") | 283 assertThrows(function(){ %Call(f, {}) }, "myexn") |
284 assertThrows(function(){ %Call({}, 1, 2, f) }, "myexn") | 284 assertThrows(function(){ %Call(f, {}, 1, 2) }, "myexn") |
285 assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn") | 285 assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn") |
286 assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn") | 286 assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn") |
287 assertThrows(function(){ %_CallFunction({}, f) }, "myexn") | 287 assertThrows(function(){ %_CallFunction({}, f) }, "myexn") |
288 assertThrows(function(){ %_CallFunction({}, 1, 2, f) }, "myexn") | 288 assertThrows(function(){ %_CallFunction({}, 1, 2, f) }, "myexn") |
289 | 289 |
290 var f = CreateFrozen({}, callTrap) | 290 var f = CreateFrozen({}, callTrap) |
291 assertThrows(function(){ f(11) }, "myexn") | 291 assertThrows(function(){ f(11) }, "myexn") |
292 assertThrows(function(){ ({x: f}).x(11) }, "myexn") | 292 assertThrows(function(){ ({x: f}).x(11) }, "myexn") |
293 assertThrows(function(){ ({x: f})["x"](11) }, "myexn") | 293 assertThrows(function(){ ({x: f})["x"](11) }, "myexn") |
294 assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") | 294 assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") |
295 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") | 295 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") |
296 assertThrows(function(){ %Call({}, f) }, "myexn") | 296 assertThrows(function(){ %Call(f, {}) }, "myexn") |
297 assertThrows(function(){ %Call({}, 1, 2, f) }, "myexn") | 297 assertThrows(function(){ %Call(f, {}, 1, 2) }, "myexn") |
298 assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn") | 298 assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn") |
299 assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn") | 299 assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn") |
300 assertThrows(function(){ %_CallFunction({}, f) }, "myexn") | 300 assertThrows(function(){ %_CallFunction({}, f) }, "myexn") |
301 assertThrows(function(){ %_CallFunction({}, 1, 2, f) }, "myexn") | 301 assertThrows(function(){ %_CallFunction({}, 1, 2, f) }, "myexn") |
302 } | 302 } |
303 | 303 |
304 TestCallThrow(function() { throw "myexn" }) | 304 TestCallThrow(function() { throw "myexn" }) |
305 TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" })) | 305 TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" })) |
306 TestCallThrow(CreateFrozen({}, function() { throw "myexn" })) | 306 TestCallThrow(CreateFrozen({}, function() { throw "myexn" })) |
307 | 307 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 function(f, x, y) { return f(x, y) }, | 691 function(f, x, y) { return f(x, y) }, |
692 function(f, x, y) { var g = f; return g(x, y) }, | 692 function(f, x, y) { var g = f; return g(x, y) }, |
693 function(f, x, y) { with ({}) return f(x, y) }, | 693 function(f, x, y) { with ({}) return f(x, y) }, |
694 function(f, x, y) { var g = f; with ({}) return g(x, y) }, | 694 function(f, x, y) { var g = f; with ({}) return g(x, y) }, |
695 function(f, x, y, o) { with (o) return f(x, y) }, | 695 function(f, x, y, o) { with (o) return f(x, y) }, |
696 function(f, x, y, o) { return f.call(o, x, y) }, | 696 function(f, x, y, o) { return f.call(o, x, y) }, |
697 function(f, x, y, o) { return f.apply(o, [x, y]) }, | 697 function(f, x, y, o) { return f.apply(o, [x, y]) }, |
698 function(f, x, y, o) { return Function.prototype.call.call(f, o, x, y) }, | 698 function(f, x, y, o) { return Function.prototype.call.call(f, o, x, y) }, |
699 function(f, x, y, o) { return Function.prototype.apply.call(f, o, [x, y]) }, | 699 function(f, x, y, o) { return Function.prototype.apply.call(f, o, [x, y]) }, |
700 function(f, x, y, o) { return %_CallFunction(o, x, y, f) }, | 700 function(f, x, y, o) { return %_CallFunction(o, x, y, f) }, |
701 function(f, x, y, o) { return %Call(o, x, y, f) }, | 701 function(f, x, y, o) { return %Call(f, o, x, y) }, |
702 function(f, x, y, o) { return %Apply(f, o, [null, x, y, null], 1, 2) }, | 702 function(f, x, y, o) { return %Apply(f, o, [null, x, y, null], 1, 2) }, |
703 function(f, x, y, o) { return %Apply(f, o, arguments, 2, 2) }, | 703 function(f, x, y, o) { return %Apply(f, o, arguments, 2, 2) }, |
704 function(f, x, y, o) { if (typeof o == "object") return o.f(x, y) }, | 704 function(f, x, y, o) { if (typeof o == "object") return o.f(x, y) }, |
705 function(f, x, y, o) { if (typeof o == "object") return o["f"](x, y) }, | 705 function(f, x, y, o) { if (typeof o == "object") return o["f"](x, y) }, |
706 function(f, x, y, o) { if (typeof o == "object") return (1, o).f(x, y) }, | 706 function(f, x, y, o) { if (typeof o == "object") return (1, o).f(x, y) }, |
707 function(f, x, y, o) { if (typeof o == "object") return (1, o)["f"](x, y) }, | 707 function(f, x, y, o) { if (typeof o == "object") return (1, o)["f"](x, y) }, |
708 ] | 708 ] |
709 var receivers = [o, global_object, undefined, null, 2, "bla", true] | 709 var receivers = [o, global_object, undefined, null, 2, "bla", true] |
710 var expectedSloppies = [o, global_object, global_object, global_object] | 710 var expectedSloppies = [o, global_object, global_object, global_object] |
711 | 711 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 with (this) { | 765 with (this) { |
766 assertEquals(this, fp()); | 766 assertEquals(this, fp()); |
767 assertEquals(this, gp()); | 767 assertEquals(this, gp()); |
768 } | 768 } |
769 | 769 |
770 with ({}) { | 770 with ({}) { |
771 assertEquals(Realm.shared.fg, fp()); | 771 assertEquals(Realm.shared.fg, fp()); |
772 assertEquals(Realm.shared.gg, gp()); | 772 assertEquals(Realm.shared.gg, gp()); |
773 } | 773 } |
774 } | 774 } |
OLD | NEW |