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

Unified Diff: test/mjsunit/json.js

Issue 6930006: Make RegExp objects not callable. (Closed)
Patch Set: Address review comments Created 9 years, 7 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/runtime.cc ('k') | test/mjsunit/number-string-index-call.js » ('j') | 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 812ffeb5a7ba3c74ca51f4cec34ee32945a88686..8b06a34aa088f0177486c1861034c9829f56662b 100644
--- a/test/mjsunit/json.js
+++ b/test/mjsunit/json.js
@@ -67,7 +67,7 @@ var d4 = {toJSON: Date.prototype.toJSON,
valueOf: "not callable",
toString: "not callable either",
toISOString: function() { return 42; }};
-assertThrows("d4.toJSON()", TypeError); // ToPrimitive throws.
+assertThrows("d4.toJSON()", TypeError); // ToPrimitive throws.
var d5 = {toJSON: Date.prototype.toJSON,
valueOf: "not callable",
@@ -196,9 +196,6 @@ TestInvalid('"Unterminated string');
TestInvalid('"Unterminated string\\"');
TestInvalid('"Unterminated string\\\\\\"');
-// JavaScript RegExp literals not valid in JSON.
-TestInvalid('/true/');
-
// Test bad JSON that would be good JavaScript (ES5).
TestInvalid("{true:42}");
TestInvalid("{false:42}");
@@ -382,7 +379,7 @@ var reJSON = /Is callable/;
reJSON.toJSON = function() { return "has toJSON"; };
assertEquals(
- '[37,null,1,"foo","37","true",null,"has toJSON",null,"has toJSON"]',
+ '[37,null,1,"foo","37","true",null,"has toJSON",{},"has toJSON"]',
JSON.stringify([num37, numFoo, numTrue,
strFoo, str37, strTrue,
func, funcJSON, re, reJSON]));
@@ -397,6 +394,9 @@ var callCount = 0;
var counter = { get toJSON() { getCount++;
return function() { callCount++;
return 42; }; } };
+
+// RegExps are not callable, so they are stringified as objects.
+assertEquals('{}', JSON.stringify(/regexp/));
assertEquals('42', JSON.stringify(counter));
assertEquals(1, getCount);
assertEquals(1, callCount);
@@ -419,9 +419,9 @@ assertEquals('"42"', JSON.stringify(falseNum));
// We don't currently allow plain properties called __proto__ in JSON
// objects in JSON.parse. Instead we read them as we would JS object
// literals. If we change that, this test should change with it.
-//
-// Parse a non-object value as __proto__. This must not create a
-// __proto__ property different from the original, and should not
+//
+// Parse a non-object value as __proto__. This must not create a
+// __proto__ property different from the original, and should not
// change the original.
var o = JSON.parse('{"__proto__":5}');
assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed.
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/number-string-index-call.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698