indexeddbshim 12.0.0 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/badges/licenses-badge-dev.svg +1 -1
- package/dist/CFG.d.ts +80 -0
- package/dist/CFG.d.ts.map +1 -0
- package/dist/DOMException.d.ts +71 -0
- package/dist/DOMException.d.ts.map +1 -0
- package/dist/DOMStringList.d.ts +20 -0
- package/dist/DOMStringList.d.ts.map +1 -0
- package/dist/Event.d.ts +21 -0
- package/dist/Event.d.ts.map +1 -0
- package/dist/IDBCursor.d.ts +288 -0
- package/dist/IDBCursor.d.ts.map +1 -0
- package/dist/IDBDatabase.d.ts +143 -0
- package/dist/IDBDatabase.d.ts.map +1 -0
- package/dist/IDBFactory.d.ts +96 -0
- package/dist/IDBFactory.d.ts.map +1 -0
- package/dist/IDBIndex.d.ts +243 -0
- package/dist/IDBIndex.d.ts.map +1 -0
- package/dist/IDBKeyRange.d.ts +79 -0
- package/dist/IDBKeyRange.d.ts.map +1 -0
- package/dist/IDBObjectStore.d.ts +273 -0
- package/dist/IDBObjectStore.d.ts.map +1 -0
- package/dist/IDBRequest.d.ts +88 -0
- package/dist/IDBRequest.d.ts.map +1 -0
- package/dist/IDBTransaction.d.ts +270 -0
- package/dist/IDBTransaction.d.ts.map +1 -0
- package/dist/IDBVersionChangeEvent.d.ts +22 -0
- package/dist/IDBVersionChangeEvent.d.ts.map +1 -0
- package/dist/Key.d.ts +214 -0
- package/dist/Key.d.ts.map +1 -0
- package/dist/Sca.d.ts +31 -0
- package/dist/Sca.d.ts.map +1 -0
- package/dist/UnicodeIdentifiers.d.ts +3 -0
- package/dist/UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/browser-UnicodeIdentifiers.d.ts +2 -0
- package/dist/browser-UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/browser-noninvasive.d.ts +3 -0
- package/dist/browser-noninvasive.d.ts.map +1 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/cmp.d.ts +9 -0
- package/dist/cmp.d.ts.map +1 -0
- package/dist/indexeddbshim-Key.js +553 -252
- package/dist/indexeddbshim-Key.js.map +1 -1
- package/dist/indexeddbshim-Key.min.js +2 -2
- package/dist/indexeddbshim-Key.min.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +17560 -1302
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +4367 -1604
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -2
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +17556 -1302
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +4362 -1604
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +2 -2
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +4362 -1604
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +2 -2
- package/dist/indexeddbshim.min.js.map +1 -1
- package/dist/node-UnicodeIdentifiers.d.ts +8 -0
- package/dist/node-UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/node.d.ts +8 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/nodeWebSQL.d.ts +3 -0
- package/dist/nodeWebSQL.d.ts.map +1 -0
- package/dist/setGlobalVars.d.ts +79 -0
- package/dist/setGlobalVars.d.ts.map +1 -0
- package/dist/unicode-regex.d.ts +3 -0
- package/dist/unicode-regex.d.ts.map +1 -0
- package/dist/util.d.ts +174 -0
- package/dist/util.d.ts.map +1 -0
- package/index.html +1 -1
- package/package.json +51 -37
- package/src/CFG.js +89 -11
- package/src/DOMException.js +117 -31
- package/src/DOMStringList.js +93 -3
- package/src/Event.js +19 -4
- package/src/IDBCursor.js +350 -76
- package/src/IDBDatabase.js +88 -10
- package/src/IDBFactory.js +331 -61
- package/src/IDBIndex.js +393 -110
- package/src/IDBKeyRange.js +90 -17
- package/src/IDBObjectStore.js +347 -86
- package/src/IDBRequest.js +59 -1
- package/src/IDBTransaction.js +254 -46
- package/src/IDBVersionChangeEvent.js +28 -3
- package/src/Key.d.ts +1 -0
- package/src/Key.js +272 -162
- package/src/Sca.js +29 -4
- package/src/browser-UnicodeIdentifiers.js +5 -1
- package/src/cmp.js +5 -5
- package/src/node-UnicodeIdentifiers.js +9 -0
- package/src/node.js +5 -0
- package/src/nodeWebSQL.js +11 -5
- package/src/setGlobalVars.js +159 -22
- package/src/unicode-regex.js +2 -0
- package/src/util.js +229 -40
- package/typings/shimIndexedDB.d.ts +9 -0
package/src/DOMException.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* globals DOMException */
|
|
2
1
|
import CFG from './CFG.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -8,6 +7,7 @@ import CFG from './CFG.js';
|
|
|
8
7
|
* @returns {DOMException}
|
|
9
8
|
*/
|
|
10
9
|
function createNativeDOMException (name, message) {
|
|
10
|
+
// @ts-expect-error It's ok
|
|
11
11
|
return new DOMException.prototype.constructor(
|
|
12
12
|
message,
|
|
13
13
|
name || 'DOMException'
|
|
@@ -15,6 +15,20 @@ function createNativeDOMException (name, message) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// From web-platform-tests testharness.js name_code_map (though not in new spec)
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {"IndexSizeError"|"HierarchyRequestError"|"WrongDocumentError"|
|
|
21
|
+
* "InvalidCharacterError"|"NoModificationAllowedError"|"NotFoundError"|
|
|
22
|
+
* "NotSupportedError"|"InUseAttributeError"|"InvalidStateError"|
|
|
23
|
+
* "SyntaxError"|"InvalidModificationError"|"NamespaceError"|
|
|
24
|
+
* "InvalidAccessError"|"TypeMismatchError"|"SecurityError"|
|
|
25
|
+
* "NetworkError"|"AbortError"|"URLMismatchError"|"QuotaExceededError"|
|
|
26
|
+
* "TimeoutError"|"InvalidNodeTypeError"|"DataCloneError"|"EncodingError"|
|
|
27
|
+
* "NotReadableError"|"UnknownError"|"ConstraintError"|"DataError"|
|
|
28
|
+
* "TransactionInactiveError"|"ReadOnlyError"|"VersionError"|
|
|
29
|
+
* "OperationError"|"NotAllowedError"} Code
|
|
30
|
+
*/
|
|
31
|
+
|
|
18
32
|
const codes = {
|
|
19
33
|
IndexSizeError: 1,
|
|
20
34
|
HierarchyRequestError: 3,
|
|
@@ -51,6 +65,17 @@ const codes = {
|
|
|
51
65
|
NotAllowedError: 0
|
|
52
66
|
};
|
|
53
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @typedef {"INDEX_SIZE_ERR"|"DOMSTRING_SIZE_ERR"|"HIERARCHY_REQUEST_ERR"|
|
|
70
|
+
* "WRONG_DOCUMENT_ERR"|"INVALID_CHARACTER_ERR"|"NO_DATA_ALLOWED_ERR"|
|
|
71
|
+
* "NO_MODIFICATION_ALLOWED_ERR"|"NOT_FOUND_ERR"|"NOT_SUPPORTED_ERR"|
|
|
72
|
+
* "INUSE_ATTRIBUTE_ERR"|"INVALID_STATE_ERR"|"SYNTAX_ERR"|
|
|
73
|
+
* "INVALID_MODIFICATION_ERR"|"NAMESPACE_ERR"|"INVALID_ACCESS_ERR"|
|
|
74
|
+
* "VALIDATION_ERR"|"TYPE_MISMATCH_ERR"|"SECURITY_ERR"|"NETWORK_ERR"|
|
|
75
|
+
* "ABORT_ERR"|"URL_MISMATCH_ERR"|"QUOTA_EXCEEDED_ERR"|"TIMEOUT_ERR"|
|
|
76
|
+
* "INVALID_NODE_TYPE_ERR"|"DATA_CLONE_ERR"} LegacyCode
|
|
77
|
+
*/
|
|
78
|
+
|
|
54
79
|
const legacyCodes = {
|
|
55
80
|
INDEX_SIZE_ERR: 1,
|
|
56
81
|
DOMSTRING_SIZE_ERR: 2,
|
|
@@ -81,13 +106,20 @@ const legacyCodes = {
|
|
|
81
106
|
|
|
82
107
|
/**
|
|
83
108
|
*
|
|
84
|
-
* @returns {DOMException}
|
|
109
|
+
* @returns {typeof DOMException}
|
|
85
110
|
*/
|
|
86
111
|
function createNonNativeDOMExceptionClass () {
|
|
112
|
+
/**
|
|
113
|
+
* @param {string|undefined} message
|
|
114
|
+
* @param {Code|LegacyCode} name
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
87
117
|
function DOMException (message, name) {
|
|
88
118
|
// const err = Error.prototype.constructor.call(this, message); // Any use to this? Won't set this.message
|
|
89
119
|
this[Symbol.toStringTag] = 'DOMException';
|
|
90
|
-
this._code = name in codes
|
|
120
|
+
this._code = name in codes
|
|
121
|
+
? codes[/** @type {Code} */ (name)]
|
|
122
|
+
: (legacyCodes[/** @type {LegacyCode} */ (name)] || 0);
|
|
91
123
|
this._name = name || 'Error';
|
|
92
124
|
// We avoid `String()` in this next line as it converts Symbols
|
|
93
125
|
this._message = message === undefined ? '' : ('' + message); // eslint-disable-line no-implicit-coercion
|
|
@@ -118,19 +150,29 @@ function createNonNativeDOMExceptionClass () {
|
|
|
118
150
|
// Necessary for W3C tests which complains if `DOMException` has properties on its "own" prototype
|
|
119
151
|
|
|
120
152
|
// class DummyDOMException extends Error {}; // Sometimes causing problems in Node
|
|
121
|
-
|
|
153
|
+
/* eslint-disable func-name-matching */
|
|
154
|
+
/**
|
|
155
|
+
* @class
|
|
156
|
+
*/
|
|
122
157
|
const DummyDOMException = function DOMException () { /* */ };
|
|
158
|
+
/* eslint-enable func-name-matching */
|
|
123
159
|
DummyDOMException.prototype = Object.create(Error.prototype); // Intended for subclassing
|
|
124
|
-
['name', 'message'].forEach((prop) => {
|
|
160
|
+
/** @type {const} */ (['name', 'message']).forEach((prop) => {
|
|
125
161
|
Object.defineProperty(DummyDOMException.prototype, prop, {
|
|
126
162
|
enumerable: true,
|
|
163
|
+
/**
|
|
164
|
+
* @this {DOMException}
|
|
165
|
+
* @returns {string}
|
|
166
|
+
*/
|
|
127
167
|
get () {
|
|
128
168
|
if (!(this instanceof DOMException ||
|
|
169
|
+
// @ts-expect-error Just checking
|
|
129
170
|
this instanceof DummyDOMException ||
|
|
171
|
+
// @ts-expect-error Just checking
|
|
130
172
|
this instanceof Error)) {
|
|
131
173
|
throw new TypeError('Illegal invocation');
|
|
132
174
|
}
|
|
133
|
-
return this['
|
|
175
|
+
return this[prop === 'name' ? '_name' : '_message'];
|
|
134
176
|
}
|
|
135
177
|
});
|
|
136
178
|
});
|
|
@@ -142,6 +184,7 @@ function createNonNativeDOMExceptionClass () {
|
|
|
142
184
|
throw new TypeError('Illegal invocation');
|
|
143
185
|
}
|
|
144
186
|
});
|
|
187
|
+
// @ts-expect-error It's ok
|
|
145
188
|
DOMException.prototype = new DummyDOMException();
|
|
146
189
|
|
|
147
190
|
DOMException.prototype[Symbol.toStringTag] = 'DOMExceptionPrototype';
|
|
@@ -149,19 +192,25 @@ function createNonNativeDOMExceptionClass () {
|
|
|
149
192
|
writable: false
|
|
150
193
|
});
|
|
151
194
|
|
|
152
|
-
Object.keys(codes)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
195
|
+
const keys = Object.keys(codes);
|
|
196
|
+
|
|
197
|
+
/** @type {(keyof codes)[]} */ (keys).forEach(
|
|
198
|
+
(codeName) => {
|
|
199
|
+
Object.defineProperty(DOMException.prototype, codeName, {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
configurable: false,
|
|
202
|
+
value: codes[codeName]
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(DOMException, codeName, {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
configurable: false,
|
|
207
|
+
value: codes[codeName]
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
/** @type {(keyof legacyCodes)[]} */ (Object.keys(legacyCodes)).forEach((
|
|
212
|
+
codeName
|
|
213
|
+
) => {
|
|
165
214
|
Object.defineProperty(DOMException.prototype, codeName, {
|
|
166
215
|
enumerable: true,
|
|
167
216
|
configurable: false,
|
|
@@ -180,6 +229,7 @@ function createNonNativeDOMExceptionClass () {
|
|
|
180
229
|
value: DOMException
|
|
181
230
|
});
|
|
182
231
|
|
|
232
|
+
// @ts-expect-error We don't need all its properties
|
|
183
233
|
return DOMException;
|
|
184
234
|
}
|
|
185
235
|
|
|
@@ -195,25 +245,39 @@ function createNonNativeDOMException (name, message) {
|
|
|
195
245
|
return new ShimNonNativeDOMException(message, name);
|
|
196
246
|
}
|
|
197
247
|
|
|
248
|
+
/**
|
|
249
|
+
* @typedef {{
|
|
250
|
+
* message: string|DOMString
|
|
251
|
+
* }} ErrorLike
|
|
252
|
+
*/
|
|
253
|
+
|
|
198
254
|
/**
|
|
199
255
|
* Logs detailed error information to the console.
|
|
200
256
|
* @param {string} name
|
|
201
257
|
* @param {string} message
|
|
202
|
-
* @param {string|
|
|
258
|
+
* @param {string|ErrorLike|boolean|null} [error]
|
|
203
259
|
* @returns {void}
|
|
204
260
|
*/
|
|
205
261
|
function logError (name, message, error) {
|
|
206
262
|
if (CFG.DEBUG) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
263
|
+
const msg = error && typeof error === 'object' && error.message
|
|
264
|
+
? error.message
|
|
265
|
+
: /** @type {string} */ (error);
|
|
210
266
|
|
|
211
267
|
const method = typeof (console.error) === 'function' ? 'error' : 'log';
|
|
212
|
-
console[method](name + ': ' + message + '. ' + (
|
|
213
|
-
console.trace
|
|
268
|
+
console[method](name + ': ' + message + '. ' + (msg || ''));
|
|
269
|
+
if (console.trace) { console.trace(); }
|
|
214
270
|
}
|
|
215
271
|
}
|
|
216
272
|
|
|
273
|
+
/**
|
|
274
|
+
* @typedef {any} ArbitraryValue
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @param {ArbitraryValue} obj
|
|
279
|
+
* @returns {boolean}
|
|
280
|
+
*/
|
|
217
281
|
function isErrorOrDOMErrorOrDOMException (obj) {
|
|
218
282
|
return obj && typeof obj === 'object' && // We don't use util.isObj here as mutual dependency causing problems in Babel with browser
|
|
219
283
|
typeof obj.name === 'string';
|
|
@@ -223,7 +287,7 @@ function isErrorOrDOMErrorOrDOMException (obj) {
|
|
|
223
287
|
* Finds the error argument. This is useful because some WebSQL callbacks
|
|
224
288
|
* pass the error as the first argument, and some pass it as the second
|
|
225
289
|
* argument.
|
|
226
|
-
* @param {
|
|
290
|
+
* @param {(Error|{message?: string, name?: string}|any)[]} args
|
|
227
291
|
* @returns {Error|DOMException|undefined}
|
|
228
292
|
*/
|
|
229
293
|
function findError (args) {
|
|
@@ -246,8 +310,10 @@ function findError (args) {
|
|
|
246
310
|
|
|
247
311
|
/**
|
|
248
312
|
*
|
|
249
|
-
* @param {
|
|
250
|
-
* @returns {DOMException
|
|
313
|
+
* @param {SQLError} webSQLErr
|
|
314
|
+
* @returns {(DOMException|Error) & {
|
|
315
|
+
* sqlError: SQLError
|
|
316
|
+
* }}
|
|
251
317
|
*/
|
|
252
318
|
function webSQLErrback (webSQLErr) {
|
|
253
319
|
let name, message;
|
|
@@ -275,7 +341,13 @@ function webSQLErrback (webSQLErr) {
|
|
|
275
341
|
}
|
|
276
342
|
}
|
|
277
343
|
message += ' (' + webSQLErr.message + ')--(' + webSQLErr.code + ')';
|
|
278
|
-
const err =
|
|
344
|
+
const err =
|
|
345
|
+
/**
|
|
346
|
+
* @type {(Error | DOMException) & {
|
|
347
|
+
* sqlError: SQLError
|
|
348
|
+
* }}
|
|
349
|
+
*/
|
|
350
|
+
(createDOMException(name, message));
|
|
279
351
|
err.sqlError = webSQLErr;
|
|
280
352
|
return err;
|
|
281
353
|
}
|
|
@@ -292,11 +364,25 @@ try {
|
|
|
292
364
|
} catch (e) {}
|
|
293
365
|
|
|
294
366
|
const createDOMException = useNativeDOMException
|
|
295
|
-
|
|
367
|
+
// eslint-disable-next-line @stylistic/operator-linebreak -- Need JSDoc
|
|
368
|
+
? /**
|
|
369
|
+
* @param {string} name
|
|
370
|
+
* @param {string} message
|
|
371
|
+
* @param {ErrorLike} [error]
|
|
372
|
+
* @returns {DOMException}
|
|
373
|
+
*/
|
|
374
|
+
function (name, message, error) {
|
|
296
375
|
logError(name, message, error);
|
|
297
376
|
return createNativeDOMException(name, message);
|
|
298
377
|
}
|
|
299
|
-
|
|
378
|
+
// eslint-disable-next-line @stylistic/operator-linebreak -- Need JSDoc
|
|
379
|
+
: /**
|
|
380
|
+
* @param {string} name
|
|
381
|
+
* @param {string} message
|
|
382
|
+
* @param {ErrorLike} [error]
|
|
383
|
+
* @returns {Error}
|
|
384
|
+
*/
|
|
385
|
+
function (name, message, error) {
|
|
300
386
|
logError(name, message, error);
|
|
301
387
|
return createNonNativeDOMException(name, message);
|
|
302
388
|
};
|
package/src/DOMStringList.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {number} Integer
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {{
|
|
7
|
+
* _items: string[],
|
|
8
|
+
* _length: Integer,
|
|
9
|
+
* [key: number]: string,
|
|
10
|
+
* addIndexes: () => void,
|
|
11
|
+
* sortList: () => string[],
|
|
12
|
+
* push: (item: string) => void,
|
|
13
|
+
* clone: () => DOMStringListFull,
|
|
14
|
+
* contains: (str: string) => boolean,
|
|
15
|
+
* indexOf: (str: string) => Integer,
|
|
16
|
+
* splice: (index: Integer, howmany: Integer, ...args: any) => void
|
|
17
|
+
* length: Integer
|
|
18
|
+
* }} DOMStringListFull
|
|
19
|
+
*/
|
|
20
|
+
|
|
1
21
|
let cleanInterface = false;
|
|
2
22
|
|
|
3
23
|
const testObject = {test: true};
|
|
@@ -19,17 +39,33 @@ if (Object.defineProperty) {
|
|
|
19
39
|
* @class
|
|
20
40
|
*/
|
|
21
41
|
const DOMStringList = function () {
|
|
42
|
+
/** @type {string[]} */
|
|
43
|
+
this._items = [];
|
|
44
|
+
/** @type {Integer} */
|
|
45
|
+
this._length = 0;
|
|
22
46
|
throw new TypeError('Illegal constructor');
|
|
23
47
|
};
|
|
48
|
+
|
|
49
|
+
// @ts-expect-error It's ok
|
|
24
50
|
DOMStringList.prototype = {
|
|
25
51
|
constructor: DOMStringList,
|
|
26
52
|
// Interface.
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {string} str
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
27
58
|
contains (str) {
|
|
28
59
|
if (!arguments.length) {
|
|
29
60
|
throw new TypeError('DOMStringList.contains must be supplied a value');
|
|
30
61
|
}
|
|
31
62
|
return this._items.includes(str);
|
|
32
63
|
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {number} key
|
|
67
|
+
* @returns {string|null}
|
|
68
|
+
*/
|
|
33
69
|
item (key) {
|
|
34
70
|
if (!arguments.length) {
|
|
35
71
|
throw new TypeError('DOMStringList.item must be supplied a value');
|
|
@@ -41,6 +77,9 @@ DOMStringList.prototype = {
|
|
|
41
77
|
},
|
|
42
78
|
|
|
43
79
|
// Helpers. Should only be used internally.
|
|
80
|
+
/**
|
|
81
|
+
* @returns {DOMStringListFull}
|
|
82
|
+
*/
|
|
44
83
|
clone () {
|
|
45
84
|
const stringList = DOMStringList.__createInstance();
|
|
46
85
|
stringList._items = this._items.slice();
|
|
@@ -48,11 +87,19 @@ DOMStringList.prototype = {
|
|
|
48
87
|
stringList.addIndexes();
|
|
49
88
|
return stringList;
|
|
50
89
|
},
|
|
90
|
+
/**
|
|
91
|
+
* @this {DOMStringListFull}
|
|
92
|
+
* @returns {void}
|
|
93
|
+
*/
|
|
51
94
|
addIndexes () {
|
|
52
95
|
for (let i = 0; i < this._items.length; i++) {
|
|
53
96
|
this[i] = this._items[i];
|
|
54
97
|
}
|
|
55
98
|
},
|
|
99
|
+
/**
|
|
100
|
+
* @this {DOMStringListFull}
|
|
101
|
+
* @returns {string[]}
|
|
102
|
+
*/
|
|
56
103
|
sortList () {
|
|
57
104
|
// http://w3c.github.io/IndexedDB/#sorted-list
|
|
58
105
|
// https://tc39.github.io/ecma262/#sec-abstract-relational-comparison
|
|
@@ -60,22 +107,49 @@ DOMStringList.prototype = {
|
|
|
60
107
|
this.addIndexes();
|
|
61
108
|
return this._items;
|
|
62
109
|
},
|
|
110
|
+
/**
|
|
111
|
+
* @param {(value: string, i: Integer, arr: string[]) => void} cb
|
|
112
|
+
* @param {object} thisArg
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
63
115
|
forEach (cb, thisArg) {
|
|
64
116
|
// eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
|
|
65
117
|
this._items.forEach(cb, thisArg);
|
|
66
118
|
},
|
|
119
|
+
/**
|
|
120
|
+
* @param {(value: string, i: Integer, arr: string[]) => any[]} cb
|
|
121
|
+
* @param {object} thisArg
|
|
122
|
+
* @returns {any[]}
|
|
123
|
+
*/
|
|
67
124
|
map (cb, thisArg) {
|
|
68
125
|
// eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
|
|
69
126
|
return this._items.map(cb, thisArg);
|
|
70
127
|
},
|
|
128
|
+
/**
|
|
129
|
+
* @param {string} str
|
|
130
|
+
* @returns {Integer}
|
|
131
|
+
*/
|
|
71
132
|
indexOf (str) {
|
|
72
133
|
return this._items.indexOf(str);
|
|
73
134
|
},
|
|
135
|
+
/**
|
|
136
|
+
* @param {string} item
|
|
137
|
+
* @this {DOMStringListFull}
|
|
138
|
+
* @returns {void}
|
|
139
|
+
*/
|
|
74
140
|
push (item) {
|
|
75
141
|
this._items.push(item);
|
|
76
142
|
this._length++;
|
|
77
143
|
this.sortList();
|
|
78
144
|
},
|
|
145
|
+
/**
|
|
146
|
+
* @typedef {any} AnyArgs
|
|
147
|
+
*/
|
|
148
|
+
/**
|
|
149
|
+
* @param {[index: Integer, howmany: Integer, ...args: any]} args
|
|
150
|
+
* @this {DOMStringListFull}
|
|
151
|
+
* @returns {void}
|
|
152
|
+
*/
|
|
79
153
|
splice (...args /* index, howmany, item1, ..., itemX */) {
|
|
80
154
|
this._items.splice(...args);
|
|
81
155
|
this._length = this._items.length;
|
|
@@ -92,21 +166,36 @@ DOMStringList.prototype = {
|
|
|
92
166
|
// and particularly as some methods, e.g., `IDBDatabase.transaction`
|
|
93
167
|
// expect such sequence<DOMString> (or DOMString), we need an iterator (some of
|
|
94
168
|
// the Mocha tests rely on these)
|
|
95
|
-
*
|
|
169
|
+
*[Symbol.iterator] () {
|
|
96
170
|
let i = 0;
|
|
97
171
|
while (i < this._items.length) {
|
|
98
172
|
yield this._items[i++];
|
|
99
173
|
}
|
|
100
174
|
}
|
|
101
175
|
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @typedef {any} AnyValue
|
|
179
|
+
*/
|
|
102
180
|
Object.defineProperty(DOMStringList, Symbol.hasInstance, {
|
|
181
|
+
/**
|
|
182
|
+
* @param {AnyValue} obj
|
|
183
|
+
* @returns {boolean}
|
|
184
|
+
*/
|
|
103
185
|
value (obj) {
|
|
104
186
|
return Object.prototype.toString.call(obj) === 'DOMStringListPrototype';
|
|
105
187
|
}
|
|
106
188
|
});
|
|
107
189
|
const DOMStringListAlias = DOMStringList;
|
|
108
190
|
Object.defineProperty(DOMStringList, '__createInstance', {
|
|
191
|
+
/**
|
|
192
|
+
* @returns {DOMStringListFull}
|
|
193
|
+
*/
|
|
109
194
|
value () {
|
|
195
|
+
/**
|
|
196
|
+
* @class
|
|
197
|
+
* @this {DOMStringList}
|
|
198
|
+
*/
|
|
110
199
|
const DOMStringList = function DOMStringList () {
|
|
111
200
|
this.toString = function () {
|
|
112
201
|
return '[object DOMStringList]';
|
|
@@ -118,11 +207,11 @@ Object.defineProperty(DOMStringList, '__createInstance', {
|
|
|
118
207
|
return this._length;
|
|
119
208
|
}
|
|
120
209
|
});
|
|
121
|
-
this._items = [];
|
|
210
|
+
this._items = /** @type {string[]} */ ([]);
|
|
122
211
|
this._length = 0;
|
|
123
212
|
};
|
|
124
213
|
DOMStringList.prototype = DOMStringListAlias.prototype;
|
|
125
|
-
return new DOMStringList();
|
|
214
|
+
return /** @type {DOMStringListFull} */ (new DOMStringList());
|
|
126
215
|
}
|
|
127
216
|
});
|
|
128
217
|
|
|
@@ -139,6 +228,7 @@ if (cleanInterface) {
|
|
|
139
228
|
});
|
|
140
229
|
|
|
141
230
|
// Illegal invocations
|
|
231
|
+
// @ts-expect-error No return value
|
|
142
232
|
Object.defineProperty(DOMStringList.prototype, 'length', {
|
|
143
233
|
configurable: true,
|
|
144
234
|
enumerable: true,
|
package/src/Event.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import {ShimEventTarget, ShimEvent, ShimCustomEvent} from 'eventtargeter';
|
|
2
2
|
import * as util from './util.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Error} DebuggingError
|
|
6
|
+
*/
|
|
7
|
+
|
|
4
8
|
/**
|
|
5
9
|
*
|
|
6
10
|
* @param {string} type
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {EventInit} evInit
|
|
9
|
-
* @returns {Event
|
|
11
|
+
* @param {DebuggingError|null} [debug]
|
|
12
|
+
* @param {EventInit} [evInit]
|
|
13
|
+
* @returns {Event & {
|
|
14
|
+
* __legacyOutputDidListenersThrowError?: boolean
|
|
15
|
+
* }}
|
|
10
16
|
*/
|
|
11
17
|
function createEvent (type, debug, evInit) {
|
|
18
|
+
// @ts-expect-error It's ok
|
|
12
19
|
const ev = new ShimEvent(type, evInit);
|
|
13
20
|
ev.debug = debug;
|
|
14
21
|
return ev;
|
|
@@ -16,7 +23,15 @@ function createEvent (type, debug, evInit) {
|
|
|
16
23
|
|
|
17
24
|
// We don't add within polyfill repo as might not always be the desired implementation
|
|
18
25
|
Object.defineProperty(ShimEvent, Symbol.hasInstance, {
|
|
19
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {any} AnyValue
|
|
28
|
+
*/
|
|
29
|
+
value:
|
|
30
|
+
/**
|
|
31
|
+
* @param {AnyValue} obj
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
*/
|
|
34
|
+
(obj) => util.isObj(obj) && 'target' in obj && 'bubbles' in obj && typeof obj.bubbles === 'boolean'
|
|
20
35
|
});
|
|
21
36
|
|
|
22
37
|
export {createEvent, ShimEvent, ShimCustomEvent, ShimEventTarget};
|