Summary: | Web Inspector: Typing object literal in the console causes a parse error | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Nikita Vasilyev <nvasilyev> | ||||||||||||||
Component: | Web Inspector | Assignee: | Nobody <webkit-unassigned> | ||||||||||||||
Status: | RESOLVED FIXED | ||||||||||||||||
Severity: | Normal | CC: | bburg, buildbot, commit-queue, graouts, joepeck, jonowells, mattbaker, nvasilyev, rniwa, timothy, webkit-bug-importer | ||||||||||||||
Priority: | P2 | Keywords: | InRadar | ||||||||||||||
Version: | 528+ (Nightly build) | ||||||||||||||||
Hardware: | All | ||||||||||||||||
OS: | All | ||||||||||||||||
Attachments: |
|
Description
Nikita Vasilyev
2015-02-17 19:11:13 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. My suggestion to fix this would be to try evaluation as-is, if there is a syntax error, try evaluation wrapped in (). 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 {}`.
Even more annoying now that we have $n. *** Bug 144034 has been marked as a duplicate of this bug. *** 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.
(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> Apparently node.js's interpreter does the same thing. 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. 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
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. 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
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. 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
Created attachment 267435 [details]
[PATCH] Proposed Fix - For Object Literals
Comment on attachment 267435 [details] [PATCH] Proposed Fix - For Object Literals Clearing flags on attachment: 267435 Committed r194149: <http://trac.webkit.org/changeset/194149> All reviewed patches have been landed. Closing bug. |