OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-reflect | 5 // Flags: --harmony-reflect --harmony-simd |
6 | 6 |
7 | 7 |
8 (function testReflectApplyArity() { | 8 (function testReflectApplyArity() { |
9 assertEquals(3, Reflect.apply.length); | 9 assertEquals(3, Reflect.apply.length); |
10 })(); | 10 })(); |
11 | 11 |
12 | 12 |
13 (function testReflectApplyNonConstructor() { | 13 (function testReflectApplyNonConstructor() { |
14 assertThrows(function() { | 14 assertThrows(function() { |
15 new Reflect.apply(function(){}, null, []); | 15 new Reflect.apply(function(){}, null, []); |
(...skipping 13 matching lines...) Loading... |
29 // Wrap JS values | 29 // Wrap JS values |
30 assertSame(String.prototype, | 30 assertSame(String.prototype, |
31 Object.getPrototypeOf(Reflect.apply(returnThis, "str", []))); | 31 Object.getPrototypeOf(Reflect.apply(returnThis, "str", []))); |
32 assertSame(Number.prototype, | 32 assertSame(Number.prototype, |
33 Object.getPrototypeOf(Reflect.apply(returnThis, 123, []))); | 33 Object.getPrototypeOf(Reflect.apply(returnThis, 123, []))); |
34 assertSame(Boolean.prototype, | 34 assertSame(Boolean.prototype, |
35 Object.getPrototypeOf(Reflect.apply(returnThis, true, []))); | 35 Object.getPrototypeOf(Reflect.apply(returnThis, true, []))); |
36 assertSame(Symbol.prototype, | 36 assertSame(Symbol.prototype, |
37 Object.getPrototypeOf( | 37 Object.getPrototypeOf( |
38 Reflect.apply(returnThis, Symbol("test"), []))); | 38 Reflect.apply(returnThis, Symbol("test"), []))); |
| 39 assertSame(SIMD.float32x4.prototype, |
| 40 Object.getPrototypeOf( |
| 41 Reflect.apply(returnThis, SIMD.float32x4(1, 2, 3, 4), []))); |
39 })(); | 42 })(); |
40 | 43 |
41 | 44 |
42 (function testAppliedReceiverStrict() { | 45 (function testAppliedReceiverStrict() { |
43 function returnThis() { 'use strict'; return this; } | 46 function returnThis() { 'use strict'; return this; } |
44 var receiver = {}; | 47 var receiver = {}; |
45 | 48 |
46 assertSame(void 0, Reflect.apply(returnThis, void 0, [])); | 49 assertSame(void 0, Reflect.apply(returnThis, void 0, [])); |
47 assertSame(this, Reflect.apply(returnThis, this, [])); | 50 assertSame(this, Reflect.apply(returnThis, this, [])); |
48 assertSame(receiver, Reflect.apply(returnThis, receiver, [])); | 51 assertSame(receiver, Reflect.apply(returnThis, receiver, [])); |
49 | 52 |
50 // Don't wrap value types | 53 // Don't wrap value types |
51 var regexp = /123/; | 54 var regexp = /123/; |
52 var symbol = Symbol("test"); | 55 var symbol = Symbol("test"); |
| 56 var float32x4 = SIMD.float32x4(1, 2, 3, 4); |
53 assertSame("str", Reflect.apply(returnThis, "str", [])); | 57 assertSame("str", Reflect.apply(returnThis, "str", [])); |
54 assertSame(123, Reflect.apply(returnThis, 123, [])); | 58 assertSame(123, Reflect.apply(returnThis, 123, [])); |
55 assertSame(true, Reflect.apply(returnThis, true, [])); | 59 assertSame(true, Reflect.apply(returnThis, true, [])); |
56 assertSame(regexp, Reflect.apply(returnThis, regexp, [])); | 60 assertSame(regexp, Reflect.apply(returnThis, regexp, [])); |
57 assertSame(symbol, Reflect.apply(returnThis, symbol, [])); | 61 assertSame(symbol, Reflect.apply(returnThis, symbol, [])); |
| 62 assertSame(float32x4, Reflect.apply(returnThis, float32x4, [])); |
58 })(); | 63 })(); |
59 | 64 |
60 | 65 |
61 (function testAppliedArgumentsLength() { | 66 (function testAppliedArgumentsLength() { |
62 function returnLengthStrict() { 'use strict'; return arguments.length; } | 67 function returnLengthStrict() { 'use strict'; return arguments.length; } |
63 function returnLengthSloppy() { return arguments.length; } | 68 function returnLengthSloppy() { return arguments.length; } |
64 | 69 |
65 assertEquals(0, Reflect.apply(returnLengthStrict, this, [])); | 70 assertEquals(0, Reflect.apply(returnLengthStrict, this, [])); |
66 assertEquals(0, Reflect.apply(returnLengthSloppy, this, [])); | 71 assertEquals(0, Reflect.apply(returnLengthSloppy, this, [])); |
67 assertEquals(0, Reflect.apply(returnLengthStrict, this, {})); | 72 assertEquals(0, Reflect.apply(returnLengthStrict, this, {})); |
(...skipping 48 matching lines...) Loading... |
116 })(); | 121 })(); |
117 | 122 |
118 | 123 |
119 (function testAppliedNonFunctionStrict() { | 124 (function testAppliedNonFunctionStrict() { |
120 'use strict'; | 125 'use strict'; |
121 assertThrows(function() { Reflect.apply(void 0); }, TypeError); | 126 assertThrows(function() { Reflect.apply(void 0); }, TypeError); |
122 assertThrows(function() { Reflect.apply(null); }, TypeError); | 127 assertThrows(function() { Reflect.apply(null); }, TypeError); |
123 assertThrows(function() { Reflect.apply(123); }, TypeError); | 128 assertThrows(function() { Reflect.apply(123); }, TypeError); |
124 assertThrows(function() { Reflect.apply("str"); }, TypeError); | 129 assertThrows(function() { Reflect.apply("str"); }, TypeError); |
125 assertThrows(function() { Reflect.apply(Symbol("x")); }, TypeError); | 130 assertThrows(function() { Reflect.apply(Symbol("x")); }, TypeError); |
| 131 assertThrows( |
| 132 function() { Reflect.apply(SIMD.float32x4(1, 2, 3, 4)); }, TypeError); |
126 assertThrows(function() { Reflect.apply(/123/); }, TypeError); | 133 assertThrows(function() { Reflect.apply(/123/); }, TypeError); |
127 assertThrows(function() { Reflect.apply(NaN); }, TypeError); | 134 assertThrows(function() { Reflect.apply(NaN); }, TypeError); |
128 assertThrows(function() { Reflect.apply({}); }, TypeError); | 135 assertThrows(function() { Reflect.apply({}); }, TypeError); |
129 assertThrows(function() { Reflect.apply([]); }, TypeError); | 136 assertThrows(function() { Reflect.apply([]); }, TypeError); |
130 })(); | 137 })(); |
131 | 138 |
132 | 139 |
133 (function testAppliedNonFunctionSloppy() { | 140 (function testAppliedNonFunctionSloppy() { |
134 assertThrows(function() { Reflect.apply(void 0); }, TypeError); | 141 assertThrows(function() { Reflect.apply(void 0); }, TypeError); |
135 assertThrows(function() { Reflect.apply(null); }, TypeError); | 142 assertThrows(function() { Reflect.apply(null); }, TypeError); |
136 assertThrows(function() { Reflect.apply(123); }, TypeError); | 143 assertThrows(function() { Reflect.apply(123); }, TypeError); |
137 assertThrows(function() { Reflect.apply("str"); }, TypeError); | 144 assertThrows(function() { Reflect.apply("str"); }, TypeError); |
138 assertThrows(function() { Reflect.apply(Symbol("x")); }, TypeError); | 145 assertThrows(function() { Reflect.apply(Symbol("x")); }, TypeError); |
| 146 assertThrows( |
| 147 function() { Reflect.apply(SIMD.float32x4(1, 2, 3, 4)); }, TypeError); |
139 assertThrows(function() { Reflect.apply(/123/); }, TypeError); | 148 assertThrows(function() { Reflect.apply(/123/); }, TypeError); |
140 assertThrows(function() { Reflect.apply(NaN); }, TypeError); | 149 assertThrows(function() { Reflect.apply(NaN); }, TypeError); |
141 assertThrows(function() { Reflect.apply({}); }, TypeError); | 150 assertThrows(function() { Reflect.apply({}); }, TypeError); |
142 assertThrows(function() { Reflect.apply([]); }, TypeError); | 151 assertThrows(function() { Reflect.apply([]); }, TypeError); |
143 })(); | 152 })(); |
144 | 153 |
145 | 154 |
146 (function testAppliedArgumentsNonList() { | 155 (function testAppliedArgumentsNonList() { |
147 function noopStrict() { 'use strict'; } | 156 function noopStrict() { 'use strict'; } |
148 function noopSloppy() {} | 157 function noopSloppy() {} |
149 var R = void 0; | 158 var R = void 0; |
150 assertThrows(function() { Reflect.apply(noopStrict, R, null); }, TypeError); | 159 assertThrows(function() { Reflect.apply(noopStrict, R, null); }, TypeError); |
151 assertThrows(function() { Reflect.apply(noopSloppy, R, null); }, TypeError); | 160 assertThrows(function() { Reflect.apply(noopSloppy, R, null); }, TypeError); |
152 assertThrows(function() { Reflect.apply(noopStrict, R, 1); }, TypeError); | 161 assertThrows(function() { Reflect.apply(noopStrict, R, 1); }, TypeError); |
153 assertThrows(function() { Reflect.apply(noopSloppy, R, 1); }, TypeError); | 162 assertThrows(function() { Reflect.apply(noopSloppy, R, 1); }, TypeError); |
154 assertThrows(function() { Reflect.apply(noopStrict, R, "BAD"); }, TypeError); | 163 assertThrows(function() { Reflect.apply(noopStrict, R, "BAD"); }, TypeError); |
155 assertThrows(function() { Reflect.apply(noopSloppy, R, "BAD"); }, TypeError); | 164 assertThrows(function() { Reflect.apply(noopSloppy, R, "BAD"); }, TypeError); |
156 assertThrows(function() { Reflect.apply(noopStrict, R, true); }, TypeError); | 165 assertThrows(function() { Reflect.apply(noopStrict, R, true); }, TypeError); |
157 assertThrows(function() { Reflect.apply(noopSloppy, R, true); }, TypeError); | 166 assertThrows(function() { Reflect.apply(noopSloppy, R, true); }, TypeError); |
158 var sym = Symbol("x"); | 167 var sym = Symbol("x"); |
159 assertThrows(function() { Reflect.apply(noopStrict, R, sym); }, TypeError); | 168 assertThrows(function() { Reflect.apply(noopStrict, R, sym); }, TypeError); |
160 assertThrows(function() { Reflect.apply(noopSloppy, R, sym); }, TypeError); | 169 assertThrows(function() { Reflect.apply(noopSloppy, R, sym); }, TypeError); |
| 170 var float32x4 = SIMD.float32x4(1, 2, 3, 4); |
| 171 assertThrows( |
| 172 function() { Reflect.apply(noopStrict, R, float32x4); }, TypeError); |
| 173 assertThrows( |
| 174 function() { Reflect.apply(noopSloppy, R, float32x4); }, TypeError); |
161 })(); | 175 })(); |
162 | 176 |
163 | 177 |
164 (function testAppliedArgumentValue() { | 178 (function testAppliedArgumentValue() { |
165 function returnFirstStrict(a) { 'use strict'; return a; } | 179 function returnFirstStrict(a) { 'use strict'; return a; } |
166 function returnFirstSloppy(a) { return a; } | 180 function returnFirstSloppy(a) { return a; } |
167 function returnLastStrict(a) { | 181 function returnLastStrict(a) { |
168 'use strict'; return arguments[arguments.length - 1]; } | 182 'use strict'; return arguments[arguments.length - 1]; } |
169 function returnLastSloppy(a) { return arguments[arguments.length - 1]; } | 183 function returnLastSloppy(a) { return arguments[arguments.length - 1]; } |
170 function returnSumStrict() { | 184 function returnSumStrict() { |
(...skipping 32 matching lines...) Loading... |
203 ["T", "E", "S", "T", "!", "!"])); | 217 ["T", "E", "S", "T", "!", "!"])); |
204 assertEquals(10, Reflect.apply(returnSumStrict, this, | 218 assertEquals(10, Reflect.apply(returnSumStrict, this, |
205 { 0: 1, 1: 2, 2: 3, 3: 4, length: 4 })); | 219 { 0: 1, 1: 2, 2: 3, 3: 4, length: 4 })); |
206 assertEquals("TEST", Reflect.apply(returnSumSloppy, this, | 220 assertEquals("TEST", Reflect.apply(returnSumSloppy, this, |
207 ["T", "E", "S", "T"])); | 221 ["T", "E", "S", "T"])); |
208 assertEquals("TEST!!", Reflect.apply(returnSumSloppy, this, | 222 assertEquals("TEST!!", Reflect.apply(returnSumSloppy, this, |
209 ["T", "E", "S", "T", "!", "!"])); | 223 ["T", "E", "S", "T", "!", "!"])); |
210 assertEquals(10, Reflect.apply(returnSumSloppy, this, | 224 assertEquals(10, Reflect.apply(returnSumSloppy, this, |
211 { 0: 1, 1: 2, 2: 3, 3: 4, length: 4 })); | 225 { 0: 1, 1: 2, 2: 3, 3: 4, length: 4 })); |
212 })(); | 226 })(); |
OLD | NEW |