| 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-json.stringify |
| 5 |
es6id: 24.3.2 |
| 6 |
description: Proxy of an array is treated as an array |
| 7 |
info: | |
| 8 |
[...] |
| 9 |
12. Return ? SerializeJSONProperty(the empty String, wrapper). |
| 10 |
|
| 11 |
24.3.2.1 Runtime Semantics: SerializeJSONProperty |
| 12 |
|
| 13 |
[...] |
| 14 |
10. If Type(value) is Object and IsCallable(value) is false, then |
| 15 |
a. Let isArray be ? IsArray(value). |
| 16 |
b. If isArray is true, return ? SerializeJSONArray(value). |
| 17 |
c. Else, return ? SerializeJSONObject(value). |
| 18 |
[...] |
| 19 |
|
| 20 |
7.2.2 IsArray |
| 21 |
|
| 22 |
[...] |
| 23 |
3. If argument is a Proxy exotic object, then |
| 24 |
a. If the value of the [[ProxyHandler]] internal slot of argument is null, |
| 25 |
throw a TypeError exception. |
| 26 |
b. Let target be the value of the [[ProxyTarget]] internal slot of |
| 27 |
argument. |
| 28 |
c. Return ? IsArray(target). |
| 29 |
features: [Proxy] |
| 30 |
---*/ |
| 31 |
|
| 32 |
var objectProxy = new Proxy({}, {}); |
| 33 |
var arrayProxy = new Proxy([], {}); |
| 34 |
var arrayProxyProxy = new Proxy(arrayProxy, {}); |
| 35 |
|
| 36 |
assert.sameValue(JSON.stringify(objectProxy), '{}'); |
| 37 |
assert.sameValue(JSON.stringify(arrayProxy), '[]', 'proxy for an array'); |
| 38 |
assert.sameValue( |
| 39 |
JSON.stringify([[arrayProxy]]), '[[[]]]', 'proxy for an array (nested)' |
| 40 |
); |
| 41 |
assert.sameValue( |
| 42 |
JSON.stringify([[arrayProxyProxy]]), |
| 43 |
'[[[]]]', |
| 44 |
'proxy for a proxy for an array (nested)' |
| 45 |
); |