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-arrow-functions | 5 // Flags: --harmony-arrow-functions |
6 | 6 |
7 // Arrow functions are like functions, except they throw when using the | 7 // Arrow functions are like functions, except they throw when using the |
8 // "new" operator on them. | 8 // "new" operator on them. |
9 assertEquals("function", typeof (() => {})); | 9 assertEquals("function", typeof (() => {})); |
10 assertEquals(Function.prototype, Object.getPrototypeOf(() => {})); | 10 assertEquals(Function.prototype, Object.getPrototypeOf(() => {})); |
11 assertThrows("new (() => {})", TypeError); | 11 assertThrows(function() { new (() => {}); }, TypeError); |
| 12 assertFalse("prototype" in (() => {})); |
12 | 13 |
13 // Check the different syntax variations | 14 // Check the different syntax variations |
14 assertEquals(1, (() => 1)()); | 15 assertEquals(1, (() => 1)()); |
15 assertEquals(2, (a => a + 1)(1)); | 16 assertEquals(2, (a => a + 1)(1)); |
16 assertEquals(3, (() => { return 3; })()); | 17 assertEquals(3, (() => { return 3; })()); |
17 assertEquals(4, (a => { return a + 3; })(1)); | 18 assertEquals(4, (a => { return a + 3; })(1)); |
18 assertEquals(5, ((a, b) => a + b)(1, 4)); | 19 assertEquals(5, ((a, b) => a + b)(1, 4)); |
19 assertEquals(6, ((a, b) => { return a + b; })(1, 5)); | 20 assertEquals(6, ((a, b) => { return a + b; })(1, 5)); |
20 | 21 |
21 // The following are tests from: | 22 // The following are tests from: |
(...skipping 17 matching lines...) Expand all Loading... |
39 | 40 |
40 // Statement body needs braces, must use 'return' explicitly if not void | 41 // Statement body needs braces, must use 'return' explicitly if not void |
41 var evens = [0, 2, 4, 6, 8]; | 42 var evens = [0, 2, 4, 6, 8]; |
42 assertEquals([1, 3, 5, 7, 9], evens.map(v => v + 1)); | 43 assertEquals([1, 3, 5, 7, 9], evens.map(v => v + 1)); |
43 | 44 |
44 var fives = []; | 45 var fives = []; |
45 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].forEach(v => { | 46 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].forEach(v => { |
46 if (v % 5 === 0) fives.push(v); | 47 if (v % 5 === 0) fives.push(v); |
47 }); | 48 }); |
48 assertEquals([5, 10], fives); | 49 assertEquals([5, 10], fives); |
OLD | NEW |