Debian Codegraph @

js/src/tests/test262/built-ins/JSON/stringify/replacer-function-array-circular.js

raw
1 // Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-serializejsonarray
5 description: >
6 Circular array value (returned from replacer function) throws a TypeError.
7 info: |
8 JSON.stringify ( value [ , replacer [ , space ] ] )
9
10 [...]
11 12. Return ? SerializeJSONProperty(the empty String, wrapper).
12
13 SerializeJSONProperty ( key, holder )
14
15 [...]
16 3. If ReplacerFunction is not undefined, then
17 a. Set value to ? Call(ReplacerFunction, holder, « key, value »).
18 [...]
19 10. If Type(value) is Object and IsCallable(value) is false, then
20 a. Let isArray be ? IsArray(value).
21 b. If isArray is true, return ? SerializeJSONArray(value).
22
23 SerializeJSONArray ( value )
24
25 1. If stack contains value, throw a TypeError exception because the structure is cyclical.
26 ---*/
27
28 var circular = [{}];
29 var circularReplacer = function(k, v) {
30 return circular;
31 };
32
33 assert.throws(TypeError, function() {
34 JSON.stringify(circular, circularReplacer);
35 });
36
37 reportCompare(0, 0);