-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSON.parse(): bail if we don't get a string key (in non-relaxed mode)
- Loading branch information
1 parent
693bd55
commit 4dd95bf
Showing
2 changed files
with
25 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
// JSON shouldn't print stuff like __proto__ and constructor | ||
|
||
function A() {} | ||
function A() {} | ||
var a = new A(); | ||
|
||
result = JSON.stringify(a)=="{}"; | ||
|
||
function assertEq(got, expected) { | ||
if (typeof got !== typeof expected) | ||
throw new Error("mismatch, " + typeof got + " != " + typeof expected); | ||
|
||
if (typeof got === "object") | ||
// note: doesn't check keys in `got` | ||
for (var k in expected) | ||
assertEq(got[k], expected[k]); | ||
else if (got !== expected) | ||
throw new Error("mismatch, " + got + " != " + expected); | ||
} | ||
|
||
// no exceptions thrown: | ||
assertEq(JSON.parse('{"a": 1}'), {"a": 1}); | ||
assertEq(JSON.parse('["4", 5, "six"]'), ["4", 5, "six"]); | ||
assertEq(JSON.parse('["4", 5, "six", {"x": 5}]'), ["4", 5, "six", {"x": 5}]); | ||
assertEq(JSON.parse('""'), ""); | ||
assertEq(JSON.parse('5'), 5); | ||
assertEq(JSON.parse('[]'), []); | ||
assertEq(JSON.parse('{}'), {}); |