| 1 |
// Test reading and setting values on "hollow" debug scopes. In testGet and |
| 2 |
// testSet below, f and g *must* be called from a non-heavyweight lambda to |
| 3 |
// trigger the creation of the "hollow" debug scopes for the missing scopes. |
| 4 |
// |
| 5 |
// The reason is that a direct call to f or g that accesses a in testGet or |
| 6 |
// testSet's frame is actually recoverable. The Debugger can synthesize a scope |
| 7 |
// based on the frame. By contorting through a lambda, it becomes unsound to |
| 8 |
// synthesize a scope based on the lambda function's frame. Since f and g are |
| 9 |
// accessing a, which is itself free inside the lambda, the Debugger has no way |
| 10 |
// to tell if the on-stack testGet or testSet frame is the frame that *would |
| 11 |
// have* allocated a scope for the lambda, *had the lambda been heavyweight*. |
| 12 |
// |
| 13 |
// More concretely, if the inner lambda were returned from testGet and testSet, |
| 14 |
// then called from a different invocation of testGet or testSet, it becomes |
| 15 |
// obvious that it is incorrect to synthesize a scope based on the frame of |
| 16 |
// that different invocation. |
| 17 |
|
| 18 |
load(libdir + "evalInFrame.js"); |
| 19 |
|
| 20 |
function f() { |
| 21 |
// Eval one frame up. Nothing aliases a. |
| 22 |
evalInFrame(1, "print(a)"); |
| 23 |
} |
| 24 |
|
| 25 |
function g() { |
| 26 |
evalInFrame(1, "a = 43"); |
| 27 |
} |
| 28 |
|
| 29 |
function testGet() { |
| 30 |
{ |
| 31 |
let a = 42; |
| 32 |
(function () { f(); })(); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
function testSet() { |
| 37 |
{ |
| 38 |
let a = 42; |
| 39 |
(function () { g(); })(); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
var log = ""; |
| 44 |
|
| 45 |
try { |
| 46 |
testGet(); |
| 47 |
} catch (e) { |
| 48 |
// Throws due to a having been optimized out. |
| 49 |
log += "g"; |
| 50 |
} |
| 51 |
|
| 52 |
try { |
| 53 |
testSet(); |
| 54 |
} catch (e) { |
| 55 |
// Throws due to a having been optimized out. |
| 56 |
log += "s"; |
| 57 |
} |
| 58 |
|
| 59 |
assertEq(log, "gs"); |