-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for stringify array replacer #725
- Per spec, Numbers in an array replacer should be converted to strings prior to adding to the property list - Duplicates should be removed during construction of the property list - Changed some variables declared as List to Collection instead because that is sufficient for how they are being used - Moved List to array conversion from happening in every iteration of the jo method to being called once in the stringify method - Convert strings items representing integers to their Integer value for correct property lookup
- Loading branch information
1 parent
522b92a
commit 2a3fd06
Showing
2 changed files
with
54 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
// This test is a stand-in for the following until they are run by the Test262SuiteTest. | ||
// https://github.com/tc39/test262/blob/70bc32edab22b44db9d671ce505db8842ae200b6/test/built-ins/JSON/stringify/replacer-array-duplicates.js | ||
// https://github.com/tc39/test262/blob/70bc32edab22b44db9d671ce505db8842ae200b6/test/built-ins/JSON/stringify/replacer-array-number.js | ||
|
||
|
||
function assertEqual(actual, expected) { | ||
if (actual !== expected) throw 'expected: <' + expected + '> but found <' + actual + '>'; | ||
} | ||
|
||
var obj = {"0":1, "1":2, "2":3, "name":4}; | ||
var actual = JSON.stringify(obj, ["0", "1", "name", "name"]); | ||
var expected = JSON.stringify({"0":1, "1":2, "name":4}); | ||
assertEqual(expected, actual); | ||
|
||
var obj = {"2":"b","3":"c","1":"a"}; | ||
var expected = JSON.stringify({"1":"a","2":"b","3":"c"}); | ||
|
||
var actual = JSON.stringify(obj, ["1","2","3"]); | ||
assertEqual(expected, actual); | ||
|
||
var actual = JSON.stringify(obj, [1,2,3]); | ||
assertEqual(expected, actual); | ||
|
||
"success" |