Serenity Operating System
at hosted 27 lines 1.4 kB view raw
1try { 2 assert(Function.length === 1); 3 assert(Function.prototype.length === 0); 4 assert(typeof Function() === "function"); 5 assert(typeof new Function() === "function"); 6 assert(Function()() === undefined); 7 assert(new Function()() === undefined); 8 assert(Function("return 42")() === 42); 9 assert(new Function("return 42")() === 42); 10 assert(new Function("foo", "return foo")(42) === 42); 11 assert(new Function("foo,bar", "return foo + bar")(1, 2) === 3); 12 assert(new Function("foo", "bar", "return foo + bar")(1, 2) === 3); 13 assert(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3) === 6); 14 assert(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3) === 6); 15 assert(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true) === 42); 16 assert(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false) === "bar"); 17 assert(new Function("return typeof Function()")() === "function"); 18 // FIXME: This is equivalent to 19 // (function (x) { return function (y) { return x + y;} })(1)(2) 20 // and should totally work, but both currently fail with 21 // Uncaught exception: [ReferenceError]: 'x' not known 22 // assert(new Function("x", "return function (y) { return x + y };")(1)(2) === 3); 23 24 console.log("PASS"); 25} catch (e) { 26 console.log("FAIL: " + e.message); 27}