tor-browser

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

replacer-function-object-deleted-property.js (1080B)


      1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-serializejsonproperty
      5 description: >
      6  Replacer function is called on properties, deleted during stringification.
      7 info: |
      8  SerializeJSONObject ( value )
      9 
     10  [...]
     11  5. If PropertyList is not undefined, then
     12    [...]
     13  6. Else,
     14    a. Let K be ? EnumerableOwnPropertyNames(value, key).
     15  [...]
     16  8. For each element P of K, do
     17    a. Let strP be ? SerializeJSONProperty(P, value).
     18    [...]
     19 
     20  SerializeJSONProperty ( key, holder )
     21 
     22  1. Let value be ? Get(holder, key).
     23  [...]
     24  3. If ReplacerFunction is not undefined, then
     25    a. Set value to ? Call(ReplacerFunction, holder, « key, value »).
     26 ---*/
     27 
     28 var obj = {
     29  get a() {
     30    delete this.b;
     31    return 1;
     32  },
     33  b: 2,
     34 };
     35 
     36 var replacer = function(key, value) {
     37  if (key === 'b') {
     38    assert.sameValue(value, undefined);
     39    return '<replaced>';
     40  }
     41 
     42  return value;
     43 };
     44 
     45 assert.sameValue(
     46  JSON.stringify(obj, replacer),
     47  '{"a":1,"b":"<replaced>"}'
     48 );
     49 
     50 reportCompare(0, 0);