When the debugger is paused, running > var x = 42; in the console will not actually assign x to a local variable. This is fine, except that the command silently fails. If you later type > x while still paused, a TypeError will be thrown. This is confusing if you don't know how the console/debugger is implemented. So, should an error be thrown when a variable is introduced when debugger is paused, or should this work somehow?
<rdar://problem/19796707>
I would expect this to just work while debugging.
To work with strict mode we have to make a closure and call eval() inside it while paused in the debugger. http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js#L409 The closure captures the var and it is thrown away each time. We could potentially reuse it while paused. But we really just need JSC support to avoid this hack. It we could use with() while in strict mode, then we wouldn't need the closure.
So this code has changed a bunch. I believe doing `var x` will work outside of strict mode code. Using `let x` probably won't work in strict or non-strict. And `var` probably won't work in strict mode. If we wanted this to work, we'd probably have to do some really tricky stuff. How do debuggers like lldb make this work? They store the result in a temporary variable, or you can create custom variables. Maybe we could approach this problem from that angle.