tor-browser

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

attributes-accessors-unique-function-objects.html (1334B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>All attributes accessors are unique function objects</title>
      4 <link rel="help" href="https://webidl.spec.whatwg.org/#idl-interface-mixins">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 "use strict";
      9 
     10 test(() => {
     11  const seenPrototypes = new WeakSet([Function.prototype]);
     12  const seenFunctions = new WeakMap();
     13 
     14  for (const windowKey of Object.getOwnPropertyNames(window)) {
     15    const windowValue = window[windowKey];
     16    if (typeof windowValue !== "function") continue;
     17 
     18    const {prototype} = windowValue;
     19    if (!prototype || seenPrototypes.has(prototype)) continue;
     20    seenPrototypes.add(prototype);
     21 
     22    for (const key of Object.getOwnPropertyNames(prototype)) {
     23      const assert_not_seen = (fn, field) => {
     24        const fnInfo = `${windowKey}.${key}.${field}`;
     25        assert_equals(seenFunctions.get(fn), undefined, fnInfo);
     26        seenFunctions.set(fn, fnInfo);
     27      };
     28 
     29      const desc = Object.getOwnPropertyDescriptor(prototype, key);
     30      if (desc.get) assert_not_seen(desc.get, "[[Get]]");
     31      if (desc.set) assert_not_seen(desc.set, "[[Set]]");
     32    }
     33  }
     34 }, "For attributes, each copy of the accessor property has distinct built-in function objects for its getters and setters.");
     35 </script>