Bug 47862
Summary: | Web Inspector: js executed in the console doesn't trigger strict mode | ||
---|---|---|---|
Product: | WebKit | Reporter: | Oliver Hunt <oliver> |
Component: | Web Inspector (Deprecated) | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | Normal | CC: | apavlov, burg, bweinstein, joepeck, keishi, loislo, pfeldman, pmuellr, rik, steve_sims7, yurys |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | All | ||
OS: | All |
Oliver Hunt
Entering this code
(function(){ "use strict"; eval('with({ }) { }') })()
in the inspector console should produce a syntax error, yet it is not, which implies that the inspector is doing something bizarre to the code that i enter into the console.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Pavel Feldman
That's the way we wrap it:
if (!isEvalOnCallFrame)
expression = "with (window) {\n" + expression + "\n} ";
expression = "with (window.console._commandLineAPI) {\n" + expression + "\n}";
Oliver Hunt
(In reply to comment #1)
> That's the way we wrap it:
> if (!isEvalOnCallFrame)
> expression = "with (window) {\n" + expression + "\n} ";
> expression = "with (window.console._commandLineAPI) {\n" + expression + "\n}";
Are there any other changes that you make to it? And where do you actually cause it to be evaluated? are there any string replacements happening?
Pavel Feldman
(In reply to comment #2)
> (In reply to comment #1)
> > That's the way we wrap it:
> > if (!isEvalOnCallFrame)
> > expression = "with (window) {\n" + expression + "\n} ";
> > expression = "with (window.console._commandLineAPI) {\n" + expression + "\n}";
>
> Are there any other changes that you make to it? And where do you actually cause it to be evaluated? are there any string replacements happening?
There are no other changes, but the ones above are enough to prevent ToT from producing a syntax error:
<script>
with (window) {
(function(){ "use strict"; eval('with({ }) { }') })()
}
</script>
is processed silently.
steve_sims7
This inspector console behaviour is infectious, affecting not only immediate calls but seemingly the entire call stack, and can lead to the mistaken belief that WebKit doesn't properly support strict mode.
To test this out I entered the following two function definitions into both the WebKit inspector, and Firebug on Firefox 4:
function test() { "use strict"; return this === undefined }
function test2() { "use strict"; return test() }
Executing both these functions returns false in WebKit, and true in Firefox 4. Given the description given in other comments of how the WebKit inspector works I had thought that calling test2() would have returned true in WebKit.
I then attempted to simulate how the WebKit inspector operates by trying the following in Firefox 4:
with (window) { test(); }
with (window) { test2(); }
The first of these returned false, but the second (calling test2()) returns true, which is what I expected. (Attempting these in WebKit returns false for both.)
Sadly, and frustratingly, this behaviour would seem to make the inspector console useless when it comes to attempting to test or use strict mode code. :-(