RESOLVED FIXED 141737
Web Inspector: Typing object literal in the console causes a parse error
https://bugs.webkit.org/show_bug.cgi?id=141737
Summary Web Inspector: Typing object literal in the console causes a parse error
Nikita Vasilyev
Reported 2015-02-17 19:11:13 PST
Created attachment 246785 [details] A screenshot > {a: 1, b: 2} < SyntaxError: Unexpected token ':'. Parse error. Note that `obj = {a: 1, b: 2}` doesn't throw any errors.
Attachments
A screenshot (27.38 KB, image/png)
2015-02-17 19:11 PST, Nikita Vasilyev
no flags
[PATCH] Proposed Fix - For Object Literals (7.12 KB, patch)
2015-12-15 18:35 PST, Joseph Pecoraro
buildbot: commit-queue-
Archive of layout-test-results from ews103 for mac-yosemite (951.45 KB, application/zip)
2015-12-15 19:14 PST, Build Bot
no flags
Archive of layout-test-results from ews113 for mac-yosemite (745.24 KB, application/zip)
2015-12-15 19:18 PST, Build Bot
no flags
Archive of layout-test-results from ews105 for mac-yosemite-wk2 (924.61 KB, application/zip)
2015-12-15 19:20 PST, Build Bot
no flags
[PATCH] Proposed Fix - For Object Literals (7.28 KB, patch)
2015-12-15 23:19 PST, Joseph Pecoraro
no flags
Radar WebKit Bug Importer
Comment 1 2015-02-17 19:11:34 PST
Joseph Pecoraro
Comment 2 2015-02-18 01:17:37 PST
(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.
Timothy Hatcher
Comment 3 2015-03-24 09:58:35 PDT
My suggestion to fix this would be to try evaluation as-is, if there is a syntax error, try evaluation wrapped in ().
Joseph Pecoraro
Comment 4 2015-03-24 12:10:36 PDT
I believe this also affects class expressions. > js> class foo {}; > <- SyntaxError: Unexpected keyword 'class'. Class declaration is not allowed in a lexically nested statement. Which is pretty annoying. I end up having to type `foo = class foo {}`.
Timothy Hatcher
Comment 5 2015-03-24 15:38:49 PDT
Even more annoying now that we have $n.
Timothy Hatcher
Comment 6 2015-04-22 07:43:32 PDT
*** Bug 144034 has been marked as a duplicate of this bug. ***
Joseph Pecoraro
Comment 7 2015-12-15 18:35:29 PST
Created attachment 267417 [details] [PATCH] Proposed Fix - For Object Literals Basing this off of Blink's recent change that does the same thing. I think it is a good idea, and easy to opt-out for those that really understand what they are doing.
Joseph Pecoraro
Comment 8 2015-12-15 18:39:15 PST
(In reply to comment #7) > Created attachment 267417 [details] > [PATCH] Proposed Fix - For Object Literals > > Basing this off of Blink's recent change that does the same thing. Which was: <https://twitter.com/ChromeDevTools/status/676531222609182720> <https://chromium.googlesource.com/chromium/src.git/+/4fd348fdb9c0b3842829acdfb2b82c86dacd8e0a%5E%21/#F2>
Joseph Pecoraro
Comment 9 2015-12-15 18:41:29 PST
Apparently node.js's interpreter does the same thing.
Build Bot
Comment 10 2015-12-15 19:14:50 PST
Comment on attachment 267417 [details] [PATCH] Proposed Fix - For Object Literals Attachment 267417 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/564892 Number of test failures exceeded the failure limit.
Build Bot
Comment 11 2015-12-15 19:14:53 PST
Created attachment 267421 [details] Archive of layout-test-results from ews103 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 12 2015-12-15 19:18:53 PST
Comment on attachment 267417 [details] [PATCH] Proposed Fix - For Object Literals Attachment 267417 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/564884 Number of test failures exceeded the failure limit.
Build Bot
Comment 13 2015-12-15 19:18:56 PST
Created attachment 267422 [details] Archive of layout-test-results from ews113 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews113 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 14 2015-12-15 19:20:18 PST
Comment on attachment 267417 [details] [PATCH] Proposed Fix - For Object Literals Attachment 267417 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.webkit.org/results/564899 Number of test failures exceeded the failure limit.
Build Bot
Comment 15 2015-12-15 19:20:20 PST
Created attachment 267423 [details] Archive of layout-test-results from ews105 for mac-yosemite-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews105 Port: mac-yosemite-wk2 Platform: Mac OS X 10.10.5
Joseph Pecoraro
Comment 16 2015-12-15 23:19:05 PST
Created attachment 267435 [details] [PATCH] Proposed Fix - For Object Literals
WebKit Commit Bot
Comment 17 2015-12-16 09:40:42 PST
Comment on attachment 267435 [details] [PATCH] Proposed Fix - For Object Literals Clearing flags on attachment: 267435 Committed r194149: <http://trac.webkit.org/changeset/194149>
WebKit Commit Bot
Comment 18 2015-12-16 09:40:47 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.