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


      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-set-p-v-receiver
      6 description: >
      7  If "set" trap is null or undefined, [[Set]] call is properly
      8  forwarded to [[ProxyTarget]] (which is also a Proxy object).
      9 info: |
     10  [[Set]] ( P, V, Receiver )
     11 
     12  [...]
     13  5. Let target be O.[[ProxyTarget]].
     14  6. Let trap be ? GetMethod(handler, "set").
     15  7. If trap is undefined, then
     16    a. Return ? target.[[Set]](P, V, Receiver).
     17 features: [Proxy, Reflect]
     18 ---*/
     19 
     20 var func = function() {};
     21 var funcTarget = new Proxy(func, {});
     22 var funcProxy = new Proxy(funcTarget, {
     23  set: undefined,
     24 });
     25 
     26 assert(Reflect.set(funcProxy, "prototype", null));
     27 assert.sameValue(func.prototype, null);
     28 
     29 assert(!Reflect.set(funcProxy, "length", 2));
     30 assert.throws(TypeError, function() {
     31  "use strict";
     32  funcProxy.name = "foo";
     33 });
     34 
     35 
     36 var trapCalls = 0;
     37 var target = new Proxy({}, {
     38  set: function(_target, key) {
     39    trapCalls++;
     40    return key === "foo";
     41  },
     42 });
     43 
     44 var proxy = new Proxy(target, {
     45  set: undefined,
     46 });
     47 
     48 assert(Reflect.set(Object.create(proxy), "foo", 1));
     49 assert.sameValue(trapCalls, 1);
     50 
     51 assert(!Reflect.set(proxy, "bar", 2));
     52 assert.sameValue(trapCalls, 2);
     53 
     54 reportCompare(0, 0);