Bug 53072 - Web Inspector: evaluate in console may not work when window.console is substituted
Summary: Web Inspector: evaluate in console may not work when window.console is substi...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Pavel Podivilov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-25 02:41 PST by Pavel Podivilov
Modified: 2011-01-26 10:26 PST (History)
10 users (show)

See Also:


Attachments
Patch. (1.39 KB, patch)
2011-01-25 02:42 PST, Pavel Podivilov
no flags Details | Formatted Diff | Diff
Added test. (4.54 KB, patch)
2011-01-25 07:18 PST, Pavel Podivilov
no flags Details | Formatted Diff | Diff
Patch. (4.45 KB, patch)
2011-01-26 01:45 PST, Pavel Podivilov
pfeldman: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Podivilov 2011-01-25 02:41:56 PST
Web Inspector: evaluate in console may not work when window.console is substituted

Initial bug - http://code.google.com/p/chromium/issues/detail?id=70629.
Comment 1 Pavel Podivilov 2011-01-25 02:42:48 PST
Created attachment 80039 [details]
Patch.
Comment 2 Yury Semikhatsky 2011-01-25 04:24:10 PST
Comment on attachment 80039 [details]
Patch.

Can you provide a test for this?
Comment 3 Yury Semikhatsky 2011-01-25 04:27:19 PST
Comment on attachment 80039 [details]
Patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=80039&action=review

> Source/WebCore/inspector/InjectedScriptSource.js:261
> +        expression = "with ((window && window.console && window.console._commandLineAPI) || {}) {\n" + expression + "\n}";

If .console is undefined then this method will fail at line 256 and not get here:

inspectedWindow.console._commandLineAPI = this._commandLineAPI;
Comment 4 Pavel Podivilov 2011-01-25 05:03:19 PST
(In reply to comment #3)
> (From update of attachment 80039 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=80039&action=review
> 
> > Source/WebCore/inspector/InjectedScriptSource.js:261
> > +        expression = "with ((window && window.console && window.console._commandLineAPI) || {}) {\n" + expression + "\n}";
> 
> If .console is undefined then this method will fail at line 256 and not get here:
> 
> inspectedWindow.console._commandLineAPI = this._commandLineAPI;

Not undefined, but substituted. In any case this patch looks safe and fixes the problem.
Comment 5 Pavel Podivilov 2011-01-25 07:18:30 PST
Created attachment 80063 [details]
Added test.
Comment 6 Yury Semikhatsky 2011-01-25 08:01:51 PST
Comment on attachment 80063 [details]
Added test.

View in context: https://bugs.webkit.org/attachment.cgi?id=80063&action=review

> LayoutTests/inspector/console-substituted.html:21
> +    InspectorTest.evaluateInConsole("setTimeout(deleteConsole, 0)", step1);

Why do you need setTimeout here?

> LayoutTests/inspector/console-substituted.html:31
> +        InspectorTest.evaluateInConsole("setTimeout(substituteConsole, 0)", step3);

The same question for this call.

> Source/WebCore/inspector/InjectedScriptSource.js:261
> +            expression = "with (window || {}) {\n" + expression + "\n} ";

is there a real scenario when there are no window?
Comment 7 Pavel Podivilov 2011-01-25 08:08:26 PST
(In reply to comment #6)
> (From update of attachment 80063 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=80063&action=review
> 
> > LayoutTests/inspector/console-substituted.html:21
> > +    InspectorTest.evaluateInConsole("setTimeout(deleteConsole, 0)", step1);
> 
> Why do you need setTimeout here?
> 
> > LayoutTests/inspector/console-substituted.html:31
> > +        InspectorTest.evaluateInConsole("setTimeout(substituteConsole, 0)", step3);
> 
> The same question for this call.
> 
> > Source/WebCore/inspector/InjectedScriptSource.js:261
> > +            expression = "with (window || {}) {\n" + expression + "\n} ";
> 
> is there a real scenario when there are no window?

Sure, you may be inside a closure created in function with "window" argument, which is not used by that closure. In that case "window" will be undefined (v8 will drop it).
Comment 8 Pavel Podivilov 2011-01-26 01:45:05 PST
(In reply to comment #6)
> (From update of attachment 80063 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=80063&action=review
> 
> > LayoutTests/inspector/console-substituted.html:21
> > +    InspectorTest.evaluateInConsole("setTimeout(deleteConsole, 0)", step1);
> 
> Why do you need setTimeout here?

Replaced with direct call.

> 
> > LayoutTests/inspector/console-substituted.html:31
> > +        InspectorTest.evaluateInConsole("setTimeout(substituteConsole, 0)", step3);
> 
> The same question for this call.

Replaced with direct call.

> 
> > Source/WebCore/inspector/InjectedScriptSource.js:261
> > +            expression = "with (window || {}) {\n" + expression + "\n} ";
> 
> is there a real scenario when there are no window?

Fixed. Since this is behind !isEvalOnCallFrame, there is probably no such scenario.
Comment 9 Pavel Podivilov 2011-01-26 01:45:57 PST
Created attachment 80176 [details]
Patch.
Comment 10 Pavel Feldman 2011-01-26 02:16:59 PST
Comment on attachment 80176 [details]
Patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=80176&action=review

> Source/WebCore/inspector/InjectedScriptSource.js:257
> +            inspectedWindow.console._commandLineAPI = this._commandLineAPI;

Nit: defining non-enumerable property would be even better.
Comment 11 Pavel Podivilov 2011-01-26 10:26:09 PST
Committed r76699: <http://trac.webkit.org/changeset/76699>