Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: test/mjsunit/strong/function-arity.js

Issue 1115263004: [strong] Check arity of functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cleanup Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/strong/function-arity.js
diff --git a/test/mjsunit/strong/function-arity.js b/test/mjsunit/strong/function-arity.js
new file mode 100644
index 0000000000000000000000000000000000000000..869126ad3593b8256c6fec9613f289916994a6d5
--- /dev/null
+++ b/test/mjsunit/strong/function-arity.js
@@ -0,0 +1,248 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --strong-mode --harmony_arrow_functions --harmony-reflect
+
+(function NoArguments() {
+ 'use strong';
+
+ function checkNoArguments(f) {
+ f();
+ f(1);
+ f(1, 2);
+ f(undefined);
+ 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.
+ f.call(undefined, 1);
+ f.call(undefined, 1, 2);
+ f.call(undefined, undefined);
+ f.apply(undefined);
+ f.apply(undefined, []);
+ f.apply(undefined, [1]);
+ f.apply(undefined, [1, 2]);
+ 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. :)
+ }
+
+ function f() {}
+ function* g() {}
+ let a = () => 42;
+
+ checkNoArguments(f);
+ checkNoArguments(g);
+ checkNoArguments(a);
+
+})();
+
+
+(function NoArgumentsMethod() {
+ 'use strong';
+
+ function checkNoArguments(object) {
+ object.m();
+ object.m(1);
+ object.m(1, 2);
+ object.m(undefined);
+ object.m.call(object);
+ object.m.call(object, 1);
+ object.m.call(object, 1, 2);
+ object.m.call(object, undefined);
+ object.m.apply(object);
+ object.m.apply(object, []);
+ object.m.apply(object, [1]);
+ object.m.apply(object, [1, 2]);
+ object.m.apply(object, [undefined]);
+ }
+
+ class C {
+ m() {}
+ }
+ let obj = {
+ m() {}
+ };
+
+ checkNoArguments(new C());
+ checkNoArguments(obj);
+})();
+
+
+(function NoArgumentsConstructor() {
+ 'use strong';
+
+ class C {
+ constructor() {}
+ }
+
+ new C();
+ new C(1);
+ new C(1, 2);
+ new C(undefined);
+ Reflect.construct(C, []);
+ Reflect.construct(C, [1]);
+ Reflect.construct(C, [1, 2]);
+ Reflect.construct(C, [undefined]);
+})();
+
+
+(function OneArgument() {
+ 'use strong';
+
+ function checkOneArgument(fun) {
+ assertThrows(function() { fun(); }, TypeError);
+ fun(1);
+ fun(1, 2);
+ fun(undefined);
+ assertThrows(function() { fun.call(undefined); }, TypeError);
+ fun.call(undefined, 1);
+ fun.call(undefined, 1, 2);
+ fun.call(undefined, undefined);
+ assertThrows(function() { fun.apply(undefined); }, TypeError);
+ assertThrows(function() { fun.apply(undefined, []); }, TypeError);
+ fun.apply(undefined, [1]);
+ fun.apply(undefined, [1, 2]);
+ fun.apply(undefined, [undefined]);
+ }
+
+ function f(x) {}
+ function* g(x) {}
+ let a = (x) => {};
+
+ checkOneArgument(f);
+ checkOneArgument(g);
+ checkOneArgument(a);
+})();
+
+
+(function OneArgumentMethod() {
+ 'use strong';
+
+ function checkOneArgument(object) {
+ assertThrows(function() { object.m(); }, TypeError);
+ object.m(1);
+ object.m(1, 2);
+ object.m(undefined);
+ assertThrows(function() { object.m.call(undefined); }, TypeError);
+ object.m.call(object, 1);
+ object.m.call(object, 1, 2);
+ object.m.call(object, undefined);
+ assertThrows(function() { object.m.apply(object); }, TypeError);
+ assertThrows(function() { object.m.apply(object, []); }, TypeError);
+ object.m.apply(object, [1]);
+ object.m.apply(object, [1, 2]);
+ object.m.apply(object, [undefined]);
+ }
+
+ class C {
+ m(x) {}
+ }
+ let obj = {
+ m(x) {}
+ };
+
+ checkOneArgument(new C());
+ checkOneArgument(obj);
+})();
+
+
+(function OneArgumentConstructor() {
+ 'use strong';
+
+ class C {
+ constructor(x) {}
+ }
+
+ assertThrows(function() { new C(); }, TypeError);
+ new C(1);
+ new C(1, 2);
+ new C(undefined);
+ assertThrows(function() { Reflect.construct(C); }, TypeError);
+ assertThrows(function() { Reflect.construct(C, []); }, TypeError);
+ Reflect.construct(C, [1]);
+ Reflect.construct(C, [1, 2]);
+ Reflect.construct(C, [undefined]);
+})();
+
+
+(function TwoArguments() {
+ 'use strong';
+
+ function checkTwoArguments(fun) {
+ assertThrows(function() { fun(); }, TypeError);
+ assertThrows(function() { fun(1); }, TypeError);
+ fun(1, 2);
+ fun(1, 2, 3);
+ assertThrows(function() { fun(undefined); }, TypeError);
+ assertThrows(function() { fun.call(undefined); }, TypeError);
+ assertThrows(function() { fun.call(undefined, 1); }, TypeError);
+ fun.call(undefined, 1, 2);
+ fun.call(undefined, 1, 2, 3);
+ assertThrows(function() { fun.call(undefined, undefined); }, TypeError);
+ assertThrows(function() { fun.apply(undefined); }, TypeError);
+ assertThrows(function() { fun.apply(undefined, []); }, TypeError);
+ assertThrows(function() { fun.apply(undefined, [1]); }, TypeError);
+ fun.apply(undefined, [1, 2]);
+ fun.apply(undefined, [1, 2, 3]);
+ assertThrows(function() { fun.apply(undefined, [undefined]); }, TypeError);
+ }
+
+ function f(x, y) {}
+ function* g(x, y) {}
+ let a = (x, y) => {};
+
+ checkTwoArguments(f);
+ checkTwoArguments(g);
+ checkTwoArguments(a);
+})();
+
+
+(function TwoArgumentsMethod() {
+ 'use strong';
+
+ function checkTwoArguments(object) {
+ assertThrows(function() { object.m(); }, TypeError);
+ assertThrows(function() { object.m(1); }, TypeError);
+ object.m(1, 2);
+ object.m(1, 2, 3);
+ assertThrows(function() { object.m(undefined); }, TypeError);
+ assertThrows(function() { object.m.call(object); }, TypeError);
+ assertThrows(function() { object.m.call(object, 1); }, TypeError);
+ object.m.call(object, 1, 2);
+ object.m.call(object, 1, 2, 3);
+ assertThrows(function() { object.m.call(object, undefined); }, TypeError);
+ assertThrows(function() { object.m.apply(object); }, TypeError);
+ assertThrows(function() { object.m.apply(object, []); }, TypeError);
+ assertThrows(function() { object.m.apply(object, [1]); }, TypeError);
+ object.m.apply(object, [1, 2]);
+ object.m.apply(object, [1, 2, 3]);
+ assertThrows(function() { object.m.apply(object, [undefined]); }, TypeError);
+ }
+
+ class C {
+ m(x, y) {}
+ }
+ let obj = {
+ m(x, y) {}
+ };
+
+ checkTwoArguments(new C());
+ checkTwoArguments(obj);
+})();
+
+
+(function TwoArgumentsConstructor() {
+ 'use strong';
+
+ class C {
+ constructor(x, y) {}
+ }
+
+ assertThrows(function() { new C(); }, TypeError);
+ assertThrows(function() { new C(1); }, TypeError);
+ new C(1, 2);
+ new C(1, 2, 3);
+ assertThrows(function() { new C(undefined); }, TypeError);
+ assertThrows(function() { Reflect.construct(C, []); }, TypeError);
+ assertThrows(function() { Reflect.construct(C, [1]); }, TypeError);
+ Reflect.construct(C, [1, 2]);
+ Reflect.construct(C, [1, 2, 3]);
+ assertThrows(function() { Reflect.construct(C, [undefined]); }, TypeError);
+})();
« test/mjsunit/strong/declaration-after-use.js ('K') | « test/mjsunit/strong/declaration-after-use.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698