Debian Codegraph @

js/src/tests/test262/built-ins/JSON/parse/reviver-object-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 object 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 [...]
21 c. Else,
22 i. Let keys be ? EnumerableOwnProperties(val, "key").
23 ii. For each String P in keys do,
24 1. Let newElement be ? InternalizeJSONProperty(val, P).
25 2. If newElement is undefined, then
26 [...]
27 3. Else,
28 a. Perform ? CreateDataProperty(val, P, newElement).
29 features: [Proxy]
30 ---*/
31
32 var badDefine = new Proxy({
33 0: null
34 }, {
35 defineProperty: function() {
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 });
48
49 reportCompare(0, 0);