source: frontend/node_modules/domexception/lib/utils.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.9 KB
Line 
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
8function hasOwn(obj, prop) {
9 return Object.prototype.hasOwnProperty.call(obj, prop);
10}
11
12const wrapperSymbol = Symbol("wrapper");
13const implSymbol = Symbol("impl");
14const sameObjectCaches = Symbol("SameObject caches");
15const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
16
17function getSameObject(wrapper, prop, creator) {
18 if (!wrapper[sameObjectCaches]) {
19 wrapper[sameObjectCaches] = Object.create(null);
20 }
21
22 if (prop in wrapper[sameObjectCaches]) {
23 return wrapper[sameObjectCaches][prop];
24 }
25
26 wrapper[sameObjectCaches][prop] = creator();
27 return wrapper[sameObjectCaches][prop];
28}
29
30function wrapperForImpl(impl) {
31 return impl ? impl[wrapperSymbol] : null;
32}
33
34function implForWrapper(wrapper) {
35 return wrapper ? wrapper[implSymbol] : null;
36}
37
38function tryWrapperForImpl(impl) {
39 const wrapper = wrapperForImpl(impl);
40 return wrapper ? wrapper : impl;
41}
42
43function tryImplForWrapper(wrapper) {
44 const impl = implForWrapper(wrapper);
45 return impl ? impl : wrapper;
46}
47
48const iterInternalSymbol = Symbol("internal");
49const IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
50
51function isArrayIndexPropName(P) {
52 if (typeof P !== "string") {
53 return false;
54 }
55 const i = P >>> 0;
56 if (i === Math.pow(2, 32) - 1) {
57 return false;
58 }
59 const s = `${i}`;
60 if (P !== s) {
61 return false;
62 }
63 return true;
64}
65
66const byteLengthGetter =
67 Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
68function isArrayBuffer(value) {
69 try {
70 byteLengthGetter.call(value);
71 return true;
72 } catch (e) {
73 return false;
74 }
75}
76
77const supportsPropertyIndex = Symbol("supports property index");
78const supportedPropertyIndices = Symbol("supported property indices");
79const supportsPropertyName = Symbol("supports property name");
80const supportedPropertyNames = Symbol("supported property names");
81const indexedGet = Symbol("indexed property get");
82const indexedSetNew = Symbol("indexed property set new");
83const indexedSetExisting = Symbol("indexed property set existing");
84const namedGet = Symbol("named property get");
85const namedSetNew = Symbol("named property set new");
86const namedSetExisting = Symbol("named property set existing");
87const namedDelete = Symbol("named property delete");
88
89module.exports = exports = {
90 isObject,
91 hasOwn,
92 wrapperSymbol,
93 implSymbol,
94 getSameObject,
95 ctorRegistrySymbol,
96 wrapperForImpl,
97 implForWrapper,
98 tryWrapperForImpl,
99 tryImplForWrapper,
100 iterInternalSymbol,
101 IteratorPrototype,
102 isArrayBuffer,
103 isArrayIndexPropName,
104 supportsPropertyIndex,
105 supportedPropertyIndices,
106 supportsPropertyName,
107 supportedPropertyNames,
108 indexedGet,
109 indexedSetNew,
110 indexedSetExisting,
111 namedGet,
112 namedSetNew,
113 namedSetExisting,
114 namedDelete
115};
Note: See TracBrowser for help on using the repository browser.