Bug 118314

Summary: Web Inspector: cannot access `arguments` object from the console while debugger is paused
Product: WebKit Reporter: Paul Miller <paul+bugs>
Component: Web InspectorAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: burg, joepeck, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Right arguments in the sidebar none

Description Paul Miller 2013-07-02 11:57:49 PDT
set a breakpoint in function, execute `arguments` in console. You will get an array with 22 elements:

[function eval() {
    [native code]
}, "arguments", function $$() { [Command Line API] }, function $x() { [Command Line API] }, function dir() { [Command Line API] }, function dirxml() { [Command Line API] }, function keys() { [Command Line API] }, function values() { [Command Line API] }, function profile() { [Command Line API] }, function profileEnd() { [Command Line API] }, function monitorEvents() { [Command Line API] }, function unmonitorEvents() { [Command Line API] }, function inspect() { [Command Line API] }, function copy() { [Command Line API] }, function clear() { [Command Line API] }, function getEventListeners() { [Command Line API] }, 
<body style>…</body>
, undefined, undefined, undefined, undefined, undefined]
Comment 1 Radar WebKit Bug Importer 2013-07-02 11:58:14 PDT
<rdar://problem/14335152>
Comment 2 Timothy Hatcher 2013-07-02 12:01:19 PDT
Yep, this was a sacrifice to make strict mode debugging work.
Comment 3 Nikita Vasilyev 2015-01-08 18:50:06 PST
Created attachment 244313 [details]
Right arguments in the sidebar

How come we can show the right arguments on the right sidebar but the wrong ones in the console and while hovering over `arguments` in the source code?
Comment 4 Joseph Pecoraro 2015-01-08 19:13:01 PST
Evaluating in the console is doing some very non-trivial stuff. Check out InjectedScript.prototype._evaluteOn in Source/JavaScriptCore/inspector/InjectedScriptSource.js.

If you say "arguments" in the console it is boiling down to something like this:

> var expressionFunctionBody = "" +
>     "var global = Function('return this')() || (1, eval)('this');" +
>     "var __originalEval = global.eval; global.eval = __eval;" +
>     "try { return eval(__currentExpression); }" +
>     "finally { global.eval = __originalEval; }";
> 
> var expressionFunctionString = "(function(__eval, __currentExpression, " + parameterNames.join(", ") + ") { " + expressionFunctionBody + " })";
> var boundExpressionFunctionString = "(function(__function, __thisObject) { return function() { return __function.apply(__thisObject, arguments) }; })(" + expressionFunctionString + ", this)";
> 
> var parameters = [InjectedScriptHost.evaluate, expression];
> var expressionFunction = evalFunction.call(object, boundExpressionFunctionString);
> var result = expressionFunction.apply(null, parameters);

You may be able to see some of this if you sprinkle around some "//# sourceURL=foo".

The Scope Chain sidebar values are populated from the actual scope chain objects from JavaScriptCore.
Comment 5 Timothy Hatcher 2015-01-10 10:17:37 PST

*** This bug has been marked as a duplicate of bug 121208 ***