diff options
Diffstat (limited to 'extensions/web')
-rw-r--r-- | extensions/web/00_infra.js | 77 | ||||
-rw-r--r-- | extensions/web/01_dom_exception.js | 13 | ||||
-rw-r--r-- | extensions/web/01_mimesniff.js | 55 | ||||
-rw-r--r-- | extensions/web/02_event.js | 1 | ||||
-rw-r--r-- | extensions/web/02_structured_clone.js | 1 | ||||
-rw-r--r-- | extensions/web/05_base64.js | 1 | ||||
-rw-r--r-- | extensions/web/06_streams.js | 1 | ||||
-rw-r--r-- | extensions/web/10_filereader.js | 1 | ||||
-rw-r--r-- | extensions/web/12_location.js | 2 | ||||
-rw-r--r-- | extensions/web/13_message_port.js | 1 | ||||
-rw-r--r-- | extensions/web/internal.d.ts | 4 |
11 files changed, 116 insertions, 41 deletions
diff --git a/extensions/web/00_infra.js b/extensions/web/00_infra.js index 07c1ef41b..7c065bcd3 100644 --- a/extensions/web/00_infra.js +++ b/extensions/web/00_infra.js @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // @ts-check +/// <reference path="../../core/internal.d.ts" /> /// <reference path="../../core/lib.deno_core.d.ts" /> /// <reference path="../web/internal.d.ts" /> /// <reference path="../web/lib.deno_web.d.ts" /> @@ -9,6 +10,22 @@ ((window) => { const core = Deno.core; + const { + RegExp, + ArrayPrototypeMap, + StringPrototypeCharCodeAt, + NumberPrototypeToString, + StringPrototypePadStart, + TypeError, + ArrayPrototypeJoin, + StringPrototypeCharAt, + StringPrototypeSlice, + String, + StringPrototypeReplace, + StringPrototypeToUpperCase, + StringPrototypeToLowerCase, + StringPrototypeSubstring, + } = window.__bootstrap.primordials; const ASCII_DIGIT = ["\u0030-\u0039"]; const ASCII_UPPER_ALPHA = ["\u0041-\u005A"]; @@ -73,18 +90,31 @@ * @returns {string} */ function regexMatcher(chars) { - const matchers = chars.map((char) => { + const matchers = ArrayPrototypeMap(chars, (char) => { if (char.length === 1) { - return `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`; + const a = StringPrototypePadStart( + NumberPrototypeToString(StringPrototypeCharCodeAt(char, 0), 16), + 4, + "0", + ); + return `\\u${a}`; } 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") - }`; + const a = StringPrototypePadStart( + NumberPrototypeToString(StringPrototypeCharCodeAt(char, 0), 16), + 4, + "0", + ); + const b = StringPrototypePadStart( + NumberPrototypeToString(StringPrototypeCharCodeAt(char, 2), 16), + 4, + "0", + ); + return `\\u${a}-\\u${b}`; } else { throw TypeError("unreachable"); } }); - return matchers.join(""); + return ArrayPrototypeJoin(matchers, ""); } /** @@ -97,11 +127,11 @@ function collectSequenceOfCodepoints(input, position, condition) { const start = position; for ( - let c = input.charAt(position); + let c = StringPrototypeCharAt(input, position); position < input.length && condition(c); - c = input.charAt(++position) + c = StringPrototypeCharAt(input, ++position) ); - return { result: input.slice(start, position), position }; + return { result: StringPrototypeSlice(input, start, position), position }; } /** @@ -109,9 +139,13 @@ * @returns {string} */ function byteUpperCase(s) { - return String(s).replace(/[a-z]/g, function byteUpperCaseReplace(c) { - return c.toUpperCase(); - }); + return StringPrototypeReplace( + String(s), + /[a-z]/g, + function byteUpperCaseReplace(c) { + return StringPrototypeToUpperCase(c); + }, + ); } /** @@ -119,9 +153,13 @@ * @returns {string} */ function byteLowerCase(s) { - return String(s).replace(/[A-Z]/g, function byteUpperCaseReplace(c) { - return c.toLowerCase(); - }); + return StringPrototypeReplace( + String(s), + /[A-Z]/g, + function byteUpperCaseReplace(c) { + return StringPrototypeToLowerCase(c); + }, + ); } /** @@ -137,7 +175,7 @@ // 2. let value = ""; // 3. - if (input[position] !== "\u0022") throw new Error('must be "'); + if (input[position] !== "\u0022") throw new TypeError('must be "'); // 4. position++; // 5. @@ -169,7 +207,7 @@ position++; } else { // 5.6. // 5.6.1 - if (quoteOrBackslash !== "\u0022") throw new Error('must be "'); + if (quoteOrBackslash !== "\u0022") throw new TypeError('must be "'); // 5.6.2 break; } @@ -177,7 +215,10 @@ // 6. if (extractValue) return { result: value, position }; // 7. - return { result: input.substring(positionStart, position + 1), position }; + return { + result: StringPrototypeSubstring(input, positionStart, position + 1), + position, + }; } /** diff --git a/extensions/web/01_dom_exception.js b/extensions/web/01_dom_exception.js index e4bcb9fba..6c3c95f38 100644 --- a/extensions/web/01_dom_exception.js +++ b/extensions/web/01_dom_exception.js @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // @ts-check +/// <reference path="../../core/internal.d.ts" /> /// <reference path="../../core/lib.deno_core.d.ts" /> /// <reference path="../webidl/internal.d.ts" /> /// <reference path="../web/internal.d.ts" /> @@ -9,9 +10,10 @@ "use strict"; ((window) => { + const { ObjectDefineProperty, ObjectEntries } = + window.__bootstrap.primordials; const webidl = window.__bootstrap.webidl; - const { defineProperty } = Object; // Defined in WebIDL 4.3. // https://heycam.github.io/webidl/#idl-DOMException const INDEX_SIZE_ERR = 1; @@ -108,7 +110,7 @@ webidl.configurePrototype(DOMException); for ( - const [key, value] of Object.entries({ + const [key, value] of ObjectEntries({ INDEX_SIZE_ERR, DOMSTRING_SIZE_ERR, HIERARCHY_REQUEST_ERR, @@ -137,10 +139,9 @@ }) ) { const desc = { value, enumerable: true }; - defineProperty(DOMException, key, desc); - defineProperty(DOMException.prototype, key, desc); + ObjectDefineProperty(DOMException, key, desc); + ObjectDefineProperty(DOMException.prototype, key, desc); } - window.DOMException = DOMException; - defineProperty(window, "DOMException", { enumerable: false }); + window.__bootstrap.domException = { DOMException }; })(this); diff --git a/extensions/web/01_mimesniff.js b/extensions/web/01_mimesniff.js index b42dd1409..360d1ffe4 100644 --- a/extensions/web/01_mimesniff.js +++ b/extensions/web/01_mimesniff.js @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // @ts-check +/// <reference path="../../core/internal.d.ts" /> /// <reference path="../../core/lib.deno_core.d.ts" /> /// <reference path="../web/internal.d.ts" /> /// <reference path="../web/lib.deno_web.d.ts" /> @@ -9,6 +10,15 @@ ((window) => { const { + ArrayPrototypeIncludes, + Map, + MapPrototypeHas, + MapPrototypeSet, + RegExpPrototypeTest, + StringPrototypeReplaceAll, + StringPrototypeToLowerCase, + } = window.__bootstrap.primordials; + const { collectSequenceOfCodepoints, HTTP_WHITESPACE, HTTP_WHITESPACE_PREFIX_RE, @@ -31,8 +41,8 @@ */ function parseMimeType(input) { // 1. - input = input.replaceAll(HTTP_WHITESPACE_PREFIX_RE, ""); - input = input.replaceAll(HTTP_WHITESPACE_SUFFIX_RE, ""); + input = StringPrototypeReplaceAll(input, HTTP_WHITESPACE_PREFIX_RE, ""); + input = StringPrototypeReplaceAll(input, HTTP_WHITESPACE_SUFFIX_RE, ""); // 2. let position = 0; @@ -48,7 +58,9 @@ position = res1.position; // 4. - if (type === "" || !HTTP_TOKEN_CODE_POINT_RE.test(type)) return null; + if (type === "" || !RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, type)) { + return null; + } // 5. if (position >= endOfInput) return null; @@ -66,15 +78,19 @@ position = res2.position; // 8. - subtype = subtype.replaceAll(HTTP_WHITESPACE_SUFFIX_RE, ""); + subtype = StringPrototypeReplaceAll(subtype, HTTP_WHITESPACE_SUFFIX_RE, ""); // 9. - if (subtype === "" || !HTTP_TOKEN_CODE_POINT_RE.test(subtype)) return null; + if ( + subtype === "" || !RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, subtype) + ) { + return null; + } // 10. const mimeType = { - type: type.toLowerCase(), - subtype: subtype.toLowerCase(), + type: StringPrototypeToLowerCase(type), + subtype: StringPrototypeToLowerCase(subtype), /** @type {Map<string, string>} */ parameters: new Map(), }; @@ -88,7 +104,7 @@ const res1 = collectSequenceOfCodepoints( input, position, - (c) => HTTP_WHITESPACE.includes(c), + (c) => ArrayPrototypeIncludes(HTTP_WHITESPACE, c), ); position = res1.position; @@ -102,7 +118,7 @@ position = res2.position; // 11.4. - parameterName = parameterName.toLowerCase(); + parameterName = StringPrototypeToLowerCase(parameterName); // 11.5. if (position < endOfInput) { @@ -136,7 +152,8 @@ position = res.position; // 11.9.2. - parameterValue = parameterValue.replaceAll( + parameterValue = StringPrototypeReplaceAll( + parameterValue, HTTP_WHITESPACE_SUFFIX_RE, "", ); @@ -147,11 +164,15 @@ // 11.10. if ( - parameterName !== "" && HTTP_TOKEN_CODE_POINT_RE.test(parameterName) && - HTTP_QUOTED_STRING_TOKEN_POINT_RE.test(parameterValue) && - !mimeType.parameters.has(parameterName) + parameterName !== "" && + RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, parameterName) && + RegExpPrototypeTest( + HTTP_QUOTED_STRING_TOKEN_POINT_RE, + parameterValue, + ) && + !MapPrototypeHas(mimeType.parameters, parameterName) ) { - mimeType.parameters.set(parameterName, parameterValue); + MapPrototypeSet(mimeType.parameters, parameterName, parameterValue); } } @@ -176,9 +197,9 @@ for (const param of mimeType.parameters) { serialization += `;${param[0]}=`; let value = param[1]; - if (!HTTP_TOKEN_CODE_POINT_RE.test(value)) { - value = value.replaceAll("\\", "\\\\"); - value = value.replaceAll('"', '\\"'); + if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, value)) { + value = StringPrototypeReplaceAll(value, "\\", "\\\\"); + value = StringPrototypeReplaceAll(value, '"', '\\"'); value = `"${value}"`; } serialization += value; diff --git a/extensions/web/02_event.js b/extensions/web/02_event.js index 081869efd..3fed3127e 100644 --- a/extensions/web/02_event.js +++ b/extensions/web/02_event.js @@ -8,6 +8,7 @@ ((window) => { const webidl = window.__bootstrap.webidl; + const { DOMException } = window.__bootstrap.domException; // accessors for non runtime visible data diff --git a/extensions/web/02_structured_clone.js b/extensions/web/02_structured_clone.js index 2170095d9..265d89247 100644 --- a/extensions/web/02_structured_clone.js +++ b/extensions/web/02_structured_clone.js @@ -9,6 +9,7 @@ ((window) => { const core = window.Deno.core; + const { DOMException } = window.__bootstrap.domException; const objectCloneMemo = new WeakMap(); diff --git a/extensions/web/05_base64.js b/extensions/web/05_base64.js index 4c51d88f1..f0490f240 100644 --- a/extensions/web/05_base64.js +++ b/extensions/web/05_base64.js @@ -13,6 +13,7 @@ forgivingBase64Encode, forgivingBase64Decode, } = window.__bootstrap.infra; + const { DOMException } = window.__bootstrap.domException; /** * @param {string} data diff --git a/extensions/web/06_streams.js b/extensions/web/06_streams.js index d26a1a412..79403442a 100644 --- a/extensions/web/06_streams.js +++ b/extensions/web/06_streams.js @@ -9,6 +9,7 @@ ((window) => { const webidl = window.__bootstrap.webidl; + const { DOMException } = window.__bootstrap.domException; class AssertionError extends Error { constructor(msg) { diff --git a/extensions/web/10_filereader.js b/extensions/web/10_filereader.js index b8bb6172a..161ce6ed3 100644 --- a/extensions/web/10_filereader.js +++ b/extensions/web/10_filereader.js @@ -16,6 +16,7 @@ const { forgivingBase64Encode } = window.__bootstrap.infra; const { decode, TextDecoder } = window.__bootstrap.encoding; const { parseMimeType } = window.__bootstrap.mimesniff; + const { DOMException } = window.__bootstrap.domException; const state = Symbol("[[state]]"); const result = Symbol("[[result]]"); diff --git a/extensions/web/12_location.js b/extensions/web/12_location.js index 75012396a..dd56fb47b 100644 --- a/extensions/web/12_location.js +++ b/extensions/web/12_location.js @@ -3,6 +3,8 @@ ((window) => { const { URL } = window.__bootstrap.url; + const { DOMException } = window.__bootstrap.domException; + const locationConstructorKey = Symbol("locationConstuctorKey"); // The differences between the definitions of `Location` and `WorkerLocation` diff --git a/extensions/web/13_message_port.js b/extensions/web/13_message_port.js index 1928409f2..ae8e148f4 100644 --- a/extensions/web/13_message_port.js +++ b/extensions/web/13_message_port.js @@ -13,6 +13,7 @@ const webidl = window.__bootstrap.webidl; const { setEventTargetData } = window.__bootstrap.eventTarget; const { defineEventHandler } = window.__bootstrap.event; + const { DOMException } = window.__bootstrap.domException; class MessageChannel { /** @type {MessagePort} */ diff --git a/extensions/web/internal.d.ts b/extensions/web/internal.d.ts index bbf529b77..bc3982a88 100644 --- a/extensions/web/internal.d.ts +++ b/extensions/web/internal.d.ts @@ -44,6 +44,10 @@ declare namespace globalThis { forgivingBase64Decode(data: string): Uint8Array; }; + declare var domException: { + DOMException: typeof DOMException; + }; + declare namespace mimesniff { declare interface MimeType { type: string; |