OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-arrow-functions --harmony-classes |
| 6 |
| 7 |
| 8 (function testInFunctionDeclaration() { |
| 9 var calls = 0; |
| 10 function f() { |
| 11 (() => { |
| 12 calls++; |
| 13 assertEquals(2, arguments.length); |
| 14 assertEquals('a', arguments[0]); |
| 15 assertEquals('b', arguments[1]); |
| 16 })(); |
| 17 } |
| 18 f('a', 'b'); |
| 19 assertEquals(1, calls); |
| 20 |
| 21 calls = 0; |
| 22 new f('a', 'b'); |
| 23 assertEquals(1, calls); |
| 24 })(); |
| 25 |
| 26 |
| 27 (function testInFunctionExpression() { |
| 28 var calls = 0; |
| 29 var f = function() { |
| 30 (() => { |
| 31 calls++; |
| 32 assertEquals(2, arguments.length); |
| 33 assertEquals('a', arguments[0]); |
| 34 assertEquals('b', arguments[1]); |
| 35 })(); |
| 36 } |
| 37 f('a', 'b'); |
| 38 assertEquals(1, calls); |
| 39 })(); |
| 40 |
| 41 |
| 42 (function testInConstructor() { |
| 43 'use strict'; |
| 44 |
| 45 var calls = 0; |
| 46 class C { |
| 47 constructor() { |
| 48 (() => { |
| 49 calls++; |
| 50 assertEquals(2, arguments.length); |
| 51 assertEquals('a', arguments[0]); |
| 52 assertEquals('b', arguments[1]); |
| 53 })(); |
| 54 } |
| 55 } |
| 56 new C('a', 'b'); |
| 57 assertEquals(1, calls); |
| 58 })(); |
| 59 |
| 60 |
| 61 (function testInSetter() { |
| 62 'use strict'; |
| 63 |
| 64 var calls = 0; |
| 65 var o = { |
| 66 set x(_) { |
| 67 (() => { |
| 68 calls++; |
| 69 assertEquals(1, arguments.length); |
| 70 assertEquals('a', arguments[0]); |
| 71 })(); |
| 72 } |
| 73 } |
| 74 o.x = 'a'; |
| 75 assertEquals(1, calls); |
| 76 })(); |
| 77 |
| 78 |
| 79 (function testMappedArguments() { |
| 80 var calls = 0; |
| 81 function f(x) { |
| 82 x = 'c'; |
| 83 (() => { |
| 84 calls++; |
| 85 assertEquals(2, arguments.length); |
| 86 assertEquals('c', arguments[0]); |
| 87 x = 'a'; |
| 88 assertEquals('a', arguments[0]); |
| 89 assertEquals('b', arguments[1]); |
| 90 })(); |
| 91 } |
| 92 f('a', 'b'); |
| 93 assertEquals(1, calls); |
| 94 })(); |
| 95 |
| 96 |
| 97 (function testUnMappedArguments() { |
| 98 'use strict'; |
| 99 |
| 100 var calls = 0; |
| 101 function f(x) { |
| 102 x = 'c'; |
| 103 (() => { |
| 104 calls++; |
| 105 assertEquals(2, arguments.length); |
| 106 assertEquals('a', arguments[0]); |
| 107 assertEquals('b', arguments[1]); |
| 108 })(); |
| 109 } |
| 110 f('a', 'b'); |
| 111 assertEquals(1, calls); |
| 112 })(); |
| 113 |
| 114 |
| 115 (function testClosure() { |
| 116 var calls = 0; |
| 117 function f(x) { |
| 118 return () => { |
| 119 calls++; |
| 120 assertEquals(2, arguments.length); |
| 121 assertEquals('a', arguments[0]); |
| 122 assertEquals('b', arguments[1]); |
| 123 }; |
| 124 } |
| 125 f('a', 'b')(); |
| 126 assertEquals(1, calls); |
| 127 })(); |
| 128 |
| 129 |
| 130 (function testClosureMappedArguments() { |
| 131 var calls = 0; |
| 132 function f(x) { |
| 133 x = 'c'; |
| 134 return () => { |
| 135 calls++; |
| 136 assertEquals(2, arguments.length); |
| 137 assertEquals('c', arguments[0]); |
| 138 x = 'a'; |
| 139 assertEquals('a', arguments[0]); |
| 140 assertEquals('b', arguments[1]); |
| 141 }; |
| 142 } |
| 143 f('a', 'b')(); |
| 144 assertEquals(1, calls); |
| 145 })(); |
| 146 |
| 147 |
| 148 (function testParamNamedArguments() { |
| 149 var calls = 0; |
| 150 function f(arguments) { |
| 151 (() => { |
| 152 calls++; |
| 153 assertEquals('a', arguments); |
| 154 })(); |
| 155 } |
| 156 f('a'); |
| 157 assertEquals(1, calls); |
| 158 })(); |
OLD | NEW |