Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
|
wingo
2015/08/31 13:07:31
IIRC we don't update these lines; Adam?
caitp (gmail)
2015/08/31 13:23:40
This isn't really an update, it's a new file
| |
| 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-rest-parameters --harmony-arrow-functions | 5 // Flags: --harmony-rest-parameters --harmony-arrow-functions |
| 6 // Flags: --min-preparse-length=0 | |
| 6 | 7 |
| 7 (function testRestIndex() { | 8 (function testRestIndex() { |
| 8 assertEquals(5, ((...args) => args.length)(1,2,3,4,5)); | 9 assertEquals(5, ((...args) => args.length)(1,2,3,4,5)); |
| 9 assertEquals(4, ((a, ...args) => args.length)(1,2,3,4,5)); | 10 assertEquals(4, ((a, ...args) => args.length)(1,2,3,4,5)); |
| 10 assertEquals(3, ((a, b, ...args) => args.length)(1,2,3,4,5)); | 11 assertEquals(3, ((a, b, ...args) => args.length)(1,2,3,4,5)); |
| 11 assertEquals(2, ((a, b, c, ...args) => args.length)(1,2,3,4,5)); | 12 assertEquals(2, ((a, b, c, ...args) => args.length)(1,2,3,4,5)); |
| 12 assertEquals(1, ((a, b, c, d, ...args) => args.length)(1,2,3,4,5)); | 13 assertEquals(1, ((a, b, c, d, ...args) => args.length)(1,2,3,4,5)); |
| 13 assertEquals(0, ((a, b, c, d, e, ...args) => args.length)(1,2,3,4,5)); | 14 assertEquals(0, ((a, b, c, d, e, ...args) => args.length)(1,2,3,4,5)); |
| 14 })(); | 15 })(); |
| 15 | 16 |
| 16 // strictTest and sloppyTest should be called with descending natural | 17 // strictTest and sloppyTest should be called with descending natural |
| 17 // numbers, as in: | 18 // numbers, as in: |
| 18 // | 19 // |
| 19 // strictTest(6,5,4,3,2,1) | 20 // strictTest(6,5,4,3,2,1) |
| 20 // | 21 // |
| 21 var strictTest = (() => { | 22 var strictTest = (function() { |
|
wingo
2015/08/31 13:07:31
Why this change?
caitp (gmail)
2015/08/31 13:23:40
It's not legal to have a language mode directive i
| |
| 22 "use strict"; | 23 "use strict"; |
| 23 return (a, b, ...c) => { | 24 return (a, b, ...c) => { |
| 24 assertEquals(Array, c.constructor); | 25 assertEquals(Array, c.constructor); |
| 25 assertTrue(Array.isArray(c)); | 26 assertTrue(Array.isArray(c)); |
| 26 | 27 |
| 27 var expectedLength = (a === undefined) ? 0 : a - 2; | 28 var expectedLength = (a === undefined) ? 0 : a - 2; |
| 28 assertEquals(expectedLength, c.length); | 29 assertEquals(expectedLength, c.length); |
| 29 | 30 |
| 30 for (var i = 2; i < a; ++i) { | 31 for (var i = 2; i < a; ++i) { |
| 31 assertEquals(c[i - 2], a - i); | 32 assertEquals(c[i - 2], a - i); |
| 32 } | 33 } |
| 33 }; | 34 }; |
| 34 })(); | 35 })(); |
| 35 | 36 |
| 36 var sloppyTest = (a, b, ...c) => { | 37 var sloppyTest = (a, b, ...c) => { |
| 37 assertEquals(Array, c.constructor); | 38 assertEquals(Array, c.constructor); |
| 38 assertTrue(Array.isArray(c)); | 39 assertTrue(Array.isArray(c)); |
| 39 | 40 |
| 40 var expectedLength = (a === undefined) ? 0 : a - 2; | 41 var expectedLength = (a === undefined) ? 0 : a - 2; |
| 41 assertEquals(expectedLength, c.length); | 42 assertEquals(expectedLength, c.length); |
| 42 | 43 |
| 43 for (var i = 2; i < a; ++i) { | 44 for (var i = 2; i < a; ++i) { |
| 44 assertEquals(c[i - 2], a - i); | 45 assertEquals(c[i - 2], a - i); |
| 45 } | 46 } |
| 46 } | 47 }; |
| 47 | 48 |
| 48 | 49 |
| 49 var O = { | 50 var O = { |
| 50 strict: strictTest, | 51 strict: strictTest, |
| 51 sloppy: sloppyTest | 52 sloppy: sloppyTest |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 (function testStrictRestParamArity() { | 55 (function testStrictRestParamArity() { |
| 55 assertEquals(2, strictTest.length); | 56 assertEquals(2, strictTest.length); |
| 56 assertEquals(2, O.strict.length); | 57 assertEquals(2, O.strict.length); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 O.strict.call(O, 3, 2, 1); | 93 O.strict.call(O, 3, 2, 1); |
| 93 })(); | 94 })(); |
| 94 | 95 |
| 95 | 96 |
| 96 (function testsloppyRestParamArity() { | 97 (function testsloppyRestParamArity() { |
| 97 assertEquals(2, sloppyTest.length); | 98 assertEquals(2, sloppyTest.length); |
| 98 assertEquals(2, O.sloppy.length); | 99 assertEquals(2, O.sloppy.length); |
| 99 })(); | 100 })(); |
| 100 | 101 |
| 101 | 102 |
| 102 (function testRestParamssloppyMode() { | 103 (function testRestParamsSloppyMode() { |
| 103 sloppyTest(); | 104 sloppyTest(); |
| 104 sloppyTest(2, 1); | 105 sloppyTest(2, 1); |
| 105 sloppyTest(6, 5, 4, 3, 2, 1); | 106 sloppyTest(6, 5, 4, 3, 2, 1); |
| 106 sloppyTest(3, 2, 1); | 107 sloppyTest(3, 2, 1); |
| 107 O.sloppy(); | 108 O.sloppy(); |
| 108 O.sloppy(2, 1); | 109 O.sloppy(2, 1); |
| 109 O.sloppy(6, 5, 4, 3, 2, 1); | 110 O.sloppy(6, 5, 4, 3, 2, 1); |
| 110 O.sloppy(3, 2, 1); | 111 O.sloppy(3, 2, 1); |
| 111 })(); | 112 })(); |
| 112 | 113 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 135 })(); | 136 })(); |
| 136 | 137 |
| 137 | 138 |
| 138 (function testUnmappedArguments() { | 139 (function testUnmappedArguments() { |
| 139 // Normal functions make their arguments object unmapped, but arrow | 140 // Normal functions make their arguments object unmapped, but arrow |
| 140 // functions don't have an arguments object anyway. Check that the | 141 // functions don't have an arguments object anyway. Check that the |
| 141 // right thing happens for arguments in arrow functions with rest | 142 // right thing happens for arguments in arrow functions with rest |
| 142 // parameters. | 143 // parameters. |
| 143 assertSame(arguments, ((...rest) => arguments)()); | 144 assertSame(arguments, ((...rest) => arguments)()); |
| 144 })(); | 145 })(); |
| OLD | NEW |