MCPcopy Create free account
hub / github.com/ampproject/amphtml / install

Function install

src/polyfills/set.js:6–39  ·  view source on GitHub ↗
(win)

Source from the content-addressed store, hash-verified

4 * @param {!Window} win
5 */
6export function install(win) {
7 const {Set: SetConstructor} = win;
8 const s = new SetConstructor([1]);
9 // Add support for `new Set(iterable)`. IE11 lacks it.
10 if (s.size < 1) {
11 win.Set = /** @type {typeof Set} */ (
12 function (iterable) {
13 const set = new SetConstructor();
14 if (iterable) {
15 const asArray = toArray(iterable);
16 for (let i = 0; i < asArray.length; i++) {
17 set.add(asArray[i]);
18 }
19 }
20 return set;
21 }
22 );
23 }
24 // Forces the return value from Set.prototype.add to always be the set
25 // instance. IE11 returns undefined.
26 if (s.add(0) !== s) {
27 const {add} = s;
28
29 win.Object.defineProperty(SetConstructor.prototype, 'add', {
30 enumerable: false,
31 configurable: true,
32 writable: true,
33 value: function () {
34 add.apply(this, arguments);
35 return this;
36 },
37 });
38 }
39}

Callers

nothing calls this directly

Calls 3

toArrayFunction · 0.90
applyMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected