mirror of https://github.com/svaarala/duktape.git
Browse Source
Add a byte offset to JSON.parse() syntax error to make it easier to debug broken JSON.pull/85/head
Sami Vaarala
10 years ago
7 changed files with 74 additions and 13 deletions
@ -0,0 +1,34 @@ |
|||
/* |
|||
* Test JSON error byte offset |
|||
*/ |
|||
|
|||
/*--- |
|||
{ |
|||
"custom": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
SyntaxError: invalid json (at offset 11) |
|||
SyntaxError: invalid json (at offset 17) |
|||
===*/ |
|||
|
|||
function test1() { |
|||
JSON.parse('[ "\ufedcfoo"; ]'); // error at char offset 8, byte offset, 11
|
|||
} |
|||
|
|||
function test2() { |
|||
JSON.parse('{ "foo": "bar" } x'); // error at byte offset 17
|
|||
} |
|||
|
|||
try { |
|||
test1(); |
|||
} catch (e) { |
|||
print(e); |
|||
} |
|||
|
|||
try { |
|||
test2(); |
|||
} catch (e) { |
|||
print(e); |
|||
} |
Loading…
Reference in new issue