Chromium Code Reviews| 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: --strong-mode --harmony_arrow_functions --harmony-reflect | |
| 6 | |
| 7 (function NoArguments() { | |
| 8 'use strong'; | |
| 9 | |
| 10 function checkNoArguments(f) { | |
| 11 f(); | |
| 12 f(1); | |
| 13 f(1, 2); | |
| 14 f(undefined); | |
| 15 f.call(undefined); | |
|
rossberg
2015/05/05 14:26:20
Perhaps add f.call() and f.apply() (here and elsew
arv (Not doing code reviews)
2015/05/05 16:46:29
Done.
| |
| 16 f.call(undefined, 1); | |
| 17 f.call(undefined, 1, 2); | |
| 18 f.call(undefined, undefined); | |
| 19 f.apply(undefined); | |
| 20 f.apply(undefined, []); | |
| 21 f.apply(undefined, [1]); | |
| 22 f.apply(undefined, [1, 2]); | |
| 23 f.apply(undefined, [undefined]); | |
|
rossberg
2015/05/05 14:26:20
Also add tests for .bind, %Call, %Apply, %_CallFun
arv (Not doing code reviews)
2015/05/05 16:46:29
Your wish is my command.
Done.
If you can think
rossberg
2015/05/05 16:51:56
Oh, and super calls. :)
| |
| 24 } | |
| 25 | |
| 26 function f() {} | |
| 27 function* g() {} | |
| 28 let a = () => 42; | |
| 29 | |
| 30 checkNoArguments(f); | |
| 31 checkNoArguments(g); | |
| 32 checkNoArguments(a); | |
| 33 | |
| 34 })(); | |
| 35 | |
| 36 | |
| 37 (function NoArgumentsMethod() { | |
| 38 'use strong'; | |
| 39 | |
| 40 function checkNoArguments(object) { | |
| 41 object.m(); | |
| 42 object.m(1); | |
| 43 object.m(1, 2); | |
| 44 object.m(undefined); | |
| 45 object.m.call(object); | |
| 46 object.m.call(object, 1); | |
| 47 object.m.call(object, 1, 2); | |
| 48 object.m.call(object, undefined); | |
| 49 object.m.apply(object); | |
| 50 object.m.apply(object, []); | |
| 51 object.m.apply(object, [1]); | |
| 52 object.m.apply(object, [1, 2]); | |
| 53 object.m.apply(object, [undefined]); | |
| 54 } | |
| 55 | |
| 56 class C { | |
| 57 m() {} | |
| 58 } | |
| 59 let obj = { | |
| 60 m() {} | |
| 61 }; | |
| 62 | |
| 63 checkNoArguments(new C()); | |
| 64 checkNoArguments(obj); | |
| 65 })(); | |
| 66 | |
| 67 | |
| 68 (function NoArgumentsConstructor() { | |
| 69 'use strong'; | |
| 70 | |
| 71 class C { | |
| 72 constructor() {} | |
| 73 } | |
| 74 | |
| 75 new C(); | |
| 76 new C(1); | |
| 77 new C(1, 2); | |
| 78 new C(undefined); | |
| 79 Reflect.construct(C, []); | |
| 80 Reflect.construct(C, [1]); | |
| 81 Reflect.construct(C, [1, 2]); | |
| 82 Reflect.construct(C, [undefined]); | |
| 83 })(); | |
| 84 | |
| 85 | |
| 86 (function OneArgument() { | |
| 87 'use strong'; | |
| 88 | |
| 89 function checkOneArgument(fun) { | |
| 90 assertThrows(function() { fun(); }, TypeError); | |
| 91 fun(1); | |
| 92 fun(1, 2); | |
| 93 fun(undefined); | |
| 94 assertThrows(function() { fun.call(undefined); }, TypeError); | |
| 95 fun.call(undefined, 1); | |
| 96 fun.call(undefined, 1, 2); | |
| 97 fun.call(undefined, undefined); | |
| 98 assertThrows(function() { fun.apply(undefined); }, TypeError); | |
| 99 assertThrows(function() { fun.apply(undefined, []); }, TypeError); | |
| 100 fun.apply(undefined, [1]); | |
| 101 fun.apply(undefined, [1, 2]); | |
| 102 fun.apply(undefined, [undefined]); | |
| 103 } | |
| 104 | |
| 105 function f(x) {} | |
| 106 function* g(x) {} | |
| 107 let a = (x) => {}; | |
| 108 | |
| 109 checkOneArgument(f); | |
| 110 checkOneArgument(g); | |
| 111 checkOneArgument(a); | |
| 112 })(); | |
| 113 | |
| 114 | |
| 115 (function OneArgumentMethod() { | |
| 116 'use strong'; | |
| 117 | |
| 118 function checkOneArgument(object) { | |
| 119 assertThrows(function() { object.m(); }, TypeError); | |
| 120 object.m(1); | |
| 121 object.m(1, 2); | |
| 122 object.m(undefined); | |
| 123 assertThrows(function() { object.m.call(undefined); }, TypeError); | |
| 124 object.m.call(object, 1); | |
| 125 object.m.call(object, 1, 2); | |
| 126 object.m.call(object, undefined); | |
| 127 assertThrows(function() { object.m.apply(object); }, TypeError); | |
| 128 assertThrows(function() { object.m.apply(object, []); }, TypeError); | |
| 129 object.m.apply(object, [1]); | |
| 130 object.m.apply(object, [1, 2]); | |
| 131 object.m.apply(object, [undefined]); | |
| 132 } | |
| 133 | |
| 134 class C { | |
| 135 m(x) {} | |
| 136 } | |
| 137 let obj = { | |
| 138 m(x) {} | |
| 139 }; | |
| 140 | |
| 141 checkOneArgument(new C()); | |
| 142 checkOneArgument(obj); | |
| 143 })(); | |
| 144 | |
| 145 | |
| 146 (function OneArgumentConstructor() { | |
| 147 'use strong'; | |
| 148 | |
| 149 class C { | |
| 150 constructor(x) {} | |
| 151 } | |
| 152 | |
| 153 assertThrows(function() { new C(); }, TypeError); | |
| 154 new C(1); | |
| 155 new C(1, 2); | |
| 156 new C(undefined); | |
| 157 assertThrows(function() { Reflect.construct(C); }, TypeError); | |
| 158 assertThrows(function() { Reflect.construct(C, []); }, TypeError); | |
| 159 Reflect.construct(C, [1]); | |
| 160 Reflect.construct(C, [1, 2]); | |
| 161 Reflect.construct(C, [undefined]); | |
| 162 })(); | |
| 163 | |
| 164 | |
| 165 (function TwoArguments() { | |
| 166 'use strong'; | |
| 167 | |
| 168 function checkTwoArguments(fun) { | |
| 169 assertThrows(function() { fun(); }, TypeError); | |
| 170 assertThrows(function() { fun(1); }, TypeError); | |
| 171 fun(1, 2); | |
| 172 fun(1, 2, 3); | |
| 173 assertThrows(function() { fun(undefined); }, TypeError); | |
| 174 assertThrows(function() { fun.call(undefined); }, TypeError); | |
| 175 assertThrows(function() { fun.call(undefined, 1); }, TypeError); | |
| 176 fun.call(undefined, 1, 2); | |
| 177 fun.call(undefined, 1, 2, 3); | |
| 178 assertThrows(function() { fun.call(undefined, undefined); }, TypeError); | |
| 179 assertThrows(function() { fun.apply(undefined); }, TypeError); | |
| 180 assertThrows(function() { fun.apply(undefined, []); }, TypeError); | |
| 181 assertThrows(function() { fun.apply(undefined, [1]); }, TypeError); | |
| 182 fun.apply(undefined, [1, 2]); | |
| 183 fun.apply(undefined, [1, 2, 3]); | |
| 184 assertThrows(function() { fun.apply(undefined, [undefined]); }, TypeError); | |
| 185 } | |
| 186 | |
| 187 function f(x, y) {} | |
| 188 function* g(x, y) {} | |
| 189 let a = (x, y) => {}; | |
| 190 | |
| 191 checkTwoArguments(f); | |
| 192 checkTwoArguments(g); | |
| 193 checkTwoArguments(a); | |
| 194 })(); | |
| 195 | |
| 196 | |
| 197 (function TwoArgumentsMethod() { | |
| 198 'use strong'; | |
| 199 | |
| 200 function checkTwoArguments(object) { | |
| 201 assertThrows(function() { object.m(); }, TypeError); | |
| 202 assertThrows(function() { object.m(1); }, TypeError); | |
| 203 object.m(1, 2); | |
| 204 object.m(1, 2, 3); | |
| 205 assertThrows(function() { object.m(undefined); }, TypeError); | |
| 206 assertThrows(function() { object.m.call(object); }, TypeError); | |
| 207 assertThrows(function() { object.m.call(object, 1); }, TypeError); | |
| 208 object.m.call(object, 1, 2); | |
| 209 object.m.call(object, 1, 2, 3); | |
| 210 assertThrows(function() { object.m.call(object, undefined); }, TypeError); | |
| 211 assertThrows(function() { object.m.apply(object); }, TypeError); | |
| 212 assertThrows(function() { object.m.apply(object, []); }, TypeError); | |
| 213 assertThrows(function() { object.m.apply(object, [1]); }, TypeError); | |
| 214 object.m.apply(object, [1, 2]); | |
| 215 object.m.apply(object, [1, 2, 3]); | |
| 216 assertThrows(function() { object.m.apply(object, [undefined]); }, TypeError) ; | |
| 217 } | |
| 218 | |
| 219 class C { | |
| 220 m(x, y) {} | |
| 221 } | |
| 222 let obj = { | |
| 223 m(x, y) {} | |
| 224 }; | |
| 225 | |
| 226 checkTwoArguments(new C()); | |
| 227 checkTwoArguments(obj); | |
| 228 })(); | |
| 229 | |
| 230 | |
| 231 (function TwoArgumentsConstructor() { | |
| 232 'use strong'; | |
| 233 | |
| 234 class C { | |
| 235 constructor(x, y) {} | |
| 236 } | |
| 237 | |
| 238 assertThrows(function() { new C(); }, TypeError); | |
| 239 assertThrows(function() { new C(1); }, TypeError); | |
| 240 new C(1, 2); | |
| 241 new C(1, 2, 3); | |
| 242 assertThrows(function() { new C(undefined); }, TypeError); | |
| 243 assertThrows(function() { Reflect.construct(C, []); }, TypeError); | |
| 244 assertThrows(function() { Reflect.construct(C, [1]); }, TypeError); | |
| 245 Reflect.construct(C, [1, 2]); | |
| 246 Reflect.construct(C, [1, 2, 3]); | |
| 247 assertThrows(function() { Reflect.construct(C, [undefined]); }, TypeError); | |
| 248 })(); | |
| OLD | NEW |