Debian Codegraph @

js/src/tests/test262/built-ins/JSON/stringify/value-object-proxy.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-serializejsonobject
5 description: >
6 Proxy of an object is treated as regular object.
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 10. If Type(value) is Object and IsCallable(value) is false, then
17 [...]
18 c. Return ? SerializeJSONObject(value).
19
20 SerializeJSONObject ( value )
21
22 [...]
23 6. Else,
24 a. Let K be ? EnumerableOwnPropertyNames(value, "key").
25 7. Let partial be a new empty List.
26 8. For each element P of K, do
27 a. Let strP be ? SerializeJSONProperty(P, value).
28 features: [Proxy]
29 ---*/
30
31 var objectProxy = new Proxy({}, {
32 getOwnPropertyDescriptor: function() {
33 return {value: 1, writable: true, enumerable: true, configurable: true};
34 },
35 get: function() {
36 return 1;
37 },
38 ownKeys: function() {
39 return ['a', 'b'];
40 },
41 });
42
43 assert.sameValue(
44 JSON.stringify(objectProxy), '{"a":1,"b":1}', 'proxy for an object'
45 );
46 assert.sameValue(
47 JSON.stringify({l1: {l2: objectProxy}}),
48 '{"l1":{"l2":{"a":1,"b":1}}}',
49 'proxy for an object (nested)'
50 );
51
52 var objectProxyProxy = new Proxy(objectProxy, {});
53 assert.sameValue(
54 JSON.stringify({l1: {l2: objectProxyProxy}}),
55 '{"l1":{"l2":{"a":1,"b":1}}}',
56 'proxy for a proxy for an object (nested)'
57 );
58
59 reportCompare(0, 0);