tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

reviver-object-non-configurable-prop-delete.js (1391B)


      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  [[Delete]] does not remove non-configurable properties.
      7  If [[Delete]] 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          a. Perform ? val.[[Delete]](P).
     29 
     30  OrdinaryDelete ( O, P )
     31 
     32  [...]
     33  4. If desc.[[Configurable]] is true, then
     34    a. Remove the own property with name P from O.
     35 ---*/
     36 
     37 var json = '{"a": 1, "b": 2}';
     38 var obj = JSON.parse(json, function(key, value) {
     39  if (key === 'a') {
     40    Object.defineProperty(this, 'b', {configurable: false});
     41  }
     42  if (key === 'b') return;
     43 
     44  return value;
     45 });
     46 
     47 assert.sameValue(obj.a, 1);
     48 assert(obj.hasOwnProperty('b'));
     49 assert.sameValue(obj.b, 2);
     50 
     51 reportCompare(0, 0);