1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

refactor: update runtime code for primordial check for iterators (#13510)

This commit is contained in:
Bartek Iwańczuk 2022-02-07 13:54:32 +01:00 committed by GitHub
parent 9c7ed1c98b
commit bf22f114a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 141 additions and 65 deletions

View file

@ -53,6 +53,8 @@
RegExpPrototype,
RegExpPrototypeTest,
RegExpPrototypeToString,
SafeArrayIterator,
SafeSet,
SetPrototype,
SetPrototypeEntries,
Symbol,
@ -1938,11 +1940,14 @@
const [first, ...rest] = args;
if (typeof first === "string") {
this.error(`Assertion failed: ${first}`, ...rest);
this.error(
`Assertion failed: ${first}`,
...new SafeArrayIterator(rest),
);
return;
}
this.error(`Assertion failed:`, ...args);
this.error(`Assertion failed:`, ...new SafeArrayIterator(args));
};
count = (label = "default") => {
@ -1994,7 +1999,7 @@
const indexKey = isSet || isMap ? "(iter idx)" : "(idx)";
if (isSet) {
resultData = [...data];
resultData = [...new SafeSet(data)];
} else if (isMap) {
let idx = 0;
resultData = {};
@ -2048,12 +2053,16 @@
const headerKeys = ObjectKeys(objectValues);
const bodyValues = ObjectValues(objectValues);
const headerProps = properties ||
[
...new SafeArrayIterator(headerKeys),
!isMap && hasPrimitives && valuesKey,
];
const header = ArrayPrototypeFilter([
indexKey,
...(properties ||
[...headerKeys, !isMap && hasPrimitives && valuesKey]),
...new SafeArrayIterator(headerProps),
], Boolean);
const body = [indexKeys, ...bodyValues, values];
const body = [indexKeys, ...new SafeArrayIterator(bodyValues), values];
toTable(header, body);
};
@ -2080,7 +2089,7 @@
const startTime = MapPrototypeGet(timerMap, label);
const duration = DateNow() - startTime;
this.info(`${label}: ${duration}ms`, ...args);
this.info(`${label}: ${duration}ms`, ...new SafeArrayIterator(args));
};
timeEnd = (label = "default") => {
@ -2100,7 +2109,7 @@
group = (...label) => {
if (label.length > 0) {
this.log(...label);
this.log(...new SafeArrayIterator(label));
}
this.indentLevel += 2;
};

View file

@ -13,6 +13,7 @@
ArrayBufferIsView,
ArrayBufferPrototype,
ObjectPrototypeIsPrototypeOf,
SafeArrayIterator,
} = window.__bootstrap.primordials;
webidl.converters.AlgorithmIdentifier = (V, opts) => {
@ -79,7 +80,7 @@
/** @type {__bootstrap.webidl.Dictionary} */
const dictRsaKeyGenParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "modulusLength",
converter: (V, opts) =>
@ -97,7 +98,7 @@
.createDictionaryConverter("RsaKeyGenParams", dictRsaKeyGenParams);
const dictRsaHashedKeyGenParams = [
...dictRsaKeyGenParams,
...new SafeArrayIterator(dictRsaKeyGenParams),
{
key: "hash",
converter: webidl.converters.HashAlgorithmIdentifier,
@ -111,7 +112,7 @@
);
const dictRsaHashedImportParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "hash",
converter: webidl.converters.HashAlgorithmIdentifier,
@ -127,7 +128,7 @@
webidl.converters.NamedCurve = webidl.converters.DOMString;
const dictEcKeyImportParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "namedCurve",
converter: webidl.converters.NamedCurve,
@ -141,7 +142,7 @@
);
const dictEcKeyGenParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "namedCurve",
converter: webidl.converters.NamedCurve,
@ -153,7 +154,7 @@
.createDictionaryConverter("EcKeyGenParams", dictEcKeyGenParams);
const dictEcImportParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "namedCurve",
converter: webidl.converters.NamedCurve,
@ -165,7 +166,7 @@
.createDictionaryConverter("EcImportParams", dictEcImportParams);
const dictAesKeyGenParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "length",
converter: (V, opts) =>
@ -178,7 +179,7 @@
.createDictionaryConverter("AesKeyGenParams", dictAesKeyGenParams);
const dictHmacKeyGenParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "hash",
converter: webidl.converters.HashAlgorithmIdentifier,
@ -195,7 +196,7 @@
.createDictionaryConverter("HmacKeyGenParams", dictHmacKeyGenParams);
const dictRsaPssParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "saltLength",
converter: (V, opts) =>
@ -208,7 +209,7 @@
.createDictionaryConverter("RsaPssParams", dictRsaPssParams);
const dictRsaOaepParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "label",
converter: webidl.converters["BufferSource"],
@ -219,7 +220,7 @@
.createDictionaryConverter("RsaOaepParams", dictRsaOaepParams);
const dictEcdsaParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "hash",
converter: webidl.converters.HashAlgorithmIdentifier,
@ -231,7 +232,7 @@
.createDictionaryConverter("EcdsaParams", dictEcdsaParams);
const dictHmacImportParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "hash",
converter: webidl.converters.HashAlgorithmIdentifier,
@ -357,7 +358,7 @@
);
const dictHkdfParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "hash",
converter: webidl.converters.HashAlgorithmIdentifier,
@ -379,7 +380,7 @@
.createDictionaryConverter("HkdfParams", dictHkdfParams);
const dictPbkdf2Params = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "hash",
converter: webidl.converters.HashAlgorithmIdentifier,
@ -402,7 +403,7 @@
.createDictionaryConverter("Pbkdf2Params", dictPbkdf2Params);
const dictAesDerivedKeyParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "length",
converter: (V, opts) =>
@ -412,7 +413,7 @@
];
const dictAesCbcParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "iv",
converter: webidl.converters["BufferSource"],
@ -421,7 +422,7 @@
];
const dictAesGcmParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "iv",
converter: webidl.converters["BufferSource"],
@ -439,7 +440,7 @@
];
const dictAesCtrParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "counter",
converter: webidl.converters["BufferSource"],
@ -485,7 +486,7 @@
.createDictionaryConverter("CryptoKeyPair", dictCryptoKeyPair);
const dictEcdhKeyDeriveParams = [
...dictAlgorithm,
...new SafeArrayIterator(dictAlgorithm),
{
key: "public",
converter: webidl.converters.CryptoKey,

View file

@ -32,6 +32,7 @@
ObjectPrototypeHasOwnProperty,
ObjectEntries,
RegExpPrototypeTest,
SafeArrayIterator,
Symbol,
SymbolFor,
SymbolIterator,
@ -230,7 +231,10 @@
}
return ArrayPrototypeSort(
[...ObjectEntries(headers), ...cookies],
[
...new SafeArrayIterator(ObjectEntries(headers)),
...new SafeArrayIterator(cookies),
],
(a, b) => {
const akey = a[0];
const bkey = b[0];

View file

@ -38,6 +38,7 @@
ObjectKeys,
ObjectPrototypeIsPrototypeOf,
RegExpPrototypeTest,
SafeArrayIterator,
Symbol,
SymbolFor,
TypeError,
@ -101,7 +102,9 @@
*/
function cloneInnerRequest(request) {
const headerList = [
...ArrayPrototypeMap(request.headerList, (x) => [x[0], x[1]]),
...new SafeArrayIterator(
ArrayPrototypeMap(request.headerList, (x) => [x[0], x[1]]),
),
];
let body = null;
if (request.body !== null) {

View file

@ -37,6 +37,7 @@
RangeError,
RegExp,
RegExpPrototypeTest,
SafeArrayIterator,
Symbol,
SymbolFor,
TypeError,
@ -45,7 +46,11 @@
const VCHAR = ["\x21-\x7E"];
const OBS_TEXT = ["\x80-\xFF"];
const REASON_PHRASE = [...HTTP_TAB_OR_SPACE, ...VCHAR, ...OBS_TEXT];
const REASON_PHRASE = [
...new SafeArrayIterator(HTTP_TAB_OR_SPACE),
...new SafeArrayIterator(VCHAR),
...new SafeArrayIterator(OBS_TEXT),
];
const REASON_PHRASE_MATCHER = regexMatcher(REASON_PHRASE);
const REASON_PHRASE_RE = new RegExp(`^[${REASON_PHRASE_MATCHER}]*$`);
@ -90,9 +95,11 @@
* @returns {InnerResponse}
*/
function cloneInnerResponse(response) {
const urlList = [...response.urlList];
const urlList = [...new SafeArrayIterator(response.urlList)];
const headerList = [
...ArrayPrototypeMap(response.headerList, (x) => [x[0], x[1]]),
...new SafeArrayIterator(
ArrayPrototypeMap(response.headerList, (x) => [x[0], x[1]]),
),
];
let body = null;
if (response.body !== null) {

View file

@ -38,6 +38,7 @@
Promise,
PromisePrototypeThen,
PromisePrototypeCatch,
SafeArrayIterator,
String,
StringPrototypeStartsWith,
StringPrototypeToLowerCase,
@ -168,7 +169,7 @@
if (this.urlList.length == 0) return null;
return this.urlList[this.urlList.length - 1];
},
urlList: recursive ? [] : [...req.urlList],
urlList: recursive ? [] : [...new SafeArrayIterator(req.urlList)],
};
}
@ -331,7 +332,7 @@
if (recursive) return response;
if (response.urlList.length === 0) {
response.urlList = [...req.urlList];
response.urlList = [...new SafeArrayIterator(req.urlList)];
}
return response;

View file

@ -17,6 +17,7 @@
NumberPOSITIVE_INFINITY,
PromisePrototypeThen,
ObjectPrototypeIsPrototypeOf,
SafeArrayIterator,
SymbolFor,
TypeError,
} = window.__bootstrap.primordials;
@ -159,7 +160,11 @@
// 3.
// TODO(@andreubotella): Error handling.
if (typeof callback === "function") {
FunctionPrototypeCall(callback, globalThis, ...args);
FunctionPrototypeCall(
callback,
globalThis,
...new SafeArrayIterator(args),
);
} else {
// TODO(@andreubotella): eval doesn't seem to have a primordial, but
// it can be redefined in the global scope.

View file

@ -18,6 +18,7 @@
ArrayPrototypeSort,
ArrayPrototypeSplice,
ObjectKeys,
SafeArrayIterator,
StringPrototypeSlice,
Symbol,
SymbolFor,
@ -345,7 +346,12 @@
"op_url_parse_search_params",
StringPrototypeSlice(this.search, 1),
);
ArrayPrototypeSplice(params, 0, params.length, ...newParams);
ArrayPrototypeSplice(
params,
0,
params.length,
...new SafeArrayIterator(newParams),
);
}
}

View file

@ -18,6 +18,7 @@
StringPrototypePadStart,
TypeError,
ArrayPrototypeJoin,
SafeArrayIterator,
StringPrototypeCharAt,
StringPrototypeMatch,
StringPrototypeSlice,
@ -31,11 +32,21 @@
const ASCII_DIGIT = ["\u0030-\u0039"];
const ASCII_UPPER_ALPHA = ["\u0041-\u005A"];
const ASCII_LOWER_ALPHA = ["\u0061-\u007A"];
const ASCII_ALPHA = [...ASCII_UPPER_ALPHA, ...ASCII_LOWER_ALPHA];
const ASCII_ALPHANUMERIC = [...ASCII_DIGIT, ...ASCII_ALPHA];
const ASCII_ALPHA = [
...new SafeArrayIterator(ASCII_UPPER_ALPHA),
...new SafeArrayIterator(ASCII_LOWER_ALPHA),
];
const ASCII_ALPHANUMERIC = [
...new SafeArrayIterator(ASCII_DIGIT),
...new SafeArrayIterator(ASCII_ALPHA),
];
const HTTP_TAB_OR_SPACE = ["\u0009", "\u0020"];
const HTTP_WHITESPACE = ["\u000A", "\u000D", ...HTTP_TAB_OR_SPACE];
const HTTP_WHITESPACE = [
"\u000A",
"\u000D",
...new SafeArrayIterator(HTTP_TAB_OR_SPACE),
];
const HTTP_TOKEN_CODE_POINT = [
"\u0021",
@ -53,7 +64,7 @@
"\u0060",
"\u007C",
"\u007E",
...ASCII_ALPHANUMERIC,
...new SafeArrayIterator(ASCII_ALPHANUMERIC),
];
const HTTP_TOKEN_CODE_POINT_RE = new RegExp(
`^[${regexMatcher(HTTP_TOKEN_CODE_POINT)}]+$`,

View file

@ -31,6 +31,7 @@
ObjectGetOwnPropertyDescriptor,
ObjectPrototypeIsPrototypeOf,
ReflectDefineProperty,
SafeArrayIterator,
Symbol,
SymbolFor,
SymbolToStringTag,
@ -1061,7 +1062,7 @@
object: this,
evaluate: ObjectPrototypeIsPrototypeOf(ErrorEvent.prototype, this),
keys: [
...EVENT_PROPS,
...new SafeArrayIterator(EVENT_PROPS),
"message",
"filename",
"lineno",
@ -1122,7 +1123,7 @@
object: this,
evaluate: ObjectPrototypeIsPrototypeOf(CloseEvent.prototype, this),
keys: [
...EVENT_PROPS,
...new SafeArrayIterator(EVENT_PROPS),
"wasClean",
"code",
"reason",
@ -1154,7 +1155,7 @@
object: this,
evaluate: ObjectPrototypeIsPrototypeOf(MessageEvent.prototype, this),
keys: [
...EVENT_PROPS,
...new SafeArrayIterator(EVENT_PROPS),
"data",
"origin",
"lastEventId",
@ -1187,7 +1188,7 @@
object: this,
evaluate: ObjectPrototypeIsPrototypeOf(CustomEvent.prototype, this),
keys: [
...EVENT_PROPS,
...new SafeArrayIterator(EVENT_PROPS),
"detail",
],
}));
@ -1217,7 +1218,7 @@
object: this,
evaluate: ObjectPrototypeIsPrototypeOf(ProgressEvent.prototype, this),
keys: [
...EVENT_PROPS,
...new SafeArrayIterator(EVENT_PROPS),
"lengthComputable",
"loaded",
"total",

View file

@ -19,6 +19,7 @@
ArrayPrototypeMap,
StringPrototypeCharCodeAt,
ArrayPrototypeJoin,
SafeArrayIterator,
StringFromCharCode,
TypedArrayFrom,
Uint8Array,
@ -38,7 +39,7 @@
const uint8Array = forgivingBase64Decode(data);
const result = ArrayPrototypeMap(
[...uint8Array],
[...new SafeArrayIterator(uint8Array)],
(byte) => StringFromCharCode(byte),
);
return ArrayPrototypeJoin(result, "");
@ -55,16 +56,19 @@
prefix,
context: "Argument 1",
});
const byteArray = ArrayPrototypeMap([...data], (char) => {
const charCode = StringPrototypeCharCodeAt(char, 0);
if (charCode > 0xff) {
throw new DOMException(
"The string to be encoded contains characters outside of the Latin1 range.",
"InvalidCharacterError",
);
}
return charCode;
});
const byteArray = ArrayPrototypeMap(
[...new SafeArrayIterator(data)],
(char) => {
const charCode = StringPrototypeCharCodeAt(char, 0);
if (charCode > 0xff) {
throw new DOMException(
"The string to be encoded contains characters outside of the Latin1 range.",
"InvalidCharacterError",
);
}
return charCode;
},
);
return forgivingBase64Encode(TypedArrayFrom(Uint8Array, byteArray));
}

