|
@hashseed | |||||
|
Pro-tip: if the function is still on the stack, select the stack frame to see the stack locals. pic.twitter.com/yiBARGCUZ7
|
||||||
|
||||||
|
Nathanael Anderson
@CongoCart
|
27. stu |
|
Simple code is:
function bodyOnLoad() {
const outerValue = 'ipsum';
function inner() {
var innerVaue = 'test test';
debugger;
}
inner();
}
|
||
|
|
||
|
Benedikt Meurer
@bmeurer
|
27. stu |
|
The @v8js engine optimizes away the `outerValue` from the closure for `inner`, since it's no needed. So @ChromeDevTools has no way to get to its value.
|
||
|
|
||
|
Nathanael Anderson
@CongoCart
|
27. stu |
|
initially that was my idea, but it still wasn't available in the inner, when it is used after it.
function onLoad() {
const oValue = 'ipsum';
function inner() {
var innerVaue = 'test test';
debugger;
}
inner();
console.log(Value);
}
|
||
|
|
||
|
Nathanael Anderson
@CongoCart
|
27. stu |
|
Lol, last line should be `console.log(oValue);` so shouldn't oValue still be available since it has to be used AFTER inner() is called?
|
||
|
|
||
|
Benedikt Meurer
@bmeurer
|
27. stu |
|
cc @tverwaes
|
||
|
|
||
|
Toon Verwaest
@tverwaes
|
27. stu |
|
No, oValue is referenced from the function itself so is still not context allocated. Only gets context allocated if an inner function references it (or if there's an eval).
|
||
|
|
||
|
Nathanael Anderson
@CongoCart
|
27. stu |
|
Seems strange to me that oValue is not known by the debugger at that point since it is still allocated; and in the parent scope. This creates a bit of debugging pain when you are dealing with Lamda's and things like .map, .reduce, etc.
|
||
|
|
||
|
Nathanael Anderson
@CongoCart
|
27. stu |
|
The v8 engine knows what the value is; but the debugger doesn't. In this example; eval got the value and returned it -- but while in inner() the debugger still has no clue. pic.twitter.com/CXsF46Uuen
|
||
|
|
||
|
Nathanael Anderson
@CongoCart
|
27. stu |
|
So would this be something you think a feature request to enhance the tooling to change it to work the way a developer would assume it would work. (i.e. child scopes can see parent scope values, just like code can. )
|
||
|
|
||
|
Toon Verwaest
@tverwaes
|
28. stu |
|
In general this doesn't work ("onLoad" can finish and destroy "oValue" before "inner" is called), but I agree that it may make sense to provide access to values when they are still available; especially for .map etc. @hashseed
|
||
|
|
||
|
Nathanael Anderson
@CongoCart
|
28. stu |
|
Awesome pro-tip. 👏
|
||
|
|
||
|
Yang Guo
@hashseed
|
28. stu |
|
You might then ask why this doesn't happen automatically. Well, the function may be on the stack several times, e.g. in a recursion, so the same variable may have different values depending on which stack frame it belongs to.
|
||
|
|
||
|
Nathanael Anderson
@CongoCart
|
1. pro |
|
Not sure I understand even in recursion, seems like if the VALID value is accessible by clicking the prior callstack frame, then if the lambda doesn't have the value in its stack, then it auto-walks back the stack (just like a click would) to get the valid from the outer frames.
|
||
|
|
||
|
JSW
@jeffscottward
|
29. stu |
|
Is there any visual way to show scope depth like a highlight color gradient for every function that goes deeper.
Very pale blue towards a darker blue, with current line as green?
|
||
|
|
||
|
JSW
@jeffscottward
|
29. stu |
|
Like a topography map!
But in blue pic.twitter.com/phUYWGwXbk
|
||
|
|
||
|
Ian Leon
@iannleon
|
30. stu |
|
Using Linux on the desktop like a boss
|
||
|
|
||