[Webkit-unassigned] [Bug 141737] Web Inspector: Typing object literal in the console causes a parse error

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Feb 18 01:17:37 PST 2015


https://bugs.webkit.org/show_bug.cgi?id=141737

--- Comment #2 from Joseph Pecoraro <joepeck at webkit.org> ---
(In reply to comment #0)
> Created attachment 246785 [details]
> A screenshot
> 
> > {a: 1, b: 2}
> < SyntaxError: Unexpected token ':'. Parse error.

This is because typing in the console is treated as a complete program. If this is treated as a program it is parsed as an anonymous block with a label.

That is why "{a: 1}" is treated as "1" instead of Object. Because it was a program, with a statement of just "1".

We've debated in the past whether or not we should or even can detect. A simple workaround for developers is to wrap in parenthesis and force it to evaluate as an expression. E.g. "({a:1, b:2})". Note this is used to be a common practice when parsing XHR JSON responses before JSON.parse, people would "obj = eval( '(' + str + ')' )" because of the same issue.

That said, I think we've had enough people be confused by this that we should probably just fix it.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20150218/8f35ebb6/attachment-0002.html>


More information about the webkit-unassigned mailing list