View file

@ -30,6 +30,7 @@
ObjectDefineProperty,
ObjectPrototypeIsPrototypeOf,
queueMicrotask,
SafeArrayIterator,
StringFromCodePoint,
Symbol,
TypedArrayPrototypeSet,
@ -484,7 +485,11 @@
if (typeof wrappedHandler.handler !== "function") {
return;
}
return FunctionPrototypeCall(wrappedHandler.handler, this, ...args);
return FunctionPrototypeCall(
wrappedHandler.handler,
this,
...new SafeArrayIterator(args),
);
}
wrappedHandler.handler = handler;
return wrappedHandler;

View file

@ -32,6 +32,7 @@
PromisePrototypeThen,
PromiseReject,
PromiseResolve,
SafeArrayIterator,
Set,
SetPrototypeEntries,
SetPrototypeForEach,
@ -543,7 +544,9 @@
}
[SymbolFor("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect([...this.values()])}`;
return `${this.constructor.name} ${
inspect([...new SafeArrayIterator(this.values())])
}`;
}
}
@ -1923,7 +1926,7 @@
const { err } = core.opSync("op_webgpu_buffer_unmap", {
bufferRid,
mappedRid,
}, ...(write ? [new Uint8Array(buffer)] : []));
}, ...new SafeArrayIterator(write ? [new Uint8Array(buffer)] : []));
device.pushError(err);
if (err) return;
}

