// |jit-test| skip-if: getBuildConfiguration("wasi") // // Two Environments nested in the same runtime scope share the correct tail of their parent chains.
// The compiler must be allowed to elide empty scopes and so forth, so this // test does not check the number of unshared Environments. Instead, each test // case identifies the expected innermost shared scope by the name of a // variable in it.
var g = newGlobal({newCompartment: true});
g.eval("function h() { debugger; }"); var dbg = Debugger(g); var hits, name, shared, unshared;
dbg.onDebuggerStatement = function (hframe) { var frame = hframe.older;
// Find name in frame.environment. var env, child = null; for (env = frame.environment; env !== null; env = env.parent) { if (env.names().indexOf(name) != -1) break;
child = env;
}
assertEq(env !== null, true, "expected '" + name + "' to be in scope");
assertEq(env, frame.environment.find(name), "env.find should find the same frame as the written out search");
if (hits === 0) { // First hit.
shared = env;
unshared = child;
} else { // Subsequent hit.
assertEq(env, shared, "the environment containing '" + name + "' should be shared");
assertEq(child === null || unshared === null || unshared !== child, true, "environments nested within the one containing '" + name + "' should not be shared");
}
hits++;
};
function test(sharedName, expectedHits, code) {
hits = 0;
name = sharedName;
shared = unshared = undefined;
g.eval(code);
assertEq(hits, expectedHits);
}
// Basic test cases. // // (The stray "a = b" assignments in these tests are to inhibit the flat closure // optimization, which Environments expose. There's nothing really wrong with // the optimization or with the debugger exposing it, but that's not what we // want to test here.)
test("q", 2, "let q = function (a) { h(); }; q(1); q(2);");
test("a", 2, "q = function (a) { (function (b) { h(); a = b; })(2); h(); }; q(1);");
test("a", 2, "q = function (a) { h(); return function (b) { h(); a = b; }; }; q(1)(2);");
test("n", 3, "q = function (n) { for (var i = 0; i < n; i++) { { let j = i; h(); } } }; q(3);");
// A function with long dynamic and static chains. var N = 80;
var code = "function f" + N + "(a" + N + ") {\neval('a0 + a1'); h();\n}\n"; for (var i = N; --i >= 0;) { var call = "f" + (i + 1) + "(a" + i + " - 1);\n";
code = ("function f" + i + "(a" + i + ") {\n" +
code +
call + "if (a" + i + " === 0) " + call + "}\n");
}
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.