UNCONFIRMED 87192
Web Inspector: Expose function scope / closure data
https://bugs.webkit.org/show_bug.cgi?id=87192
Summary Web Inspector: Expose function scope / closure data
Peter Rybin
Reported 2012-05-22 18:24:43 PDT
In JavaScript function has its own context (i.e. it's a closure). While the language doesn't provide any external access to this context, debugger should expose it as it might be a valuable piece of data. In debug API there should be a way to access this inner context.
Attachments
Peter Rybin
Comment 1 2012-05-22 18:25:38 PDT
Note that WebKit Remote Debugging protocol is about to include this feature as an optional one.
Peter Rybin
Comment 2 2012-05-22 19:45:23 PDT
Peter Rybin
Comment 3 2012-05-23 16:06:08 PDT
This bug might be no-op and only a formal one since there is JSC::JSFunction::scope in public API.
Geoffrey Garen
Comment 4 2012-05-23 16:20:18 PDT
function->scope()->object will give you the scope in which a function was defined. Do you expect all functions to create closures all the time? That isn't usually the case.
Oliver Hunt
Comment 5 2012-05-23 16:22:11 PDT
(In reply to comment #4) > function->scope()->object will give you the scope in which a function was defined. > > Do you expect all functions to create closures all the time? That isn't usually the case. This si for the debugger. If the debugger is on everything gets a full and beautiful scope chain
Geoffrey Garen
Comment 6 2012-05-23 16:24:56 PDT
> If the debugger is on everything gets a full and beautiful scope chain What happens to functions that were created before the debugger was attached?
Oliver Hunt
Comment 7 2012-05-23 16:37:45 PDT
they're kind of screwed. /me thinks...
Peter Rybin
Comment 8 2012-05-23 16:38:51 PDT
(In reply to comment #5) > (In reply to comment #4) > > function->scope()->object will give you the scope in which a function was defined. > > > > Do you expect all functions to create closures all the time? That isn't usually the case. > > This si for the debugger. If the debugger is on everything gets a full and beautiful scope chain That's exactly what I need. But how end user can see this scope chain? I plan on showing the scope chain from WebInspector (Safari and Chrome) and from Java-based http://code.google.com/p/chromedevtools/ for every function value. So I'm working on adding scope chain to Remote Debugging protocol (with V8 engine right now).
Oliver Hunt
Comment 9 2012-05-23 16:42:39 PDT
(In reply to comment #7) > they're kind of screwed. > > /me thinks... Yeah they're screwed as their parent scope will be the first scope that was actually necessary. Presumably we could reify the entire scope chain when the debugger is enabled, but then you may get issues going backwards. Also in the absence pre-debugger functions won't have all the variables that were not captured initially.
Peter Rybin
Comment 10 2012-05-23 16:46:18 PDT
(In reply to comment #5) > (In reply to comment #4) > > function->scope()->object will give you the scope in which a function was defined. > > > > Do you expect all functions to create closures all the time? That isn't usually the case. > > This si for the debugger. If the debugger is on everything gets a full and beautiful scope chain That's exactly what I need. But how end user can see this scope chain? I plan on showing the scope chain from WebInspector (Safari and Chrome) and from Java-based http://code.google.com/p/chromedevtools/ for every function value. So I'm working on adding scope chain to Remote Debugging protocol (with V8 engine right now).
Timothy Hatcher
Comment 11 2012-05-23 18:36:51 PDT
We recompile all the functions when the debugger attaches/detaches using Debugger::recompileAllJSFunctions. Dosen't that help here?
Geoffrey Garen
Comment 12 2012-05-23 23:35:14 PDT
> We recompile all the functions when the debugger attaches/detaches using Debugger::recompileAllJSFunctions. Dosen't that help here? It helps, but there's an edge case: closures created before the recompile will capture only a subset of their variables (possibly 0).
Note You need to log in before you can comment on or make changes to this bug.