tor-browser

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

reviver-array-non-configurable-prop-create.js (1336B)


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