diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-04 14:34:31 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-04 15:58:49 +0200 |
commit | 2944039d6b2ccecaef88f64cffcb7ec5f7f3804c (patch) | |
tree | 1d75355d93e420791d54ba3657bf10329ab02fdb /Libraries/LibJS/Tests/Function.js | |
parent | 4d931b524de35d0c4c9c40656b0c4ac0eb9b025e (diff) | |
download | serenity-2944039d6b2ccecaef88f64cffcb7ec5f7f3804c.zip |
LibJS: Add Function() and Function.prototype
Diffstat (limited to 'Libraries/LibJS/Tests/Function.js')
-rw-r--r-- | Libraries/LibJS/Tests/Function.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/Function.js b/Libraries/LibJS/Tests/Function.js new file mode 100644 index 0000000000..5618aa5219 --- /dev/null +++ b/Libraries/LibJS/Tests/Function.js @@ -0,0 +1,29 @@ +function assert(x) { if (!x) throw 1; } + +try { + assert(Function.length === 1); + assert(Function.prototype.length === 0); + assert(typeof Function() === "function"); + assert(typeof new Function() === "function"); + assert(Function()() === undefined); + assert(new Function()() === undefined); + assert(Function("return 42")() === 42); + assert(new Function("return 42")() === 42); + assert(new Function("foo", "return foo")(42) === 42); + assert(new Function("foo,bar", "return foo + bar")(1, 2) === 3); + assert(new Function("foo", "bar", "return foo + bar")(1, 2) === 3); + assert(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3) === 6); + assert(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3) === 6); + assert(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true) === 42); + assert(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false) === "bar"); + assert(new Function("return typeof Function()")() === "function"); + // FIXME: This is equivalent to + // (function (x) { return function (y) { return x + y;} })(1)(2) + // and should totally work, but both currently fail with + // Uncaught exception: [ReferenceError]: 'x' not known + // assert(new Function("x", "return function (y) { return x + y };")(1)(2) === 3); + + console.log("PASS"); +} catch (e) { + console.log("FAIL: " + e.message); +} |