source: frontend/node_modules/whatwg-url/dist/utils.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[9af201e]1"use strict";
2
3// Returns "Type(value) is Object" in ES terminology.
4function isObject(value) {
5 return typeof value === "object" && value !== null || typeof value === "function";
6}
7
8const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
9
10const wrapperSymbol = Symbol("wrapper");
11const implSymbol = Symbol("impl");
12const sameObjectCaches = Symbol("SameObject caches");
13const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
14
15function getSameObject(wrapper, prop, creator) {
16 if (!wrapper[sameObjectCaches]) {
17 wrapper[sameObjectCaches] = Object.create(null);
18 }
19
20 if (prop in wrapper[sameObjectCaches]) {
21 return wrapper[sameObjectCaches][prop];
22 }
23
24 wrapper[sameObjectCaches][prop] = creator();
25 return wrapper[sameObjectCaches][prop];
26}
27
28function wrapperForImpl(impl) {
29 return impl ? impl[wrapperSymbol] : null;
30}
31
32function implForWrapper(wrapper) {
33 return wrapper ? wrapper[implSymbol] : null;
34}
35
36function tryWrapperForImpl(impl) {
37 const wrapper = wrapperForImpl(impl);
38 return wrapper ? wrapper : impl;
39}
40
41function tryImplForWrapper(wrapper) {
42 const impl = implForWrapper(wrapper);
43 return impl ? impl : wrapper;
44}
45
46const iterInternalSymbol = Symbol("internal");
47const IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
48const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
49
50function isArrayIndexPropName(P) {
51 if (typeof P !== "string") {
52 return false;
53 }
54 const i = P >>> 0;
55 if (i === Math.pow(2, 32) - 1) {
56 return false;
57 }
58 const s = `${i}`;
59 if (P !== s) {
60 return false;
61 }
62 return true;
63}
64
65const byteLengthGetter =
66 Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
67function isArrayBuffer(value) {
68 try {
69 byteLengthGetter.call(value);
70 return true;
71 } catch (e) {
72 return false;
73 }
74}
75
76function iteratorResult([key, value], kind) {
77 let result;
78 switch (kind) {
79 case "key":
80 result = key;
81 break;
82 case "value":
83 result = value;
84 break;
85 case "key+value":
86 result = [key, value];
87 break;
88 }
89 return { value: result, done: false };
90}
91
92const supportsPropertyIndex = Symbol("supports property index");
93const supportedPropertyIndices = Symbol("supported property indices");
94const supportsPropertyName = Symbol("supports property name");
95const supportedPropertyNames = Symbol("supported property names");
96const indexedGet = Symbol("indexed property get");
97const indexedSetNew = Symbol("indexed property set new");
98const indexedSetExisting = Symbol("indexed property set existing");
99const namedGet = Symbol("named property get");
100const namedSetNew = Symbol("named property set new");
101const namedSetExisting = Symbol("named property set existing");
102const namedDelete = Symbol("named property delete");
103
104const asyncIteratorNext = Symbol("async iterator get the next iteration result");
105const asyncIteratorReturn = Symbol("async iterator return steps");
106const asyncIteratorInit = Symbol("async iterator initialization steps");
107const asyncIteratorEOI = Symbol("async iterator end of iteration");
108
109module.exports = exports = {
110 isObject,
111 hasOwn,
112 wrapperSymbol,
113 implSymbol,
114 getSameObject,
115 ctorRegistrySymbol,
116 wrapperForImpl,
117 implForWrapper,
118 tryWrapperForImpl,
119 tryImplForWrapper,
120 iterInternalSymbol,
121 IteratorPrototype,
122 AsyncIteratorPrototype,
123 isArrayBuffer,
124 isArrayIndexPropName,
125 supportsPropertyIndex,
126 supportedPropertyIndices,
127 supportsPropertyName,
128 supportedPropertyNames,
129 indexedGet,
130 indexedSetNew,
131 indexedSetExisting,
132 namedGet,
133 namedSetNew,
134 namedSetExisting,
135 namedDelete,
136 asyncIteratorNext,
137 asyncIteratorReturn,
138 asyncIteratorInit,
139 asyncIteratorEOI,
140 iteratorResult
141};
Note: See TracBrowser for help on using the repository browser.