summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/JSON/cyclic-stringify-unrelated.js
blob: 127c2ca6004af2dc51d7b0876faf7cca7bd05900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/

//-----------------------------------------------------------------------------
var BUGNUMBER = 1197097;
var summary = "JSON.stringify shouldn't use context-wide cycle detection";

print(BUGNUMBER + ": " + summary);

/**************
 * BEGIN TEST *
 **************/

var arr;

// Nested yet separate JSON.stringify is okay.
arr = [{}];
assertEq(JSON.stringify(arr, function(k, v) {
  assertEq(JSON.stringify(arr), "[{}]");
  return v;
}), "[{}]");

// SpiderMonkey censors cycles in array-joining.  This mechanism must not
// interfere with the cycle detection in JSON.stringify.
arr = [{
  toString: function() {
    var s = JSON.stringify(arr);
    assertEq(s, "[{}]");
    return s;
  }
}];
assertEq(arr.join(), "[{}]");

/******************************************************************************/

if (typeof reportCompare === "function")
  reportCompare(true, true);

print("Tests complete");