View file

@ -9,6 +9,8 @@
const { writableStreamClose, Deferred } = window.__bootstrap.streams;
const { DOMException } = window.__bootstrap.domException;
const { add, remove } = window.__bootstrap.abortSignal;
const { headersFromHeaderList, headerListFromHeaders, fillHeaders } =
window.__bootstrap.headers;
const {
ArrayPrototypeJoin,
@ -121,6 +123,11 @@
);
}
const headers = headersFromHeaderList([], "request");
if (options.headers !== undefined) {
fillHeaders(headers, options.headers);
}
const cancelRid = core.opSync(
"op_ws_check_permission_and_cancel_handle",
this[_url],
@ -144,7 +151,7 @@
? ArrayPrototypeJoin(options.protocols, ", ")
: "",
cancelHandle: cancelRid,
headers: [...new Headers(options.headers).entries()],
headers: headerListFromHeaders(headers),
}),
(create) => {
options.signal?.[remove](abort);

View file

@ -6,6 +6,7 @@
const core = window.Deno.core;
const webidl = window.__bootstrap.webidl;
const {
SafeArrayIterator,
Symbol,
SymbolFor,
ObjectDefineProperty,
@ -116,7 +117,7 @@
get(target, key) {
if (typeof key == "symbol") return target[key];
if (key in target) {
return ReflectGet(...arguments);
return ReflectGet(...new SafeArrayIterator(arguments));
} else {
return target.getItem(key) ?? undefined;
}

View file

@ -7,6 +7,7 @@
Error,
ObjectPrototypeIsPrototypeOf,
Promise,
SafeArrayIterator,
StringPrototypeReplace,
TypeError,
} = window.__bootstrap.primordials;
@ -26,7 +27,10 @@
if (logDebug) {
// if we destructure `console` off `globalThis` too early, we don't bind to
// the right console, therefore we don't log anything out.
globalThis.console.log(`DEBUG ${logSource} -`, ...args);
globalThis.console.log(
`DEBUG ${logSource} -`,
...new SafeArrayIterator(args),
);
}
}

View file

@ -24,6 +24,7 @@
RegExp,
RegExpPrototypeTest,
Set,
SafeArrayIterator,
StringPrototypeEndsWith,
StringPrototypeIncludes,
StringPrototypeSlice,
@ -278,7 +279,10 @@ finishing test case.`;
const post = core.resources();
const allResources = new Set([...ObjectKeys(pre), ...ObjectKeys(post)]);
const allResources = new Set([
...new SafeArrayIterator(ObjectKeys(pre)),
...new SafeArrayIterator(ObjectKeys(post)),
]);
const details = [];
for (const resource of allResources) {
@ -322,7 +326,7 @@ finishing test case.`;
});
try {
await fn(...params);
await fn(...new SafeArrayIterator(params));
} catch (err) {
throw err;
} finally {
@ -423,7 +427,7 @@ finishing test case.`;
const token = pledgePermissions(permissions);
try {
await fn(...params);
await fn(...new SafeArrayIterator(params));
} finally {
restorePermissions(token);
}