Skip to content

Commit cfbe26b

Browse files
committed
[GR-22127] Invert logic around JSON.parse errors - have Node.js/V8 syntax by default, Nashorn only behind flag.
PullRequest: js/1444
2 parents d07d39c + 6f12707 commit cfbe26b

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

graal-js/src/com.oracle.truffle.js.parser/src/com/oracle/truffle/js/parser/json/JSONParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ private ParserException numberError(final int start) {
474474
}
475475

476476
private ParserException expectedError(final int start, final String expected, final String found) {
477-
return context.isOptionV8CompatibilityMode()
478-
? expectedErrorV8(start, found)
479-
: error(parserMessage("expected", expected, found), start);
477+
return context.isOptionNashornCompatibilityMode()
478+
? error(parserMessage("expected", expected, found), start)
479+
: expectedErrorV8(start, found);
480480
}
481481

482482
private static ParserException expectedErrorV8(final int start, final String found) {

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/builtins/CommonJSRequireTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,7 @@ public void testLoadBrokenJson() {
346346
throw new AssertionError("Unexpected exception " + t);
347347
}
348348
assertEquals(t.getMessage(),
349-
"SyntaxError: Invalid JSON: <json>:1:1 Expected " +
350-
", or } but found n\n" +
351-
"{not_a_valid:##json}\n" +
352-
" ^");
349+
"SyntaxError: Unexpected token n in JSON at position 1");
353350
}
354351
}
355352

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/helper/TruffleJSONParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ protected Object error(String message) {
487487

488488
@TruffleBoundary
489489
public static RuntimeException createSyntaxError(Exception ex, JSContext context) {
490-
throw context.isOptionV8CompatibilityMode() ? Errors.createSyntaxError(ex.getMessage().replace("\r\n", "\n"))
491-
: Errors.createSyntaxError("Invalid JSON: " +
492-
ex.getMessage().replace("\r\n", "\n"));
490+
String msg = ex.getMessage().replace("\r\n", "\n");
491+
throw context.isOptionNashornCompatibilityMode() ? Errors.createSyntaxError("Invalid JSON: " + msg)
492+
: Errors.createSyntaxError(msg);
493493
}
494494

495495
// ************************* Helper Functions ****************************************//

0 commit comments

Comments
 (0)