tor-browser

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

trap-is-null-target-is-proxy.js (1252B)


      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 /*---
      5 esid: sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver
      6 description: >
      7  If "get" trap is null or undefined, [[Get]] call is properly
      8  forwarded to [[ProxyTarget]] (which is also a Proxy object).
      9 info: |
     10  [[Get]] ( P, Receiver )
     11 
     12  [...]
     13  5. Let target be O.[[ProxyTarget]].
     14  6. Let trap be ? GetMethod(handler, "get").
     15  7. If trap is undefined, then
     16    a. Return ? target.[[Get]](P, Receiver).
     17 features: [Proxy, Symbol]
     18 ---*/
     19 
     20 var stringTarget = new Proxy(new String("str"), {});
     21 var stringProxy = new Proxy(stringTarget, {
     22  get: null,
     23 });
     24 
     25 assert.sameValue(stringProxy.length, 3);
     26 assert.sameValue(stringProxy[0], "s");
     27 assert.sameValue(stringProxy[4], undefined);
     28 
     29 
     30 var sym = Symbol();
     31 var target = new Proxy({}, {
     32  get: function(_target, key) {
     33    switch (key) {
     34      case sym: return 1;
     35      case "10": return 2;
     36      case "foo": return 3;
     37    }
     38  },
     39 });
     40 
     41 var proxy = new Proxy(target, {
     42  get: null,
     43 });
     44 
     45 assert.sameValue(proxy[sym], 1);
     46 assert.sameValue(proxy[10], 2);
     47 assert.sameValue(Object.create(proxy).foo, 3);
     48 assert.sameValue(proxy.bar, undefined);
     49 
     50 reportCompare(0, 0);