Bug 87192
Summary: | Web Inspector: Expose function scope / closure data | ||
---|---|---|---|
Product: | WebKit | Reporter: | Peter Rybin <prybin> |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | UNCONFIRMED | ||
Severity: | Normal | CC: | ggaren, joepeck, mark.lam, ngockhanhlam87, oliver, prybin, yurys |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Peter Rybin
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 | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Peter Rybin
Note that WebKit Remote Debugging protocol is about to include this feature as an optional one.
Peter Rybin
See https://bugs.webkit.org/show_bug.cgi?id=86861
Peter Rybin
This bug might be no-op and only a formal one since there is
JSC::JSFunction::scope in public API.
Geoffrey Garen
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
(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
> 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
they're kind of screwed.
/me thinks...
Peter Rybin
(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
(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
(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
We recompile all the functions when the debugger attaches/detaches using Debugger::recompileAllJSFunctions. Dosen't that help here?
Geoffrey Garen
> 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).