load(libdir + 'bytecode-cache.js'); var test = ""; var checkAfter;
// code a function which has both used and unused inner functions.
test = (function () { function f(x) { function ifTrue() { returntrue;
}; function ifFalse() { returnfalse;
};
// code a function which uses different inner functions based on the generation.
test = (function () { function f(x) { function ifTrue() { returntrue;
}; function ifFalse() { returnfalse;
};
// Code a function which has an enclosing scope.
test = (function () { function f() { var upvar = ""; function g() { upvar += ""; return upvar; } return g;
}
// Code a lazy function which has an enclosing scope.
test = (function () { function f() { var upvar = ""; function g() { upvar += ""; return upvar; } return g;
}
// (basic/bug535930) Code an enclosing scope which is a Call object.
test = (function () { return"(" + (function () {
p = function () {
Set()
}; var Set = function () {}; for (var x = 0; x < 5; x++) {
Set = function (z) { returnfunction () {
[z]
}
} (x)
}
}).toString() + ")()";
})();
evalWithCache(test, { assertEqBytecode: true });
// Code an arrow function, and execute it.
test = (function () { function f() { var g = (a) => a + a; return g;
}
// Extra zeal GCs can cause isRelazifiableFunction() to become true after we // record its value by throwing away JIT code for the function.
gczeal(0);
// Ensure that decoded functions can be relazified.
test = "function f() { }; f();"
+ "assertEq(isLazyFunction(f), false);"
+ "var expect = isRelazifiableFunction(f);";
checkAfter = function (ctx) {
relazifyFunctions(); // relazify f, if possible.
evaluate("assertEq(isLazyFunction(f), expect);", ctx);
};
evalWithCache(test, {
assertEqBytecode: true, // Check that we re-encode the same thing.
assertEqResult: true, // The function should remain relazifiable, if it was // during the first run.
checkAfter: checkAfter // Check that relazifying the restored function works // if the original was relazifiable.
});
// Ensure that decoded functions can be relazified, even if they have free // variables.
test = "function f() { return isRelazifiableFunction(f) }; var expect = f();"
+ "assertEq(isLazyFunction(f), false);"
+ "expect";
checkAfter = function (ctx) {
relazifyFunctions(); // relazify f, if possible.
evaluate("assertEq(isLazyFunction(f), expect);", ctx);
};
evalWithCache(test, {
assertEqBytecode: true, // Check that we re-encode the same thing.
assertEqResult: true, // The function should remain relazifiable, if it was // during the first run.
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() { returntrue; }; 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({ cloneSingletons: true }); var g2 = newGlobal(); var res = "function f(){}"; var code = cacheEntry(res + "; f();");
evaluate(code, {global:g1, saveBytecodeWithDelazifications: {value: true}});
evaluate(code, {global:g2, loadBytecode: true});
gc();
assertEq(g2.f.toString(), res);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.