Debian Codegraph @

js/src/tests/test262/built-ins/JSON/parse/reviver-array-define-prop-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 description: Abrupt completion from defining array property while reviving
6 info: |
7 JSON.parse ( text [ , reviver ] )
8
9 [...]
10 7. If IsCallable(reviver) is true, then
11 [...]
12 e. Return ? InternalizeJSONProperty(root, rootName).
13
14 Runtime Semantics: InternalizeJSONProperty ( holder, name)
15
16 1. Let val be ? Get(holder, name).
17 2. If Type(val) is Object, then
18 a. Let isArray be ? IsArray(val).
19 b. If isArray is true, then
20 i. Set I to 0.
21 ii. Let len be ? ToLength(? Get(val, "length")).
22 iii. Repeat while I < len,
23 1. Let newElement be ? InternalizeJSONProperty(val, !
24 ToString(I)).
25 2. If newElement is undefined, then
26 [...]
27 3. Else,
28 a. Perform ? CreateDataProperty(val, ! ToString(I),
29 newElement).
30 features: [Proxy]
31 ---*/
32
33 var badDefine = new Proxy([null], {
34 defineProperty: function(_, name) {
35 throw new Test262Error();
36 }
37 });
38
39 assert.throws(Test262Error, function() {
40 JSON.parse('["first", null]', function(_, value) {
41 if (value === 'first') {
42 this[1] = badDefine;
43 }
44 return value;
45 });
46 });
47
48 reportCompare(0, 0);