Bug 47862 - Web Inspector: js executed in the console doesn't trigger strict mode
Summary: Web Inspector: js executed in the console doesn't trigger strict mode
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: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-18 16:46 PDT by Oliver Hunt
Modified: 2014-12-15 22:55 PST (History)
11 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Hunt 2010-10-18 16:46:52 PDT
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.
Comment 1 Pavel Feldman 2010-10-19 01:17:52 PDT
That's the way we wrap it:
        if (!isEvalOnCallFrame)
            expression = "with (window) {\n" + expression + "\n} ";
        expression = "with (window.console._commandLineAPI) {\n" + expression + "\n}";
Comment 2 Oliver Hunt 2010-10-19 15:10:44 PDT
(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?
Comment 3 Pavel Feldman 2010-10-19 23:58:58 PDT
(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.
Comment 4 steve_sims7 2011-02-03 14:08:51 PST
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.  :-(