tor-browser

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

trap-is-undefined-target-is-proxy.js (1170B)


      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-hasproperty-p
      6 description: >
      7  If "has" trap is null or undefined, [[HasProperty]] call is properly
      8  forwarded to [[ProxyTarget]] (which is also a Proxy object).
      9 info: |
     10  [[HasProperty]] ( P )
     11 
     12  [...]
     13  5. Let target be O.[[ProxyTarget]].
     14  6. Let trap be ? GetMethod(handler, "has").
     15  7. If trap is undefined, then
     16    a. Return ? target.[[HasProperty]](P).
     17 features: [Proxy, Reflect]
     18 ---*/
     19 
     20 var plainObject = {
     21  get 0() {
     22    return 1;
     23  },
     24  foo: 2,
     25  set bar(_value) {},
     26 };
     27 
     28 var plainObjectTarget = new Proxy(plainObject, {});
     29 var plainObjectProxy = new Proxy(plainObjectTarget, {
     30  get: undefined,
     31 });
     32 
     33 assert(0 in Object.create(plainObjectProxy));
     34 assert("foo" in plainObjectProxy);
     35 assert(Reflect.has(plainObjectProxy, "bar"));
     36 
     37 
     38 var arrayTarget = new Proxy([1, 2], {});
     39 var arrayProxy = new Proxy(arrayTarget, {
     40  get: undefined,
     41 });
     42 
     43 assert("length" in Object.create(arrayProxy));
     44 assert("1" in arrayProxy);
     45 assert(!("2" in arrayProxy));
     46 
     47 reportCompare(0, 0);