| [9af201e] | 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | // Returns "Type(value) is Object" in ES terminology.
|
|---|
| 4 | function isObject(value) {
|
|---|
| 5 | return typeof value === "object" && value !== null || typeof value === "function";
|
|---|
| 6 | }
|
|---|
| 7 |
|
|---|
| 8 | function hasOwn(obj, prop) {
|
|---|
| 9 | return Object.prototype.hasOwnProperty.call(obj, prop);
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | const wrapperSymbol = Symbol("wrapper");
|
|---|
| 13 | const implSymbol = Symbol("impl");
|
|---|
| 14 | const sameObjectCaches = Symbol("SameObject caches");
|
|---|
| 15 | const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
|
|---|
| 16 |
|
|---|
| 17 | function 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 |
|
|---|
| 30 | function wrapperForImpl(impl) {
|
|---|
| 31 | return impl ? impl[wrapperSymbol] : null;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | function implForWrapper(wrapper) {
|
|---|
| 35 | return wrapper ? wrapper[implSymbol] : null;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | function tryWrapperForImpl(impl) {
|
|---|
| 39 | const wrapper = wrapperForImpl(impl);
|
|---|
| 40 | return wrapper ? wrapper : impl;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | function tryImplForWrapper(wrapper) {
|
|---|
| 44 | const impl = implForWrapper(wrapper);
|
|---|
| 45 | return impl ? impl : wrapper;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | const iterInternalSymbol = Symbol("internal");
|
|---|
| 49 | const IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
|---|
| 50 |
|
|---|
| 51 | function 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 |
|
|---|
| 66 | const byteLengthGetter =
|
|---|
| 67 | Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|---|
| 68 | function isArrayBuffer(value) {
|
|---|
| 69 | try {
|
|---|
| 70 | byteLengthGetter.call(value);
|
|---|
| 71 | return true;
|
|---|
| 72 | } catch (e) {
|
|---|
| 73 | return false;
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | const supportsPropertyIndex = Symbol("supports property index");
|
|---|
| 78 | const supportedPropertyIndices = Symbol("supported property indices");
|
|---|
| 79 | const supportsPropertyName = Symbol("supports property name");
|
|---|
| 80 | const supportedPropertyNames = Symbol("supported property names");
|
|---|
| 81 | const indexedGet = Symbol("indexed property get");
|
|---|
| 82 | const indexedSetNew = Symbol("indexed property set new");
|
|---|
| 83 | const indexedSetExisting = Symbol("indexed property set existing");
|
|---|
| 84 | const namedGet = Symbol("named property get");
|
|---|
| 85 | const namedSetNew = Symbol("named property set new");
|
|---|
| 86 | const namedSetExisting = Symbol("named property set existing");
|
|---|
| 87 | const namedDelete = Symbol("named property delete");
|
|---|
| 88 |
|
|---|
| 89 | module.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 | };
|
|---|