Debian Codegraph @

js/src/tests/test262/built-ins/JSON/stringify/replacer-array-undefined.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-json.stringify
5 description: >
6 Undefined values in replacer array are ignored.
7 info: |
8 JSON.stringify ( value [ , replacer [ , space ] ] )
9
10 [...]
11 4. If Type(replacer) is Object, then
12 [...]
13 4. Repeat, while k < len,
14 a. Let v be ? Get(replacer, ! ToString(k)).
15 [...]
16 f. If item is not undefined and item is not currently an element of PropertyList, then
17 i. Append item to the end of PropertyList.
18 ---*/
19
20 assert.sameValue(JSON.stringify({undefined: 1}, [undefined]), '{}');
21 assert.sameValue(JSON.stringify({key: 1, undefined: 2}, [,,,]), '{}');
22
23 var sparse = new Array(3);
24 sparse[1] = 'key';
25
26 assert.sameValue(
27 JSON.stringify({undefined: 1, key: 2}, sparse),
28 '{"key":2}'
29 );
30
31 reportCompare(0, 0);