Bug 87192 - Web Inspector: Expose function scope / closure data
Summary: Web Inspector: Expose function scope / closure data
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-22 18:24 PDT by Peter Rybin
Modified: 2019-06-09 19:14 PDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Rybin 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.
Comment 1 Peter Rybin 2012-05-22 18:25:38 PDT
Note that WebKit Remote Debugging protocol is about to include this feature as an optional one.
Comment 2 Peter Rybin 2012-05-22 19:45:23 PDT
See https://bugs.webkit.org/show_bug.cgi?id=86861
Comment 3 Peter Rybin 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.
Comment 4 Geoffrey Garen 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.
Comment 5 Oliver Hunt 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
Comment 6 Geoffrey Garen 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?
Comment 7 Oliver Hunt 2012-05-23 16:37:45 PDT
they're kind of screwed.

/me thinks...
Comment 8 Peter Rybin 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).
Comment 9 Oliver Hunt 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.
Comment 10 Peter Rybin 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).
Comment 11 Timothy Hatcher 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?
Comment 12 Geoffrey Garen 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).