RESOLVED FIXED Bug 47862
Web Inspector: js executed in the console doesn't trigger strict mode
https://bugs.webkit.org/show_bug.cgi?id=47862
Summary Web Inspector: js executed in the console doesn't trigger strict mode
Oliver Hunt
Reported 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.
Attachments
Pavel Feldman
Comment 1 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}";
Oliver Hunt
Comment 2 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?
Pavel Feldman
Comment 3 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.
steve_sims7
Comment 4 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. :-(
Note You need to log in before you can comment on or make changes to this bug.