Debian Codegraph @

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