Bug 679939 part 6. Drop function-cloning uses of compileAndGo, since it no longer affects the bytecode. r=luke

This commit is contained in:
Boris Zbarsky 2015-04-01 12:05:29 -04:00
parent 44fe165422
commit edfec71b46
4 changed files with 10 additions and 24 deletions

View File

@ -1,28 +1,24 @@
var g = newGlobal();
function cloneableFunction(body) {
return evaluate("(function () { " + body + " })", {compileAndGo: false});
}
g.f = cloneableFunction('return function(x) { return x };');
g.f = new Function('return function(x) { return x };');
assertEq(g.eval("clone(f)()(9)"), 9);
g.f = cloneableFunction('return function(x) { let(y = x+1) { return y } };');
g.f = new Function('return function(x) { let(y = x+1) { return y } };');
assertEq(g.eval("clone(f)()(9)"), 10);
g.f = cloneableFunction('return function(x) { let(y = x, z = 1) { return y+z } };');
g.f = new Function('return function(x) { let(y = x, z = 1) { return y+z } };');
assertEq(g.eval("clone(f)()(9)"), 10);
g.f = cloneableFunction('return function(x) { return x.search(/ponies/) };');
g.f = new Function('return function(x) { return x.search(/ponies/) };');
assertEq(g.eval("clone(f)()('123ponies')"), 3);
g.f = cloneableFunction('return function(x,y) { return x.search(/a/) + y.search(/b/) };');
g.f = new Function('return function(x,y) { return x.search(/a/) + y.search(/b/) };');
assertEq(g.eval("clone(f)()('12a','foo')"), 1);
g.f = cloneableFunction('return [function(x) x+2, function(y) let(z=y+1) z];');
g.f = new Function('return [function(x) x+2, function(y) let(z=y+1) z];');
assertEq(g.eval("let ([f,g] = clone(f)()) f(g(4))"), 7);
g.f = cloneableFunction('return function(x) { switch(x) { case "a": return "b"; case null: return "c" } };');
g.f = new Function('return function(x) { switch(x) { case "a": return "b"; case null: return "c" } };');
assertEq(g.eval("clone(f)()('a')"), "b");
assertEq(g.eval("clone(f)()(null)"), "c");
assertEq(g.eval("clone(f)()(3)"), undefined);

View File

@ -6,9 +6,7 @@ function assertWithMessage(got, expected, message) {
assertEq(message + ": " + got, message + ": " + expected);
}
// Create our test func via "evaluate" so it won't be compileAndGo and
// we can clone it.
evaluate(`function testFunc() {
function testFunc() {
assertWithMessage(checkNameLookup(), "local", "nameLookup");
assertWithMessage(checkThisBinding(), "local", "thisBinding");
@ -20,7 +18,7 @@ evaluate(`function testFunc() {
assertWithMessage(checkNameLookup(), "local", "nameLookup" + reason);
assertWithMessage(checkThisBinding(), "local", "thisBinding" + reason);
})();
}`, { compileAndGo: false });
}
var obj = {
checkNameLookup: function() {

View File

@ -3250,7 +3250,7 @@ IsFunctionCloneable(HandleFunction fun, HandleObject dynamicScope)
return false;
}
return !fun->nonLazyScript()->compileAndGo() || dynamicScope->is<GlobalObject>();
return true;
}
static JSObject*

View File

@ -2567,14 +2567,6 @@ Clone(JSContext* cx, unsigned argc, jsval* vp)
funobj = JS_GetFunctionObject(fun);
}
}
if (funobj->compartment() != cx->compartment()) {
JSFunction* fun = &funobj->as<JSFunction>();
if (fun->hasScript() && fun->nonLazyScript()->compileAndGo()) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_UNEXPECTED_TYPE,
"function", "compile-and-go");
return false;
}
}
if (args.length() > 1) {
if (!JS_ValueToObject(cx, args[1], &parent))