Chromium Code Reviews| Index: test/mjsunit/json.js |
| diff --git a/test/mjsunit/json.js b/test/mjsunit/json.js |
| index 56562e7694b28423749811829d0b9b760584d2c4..5af6a568ef2edaffe56d7409fb9e7690a745347f 100644 |
| --- a/test/mjsunit/json.js |
| +++ b/test/mjsunit/json.js |
| @@ -200,8 +200,10 @@ TestInvalid('"Unterminated string'); |
| TestInvalid('"Unterminated string\\"'); |
| TestInvalid('"Unterminated string\\\\\\"'); |
| -// Test bad JSON that would be good JavaScript (ES5). |
| +// JavaScript RegExp literals not valid in JSON. |
| +TestInvalid('/true/'); |
| +// Test bad JSON that would be good JavaScript (ES5). |
| TestInvalid("{true:42}"); |
| TestInvalid("{false:42}"); |
| TestInvalid("{null:42}"); |
| @@ -211,7 +213,6 @@ TestInvalid("{0:42}"); |
| TestInvalid("{-1:42}"); |
| // Test for trailing garbage detection. |
| - |
| TestInvalid('42 px'); |
| TestInvalid('42 .2'); |
| TestInvalid('42 2'); |
| @@ -277,9 +278,26 @@ assertEquals('{\n "a": "b",\n "c": "d"\n}', |
| JSON.stringify({a:"b",c:"d"}, null, 1)); |
| assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x'])); |
| +// The gap is capped at ten characters if specified as string. |
| +assertEquals('{\n "a": "b",\n "c": "d"\n}', |
| + JSON.stringify({a:"b",c:"d"}, null, |
| + " /*characters after 10th*/")); |
| + |
| +//The gap is capped at ten characters if specified as number. |
| +assertEquals('{\n "a": "b",\n "c": "d"\n}', |
| + JSON.stringify({a:"b",c:"d"}, null, 15)); |
| + |
| +// Replaced wrapped primitives are unwrapped. |
| +function newx(k, v) { return (k == "x") ? new v(42) : v; } |
| +assertEquals('{"x":"42"}', JSON.stringify({x: String}, newx)); |
| +assertEquals('{"x":42}', JSON.stringify({x: Number}, newx)); |
| +assertEquals('{"x":true}', JSON.stringify({x: Boolean}, newx)); |
| + |
| assertEquals(undefined, JSON.stringify(undefined)); |
| assertEquals(undefined, JSON.stringify(function () { })); |
|
Rico
2010/02/03 12:57:23
Maybe check for stringify on an array with undefin
Lasse Reichstein
2010/02/03 13:18:30
Check added for behavior of undefined and function
|
| +assertThrows("var a = [];a[0] = a;JSON.stringify(a);", TypeError); |
|
Rico
2010/02/03 12:57:23
Don't we check the same in line 269
Lasse Reichstein
2010/02/03 13:18:30
We do. Removed.
|
| + |
| TestInvalid('1); throw "foo"; (1'); |
| var x = 0; |