Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Unified Diff: test/mjsunit/json.js

Issue 562034: Updated JSON.stringify to newest version of ES5. (Closed)
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/json-delay.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « src/json-delay.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698