diff options
Diffstat (limited to 'ext/web')
-rw-r--r-- | ext/web/00_infra.js | 33 | ||||
-rw-r--r-- | ext/web/01_mimesniff.js | 4 | ||||
-rw-r--r-- | ext/web/02_event.js | 4 | ||||
-rw-r--r-- | ext/web/02_structured_clone.js | 4 | ||||
-rw-r--r-- | ext/web/02_timers.js | 4 | ||||
-rw-r--r-- | ext/web/03_abort_signal.js | 4 | ||||
-rw-r--r-- | ext/web/06_streams.js | 10 | ||||
-rw-r--r-- | ext/web/09_file.js | 4 | ||||
-rw-r--r-- | ext/web/10_filereader.js | 4 | ||||
-rw-r--r-- | ext/web/12_location.js | 4 |
10 files changed, 48 insertions, 27 deletions
diff --git a/ext/web/00_infra.js b/ext/web/00_infra.js index efe7217de..e9d5dd48b 100644 --- a/ext/web/00_infra.js +++ b/ext/web/00_infra.js @@ -18,6 +18,7 @@ const { JSONStringify, NumberPrototypeToString, ObjectPrototypeIsPrototypeOf, + RegExpPrototypeTest, SafeArrayIterator, SafeRegExp, String, @@ -26,6 +27,7 @@ const { StringPrototypeMatch, StringPrototypePadStart, StringPrototypeReplace, + StringPrototypeReplaceAll, StringPrototypeSlice, StringPrototypeSubstring, StringPrototypeToLowerCase, @@ -274,17 +276,24 @@ function addPaddingToBase64url(base64url) { return base64url; } +const BASE64URL_PATTERN = new SafeRegExp(/^[-_A-Z0-9]*?={0,2}$/i); + /** * @param {string} base64url * @returns {string} */ function convertBase64urlToBase64(base64url) { - if (!/^[-_A-Z0-9]*?={0,2}$/i.test(base64url)) { + if (!RegExpPrototypeTest(BASE64URL_PATTERN, base64url)) { // Contains characters not part of base64url spec. throw new TypeError("Failed to decode base64url: invalid character"); } - return addPaddingToBase64url(base64url).replace(/\-/g, "+").replace( - /_/g, + return StringPrototypeReplaceAll( + StringPrototypeReplaceAll( + addPaddingToBase64url(base64url), + "-", + "+", + ), + "_", "/", ); } @@ -295,9 +304,21 @@ function convertBase64urlToBase64(base64url) { * @returns {string} */ function forgivingBase64UrlEncode(data) { - return forgivingBase64Encode( - typeof data === "string" ? new TextEncoder().encode(data) : data, - ).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); + return StringPrototypeReplaceAll( + StringPrototypeReplaceAll( + StringPrototypeReplaceAll( + forgivingBase64Encode( + typeof data === "string" ? new TextEncoder().encode(data) : data, + ), + "=", + "", + ), + "+", + "-", + ), + "/", + "_", + ); } /** diff --git a/ext/web/01_mimesniff.js b/ext/web/01_mimesniff.js index 147ee095e..ad89f33cd 100644 --- a/ext/web/01_mimesniff.js +++ b/ext/web/01_mimesniff.js @@ -9,11 +9,11 @@ const primordials = globalThis.__bootstrap.primordials; const { ArrayPrototypeIncludes, - Map, MapPrototypeGet, MapPrototypeHas, MapPrototypeSet, RegExpPrototypeTest, + SafeMap, SafeMapIterator, StringPrototypeReplaceAll, StringPrototypeToLowerCase, @@ -92,7 +92,7 @@ function parseMimeType(input) { type: StringPrototypeToLowerCase(type), subtype: StringPrototypeToLowerCase(subtype), /** @type {Map<string, string>} */ - parameters: new Map(), + parameters: new SafeMap(), }; // 11. diff --git a/ext/web/02_event.js b/ext/web/02_event.js index fe4f3e198..34b3502a7 100644 --- a/ext/web/02_event.js +++ b/ext/web/02_event.js @@ -24,7 +24,6 @@ const { DateNow, Error, FunctionPrototypeCall, - Map, MapPrototypeGet, MapPrototypeSet, ObjectCreate, @@ -34,6 +33,7 @@ const { ReflectDefineProperty, ReflectHas, SafeArrayIterator, + SafeMap, StringPrototypeStartsWith, Symbol, SymbolFor, @@ -1443,7 +1443,7 @@ function defineEventHandler( } if (!this[_eventHandlers]) { - this[_eventHandlers] = new Map(); + this[_eventHandlers] = new SafeMap(); } let handlerWrapper = MapPrototypeGet(this[_eventHandlers], name); if (handlerWrapper) { diff --git a/ext/web/02_structured_clone.js b/ext/web/02_structured_clone.js index 6dd1d4d03..b0c7559c0 100644 --- a/ext/web/02_structured_clone.js +++ b/ext/web/02_structured_clone.js @@ -20,12 +20,12 @@ const { DataViewPrototypeGetByteLength, DataViewPrototypeGetByteOffset, ObjectPrototypeIsPrototypeOf, + SafeWeakMap, TypedArrayPrototypeGetBuffer, TypedArrayPrototypeGetByteOffset, TypedArrayPrototypeGetLength, TypedArrayPrototypeGetSymbolToStringTag, TypeErrorPrototype, - WeakMap, WeakMapPrototypeSet, Int8Array, Int16Array, @@ -40,7 +40,7 @@ const { Float64Array, } = primordials; -const objectCloneMemo = new WeakMap(); +const objectCloneMemo = new SafeWeakMap(); function cloneArrayBuffer( srcBuffer, diff --git a/ext/web/02_timers.js b/ext/web/02_timers.js index 753848af1..78cf06e44 100644 --- a/ext/web/02_timers.js +++ b/ext/web/02_timers.js @@ -7,7 +7,6 @@ const { ArrayPrototypePush, ArrayPrototypeShift, FunctionPrototypeCall, - Map, MapPrototypeDelete, MapPrototypeGet, MapPrototypeHas, @@ -18,6 +17,7 @@ const { NumberPOSITIVE_INFINITY, PromisePrototypeThen, SafeArrayIterator, + SafeMap, SymbolFor, TypedArrayPrototypeGetBuffer, TypeError, @@ -76,7 +76,7 @@ function handleTimerMacrotask() { * * @type {Map<number, { cancelRid: number, isRef: boolean, promiseId: number }>} */ -const activeTimers = new Map(); +const activeTimers = new SafeMap(); let nextId = 1; diff --git a/ext/web/03_abort_signal.js b/ext/web/03_abort_signal.js index 5ad52443d..2122d642e 100644 --- a/ext/web/03_abort_signal.js +++ b/ext/web/03_abort_signal.js @@ -14,8 +14,8 @@ import { const primordials = globalThis.__bootstrap.primordials; const { SafeArrayIterator, + SafeSet, SafeSetIterator, - Set, SetPrototypeAdd, SetPrototypeDelete, Symbol, @@ -69,7 +69,7 @@ class AbortSignal extends EventTarget { return; } if (this[abortAlgos] === null) { - this[abortAlgos] = new Set(); + this[abortAlgos] = new SafeSet(); } SetPrototypeAdd(this[abortAlgos], algorithm); } diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index b49d7ecd7..c51606365 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -34,7 +34,6 @@ const { DataViewPrototypeGetByteOffset, Float32Array, Float64Array, - FinalizationRegistry, Int8Array, Int16Array, Int32Array, @@ -56,7 +55,9 @@ const { queueMicrotask, RangeError, ReflectHas, + SafeFinalizationRegistry, SafePromiseAll, + SafeWeakMap, // TODO(lucacasonato): add SharedArrayBuffer to primordials // SharedArrayBufferPrototype Symbol, @@ -73,7 +74,6 @@ const { Uint16Array, Uint32Array, Uint8ClampedArray, - WeakMap, WeakMapPrototypeGet, WeakMapPrototypeHas, WeakMapPrototypeSet, @@ -695,7 +695,7 @@ function isReadableStreamDisturbed(stream) { const DEFAULT_CHUNK_SIZE = 64 * 1024; // 64 KiB // A finalization registry to clean up underlying resources that are GC'ed. -const RESOURCE_REGISTRY = new FinalizationRegistry((rid) => { +const RESOURCE_REGISTRY = new SafeFinalizationRegistry((rid) => { core.tryClose(rid); }); @@ -4743,7 +4743,7 @@ webidl.configurePrototype(ByteLengthQueuingStrategy); const ByteLengthQueuingStrategyPrototype = ByteLengthQueuingStrategy.prototype; /** @type {WeakMap<typeof globalThis, (chunk: ArrayBufferView) => number>} */ -const byteSizeFunctionWeakMap = new WeakMap(); +const byteSizeFunctionWeakMap = new SafeWeakMap(); function initializeByteLengthSizeFunction(globalObject) { if (WeakMapPrototypeHas(byteSizeFunctionWeakMap, globalObject)) { @@ -4800,7 +4800,7 @@ webidl.configurePrototype(CountQueuingStrategy); const CountQueuingStrategyPrototype = CountQueuingStrategy.prototype; /** @type {WeakMap<typeof globalThis, () => 1>} */ -const countSizeFunctionWeakMap = new WeakMap(); +const countSizeFunctionWeakMap = new SafeWeakMap(); /** @param {typeof globalThis} globalObject */ function initializeCountSizeFunction(globalObject) { diff --git a/ext/web/09_file.js b/ext/web/09_file.js index cb42c8c72..dccb20611 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -27,13 +27,13 @@ const { DataViewPrototypeGetByteOffset, Date, DatePrototypeGetTime, - FinalizationRegistry, MathMax, MathMin, ObjectPrototypeIsPrototypeOf, RegExpPrototypeTest, // TODO(lucacasonato): add SharedArrayBuffer to primordials // SharedArrayBufferPrototype + SafeFinalizationRegistry, SafeRegExp, StringPrototypeCharAt, StringPrototypeToLowerCase, @@ -549,7 +549,7 @@ webidl.converters["FilePropertyBag"] = webidl.createDictionaryConverter( // A finalization registry to deallocate a blob part when its JS reference is // garbage collected. -const registry = new FinalizationRegistry((uuid) => { +const registry = new SafeFinalizationRegistry((uuid) => { ops.op_blob_remove_part(uuid); }); diff --git a/ext/web/10_filereader.js b/ext/web/10_filereader.js index c59f009bb..897ac7e93 100644 --- a/ext/web/10_filereader.js +++ b/ext/web/10_filereader.js @@ -23,12 +23,12 @@ const { ArrayPrototypePush, ArrayPrototypeReduce, FunctionPrototypeCall, - Map, MapPrototypeGet, MapPrototypeSet, ObjectDefineProperty, queueMicrotask, SafeArrayIterator, + SafeMap, Symbol, TypedArrayPrototypeSet, TypedArrayPrototypeGetBuffer, @@ -273,7 +273,7 @@ class FileReader extends EventTarget { webidl.assertBranded(this, FileReaderPrototype); if (!this[handlerSymbol]) { - this[handlerSymbol] = new Map(); + this[handlerSymbol] = new SafeMap(); } let handlerWrapper = MapPrototypeGet(this[handlerSymbol], name); if (handlerWrapper) { diff --git a/ext/web/12_location.js b/ext/web/12_location.js index b80e7ef56..680f3d53b 100644 --- a/ext/web/12_location.js +++ b/ext/web/12_location.js @@ -8,11 +8,11 @@ const primordials = globalThis.__bootstrap.primordials; const { Error, ObjectDefineProperties, + SafeWeakMap, Symbol, SymbolFor, SymbolToStringTag, TypeError, - WeakMap, WeakMapPrototypeGet, WeakMapPrototypeSet, } = primordials; @@ -206,7 +206,7 @@ ObjectDefineProperties(Location.prototype, { }, }); -const workerLocationUrls = new WeakMap(); +const workerLocationUrls = new SafeWeakMap(); class WorkerLocation { constructor(href = null, key = null) { |