summaryrefslogtreecommitdiff
path: root/ext/web
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-02-07 13:54:32 +0100
committerGitHub <noreply@github.com>2022-02-07 13:54:32 +0100
commitbf22f114a6e049744866ebaba48faec2cb86549b (patch)
treeea6814e51bade2355144546f21178f54811a57f2 /ext/web
parent9c7ed1c98b75c3557ac9e269212dcf655f69c0a2 (diff)
refactor: update runtime code for primordial check for iterators (#13510)
Diffstat (limited to 'ext/web')
-rw-r--r--ext/web/00_infra.js19
-rw-r--r--ext/web/02_event.js11
-rw-r--r--ext/web/05_base64.js26
-rw-r--r--ext/web/10_filereader.js7
4 files changed, 42 insertions, 21 deletions
diff --git a/ext/web/00_infra.js b/ext/web/00_infra.js
index 40595be76..a250dd69b 100644
--- a/ext/web/00_infra.js
+++ b/ext/web/00_infra.js
@@ -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)}]+$`,
diff --git a/ext/web/02_event.js b/ext/web/02_event.js
index b32bb01b8..e85b4f5cb 100644
--- a/ext/web/02_event.js
+++ b/ext/web/02_event.js
@@ -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",
diff --git a/ext/web/05_base64.js b/ext/web/05_base64.js
index 7f4b607c9..1244ecfd5 100644
--- a/ext/web/05_base64.js
+++ b/ext/web/05_base64.js
@@ -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));
}
diff --git a/ext/web/10_filereader.js b/ext/web/10_filereader.js
index 039d3395d..c50635ea8 100644
--- a/ext/web/10_filereader.js
+++ b/ext/web/10_filereader.js
@@ -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;