Bug 1142844. When xdr-decoding a non-lazy but relazifiable function, don't forget to set up the source object on the LazyScript we create for it. r=luke

This commit is contained in:
Boris Zbarsky 2015-03-26 23:02:55 -04:00
parent 8cc673ff66
commit a8ca10408d
2 changed files with 25 additions and 2 deletions

View File

@ -138,3 +138,23 @@ evalWithCache(test, {
checkAfter: checkAfter // Check that relazifying the restored function works
// if the original was relazifiable.
});
// Ensure that if a function is encoded when non-lazy but relazifiable, then
// decoded, relazified, and then delazified, the result actually works.
test = `
function f() { return true; };
var canBeLazy = isRelazifiableFunction(f) || isLazyFunction(f);
relazifyFunctions();
assertEq(isLazyFunction(f), canBeLazy);
f()`
evalWithCache(test, { assertEqBytecode: true, assertEqResult: true });
// And more of the same, in a slightly different way
var g1 = newGlobal();
var g2 = newGlobal();
var res = "function f(){}";
var code = cacheEntry(res + "; f();");
evaluate(code, {global:g1, compileAndGo: true, saveBytecode: {value: true}});
evaluate(code, {global:g2, loadBytecode: true});
gc();
assertEq(g2.f.toString(), res);

View File

@ -484,7 +484,7 @@ XDRLazyFreeVariables(XDRState<mode> *xdr, MutableHandle<LazyScript *> lazy)
template<XDRMode mode>
static bool
XDRRelazificationInfo(XDRState<mode> *xdr, HandleFunction fun, HandleScript script,
MutableHandle<LazyScript *> lazy)
HandleObject enclosingScope, MutableHandle<LazyScript *> lazy)
{
MOZ_ASSERT_IF(mode == XDR_ENCODE, script->isRelazifiable() && script->maybeLazyScript());
MOZ_ASSERT_IF(mode == XDR_ENCODE, !lazy->numInnerFunctions());
@ -516,6 +516,9 @@ XDRRelazificationInfo(XDRState<mode> *xdr, HandleFunction fun, HandleScript scri
// of the script, as we are trying to match the fact this function
// has already been parsed and that it would need to be re-lazified.
lazy->initRuntimeFields(packedFields);
MOZ_ASSERT(!lazy->sourceObject());
lazy->setParent(enclosingScope, &script->scriptSourceUnwrap());
}
}
@ -1081,7 +1084,7 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
if (mode == XDR_ENCODE)
lazy = script->maybeLazyScript();
if (!XDRRelazificationInfo(xdr, fun, script, &lazy))
if (!XDRRelazificationInfo(xdr, fun, script, enclosingScope, &lazy))
return false;
if (mode == XDR_DECODE)