| 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 | const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
|
|---|
| 9 |
|
|---|
| 10 | const wrapperSymbol = Symbol("wrapper");
|
|---|
| 11 | const implSymbol = Symbol("impl");
|
|---|
| 12 | const sameObjectCaches = Symbol("SameObject caches");
|
|---|
| 13 | const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
|
|---|
| 14 |
|
|---|
| 15 | function 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 |
|
|---|
| 28 | function wrapperForImpl(impl) {
|
|---|
| 29 | return impl ? impl[wrapperSymbol] : null;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | function implForWrapper(wrapper) {
|
|---|
| 33 | return wrapper ? wrapper[implSymbol] : null;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | function tryWrapperForImpl(impl) {
|
|---|
| 37 | const wrapper = wrapperForImpl(impl);
|
|---|
| 38 | return wrapper ? wrapper : impl;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | function tryImplForWrapper(wrapper) {
|
|---|
| 42 | const impl = implForWrapper(wrapper);
|
|---|
| 43 | return impl ? impl : wrapper;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | const iterInternalSymbol = Symbol("internal");
|
|---|
| 47 | const IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
|---|
| 48 | const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
|
|---|
| 49 |
|
|---|
| 50 | function 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 |
|
|---|
| 65 | const byteLengthGetter =
|
|---|
| 66 | Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|---|
| 67 | function isArrayBuffer(value) {
|
|---|
| 68 | try {
|
|---|
| 69 | byteLengthGetter.call(value);
|
|---|
| 70 | return true;
|
|---|
| 71 | } catch (e) {
|
|---|
| 72 | return false;
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | function 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 |
|
|---|
| 92 | const supportsPropertyIndex = Symbol("supports property index");
|
|---|
| 93 | const supportedPropertyIndices = Symbol("supported property indices");
|
|---|
| 94 | const supportsPropertyName = Symbol("supports property name");
|
|---|
| 95 | const supportedPropertyNames = Symbol("supported property names");
|
|---|
| 96 | const indexedGet = Symbol("indexed property get");
|
|---|
| 97 | const indexedSetNew = Symbol("indexed property set new");
|
|---|
| 98 | const indexedSetExisting = Symbol("indexed property set existing");
|
|---|
| 99 | const namedGet = Symbol("named property get");
|
|---|
| 100 | const namedSetNew = Symbol("named property set new");
|
|---|
| 101 | const namedSetExisting = Symbol("named property set existing");
|
|---|
| 102 | const namedDelete = Symbol("named property delete");
|
|---|
| 103 |
|
|---|
| 104 | const asyncIteratorNext = Symbol("async iterator get the next iteration result");
|
|---|
| 105 | const asyncIteratorReturn = Symbol("async iterator return steps");
|
|---|
| 106 | const asyncIteratorInit = Symbol("async iterator initialization steps");
|
|---|
| 107 | const asyncIteratorEOI = Symbol("async iterator end of iteration");
|
|---|
| 108 |
|
|---|
| 109 | module.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 | };
|
|---|