tor-browser

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

object-rest-proxy-get-not-called-on-dontenum-keys.js (2499B)


      1 // Copyright (C) 2021 Alexey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-destructuring-binding-patterns-runtime-semantics-restbindinginitialization
      5 description: >
      6  Proxy's "get" trap is not invoked for non-enumerable keys.
      7 info: |
      8  BindingRestProperty : ... BindingIdentifier
      9 
     10  [...]
     11  3. Perform ? CopyDataProperties(restObj, value, excludedNames).
     12 
     13  CopyDataProperties ( target, source, excludedItems )
     14 
     15  [...]
     16  5. Let keys be ? from.[[OwnPropertyKeys]]().
     17  6. For each element nextKey of keys in List order, do
     18    [...]
     19    c. If excluded is false, then
     20      i. Let desc be ? from.[[GetOwnProperty]](nextKey).
     21      ii. If desc is not undefined and desc.[[Enumerable]] is true, then
     22        1. Let propValue be ? Get(from, nextKey).
     23        2. Perform ! CreateDataPropertyOrThrow(target, nextKey, propValue).
     24 
     25  [[OwnPropertyKeys]] ( )
     26 
     27  [...]
     28  7. Let trapResultArray be ? Call(trap, handler, « target »).
     29  8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »).
     30  [...]
     31  23. Return trapResult.
     32 features: [object-rest, destructuring-binding, Proxy, Symbol]
     33 includes: [compareArray.js, propertyHelper.js]
     34 ---*/
     35 
     36 var VALUE_GOPD = "VALUE_GOPD";
     37 var VALUE_GET = "VALUE_GET";
     38 
     39 var dontEnumSymbol = Symbol("dont_enum_symbol");
     40 var enumerableSymbol = Symbol("enumerable_symbol");
     41 
     42 var dontEnumKeys = [dontEnumSymbol, "dontEnumString", "0"];
     43 var enumerableKeys = [enumerableSymbol, "enumerableString", "1"];
     44 var ownKeysResult = [...dontEnumKeys, ...enumerableKeys];
     45 
     46 var getOwnKeys = [];
     47 var getKeys = [];
     48 var proxy = new Proxy({}, {
     49  getOwnPropertyDescriptor: function(_target, key) {
     50    getOwnKeys.push(key);
     51    var isEnumerable = enumerableKeys.indexOf(key) !== -1;
     52    return {value: VALUE_GOPD, writable: false, enumerable: isEnumerable, configurable: true};
     53  },
     54  get: function(_target, key) {
     55    getKeys.push(key);
     56    return VALUE_GET;
     57  },
     58  ownKeys: function() {
     59    return ownKeysResult;
     60  },
     61 });
     62 
     63 var {...rest} = proxy;
     64 assert.compareArray(getOwnKeys, ownKeysResult);
     65 assert.compareArray(getKeys, enumerableKeys);
     66 
     67 verifyProperty(rest, enumerableSymbol, {value: VALUE_GET, writable: true, enumerable: true, configurable: true});
     68 verifyProperty(rest, "enumerableString", {value: VALUE_GET, writable: true, enumerable: true, configurable: true});
     69 verifyProperty(rest, "1", {value: VALUE_GET, writable: true, enumerable: true, configurable: true});
     70 
     71 reportCompare(0, 0);