tor-browser

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

reviver-array-non-configurable-prop-delete.js (1325B)


      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      iii. Repeat, while I < len,
     24        1. Let newElement be ? InternalizeJSONProperty(val, ! ToString(I)).
     25        2. If newElement is undefined, then
     26          a. Perform ? val.[[Delete]](! ToString(I)).
     27 
     28  OrdinaryDelete ( O, P )
     29 
     30  [...]
     31  4. If desc.[[Configurable]] is true, then
     32    a. Remove the own property with name P from O.
     33 ---*/
     34 
     35 var json = '[1, 2]';
     36 var arr = JSON.parse(json, function(key, value) {
     37  if (key === '0') {
     38    Object.defineProperty(this, '1', {configurable: false});
     39  }
     40  if (key === '1') return;
     41 
     42  return value;
     43 });
     44 
     45 assert.sameValue(arr[0], 1);
     46 assert(arr.hasOwnProperty('1'));
     47 assert.sameValue(arr[1], 2);
     48 
     49 reportCompare(0, 0);