reviver-object-non-configurable-prop-create.js (1402B)
1 // Copyright (C) 2019 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-internalizejsonproperty 5 description: > 6 [[DefineOwnProperty]] validates property descriptor before applying. 7 If [[DefineOwnProperty]] is unsuccessful, no exception is thrown. 8 info: | 9 JSON.parse ( text [ , reviver ] ) 10 11 [...] 12 7. If IsCallable(reviver) is true, then 13 [...] 14 d. Return ? InternalizeJSONProperty(root, rootName). 15 16 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 [...] 23 c. Else, 24 i. Let keys be ? EnumerableOwnPropertyNames(val, "key"). 25 ii. For each String P in keys, do 26 1. Let newElement be ? InternalizeJSONProperty(val, P). 27 2. If newElement is undefined, then 28 [...] 29 3. Else, 30 a. Perform ? CreateDataProperty(val, P, newElement). 31 32 CreateDataProperty ( O, P, V ) 33 34 [...] 35 4. Return ? O.[[DefineOwnProperty]](P, newDesc). 36 ---*/ 37 38 var json = '{"a": 1, "b": 2}'; 39 var obj = JSON.parse(json, function(key, value) { 40 if (key === 'a') { 41 Object.defineProperty(this, 'b', {configurable: false}); 42 } 43 if (key === 'b') return 22; 44 45 return value; 46 }); 47 48 assert.sameValue(obj.a, 1); 49 assert.sameValue(obj.b, 2); 50 51 reportCompare(0, 0);