replacer-array-proxy.js (969B)
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 Array proxy replacer serves as a filter of object keys. 7 info: | 8 JSON.stringify ( value [ , replacer [ , space ] ] ) 9 10 [...] 11 4. If Type(replacer) is Object, then 12 a. If IsCallable(replacer) is true, then 13 i. Let ReplacerFunction be replacer. 14 b. Else, 15 i. Let isArray be ? IsArray(replacer). 16 17 IsArray ( argument ) 18 19 [...] 20 3. If argument is a Proxy exotic object, then 21 a. If argument.[[ProxyHandler]] is null, throw a TypeError exception. 22 b. Let target be argument.[[ProxyTarget]]. 23 c. Return ? IsArray(target). 24 features: [Proxy] 25 ---*/ 26 27 var replacer = new Proxy(['b'], {}); 28 29 assert.sameValue(JSON.stringify({a: 1, b: 2}, replacer), '{"b":2}'); 30 assert.sameValue(JSON.stringify({b: {a: 3, b: 4}}, replacer), '{"b":{"b":4}}'); 31 32 reportCompare(0, 0);