Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/JSON/parse/reviver-array-length-coerce-err.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-internalizejsonproperty
5 es6id: 24.3.1.1
6 description: >
7 Abrupt completion from coercing array "length" property to a number value
8 info: |
9 JSON.parse ( text [ , reviver ] )
10
11 [...]
12 7. If IsCallable(reviver) is true, then
13 [...]
14 e. Return ? InternalizeJSONProperty(root, rootName).
15
16 Runtime Semantics: InternalizeJSONProperty ( holder, name)
17
18 1. Let val be ? Get(holder, name).
19 2. If Type(val) is Object, then
20 a. Let isArray be ? IsArray(val).
21 b. If isArray is true, then
22 i. Set I to 0.
23 ii. Let len be ? ToLength(? Get(val, "length")).
24 features: [Proxy]
25 ---*/
26
27 var uncoercible = {
28 valueOf: function() {
29 throw new Test262Error();
30 }
31 };
32 var badLength = new Proxy([], {
33 get: function(_, name) {
34 if (name === 'length') {
35 return uncoercible;
36 }
37 }
38 });
39
40 assert.throws(Test262Error, function() {
41 JSON.parse('[0,0]', function() {
42 this[1] = badLength;
43 });
44 });