Bug 83267 - Web Inspector: [JSC] "SyntaxError: 'with' statements are not valid in strict mode" when debugging strict mode script
Summary: Web Inspector: [JSC] "SyntaxError: 'with' statements are not valid in strict ...
Status: RESOLVED DUPLICATE of bug 65829
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: Macintosh Intel OS X 10.6
: P2 Normal
Assignee: Nobody
Keywords: InRadar
: 99305 (view as bug list)
Depends on:
Reported: 2012-04-05 04:48 PDT by Matthew Caruana Galizia
Modified: 2013-03-21 15:03 PDT (History)
17 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Caruana Galizia 2012-04-05 04:48:02 PDT
Steps to reproduce:

1) Write a script with the "strict mode" flag at the top
2) Insert a breakpoint in your script and run something that will trigger a pause on that breakpoint
3) Open the console and attempt to evaluate something while execution is paused e.g. type 'this' and hit enter

What should happen:

The entered script should be evaluated.

What happens instead:

A SyntaxError with the message "'with' statements are not valid in strict mode" is thrown.
Comment 1 Timothy Hatcher 2012-04-18 12:55:07 PDT
Comment 2 Gavin Kistner 2012-07-25 09:48:11 PDT
If there is a Radar bug for this, is it safe to say that the status is confirmed? This is a really bad problem, especially when attempting to debug new problems introduced specifically by Safari 6.0:
Comment 3 Timothy Hatcher 2012-10-15 11:43:23 PDT
*** Bug 99305 has been marked as a duplicate of this bug. ***
Comment 4 Yury Semikhatsky 2012-10-16 01:18:55 PDT
Works fine in tip of tree Chromium and 23.0.1271.26 (Official Build 160934) beta.
Comment 5 yeecheng.chin+webkit 2012-10-18 03:18:13 PDT
Hi, is there a reason this bug is still unconfirmed, let alone fixed? It's a pretty simple, very easy to reproduce bug, and significantly discourages developers from developing strict mode code on Safari.

Basically in the inspector console, there's a hidden object "window.console._commandLineAPI" that provides some console functionality like "$", "clear" etc. There's a function called evaluateOnCallFrame (defined in InjectedScriptSource.js) that the console tries to call to wrap whatever code it's calling in a with statement to wrap around the command line api object so those functions appear on the global scope. The with statement is obviously not legal in strict mode hence the exception.

I took at look at Chrome and couldn't figure out what they are doing differently but running code in console under strict mode does work, unlike Safari.

My suggestion is either:
1) Don't execute code under strict mode when in the inspector console. This is a one line fix in DebuggerCallFrame::evaluate. Basically instead of passing along the intended strict mode setting, just pass false to EvalExecutable::create. This is kind of a hack as the console won't be giving you the correct results (e.g. error when you try to call arguments.callee), but at least the console will work!
2) Find some better ways to wrap the command line API. I'm not sure what Chrome does, but maybe we do can something like the following instead of using a with statement to wrap?
  (function() {
    var $ = window.console._commandLineAPI.$;
    var $$ = window.console._commandLineAPI.$$;
    var clear = window.console._commandLineAPI.clear;
    // The actual code the console is trying to run
    // This has an issue of masking out the global variables and other stack variables but there are ways to get around that

Either way I think it's better to get something working than the console being plain broken under strict mode!
Comment 6 Øyvind Smestad 2012-12-10 04:24:51 PST
This seems to be a duplicate of: https://bugs.webkit.org/show_bug.cgi?id=65829
Comment 7 JP Grace 2012-12-18 13:16:19 PST
How is this still not fixed?  It appears to be a duplicate of: https://bugs.webkit.org/show_bug.cgi?id=65829 that dates back to over a year ago.  I cannot debug anything in Safari as a result of this bug.  It's embarrassing.  Can we please prioritize this?
Comment 8 Timothy Hatcher 2013-03-21 15:03:53 PDT

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