var add = new Function("a", "b", "return a + b");
assert.sameValue(typeof add, "function", "new Function returns a function");
assert.sameValue(add(2, 3), 5, "new Function-built function runs");
assert.sameValue(add(40, 2), 42, "again");
var twice = Function("x", "return x * 2");
assert.sameValue(twice(21), 42, "Function() (no new) builds a function too");
assert.sameValue(add.name, "anonymous", "name is 'anonymous'");
assert.sameValue(add.length, 2, "length is the parameter count");
assert.sameValue(add instanceof Function, true, "result instanceof Function");
assert.sameValue(typeof add.prototype, "object", "has a prototype object");
function makeReader() {
var local = 123;
return new Function("return typeof local");
}
assert.sameValue(makeReader()(), "undefined", "Function() closes over globals only");
function caught(fn) { try { fn(); return null; } catch (e) { return e.constructor.name; } }
assert.sameValue(caught(function () { new Function("return )("); }), "SyntaxError", "bad body throws SyntaxError");
assert.sameValue(caught(function () { Function("a", "b b", "return 1"); }), "SyntaxError", "bad params throw SyntaxError");
var supported = (function () {
try { new Function("return 1"); return true; } catch (e) { return false; }
})();
assert.sameValue(supported, true, "feature-detect returns true");
assert.sameValue(new Map([["a", 1]]).get("a"), 1, "new Map");
assert.sameValue(new Set([1, 2, 3]).size, 3, "new Set");
assert.sameValue(new Date(0).getTime(), 0, "new Date");
assert.sameValue(new Array(3).length, 3, "new Array");
assert.sameValue(new Number(5).valueOf(), 5, "new Number");