Bug 158033

Summary: Web Inspector: JSON Parse error message should include more useful details about what caused parsing to fail
Product: WebKit Reporter: BJ Burg <bburg>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ggaren, jfbastien, joepeck, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   

Description BJ Burg 2016-05-24 11:43:33 PDT
Currently, an SyntaxError is thrown, but the line and column properties are set to the call site of JSON.parse().
What I really want to know is the string that failed to parse, and where within string parsing failed (approximately).
If the parse error says 'invalid number', I would expect to be able to figure out where it died.
This is kind of difficult since the argument to JSON.parse is generally not a resource we already have in a text editor, so we'd need to figure out how to display that text (which could be megabytes of JSON).
Comment 1 BJ Burg 2016-05-27 07:18:03 PDT
Ping for import.
Comment 2 Radar WebKit Bug Importer 2016-05-27 07:20:50 PDT
<rdar://problem/26516676>
Comment 3 JF Bastien 2016-10-04 16:24:04 PDT
This is pretty bad:
  jsc -e 'JSON.parse("{\"a\": {},}")'
  Exception: SyntaxError: JSON Parse error: Property name must be a string literal
  at [Command Line]:1
  parse@[native code]
  global code@[Command Line]:1:11

Looks like it comes from JSC:
  Source/JavaScriptCore/runtime/LiteralParser.cpp:                    m_parseErrorMessage = ASCIILiteral("Property name must be a string literal");

There are some tests for it:
  LayoutTests/js/dom/JSON-parse-expected.txt:PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Property name must be a string literal.
  LayoutTests/js/dom/JSON-parse-expected.txt:PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Property name must be a string literal.

I may un-lazy and try to improve it at some point...