-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cycle checks in
JSON.stringify
Prior to this commit, the following program will erroneously fail, with a `circular dependency` error: const template = { foo: "foo", bar: "bar", }; const x = []; x.push(template); x.push(template); x.push(template); x.push(template); x.push(template); x.push(template); console.log(JSON.stringify(x)); The logic for testing for circular dependencies didn't correctly manage the stack state and therefore pushing the same object multiple times to an array resulted in a false-positive cycle. Cycles can only really happen in Arrays and Objects. Thsi commit solidifies the approach to checking for cycles, by scoping cycle checks and cycle stack management to the `MapAccess` and `SeqAccess` structs.
- Loading branch information
1 parent
de8431f
commit 8cddaab
Showing
3 changed files
with
136 additions
and
40 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
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,15 @@ | ||
const template = { | ||
foo: "foo", | ||
bar: "bar", | ||
}; | ||
const x = []; | ||
|
||
x.push(template); | ||
x.push(template); | ||
x.push(template); | ||
x.push(template); | ||
x.push(template); | ||
x.push(template); | ||
|
||
|
||
console.log(JSON.stringify(x)); |