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 (1454B)


      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-defineownproperty-p-desc
      6 description: >
      7  If "defineProperty" trap is null or undefined, [[DefineOwnProperty]] call
      8  is properly forwarded to [[ProxyTarget]] (which is also a Proxy object).
      9 info: |
     10  [[DefineOwnProperty]] (P, Desc)
     11 
     12  [...]
     13  5. Let target be O.[[ProxyTarget]].
     14  6. Let trap be ? GetMethod(handler, "defineProperty").
     15  7. If trap is undefined, then
     16    a. Return ? target.[[DefineOwnProperty]](P, Desc).
     17 features: [Proxy, Reflect]
     18 includes: [compareArray.js]
     19 ---*/
     20 
     21 var array = [];
     22 var arrayTarget = new Proxy(array, {});
     23 var arrayProxy = new Proxy(arrayTarget, {
     24  defineProperty: undefined,
     25 });
     26 
     27 Object.defineProperty(arrayProxy, "0", {value: 1});
     28 assert.compareArray(array, [1]);
     29 
     30 assert.throws(TypeError, function() {
     31  Object.defineProperty(arrayProxy, "length", {
     32    get: function() {},
     33  });
     34 });
     35 
     36 
     37 var trapCalls = 0;
     38 var target = new Proxy({}, {
     39  defineProperty: function(_target, key) {
     40    trapCalls++;
     41    return key === "foo";
     42  },
     43 });
     44 
     45 var proxy = new Proxy(target, {
     46  defineProperty: undefined,
     47 });
     48 
     49 assert(Reflect.defineProperty(proxy, "foo", {}));
     50 assert.sameValue(trapCalls, 1);
     51 
     52 assert.throws(TypeError, function() {
     53  Object.defineProperty(proxy, "bar", {});
     54 });
     55 assert.sameValue(trapCalls, 2);
     56 
     57 reportCompare(0, 0);