summaryrefslogtreecommitdiff
path: root/op_crates/web
diff options
context:
space:
mode:
Diffstat (limited to 'op_crates/web')
-rw-r--r--op_crates/web/01_mimesniff.js52
-rw-r--r--op_crates/web/internal.d.ts3
-rw-r--r--op_crates/web/lib.deno_web.d.ts51
3 files changed, 67 insertions, 39 deletions
diff --git a/op_crates/web/01_mimesniff.js b/op_crates/web/01_mimesniff.js
index 918343f2c..f58130132 100644
--- a/op_crates/web/01_mimesniff.js
+++ b/op_crates/web/01_mimesniff.js
@@ -10,6 +10,25 @@
((window) => {
const { collectSequenceOfCodepoints } = window.__bootstrap.infra;
+ /**
+ * @param {string[]} chars
+ * @returns {string}
+ */
+ function regexMatcher(chars) {
+ const matchers = chars.map((char) => {
+ if (char.length === 1) {
+ return `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
+ } else if (char.length === 3 && char[1] === "-") {
+ return `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}-\\u${
+ char.charCodeAt(2).toString(16).padStart(4, "0")
+ }`;
+ } else {
+ throw TypeError("unreachable");
+ }
+ });
+ return matchers.join("");
+ }
+
const HTTP_TAB_OR_SPACE = ["\u0009", "\u0020"];
const HTTP_WHITESPACE = ["\u000A", "\u000D", ...HTTP_TAB_OR_SPACE];
@@ -35,14 +54,25 @@
"\u007E",
...ASCII_ALPHANUMERIC,
];
- const HTTP_TOKEN_CODE_POINT_RE = new RegExp(`^[${HTTP_TOKEN_CODE_POINT}]+$`);
+ const HTTP_TOKEN_CODE_POINT_RE = new RegExp(
+ `^[${regexMatcher(HTTP_TOKEN_CODE_POINT)}]+$`,
+ );
const HTTP_QUOTED_STRING_TOKEN_POINT = [
"\u0009",
"\u0020-\u007E",
"\u0080-\u00FF",
];
const HTTP_QUOTED_STRING_TOKEN_POINT_RE = new RegExp(
- `^[${HTTP_QUOTED_STRING_TOKEN_POINT}]+$`,
+ `^[${regexMatcher(HTTP_QUOTED_STRING_TOKEN_POINT)}]+$`,
+ );
+ const HTTP_WHITESPACE_MATCHER = regexMatcher(HTTP_WHITESPACE);
+ const HTTP_WHITESPACE_PREFIX_RE = new RegExp(
+ `^[${HTTP_WHITESPACE_MATCHER}]+`,
+ "g",
+ );
+ const HTTP_WHITESPACE_SUFFIX_RE = new RegExp(
+ `[${HTTP_WHITESPACE_MATCHER}]+$`,
+ "g",
);
/**
@@ -106,8 +136,8 @@
*/
function parseMimeType(input) {
// 1.
- input = input.replaceAll(new RegExp(`^[${HTTP_WHITESPACE}]+`, "g"), "");
- input = input.replaceAll(new RegExp(`[${HTTP_WHITESPACE}]+$`, "g"), "");
+ input = input.replaceAll(HTTP_WHITESPACE_PREFIX_RE, "");
+ input = input.replaceAll(HTTP_WHITESPACE_SUFFIX_RE, "");
// 2.
let position = 0;
@@ -123,9 +153,7 @@
position = res1.position;
// 4.
- if (type === "" || !HTTP_TOKEN_CODE_POINT_RE.test(type)) {
- return null;
- }
+ if (type === "" || !HTTP_TOKEN_CODE_POINT_RE.test(type)) return null;
// 5.
if (position >= endOfInput) return null;
@@ -143,12 +171,10 @@
position = res2.position;
// 8.
- subtype = subtype.replaceAll(new RegExp(`[${HTTP_WHITESPACE}]+$`, "g"), "");
+ subtype = subtype.replaceAll(HTTP_WHITESPACE_SUFFIX_RE, "");
// 9.
- if (subtype === "" || !HTTP_TOKEN_CODE_POINT_RE.test(subtype)) {
- return null;
- }
+ if (subtype === "" || !HTTP_TOKEN_CODE_POINT_RE.test(subtype)) return null;
// 10.
const mimeType = {
@@ -216,7 +242,7 @@
// 11.9.2.
parameterValue = parameterValue.replaceAll(
- new RegExp(`[${HTTP_WHITESPACE}]+$`, "g"),
+ HTTP_WHITESPACE_SUFFIX_RE,
"",
);
@@ -224,7 +250,7 @@
if (parameterValue === "") continue;
}
- // 11.9.
+ // 11.10.
if (
parameterName !== "" && HTTP_TOKEN_CODE_POINT_RE.test(parameterName) &&
HTTP_QUOTED_STRING_TOKEN_POINT_RE.test(parameterValue) &&
diff --git a/op_crates/web/internal.d.ts b/op_crates/web/internal.d.ts
index 18220b08e..5681edc7b 100644
--- a/op_crates/web/internal.d.ts
+++ b/op_crates/web/internal.d.ts
@@ -4,6 +4,9 @@
/// <reference lib="esnext" />
declare namespace globalThis {
+ declare var TextEncoder: typeof TextEncoder;
+ declare var TextDecoder: typeof TextDecoder;
+
declare namespace __bootstrap {
declare var infra: {
collectSequenceOfCodepoints(
diff --git a/op_crates/web/lib.deno_web.d.ts b/op_crates/web/lib.deno_web.d.ts
index 79b56f68e..0fce6ce6b 100644
--- a/op_crates/web/lib.deno_web.d.ts
+++ b/op_crates/web/lib.deno_web.d.ts
@@ -87,45 +87,44 @@ declare class Event {
*/
declare class EventTarget {
/** Appends an event listener for events whose type attribute value is type.
- * The callback argument sets the callback that will be invoked when the event
- * is dispatched.
- *
- * The options argument sets listener-specific options. For compatibility this
- * can be a boolean, in which case the method behaves exactly as if the value
- * was specified as options's capture.
- *
- * When set to true, options's capture prevents callback from being invoked
- * when the event's eventPhase attribute value is BUBBLING_PHASE. When false
- * (or not present), callback will not be invoked when event's eventPhase
- * attribute value is CAPTURING_PHASE. Either way, callback will be invoked if
- * event's eventPhase attribute value is AT_TARGET.
- *
- * When set to true, options's passive indicates that the callback will not
- * cancel the event by invoking preventDefault(). This is used to enable
- * performance optimizations described in § 2.8 Observing event listeners.
- *
- * When set to true, options's once indicates that the callback will only be
- * invoked once after which the event listener will be removed.
- *
- * The event listener is appended to target's event listener list and is not
- * appended if it has the same type, callback, and capture. */
+ * The callback argument sets the callback that will be invoked when the event
+ * is dispatched.
+ *
+ * The options argument sets listener-specific options. For compatibility this
+ * can be a boolean, in which case the method behaves exactly as if the value
+ * was specified as options's capture.
+ *
+ * When set to true, options's capture prevents callback from being invoked
+ * when the event's eventPhase attribute value is BUBBLING_PHASE. When false
+ * (or not present), callback will not be invoked when event's eventPhase
+ * attribute value is CAPTURING_PHASE. Either way, callback will be invoked if
+ * event's eventPhase attribute value is AT_TARGET.
+ *
+ * When set to true, options's passive indicates that the callback will not
+ * cancel the event by invoking preventDefault(). This is used to enable
+ * performance optimizations described in § 2.8 Observing event listeners.
+ *
+ * When set to true, options's once indicates that the callback will only be
+ * invoked once after which the event listener will be removed.
+ *
+ * The event listener is appended to target's event listener list and is not
+ * appended if it has the same type, callback, and capture. */
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject | null,
options?: boolean | AddEventListenerOptions,
): void;
/** Dispatches a synthetic event event to target and returns true if either
- * event's cancelable attribute value is false or its preventDefault() method
- * was not invoked, and false otherwise. */
+ * event's cancelable attribute value is false or its preventDefault() method
+ * was not invoked, and false otherwise. */
dispatchEvent(event: Event): boolean;
/** Removes the event listener in target's event listener list with the same
- * type, callback, and options. */
+ * type, callback, and options. */
removeEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean,
): void;
- [Symbol.toStringTag]: string;
}
interface EventListener {