diff options
Diffstat (limited to 'ext/web')
-rw-r--r-- | ext/web/01_dom_exception.js | 57 | ||||
-rw-r--r-- | ext/web/01_mimesniff.js | 6 | ||||
-rw-r--r-- | ext/web/02_event.js | 13 | ||||
-rw-r--r-- | ext/web/03_abort_signal.js | 8 | ||||
-rw-r--r-- | ext/web/05_base64.js | 9 | ||||
-rw-r--r-- | ext/web/06_streams.js | 15 | ||||
-rw-r--r-- | ext/web/09_file.js | 12 | ||||
-rw-r--r-- | ext/web/10_filereader.js | 2 | ||||
-rw-r--r-- | ext/web/13_message_port.js | 7 |
9 files changed, 74 insertions, 55 deletions
diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js index d04006204..e278c8652 100644 --- a/ext/web/01_dom_exception.js +++ b/ext/web/01_dom_exception.js @@ -19,6 +19,7 @@ ObjectEntries, ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, + SafeArrayIterator, Symbol, SymbolFor, } = window.__bootstrap.primordials; @@ -166,33 +167,35 @@ const DOMExceptionPrototype = DOMException.prototype; for ( - const [key, value] of ObjectEntries({ - INDEX_SIZE_ERR, - DOMSTRING_SIZE_ERR, - HIERARCHY_REQUEST_ERR, - WRONG_DOCUMENT_ERR, - INVALID_CHARACTER_ERR, - NO_DATA_ALLOWED_ERR, - NO_MODIFICATION_ALLOWED_ERR, - NOT_FOUND_ERR, - NOT_SUPPORTED_ERR, - INUSE_ATTRIBUTE_ERR, - INVALID_STATE_ERR, - SYNTAX_ERR, - INVALID_MODIFICATION_ERR, - NAMESPACE_ERR, - INVALID_ACCESS_ERR, - VALIDATION_ERR, - TYPE_MISMATCH_ERR, - SECURITY_ERR, - NETWORK_ERR, - ABORT_ERR, - URL_MISMATCH_ERR, - QUOTA_EXCEEDED_ERR, - TIMEOUT_ERR, - INVALID_NODE_TYPE_ERR, - DATA_CLONE_ERR, - }) + const [key, value] of new SafeArrayIterator( + ObjectEntries({ + INDEX_SIZE_ERR, + DOMSTRING_SIZE_ERR, + HIERARCHY_REQUEST_ERR, + WRONG_DOCUMENT_ERR, + INVALID_CHARACTER_ERR, + NO_DATA_ALLOWED_ERR, + NO_MODIFICATION_ALLOWED_ERR, + NOT_FOUND_ERR, + NOT_SUPPORTED_ERR, + INUSE_ATTRIBUTE_ERR, + INVALID_STATE_ERR, + SYNTAX_ERR, + INVALID_MODIFICATION_ERR, + NAMESPACE_ERR, + INVALID_ACCESS_ERR, + VALIDATION_ERR, + TYPE_MISMATCH_ERR, + SECURITY_ERR, + NETWORK_ERR, + ABORT_ERR, + URL_MISMATCH_ERR, + QUOTA_EXCEEDED_ERR, + TIMEOUT_ERR, + INVALID_NODE_TYPE_ERR, + DATA_CLONE_ERR, + }), + ) ) { const desc = { value, enumerable: true }; ObjectDefineProperty(DOMException, key, desc); diff --git a/ext/web/01_mimesniff.js b/ext/web/01_mimesniff.js index d2c784d6e..47453bd99 100644 --- a/ext/web/01_mimesniff.js +++ b/ext/web/01_mimesniff.js @@ -16,6 +16,8 @@ MapPrototypeHas, MapPrototypeSet, RegExpPrototypeTest, + SafeArrayIterator, + SafeMapIterator, StringPrototypeReplaceAll, StringPrototypeToLowerCase, } = window.__bootstrap.primordials; @@ -195,7 +197,7 @@ */ function serializeMimeType(mimeType) { let serialization = essence(mimeType); - for (const param of mimeType.parameters) { + for (const param of new SafeMapIterator(mimeType.parameters)) { serialization += `;${param[0]}=`; let value = param[1]; if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, value)) { @@ -221,7 +223,7 @@ let charset = null; let essence_ = null; let mimeType = null; - for (const value of headerValues) { + for (const value of new SafeArrayIterator(headerValues)) { const temporaryMimeType = parseMimeType(value); if ( temporaryMimeType === null || diff --git a/ext/web/02_event.js b/ext/web/02_event.js index fa1c94332..060101498 100644 --- a/ext/web/02_event.js +++ b/ext/web/02_event.js @@ -428,7 +428,7 @@ Ctor, props, ) { - for (const prop of props) { + for (const prop of new SafeArrayIterator(props)) { ReflectDefineProperty(Ctor.prototype, prop, { enumerable: true }); } } @@ -969,7 +969,7 @@ listeners[type] = []; } - for (const listener of listeners[type]) { + for (const listener of new SafeArrayIterator(listeners[type])) { if ( ((typeof listener.options === "boolean" && listener.options === options.capture) || @@ -1334,9 +1334,12 @@ [SymbolFor("Deno.privateCustomInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: this instanceof PromiseRejectionEvent, + evaluate: ObjectPrototypeIsPrototypeOf( + PromiseRejectionEvent.prototype, + this, + ), keys: [ - ...EVENT_PROPS, + ...new SafeArrayIterator(EVENT_PROPS), "promise", "reason", ], @@ -1451,7 +1454,7 @@ colno = jsError.frames[0].columnNumber; } else { const jsError = core.destructureError(new Error()); - for (const frame of jsError.frames) { + for (const frame of new SafeArrayIterator(jsError.frames)) { if ( typeof frame.fileName == "string" && !StringPrototypeStartsWith(frame.fileName, "deno:") diff --git a/ext/web/03_abort_signal.js b/ext/web/03_abort_signal.js index 2fa3c4bcf..70511a934 100644 --- a/ext/web/03_abort_signal.js +++ b/ext/web/03_abort_signal.js @@ -9,6 +9,8 @@ const { Event, setIsTrusted, defineEventHandler } = window.__bootstrap.event; const { EventTarget, listenerCount } = window.__bootstrap.eventTarget; const { + SafeArrayIterator, + SafeSetIterator, Set, SetPrototypeAdd, SetPrototypeDelete, @@ -76,7 +78,7 @@ } this[abortReason] = reason; if (this[abortAlgos] !== null) { - for (const algorithm of this[abortAlgos]) { + for (const algorithm of new SafeSetIterator(this[abortAlgos])) { algorithm(); } this[abortAlgos] = null; @@ -124,14 +126,14 @@ // only be used by Deno internals, which use it to essentially cancel async // ops which would block the event loop. addEventListener(...args) { - super.addEventListener(...args); + super.addEventListener(...new SafeArrayIterator(args)); if (this[timerId] !== null && listenerCount(this, "abort") > 0) { refTimer(this[timerId]); } } removeEventListener(...args) { - super.removeEventListener(...args); + super.removeEventListener(...new SafeArrayIterator(args)); if (this[timerId] !== null && listenerCount(this, "abort") === 0) { unrefTimer(this[timerId]); } diff --git a/ext/web/05_base64.js b/ext/web/05_base64.js index 89c409ae2..d963596ce 100644 --- a/ext/web/05_base64.js +++ b/ext/web/05_base64.js @@ -13,7 +13,10 @@ const ops = core.ops; const webidl = window.__bootstrap.webidl; const { DOMException } = window.__bootstrap.domException; - const { TypeError } = window.__bootstrap.primordials; + const { + ObjectPrototypeIsPrototypeOf, + TypeErrorPrototype, + } = window.__bootstrap.primordials; /** * @param {string} data @@ -29,7 +32,7 @@ try { return ops.op_base64_atob(data); } catch (e) { - if (e instanceof TypeError) { + if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) { throw new DOMException( "Failed to decode base64: invalid character", "InvalidCharacterError", @@ -53,7 +56,7 @@ try { return ops.op_base64_btoa(data); } catch (e) { - if (e instanceof TypeError) { + if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) { throw new DOMException( "The string to be encoded contains characters outside of the Latin1 range.", "InvalidCharacterError", diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index d51556a37..2a032b326 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -42,6 +42,7 @@ queueMicrotask, RangeError, ReflectHas, + SafeArrayIterator, SafePromiseAll, SharedArrayBuffer, Symbol, @@ -769,7 +770,7 @@ } function readableStreamIsUnrefable(stream) { - return _isUnref in stream; + return ReflectHas(stream, _isUnref); } function readableStreamForRidUnrefableRef(stream) { @@ -858,7 +859,7 @@ const finalBuffer = new Uint8Array(totalLength); let i = 0; - for (const chunk of chunks) { + for (const chunk of new SafeArrayIterator(chunks)) { TypedArrayPrototypeSet(finalBuffer, chunk, i); i += chunk.byteLength; } @@ -1345,7 +1346,7 @@ if (reader !== undefined && isReadableStreamBYOBReader(reader)) { const readIntoRequests = reader[_readIntoRequests]; reader[_readIntoRequests] = []; - for (const readIntoRequest of readIntoRequests) { + for (const readIntoRequest of new SafeArrayIterator(readIntoRequests)) { readIntoRequest.closeSteps(undefined); } } @@ -1371,7 +1372,7 @@ /** @type {Array<ReadRequest<R>>} */ const readRequests = reader[_readRequests]; reader[_readRequests] = []; - for (const readRequest of readRequests) { + for (const readRequest of new SafeArrayIterator(readRequests)) { readRequest.closeSteps(); } } @@ -1593,7 +1594,7 @@ function readableStreamDefaultReaderErrorReadRequests(reader, e) { const readRequests = reader[_readRequests]; reader[_readRequests] = []; - for (const readRequest of readRequests) { + for (const readRequest of new SafeArrayIterator(readRequests)) { readRequest.errorSteps(e); } } @@ -2613,7 +2614,7 @@ function readableStreamBYOBReaderErrorReadIntoRequests(reader, e) { const readIntoRequests = reader[_readIntoRequests]; reader[_readIntoRequests] = []; - for (const readIntoRequest of readIntoRequests) { + for (const readIntoRequest of new SafeArrayIterator(readIntoRequests)) { readIntoRequest.errorSteps(e); } } @@ -4237,7 +4238,7 @@ stream[_state] = "errored"; stream[_controller][_errorSteps](); const storedError = stream[_storedError]; - for (const writeRequest of stream[_writeRequests]) { + for (const writeRequest of new SafeArrayIterator(stream[_writeRequests])) { writeRequest.reject(storedError); } stream[_writeRequests] = []; diff --git a/ext/web/09_file.js b/ext/web/09_file.js index d01858c92..9c3a36dc0 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -26,6 +26,7 @@ MathMin, ObjectPrototypeIsPrototypeOf, RegExpPrototypeTest, + SafeArrayIterator, StringPrototypeCharAt, StringPrototypeToLowerCase, StringPrototypeSlice, @@ -94,7 +95,7 @@ /** @param {(BlobReference | Blob)[]} parts */ async function* toIterator(parts) { - for (const part of parts) { + for (const part of new SafeArrayIterator(parts)) { yield* part.stream(); } } @@ -110,7 +111,7 @@ /** @type {(BlobReference|Blob)[]} */ const processedParts = []; let size = 0; - for (const element of parts) { + for (const element of new SafeArrayIterator(parts)) { if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, element)) { const chunk = new Uint8Array(ArrayBufferPrototypeSlice(element, 0)); ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk)); @@ -158,7 +159,7 @@ * @returns {string[]} */ function getParts(blob, bag = []) { - for (const part of blob[_parts]) { + for (const part of new SafeArrayIterator(blob[_parts])) { if (ObjectPrototypeIsPrototypeOf(BlobPrototype, part)) { getParts(part, bag); } else { @@ -275,7 +276,7 @@ const blobParts = []; let added = 0; - for (const part of this[_parts]) { + for (const part of new SafeArrayIterator(this[_parts])) { // don't add the overflow to new blobParts if (added >= span) { // Could maybe be possible to remove variable `added` @@ -349,6 +350,7 @@ const bytes = new Uint8Array(size); const partIterator = toIterator(this[_parts]); let offset = 0; + // deno-lint-ignore prefer-primordials for await (const chunk of partIterator) { const byteLength = chunk.byteLength; if (byteLength > 0) { @@ -598,7 +600,7 @@ const parts = []; let totalSize = 0; - for (const { uuid, size } of blobData.parts) { + for (const { uuid, size } of new SafeArrayIterator(blobData.parts)) { ArrayPrototypePush(parts, new BlobReference(uuid, size)); totalSize += size; } diff --git a/ext/web/10_filereader.js b/ext/web/10_filereader.js index 49f4babe1..30396a8d0 100644 --- a/ext/web/10_filereader.js +++ b/ext/web/10_filereader.js @@ -158,7 +158,7 @@ ); const bytes = new Uint8Array(size); let offs = 0; - for (const chunk of chunks) { + for (const chunk of new SafeArrayIterator(chunks)) { TypedArrayPrototypeSet(bytes, chunk, offs); offs += chunk.byteLength; } diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index 7343fbe58..7ec8dc9f9 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -22,6 +22,7 @@ ArrayPrototypePush, ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, + SafeArrayIterator, Symbol, SymbolFor, SymbolIterator, @@ -204,7 +205,9 @@ const arrayBufferIdsInTransferables = []; const transferredArrayBuffers = []; - for (const transferable of messageData.transferables) { + for ( + const transferable of new SafeArrayIterator(messageData.transferables) + ) { switch (transferable.kind) { case "messagePort": { const port = createMessagePort(transferable.data); @@ -271,7 +274,7 @@ const serializedTransferables = []; let arrayBufferI = 0; - for (const transferable of transferables) { + for (const transferable of new SafeArrayIterator(transferables)) { if (ObjectPrototypeIsPrototypeOf(MessagePortPrototype, transferable)) { webidl.assertBranded(transferable, MessagePortPrototype); const id = transferable[_id]; |