1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-12 00:54:02 -05:00

perf(ext,runtime): remove using SafeArrayIterator from for-of (#17255)

This commit is contained in:
Kenta Moriuchi 2023-01-06 21:45:23 +09:00 committed by David Sherret
parent c56477654f
commit 32d66b7425
20 changed files with 173 additions and 126 deletions

View file

@ -16,7 +16,6 @@
ArrayPrototypeIndexOf, ArrayPrototypeIndexOf,
ArrayPrototypeSplice, ArrayPrototypeSplice,
ArrayPrototypePush, ArrayPrototypePush,
SafeArrayIterator,
Symbol, Symbol,
Uint8Array, Uint8Array,
} = window.__bootstrap.primordials; } = window.__bootstrap.primordials;
@ -44,7 +43,9 @@
} }
function dispatch(source, name, data) { function dispatch(source, name, data) {
for (const channel of new SafeArrayIterator(channels)) { for (let i = 0; i < channels.length; ++i) {
const channel = channels[i];
if (channel === source) continue; // Don't self-send. if (channel === source) continue; // Don't self-send.
if (channel[_name] !== name) continue; if (channel[_name] !== name) continue;
if (channel[_closed]) continue; if (channel[_closed]) continue;

View file

@ -6,7 +6,6 @@
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const { const {
Symbol, Symbol,
SafeArrayIterator,
TypeError, TypeError,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
} = window.__bootstrap.primordials; } = window.__bootstrap.primordials;
@ -115,7 +114,8 @@
const varyHeader = getHeader(innerResponse.headerList, "vary"); const varyHeader = getHeader(innerResponse.headerList, "vary");
if (varyHeader) { if (varyHeader) {
const fieldValues = varyHeader.split(","); const fieldValues = varyHeader.split(",");
for (const field of new SafeArrayIterator(fieldValues)) { for (let i = 0; i < fieldValues.length; ++i) {
const field = fieldValues[i];
if (field.trim() === "*") { if (field.trim() === "*") {
throw new TypeError("Vary header must not contain '*'"); throw new TypeError("Vary header must not contain '*'");
} }

View file

@ -277,7 +277,8 @@
}` + }` +
`${tableChars.rightMiddle}\n`; `${tableChars.rightMiddle}\n`;
for (const row of new SafeArrayIterator(rows)) { for (let i = 0; i < rows.length; ++i) {
const row = rows[i];
result += `${renderRow(row, columnWidths, columnRightAlign)}\n`; result += `${renderRow(row, columnWidths, columnRightAlign)}\n`;
} }
@ -995,7 +996,8 @@
} }
const refMap = new Map(); const refMap = new Map();
for (const cause of new SafeArrayIterator(causes)) { for (let i = 0; i < causes.length; ++i) {
const cause = causes[i];
if (circular !== undefined) { if (circular !== undefined) {
const index = MapPrototypeGet(circular, cause); const index = MapPrototypeGet(circular, cause);
if (index !== undefined) { if (index !== undefined) {
@ -1172,7 +1174,8 @@
inspectOptions.indentLevel++; inspectOptions.indentLevel++;
for (const key of new SafeArrayIterator(stringKeys)) { for (let i = 0; i < stringKeys.length; ++i) {
const key = stringKeys[i];
if (inspectOptions.getters) { if (inspectOptions.getters) {
let propertyValue; let propertyValue;
let error = null; let error = null;
@ -1208,7 +1211,8 @@
} }
} }
for (const key of new SafeArrayIterator(symbolKeys)) { for (let i = 0; i < symbolKeys.length; ++i) {
const key = symbolKeys[i];
if ( if (
!inspectOptions.showHidden && !inspectOptions.showHidden &&
!propertyIsEnumerable(value, key) !propertyIsEnumerable(value, key)
@ -1640,7 +1644,8 @@
currentPart = ""; currentPart = "";
} }
for (const [key, value] of new SafeArrayIterator(rawEntries)) { for (let i = 0; i < rawEntries.length; ++i) {
const [key, value] = rawEntries[i];
if (key == "background-color") { if (key == "background-color") {
if (value != null) { if (value != null) {
css.backgroundColor = value; css.backgroundColor = value;
@ -1661,11 +1666,9 @@
} }
} else if (key == "text-decoration-line") { } else if (key == "text-decoration-line") {
css.textDecorationLine = []; css.textDecorationLine = [];
for ( const lineTypes = StringPrototypeSplit(value, /\s+/g);
const lineType of new SafeArrayIterator( for (let i = 0; i < lineTypes.length; ++i) {
StringPrototypeSplit(value, /\s+/g), const lineType = lineTypes[i];
)
) {
if ( if (
ArrayPrototypeIncludes( ArrayPrototypeIncludes(
["line-through", "overline", "underline"], ["line-through", "overline", "underline"],
@ -1683,11 +1686,9 @@
} else if (key == "text-decoration") { } else if (key == "text-decoration") {
css.textDecorationColor = null; css.textDecorationColor = null;
css.textDecorationLine = []; css.textDecorationLine = [];
for ( const args = StringPrototypeSplit(value, /\s+/g);
const arg of new SafeArrayIterator( for (let i = 0; i < args.length; ++i) {
StringPrototypeSplit(value, /\s+/g), const arg = args[i];
)
) {
const maybeColor = parseCssColor(arg); const maybeColor = parseCssColor(arg);
if (maybeColor != null) { if (maybeColor != null) {
css.textDecorationColor = maybeColor; css.textDecorationColor = maybeColor;
@ -2144,7 +2145,8 @@
} else { } else {
const valueObj = value || {}; const valueObj = value || {};
const keys = properties || ObjectKeys(valueObj); const keys = properties || ObjectKeys(valueObj);
for (const k of new SafeArrayIterator(keys)) { for (let i = 0; i < keys.length; ++i) {
const k = keys[i];
if (!primitive && ReflectHas(valueObj, k)) { if (!primitive && ReflectHas(valueObj, k)) {
if (!(ReflectHas(objectValues, k))) { if (!(ReflectHas(objectValues, k))) {
objectValues[k] = ArrayPrototypeFill(new Array(numRows), ""); objectValues[k] = ArrayPrototypeFill(new Array(numRows), "");
@ -2339,7 +2341,9 @@
function wrapConsole(consoleFromDeno, consoleFromV8) { function wrapConsole(consoleFromDeno, consoleFromV8) {
const callConsole = core.callConsole; const callConsole = core.callConsole;
for (const key of new SafeArrayIterator(ObjectKeys(consoleFromV8))) { const keys = ObjectKeys(consoleFromV8);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
if (ObjectPrototypeHasOwnProperty(consoleFromDeno, key)) { if (ObjectPrototypeHasOwnProperty(consoleFromDeno, key)) {
consoleFromDeno[key] = FunctionPrototypeBind( consoleFromDeno[key] = FunctionPrototypeBind(
callConsole, callConsole,

View file

@ -68,7 +68,8 @@
*/ */
function fillHeaders(headers, object) { function fillHeaders(headers, object) {
if (ArrayIsArray(object)) { if (ArrayIsArray(object)) {
for (const header of new SafeArrayIterator(object)) { for (let i = 0; i < object.length; ++i) {
const header = object[i];
if (header.length !== 2) { if (header.length !== 2) {
throw new TypeError( throw new TypeError(
`Invalid header. Length must be 2, but is ${header.length}`, `Invalid header. Length must be 2, but is ${header.length}`,
@ -205,7 +206,8 @@
// spec but produce the same result. // spec but produce the same result.
const headers = {}; const headers = {};
const cookies = []; const cookies = [];
for (const entry of new SafeArrayIterator(list)) { for (let i = 0; i < list.length; ++i) {
const entry = list[i];
const name = byteLowerCase(entry[0]); const name = byteLowerCase(entry[0]);
const value = entry[1]; const value = entry[1];
if (value === null) throw new TypeError("Unreachable"); if (value === null) throw new TypeError("Unreachable");

View file

@ -25,7 +25,6 @@
MathRandom, MathRandom,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
Symbol, Symbol,
SafeArrayIterator,
StringFromCharCode, StringFromCharCode,
StringPrototypeTrim, StringPrototypeTrim,
StringPrototypeSlice, StringPrototypeSlice,
@ -163,7 +162,9 @@
context: "Argument 1", context: "Argument 1",
}); });
for (const entry of new SafeArrayIterator(this[entryList])) { const entries = this[entryList];
for (let i = 0; i < entries.length; ++i) {
const entry = entries[i];
if (entry.name === name) return entry.value; if (entry.name === name) return entry.value;
} }
return null; return null;
@ -184,7 +185,9 @@
}); });
const returnList = []; const returnList = [];
for (const entry of new SafeArrayIterator(this[entryList])) { const entries = this[entryList];
for (let i = 0; i < entries.length; ++i) {
const entry = entries[i];
if (entry.name === name) ArrayPrototypePush(returnList, entry.value); if (entry.name === name) ArrayPrototypePush(returnList, entry.value);
} }
return returnList; return returnList;
@ -204,7 +207,9 @@
context: "Argument 1", context: "Argument 1",
}); });
for (const entry of new SafeArrayIterator(this[entryList])) { const entries = this[entryList];
for (let i = 0; i < entries.length; ++i) {
const entry = entries[i];
if (entry.name === name) return true; if (entry.name === name) return true;
} }
return false; return false;
@ -374,7 +379,8 @@
#parseHeaders(headersText) { #parseHeaders(headersText) {
const headers = new Headers(); const headers = new Headers();
const rawHeaders = StringPrototypeSplit(headersText, "\r\n"); const rawHeaders = StringPrototypeSplit(headersText, "\r\n");
for (const rawHeader of new SafeArrayIterator(rawHeaders)) { for (let i = 0; i < rawHeaders.length; ++i) {
const rawHeader = rawHeaders[i];
const sepIndex = StringPrototypeIndexOf(rawHeader, ":"); const sepIndex = StringPrototypeIndexOf(rawHeader, ":");
if (sepIndex < 0) { if (sepIndex < 0) {
continue; // Skip this header continue; // Skip this header

View file

@ -31,7 +31,6 @@
PromisePrototype, PromisePrototype,
PromisePrototypeCatch, PromisePrototypeCatch,
PromisePrototypeThen, PromisePrototypeThen,
SafeArrayIterator,
SafePromiseAll, SafePromiseAll,
TypedArrayPrototypeSubarray, TypedArrayPrototypeSubarray,
TypeError, TypeError,
@ -140,7 +139,8 @@
// status-line = HTTP-version SP status-code SP reason-phrase CRLF // status-line = HTTP-version SP status-code SP reason-phrase CRLF
// Date header: https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.2 // Date header: https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.2
let str = `HTTP/1.1 ${status} ${statusCodes[status]}\r\nDate: ${date}\r\n`; let str = `HTTP/1.1 ${status} ${statusCodes[status]}\r\nDate: ${date}\r\n`;
for (const [name, value] of new SafeArrayIterator(headerList)) { for (let i = 0; i < headerList.length; ++i) {
const [name, value] = headerList[i];
// header-field = field-name ":" OWS field-value OWS // header-field = field-name ":" OWS field-value OWS
str += `${name}: ${value}\r\n`; str += `${name}: ${value}\r\n`;
} }

View file

@ -194,7 +194,9 @@
context: "Argument 1", context: "Argument 1",
}); });
const values = []; const values = [];
for (const entry of new SafeArrayIterator(this[_list])) { const entries = this[_list];
for (let i = 0; i < entries.length; ++i) {
const entry = entries[i];
if (entry[0] === name) { if (entry[0] === name) {
ArrayPrototypePush(values, entry[1]); ArrayPrototypePush(values, entry[1]);
} }
@ -214,7 +216,9 @@
prefix, prefix,
context: "Argument 1", context: "Argument 1",
}); });
for (const entry of new SafeArrayIterator(this[_list])) { const entries = this[_list];
for (let i = 0; i < entries.length; ++i) {
const entry = entries[i];
if (entry[0] === name) { if (entry[0] === name) {
return entry[1]; return entry[1];
} }

View file

@ -20,7 +20,6 @@
RegExp, RegExp,
RegExpPrototypeExec, RegExpPrototypeExec,
RegExpPrototypeTest, RegExpPrototypeTest,
SafeArrayIterator,
Symbol, Symbol,
SymbolFor, SymbolFor,
TypeError, TypeError,
@ -72,7 +71,9 @@
const components = ops.op_urlpattern_parse(input, baseURL); const components = ops.op_urlpattern_parse(input, baseURL);
for (const key of new SafeArrayIterator(ObjectKeys(components))) { const keys = ObjectKeys(components);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
try { try {
components[key].regexp = new RegExp( components[key].regexp = new RegExp(
components[key].regexpString, components[key].regexpString,
@ -156,7 +157,9 @@
const [values] = res; const [values] = res;
for (const key of new SafeArrayIterator(ObjectKeys(values))) { const keys = ObjectKeys(values);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
if (!RegExpPrototypeTest(this[_components][key].regexp, values[key])) { if (!RegExpPrototypeTest(this[_components][key].regexp, values[key])) {
return false; return false;
} }
@ -201,8 +204,9 @@
/** @type {URLPatternResult} */ /** @type {URLPatternResult} */
const result = { inputs }; const result = { inputs };
/** @type {string} */ const keys = ObjectKeys(values);
for (const key of new SafeArrayIterator(ObjectKeys(values))) { for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
/** @type {Component} */ /** @type {Component} */
const component = this[_components][key]; const component = this[_components][key];
const input = values[key]; const input = values[key];

View file

@ -19,7 +19,6 @@
ObjectEntries, ObjectEntries,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
ObjectSetPrototypeOf, ObjectSetPrototypeOf,
SafeArrayIterator,
Symbol, Symbol,
SymbolFor, SymbolFor,
} = window.__bootstrap.primordials; } = window.__bootstrap.primordials;
@ -166,9 +165,7 @@
webidl.configurePrototype(DOMException); webidl.configurePrototype(DOMException);
const DOMExceptionPrototype = DOMException.prototype; const DOMExceptionPrototype = DOMException.prototype;
for ( const entries = ObjectEntries({
const [key, value] of new SafeArrayIterator(
ObjectEntries({
INDEX_SIZE_ERR, INDEX_SIZE_ERR,
DOMSTRING_SIZE_ERR, DOMSTRING_SIZE_ERR,
HIERARCHY_REQUEST_ERR, HIERARCHY_REQUEST_ERR,
@ -194,9 +191,9 @@
TIMEOUT_ERR, TIMEOUT_ERR,
INVALID_NODE_TYPE_ERR, INVALID_NODE_TYPE_ERR,
DATA_CLONE_ERR, DATA_CLONE_ERR,
}), });
) for (let i = 0; i < entries.length; ++i) {
) { const [key, value] = entries[i];
const desc = { value, enumerable: true }; const desc = { value, enumerable: true };
ObjectDefineProperty(DOMException, key, desc); ObjectDefineProperty(DOMException, key, desc);
ObjectDefineProperty(DOMException.prototype, key, desc); ObjectDefineProperty(DOMException.prototype, key, desc);

View file

@ -16,7 +16,6 @@
MapPrototypeHas, MapPrototypeHas,
MapPrototypeSet, MapPrototypeSet,
RegExpPrototypeTest, RegExpPrototypeTest,
SafeArrayIterator,
SafeMapIterator, SafeMapIterator,
StringPrototypeReplaceAll, StringPrototypeReplaceAll,
StringPrototypeToLowerCase, StringPrototypeToLowerCase,
@ -223,7 +222,8 @@
let charset = null; let charset = null;
let essence_ = null; let essence_ = null;
let mimeType = null; let mimeType = null;
for (const value of new SafeArrayIterator(headerValues)) { for (let i = 0; i < headerValues.length; ++i) {
const value = headerValues[i];
const temporaryMimeType = parseMimeType(value); const temporaryMimeType = parseMimeType(value);
if ( if (
temporaryMimeType === null || temporaryMimeType === null ||

View file

@ -428,7 +428,8 @@
Ctor, Ctor,
props, props,
) { ) {
for (const prop of new SafeArrayIterator(props)) { for (let i = 0; i < props.length; ++i) {
const prop = props[i];
ReflectDefineProperty(Ctor.prototype, prop, { enumerable: true }); ReflectDefineProperty(Ctor.prototype, prop, { enumerable: true });
} }
} }
@ -969,7 +970,9 @@
listeners[type] = []; listeners[type] = [];
} }
for (const listener of new SafeArrayIterator(listeners[type])) { const listenerList = listeners[type];
for (let i = 0; i < listenerList.length; ++i) {
const listener = listenerList[i];
if ( if (
((typeof listener.options === "boolean" && ((typeof listener.options === "boolean" &&
listener.options === options.capture) || listener.options === options.capture) ||
@ -1454,7 +1457,9 @@
colno = jsError.frames[0].columnNumber; colno = jsError.frames[0].columnNumber;
} else { } else {
const jsError = core.destructureError(new Error()); const jsError = core.destructureError(new Error());
for (const frame of new SafeArrayIterator(jsError.frames)) { const frames = jsError.frames;
for (let i = 0; i < frames.length; ++i) {
const frame = frames[i];
if ( if (
typeof frame.fileName == "string" && typeof frame.fileName == "string" &&
!StringPrototypeStartsWith(frame.fileName, "deno:") !StringPrototypeStartsWith(frame.fileName, "deno:")

View file

@ -42,7 +42,6 @@
queueMicrotask, queueMicrotask,
RangeError, RangeError,
ReflectHas, ReflectHas,
SafeArrayIterator,
SafePromiseAll, SafePromiseAll,
SharedArrayBuffer, SharedArrayBuffer,
Symbol, Symbol,
@ -858,10 +857,11 @@
} }
const finalBuffer = new Uint8Array(totalLength); const finalBuffer = new Uint8Array(totalLength);
let i = 0; let offset = 0;
for (const chunk of new SafeArrayIterator(chunks)) { for (let i = 0; i < chunks.length; ++i) {
TypedArrayPrototypeSet(finalBuffer, chunk, i); const chunk = chunks[i];
i += chunk.byteLength; TypedArrayPrototypeSet(finalBuffer, chunk, offset);
offset += chunk.byteLength;
} }
return finalBuffer; return finalBuffer;
} }
@ -1346,7 +1346,8 @@
if (reader !== undefined && isReadableStreamBYOBReader(reader)) { if (reader !== undefined && isReadableStreamBYOBReader(reader)) {
const readIntoRequests = reader[_readIntoRequests]; const readIntoRequests = reader[_readIntoRequests];
reader[_readIntoRequests] = []; reader[_readIntoRequests] = [];
for (const readIntoRequest of new SafeArrayIterator(readIntoRequests)) { for (let i = 0; i < readIntoRequests.length; ++i) {
const readIntoRequest = readIntoRequests[i];
readIntoRequest.closeSteps(undefined); readIntoRequest.closeSteps(undefined);
} }
} }
@ -1372,7 +1373,8 @@
/** @type {Array<ReadRequest<R>>} */ /** @type {Array<ReadRequest<R>>} */
const readRequests = reader[_readRequests]; const readRequests = reader[_readRequests];
reader[_readRequests] = []; reader[_readRequests] = [];
for (const readRequest of new SafeArrayIterator(readRequests)) { for (let i = 0; i < readRequests.length; ++i) {
const readRequest = readRequests[i];
readRequest.closeSteps(); readRequest.closeSteps();
} }
} }
@ -1594,7 +1596,8 @@
function readableStreamDefaultReaderErrorReadRequests(reader, e) { function readableStreamDefaultReaderErrorReadRequests(reader, e) {
const readRequests = reader[_readRequests]; const readRequests = reader[_readRequests];
reader[_readRequests] = []; reader[_readRequests] = [];
for (const readRequest of new SafeArrayIterator(readRequests)) { for (let i = 0; i < readRequests.length; ++i) {
const readRequest = readRequests[i];
readRequest.errorSteps(e); readRequest.errorSteps(e);
} }
} }
@ -2614,7 +2617,8 @@
function readableStreamBYOBReaderErrorReadIntoRequests(reader, e) { function readableStreamBYOBReaderErrorReadIntoRequests(reader, e) {
const readIntoRequests = reader[_readIntoRequests]; const readIntoRequests = reader[_readIntoRequests];
reader[_readIntoRequests] = []; reader[_readIntoRequests] = [];
for (const readIntoRequest of new SafeArrayIterator(readIntoRequests)) { for (let i = 0; i < readIntoRequests.length; ++i) {
const readIntoRequest = readIntoRequests[i];
readIntoRequest.errorSteps(e); readIntoRequest.errorSteps(e);
} }
} }
@ -4238,7 +4242,9 @@
stream[_state] = "errored"; stream[_state] = "errored";
stream[_controller][_errorSteps](); stream[_controller][_errorSteps]();
const storedError = stream[_storedError]; const storedError = stream[_storedError];
for (const writeRequest of new SafeArrayIterator(stream[_writeRequests])) { const writeRequests = stream[_writeRequests];
for (let i = 0; i < writeRequests.length; ++i) {
const writeRequest = writeRequests[i];
writeRequest.reject(storedError); writeRequest.reject(storedError);
} }
stream[_writeRequests] = []; stream[_writeRequests] = [];

View file

@ -26,7 +26,6 @@
MathMin, MathMin,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
RegExpPrototypeTest, RegExpPrototypeTest,
SafeArrayIterator,
StringPrototypeCharAt, StringPrototypeCharAt,
StringPrototypeToLowerCase, StringPrototypeToLowerCase,
StringPrototypeSlice, StringPrototypeSlice,
@ -95,8 +94,8 @@
/** @param {(BlobReference | Blob)[]} parts */ /** @param {(BlobReference | Blob)[]} parts */
async function* toIterator(parts) { async function* toIterator(parts) {
for (const part of new SafeArrayIterator(parts)) { for (let i = 0; i < parts.length; ++i) {
yield* part.stream(); yield* parts[i].stream();
} }
} }
@ -111,7 +110,8 @@
/** @type {(BlobReference|Blob)[]} */ /** @type {(BlobReference|Blob)[]} */
const processedParts = []; const processedParts = [];
let size = 0; let size = 0;
for (const element of new SafeArrayIterator(parts)) { for (let i = 0; i < parts.length; ++i) {
const element = parts[i];
if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, element)) { if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, element)) {
const chunk = new Uint8Array(ArrayBufferPrototypeSlice(element, 0)); const chunk = new Uint8Array(ArrayBufferPrototypeSlice(element, 0));
ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk)); ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk));
@ -159,7 +159,9 @@
* @returns {string[]} * @returns {string[]}
*/ */
function getParts(blob, bag = []) { function getParts(blob, bag = []) {
for (const part of new SafeArrayIterator(blob[_parts])) { const parts = blob[_parts];
for (let i = 0; i < parts.length; ++i) {
const part = parts[i];
if (ObjectPrototypeIsPrototypeOf(BlobPrototype, part)) { if (ObjectPrototypeIsPrototypeOf(BlobPrototype, part)) {
getParts(part, bag); getParts(part, bag);
} else { } else {
@ -276,7 +278,9 @@
const blobParts = []; const blobParts = [];
let added = 0; let added = 0;
for (const part of new SafeArrayIterator(this[_parts])) { const parts = this[_parts];
for (let i = 0; i < parts.length; ++i) {
const part = parts[i];
// don't add the overflow to new blobParts // don't add the overflow to new blobParts
if (added >= span) { if (added >= span) {
// Could maybe be possible to remove variable `added` // Could maybe be possible to remove variable `added`
@ -600,7 +604,8 @@
const parts = []; const parts = [];
let totalSize = 0; let totalSize = 0;
for (const { uuid, size } of new SafeArrayIterator(blobData.parts)) { for (let i = 0; i < blobData.parts.length; ++i) {
const { uuid, size } = blobData.parts[i];
ArrayPrototypePush(parts, new BlobReference(uuid, size)); ArrayPrototypePush(parts, new BlobReference(uuid, size));
totalSize += size; totalSize += size;
} }

View file

@ -158,7 +158,8 @@
); );
const bytes = new Uint8Array(size); const bytes = new Uint8Array(size);
let offs = 0; let offs = 0;
for (const chunk of new SafeArrayIterator(chunks)) { for (let i = 0; i < chunks.length; ++i) {
const chunk = chunks[i];
TypedArrayPrototypeSet(bytes, chunk, offs); TypedArrayPrototypeSet(bytes, chunk, offs);
offs += chunk.byteLength; offs += chunk.byteLength;
} }

View file

@ -22,7 +22,6 @@
ArrayPrototypePush, ArrayPrototypePush,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
ObjectSetPrototypeOf, ObjectSetPrototypeOf,
SafeArrayIterator,
Symbol, Symbol,
SymbolFor, SymbolFor,
SymbolIterator, SymbolIterator,
@ -205,9 +204,8 @@
const arrayBufferIdsInTransferables = []; const arrayBufferIdsInTransferables = [];
const transferredArrayBuffers = []; const transferredArrayBuffers = [];
for ( for (let i = 0; i < messageData.transferables.length; ++i) {
const transferable of new SafeArrayIterator(messageData.transferables) const transferable = messageData.transferables[i];
) {
switch (transferable.kind) { switch (transferable.kind) {
case "messagePort": { case "messagePort": {
const port = createMessagePort(transferable.data); const port = createMessagePort(transferable.data);
@ -217,8 +215,8 @@
} }
case "arrayBuffer": { case "arrayBuffer": {
ArrayPrototypePush(transferredArrayBuffers, transferable.data); ArrayPrototypePush(transferredArrayBuffers, transferable.data);
const i = ArrayPrototypePush(transferables, null); const index = ArrayPrototypePush(transferables, null);
ArrayPrototypePush(arrayBufferIdsInTransferables, i); ArrayPrototypePush(arrayBufferIdsInTransferables, index);
break; break;
} }
default: default:
@ -274,7 +272,8 @@
const serializedTransferables = []; const serializedTransferables = [];
let arrayBufferI = 0; let arrayBufferI = 0;
for (const transferable of new SafeArrayIterator(transferables)) { for (let i = 0; i < transferables.length; ++i) {
const transferable = transferables[i];
if (ObjectPrototypeIsPrototypeOf(MessagePortPrototype, transferable)) { if (ObjectPrototypeIsPrototypeOf(MessagePortPrototype, transferable)) {
webidl.assertBranded(transferable, MessagePortPrototype); webidl.assertBranded(transferable, MessagePortPrototype);
const id = transferable[_id]; const id = transferable[_id];

View file

@ -316,7 +316,8 @@
context: "Argument 1", context: "Argument 1",
}); });
const requiredFeatures = descriptor.requiredFeatures ?? []; const requiredFeatures = descriptor.requiredFeatures ?? [];
for (const feature of new SafeArrayIterator(requiredFeatures)) { for (let i = 0; i < requiredFeatures.length; ++i) {
const feature = requiredFeatures[i];
if (!SetPrototypeHas(this[_adapter].features[_features], feature)) { if (!SetPrototypeHas(this[_adapter].features[_features], feature)) {
throw new TypeError( throw new TypeError(
`${prefix}: nonGuaranteedFeatures must be a subset of the adapter features.`, `${prefix}: nonGuaranteedFeatures must be a subset of the adapter features.`,
@ -1046,14 +1047,16 @@
context: "Argument 1", context: "Argument 1",
}); });
const device = assertDevice(this, { prefix, context: "this" }); const device = assertDevice(this, { prefix, context: "this" });
for (const entry of new SafeArrayIterator(descriptor.entries)) { for (let i = 0; i < descriptor.entries.length; ++i) {
let i = 0; const entry = descriptor.entries[i];
if (entry.buffer) i++;
if (entry.sampler) i++;
if (entry.texture) i++;
if (entry.storageTexture) i++;
if (i !== 1) { let count = 0;
if (entry.buffer) count++;
if (entry.sampler) count++;
if (entry.texture) count++;
if (entry.storageTexture) count++;
if (count !== 1) {
throw new Error(); // TODO(@crowlKats): correct error throw new Error(); // TODO(@crowlKats): correct error
} }
} }
@ -1591,8 +1594,8 @@
device.rid, device.rid,
commandBufferRids, commandBufferRids,
); );
for (const commandBuffer of new SafeArrayIterator(commandBuffers)) { for (let i = 0; i < commandBuffers.length; ++i) {
commandBuffer[_rid] = undefined; commandBuffers[i][_rid] = undefined;
} }
device.pushError(err); device.pushError(err);
} }
@ -1934,7 +1937,8 @@
if (!mappedRanges) { if (!mappedRanges) {
throw new DOMException(`${prefix}: invalid state.`, "OperationError"); throw new DOMException(`${prefix}: invalid state.`, "OperationError");
} }
for (const [buffer, _rid, start] of new SafeArrayIterator(mappedRanges)) { for (let i = 0; i < mappedRanges.length; ++i) {
const [buffer, _rid, start] = mappedRanges[i];
// TODO(lucacasonato): is this logic correct? // TODO(lucacasonato): is this logic correct?
const end = start + buffer.byteLength; const end = start + buffer.byteLength;
if ( if (
@ -2002,7 +2006,8 @@
if (!mappedRanges) { if (!mappedRanges) {
throw new DOMException(`${prefix}: invalid state.`, "OperationError"); throw new DOMException(`${prefix}: invalid state.`, "OperationError");
} }
for (const [buffer, mappedRid] of new SafeArrayIterator(mappedRanges)) { for (let i = 0; i < mappedRanges.length; ++i) {
const [buffer, mappedRid] = mappedRanges[i];
const { err } = ops.op_webgpu_buffer_unmap( const { err } = ops.op_webgpu_buffer_unmap(
bufferRid, bufferRid,
mappedRid, mappedRid,

View file

@ -60,7 +60,6 @@
ReflectHas, ReflectHas,
ReflectOwnKeys, ReflectOwnKeys,
RegExpPrototypeTest, RegExpPrototypeTest,
SafeArrayIterator,
Set, Set,
// TODO(lucacasonato): add SharedArrayBuffer to primordials // TODO(lucacasonato): add SharedArrayBuffer to primordials
// SharedArrayBuffer, // SharedArrayBuffer,
@ -633,8 +632,10 @@
function createDictionaryConverter(name, ...dictionaries) { function createDictionaryConverter(name, ...dictionaries) {
let hasRequiredKey = false; let hasRequiredKey = false;
const allMembers = []; const allMembers = [];
for (const members of new SafeArrayIterator(dictionaries)) { for (let i = 0; i < dictionaries.length; ++i) {
for (const member of new SafeArrayIterator(members)) { const members = dictionaries[i];
for (let j = 0; j < members.length; ++j) {
const member = members[j];
if (member.required) { if (member.required) {
hasRequiredKey = true; hasRequiredKey = true;
} }
@ -649,7 +650,8 @@
}); });
const defaultValues = {}; const defaultValues = {};
for (const member of new SafeArrayIterator(allMembers)) { for (let i = 0; i < allMembers.length; ++i) {
const member = allMembers[i];
if (ReflectHas(member, "defaultValue")) { if (ReflectHas(member, "defaultValue")) {
const idlMemberValue = member.defaultValue; const idlMemberValue = member.defaultValue;
const imvType = typeof idlMemberValue; const imvType = typeof idlMemberValue;
@ -695,7 +697,8 @@
return idlDict; return idlDict;
} }
for (const member of new SafeArrayIterator(allMembers)) { for (let i = 0; i < allMembers.length; ++i) {
const member = allMembers[i];
const key = member.key; const key = member.key;
let esMemberValue; let esMemberValue;
@ -821,7 +824,8 @@
} }
// Slow path if Proxy (e.g: in WPT tests) // Slow path if Proxy (e.g: in WPT tests)
const keys = ReflectOwnKeys(V); const keys = ReflectOwnKeys(V);
for (const key of new SafeArrayIterator(keys)) { for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
const desc = ObjectGetOwnPropertyDescriptor(V, key); const desc = ObjectGetOwnPropertyDescriptor(V, key);
if (desc !== undefined && desc.enumerable === true) { if (desc !== undefined && desc.enumerable === true) {
const typedKey = keyConverter(key, opts); const typedKey = keyConverter(key, opts);
@ -891,7 +895,9 @@
} }
function define(target, source) { function define(target, source) {
for (const key of new SafeArrayIterator(ReflectOwnKeys(source))) { const keys = ReflectOwnKeys(source);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
const descriptor = ReflectGetOwnPropertyDescriptor(source, key); const descriptor = ReflectGetOwnPropertyDescriptor(source, key);
if (descriptor && !ReflectDefineProperty(target, key, descriptor)) { if (descriptor && !ReflectDefineProperty(target, key, descriptor)) {
throw new TypeError(`Cannot redefine property: ${String(key)}`); throw new TypeError(`Cannot redefine property: ${String(key)}`);

View file

@ -12,7 +12,6 @@
Uint8Array, Uint8Array,
ArrayPrototypePush, ArrayPrototypePush,
MathMin, MathMin,
SafeArrayIterator,
TypedArrayPrototypeSubarray, TypedArrayPrototypeSubarray,
TypedArrayPrototypeSet, TypedArrayPrototypeSet,
} = window.__bootstrap.primordials; } = window.__bootstrap.primordials;
@ -157,14 +156,15 @@
function concatBuffers(buffers) { function concatBuffers(buffers) {
let totalLen = 0; let totalLen = 0;
for (const buf of new SafeArrayIterator(buffers)) { for (let i = 0; i < buffers.length; ++i) {
totalLen += buf.byteLength; totalLen += buffers[i].byteLength;
} }
const contents = new Uint8Array(totalLen); const contents = new Uint8Array(totalLen);
let n = 0; let n = 0;
for (const buf of new SafeArrayIterator(buffers)) { for (let i = 0; i < buffers.length; ++i) {
const buf = buffers[i];
TypedArrayPrototypeSet(contents, buf, n); TypedArrayPrototypeSet(contents, buf, n);
n += buf.byteLength; n += buf.byteLength;
} }

View file

@ -9,7 +9,6 @@
DatePrototype, DatePrototype,
MathTrunc, MathTrunc,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
SafeArrayIterator,
SymbolAsyncIterator, SymbolAsyncIterator,
SymbolIterator, SymbolIterator,
Function, Function,
@ -212,7 +211,10 @@
let offset = 0; let offset = 0;
let str = let str =
'const unix = Deno.build.os === "darwin" || Deno.build.os === "linux"; return {'; 'const unix = Deno.build.os === "darwin" || Deno.build.os === "linux"; return {';
for (let [name, type] of new SafeArrayIterator(ObjectEntries(types))) { const typeEntries = ObjectEntries(types);
for (let i = 0; i < typeEntries.length; ++i) {
let [name, type] = typeEntries[i];
const optional = type.startsWith("?"); const optional = type.startsWith("?");
if (optional) type = type.slice(1); if (optional) type = type.slice(1);

View file

@ -33,7 +33,6 @@ delete Intl.v8BreakIterator;
SymbolFor, SymbolFor,
SymbolIterator, SymbolIterator,
PromisePrototypeThen, PromisePrototypeThen,
SafeArrayIterator,
SafeWeakMap, SafeWeakMap,
TypeError, TypeError,
WeakMapPrototypeDelete, WeakMapPrototypeDelete,
@ -206,7 +205,8 @@ delete Intl.v8BreakIterator;
); );
loadedMainWorkerScript = true; loadedMainWorkerScript = true;
for (const { url, script } of new SafeArrayIterator(scripts)) { for (let i = 0; i < scripts.length; ++i) {
const { url, script } = scripts[i];
const err = core.evalContext(script, url)[1]; const err = core.evalContext(script, url)[1];
if (err !== null) { if (err !== null) {
throw err.thrown; throw err.thrown;