mirror of
https://github.com/denoland/deno.git
synced 2025-01-07 06:46:59 -05:00
fix(core): Use safe primordials wrappers (#18687)
This commit is contained in:
parent
eef96d1414
commit
d07a0c7bb3
22 changed files with 83 additions and 60 deletions
|
@ -9,7 +9,6 @@
|
||||||
ArrayPrototypePush,
|
ArrayPrototypePush,
|
||||||
Error,
|
Error,
|
||||||
ErrorCaptureStackTrace,
|
ErrorCaptureStackTrace,
|
||||||
Map,
|
|
||||||
MapPrototypeDelete,
|
MapPrototypeDelete,
|
||||||
MapPrototypeGet,
|
MapPrototypeGet,
|
||||||
MapPrototypeHas,
|
MapPrototypeHas,
|
||||||
|
@ -22,6 +21,7 @@
|
||||||
RangeError,
|
RangeError,
|
||||||
ReferenceError,
|
ReferenceError,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeMap,
|
||||||
SafePromisePrototypeFinally,
|
SafePromisePrototypeFinally,
|
||||||
setQueueMicrotask,
|
setQueueMicrotask,
|
||||||
StringPrototypeSlice,
|
StringPrototypeSlice,
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
registerErrorClass("URIError", URIError);
|
registerErrorClass("URIError", URIError);
|
||||||
|
|
||||||
let nextPromiseId = 1;
|
let nextPromiseId = 1;
|
||||||
const promiseMap = new Map();
|
const promiseMap = new SafeMap();
|
||||||
const RING_SIZE = 4 * 1024;
|
const RING_SIZE = 4 * 1024;
|
||||||
const NO_PROMISE = null; // Alias to null is faster than plain nulls
|
const NO_PROMISE = null; // Alias to null is faster than plain nulls
|
||||||
const promiseRing = ArrayPrototypeFill(new Array(RING_SIZE), NO_PROMISE);
|
const promiseRing = ArrayPrototypeFill(new Array(RING_SIZE), NO_PROMISE);
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId");
|
const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId");
|
||||||
|
|
||||||
let opCallTracingEnabled = false;
|
let opCallTracingEnabled = false;
|
||||||
const opCallTraces = new Map();
|
const opCallTraces = new SafeMap();
|
||||||
|
|
||||||
function enableOpCallTracing() {
|
function enableOpCallTracing() {
|
||||||
opCallTracingEnabled = true;
|
opCallTracingEnabled = true;
|
||||||
|
|
|
@ -54,6 +54,7 @@ const {
|
||||||
RegExpPrototypeTest,
|
RegExpPrototypeTest,
|
||||||
RegExpPrototypeToString,
|
RegExpPrototypeToString,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeMap,
|
||||||
SafeStringIterator,
|
SafeStringIterator,
|
||||||
SafeSet,
|
SafeSet,
|
||||||
SafeRegExp,
|
SafeRegExp,
|
||||||
|
@ -85,7 +86,6 @@ const {
|
||||||
ArrayPrototypeFind,
|
ArrayPrototypeFind,
|
||||||
FunctionPrototypeBind,
|
FunctionPrototypeBind,
|
||||||
FunctionPrototypeToString,
|
FunctionPrototypeToString,
|
||||||
Map,
|
|
||||||
MapPrototype,
|
MapPrototype,
|
||||||
MapPrototypeHas,
|
MapPrototypeHas,
|
||||||
MapPrototypeGet,
|
MapPrototypeGet,
|
||||||
|
@ -658,7 +658,7 @@ let circular;
|
||||||
function handleCircular(value, cyan) {
|
function handleCircular(value, cyan) {
|
||||||
let index = 1;
|
let index = 1;
|
||||||
if (circular === undefined) {
|
if (circular === undefined) {
|
||||||
circular = new Map();
|
circular = new SafeMap();
|
||||||
MapPrototypeSet(circular, value, index);
|
MapPrototypeSet(circular, value, index);
|
||||||
} else {
|
} else {
|
||||||
index = MapPrototypeGet(circular, value);
|
index = MapPrototypeGet(circular, value);
|
||||||
|
@ -1016,7 +1016,7 @@ function inspectError(value, cyan) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const refMap = new Map();
|
const refMap = new SafeMap();
|
||||||
for (let i = 0; i < causes.length; ++i) {
|
for (let i = 0; i < causes.length; ++i) {
|
||||||
const cause = causes[i];
|
const cause = causes[i];
|
||||||
if (circular !== undefined) {
|
if (circular !== undefined) {
|
||||||
|
@ -1405,7 +1405,7 @@ function inspectObject(value, inspectOptions, proxyDetails) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const colorKeywords = new Map([
|
const colorKeywords = new SafeMap([
|
||||||
["black", "#000000"],
|
["black", "#000000"],
|
||||||
["silver", "#c0c0c0"],
|
["silver", "#c0c0c0"],
|
||||||
["gray", "#808080"],
|
["gray", "#808080"],
|
||||||
|
@ -1990,8 +1990,8 @@ function inspectArgs(args, inspectOptions = {}) {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const countMap = new Map();
|
const countMap = new SafeMap();
|
||||||
const timerMap = new Map();
|
const timerMap = new SafeMap();
|
||||||
const isConsoleInstance = Symbol("isConsoleInstance");
|
const isConsoleInstance = Symbol("isConsoleInstance");
|
||||||
|
|
||||||
function getConsoleInspectOptions() {
|
function getConsoleInspectOptions() {
|
||||||
|
|
|
@ -33,6 +33,7 @@ const {
|
||||||
StringPrototypeCharCodeAt,
|
StringPrototypeCharCodeAt,
|
||||||
StringFromCharCode,
|
StringFromCharCode,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeWeakMap,
|
||||||
Symbol,
|
Symbol,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
SyntaxError,
|
SyntaxError,
|
||||||
|
@ -43,7 +44,6 @@ const {
|
||||||
TypedArrayPrototypeGetSymbolToStringTag,
|
TypedArrayPrototypeGetSymbolToStringTag,
|
||||||
TypeError,
|
TypeError,
|
||||||
Uint8Array,
|
Uint8Array,
|
||||||
WeakMap,
|
|
||||||
WeakMapPrototypeGet,
|
WeakMapPrototypeGet,
|
||||||
WeakMapPrototypeSet,
|
WeakMapPrototypeSet,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
@ -391,7 +391,7 @@ function usageIntersection(a, b) {
|
||||||
|
|
||||||
// TODO(lucacasonato): this should be moved to rust
|
// TODO(lucacasonato): this should be moved to rust
|
||||||
/** @type {WeakMap<object, object>} */
|
/** @type {WeakMap<object, object>} */
|
||||||
const KEY_STORE = new WeakMap();
|
const KEY_STORE = new SafeWeakMap();
|
||||||
|
|
||||||
function getKeyLength(algorithm) {
|
function getKeyLength(algorithm) {
|
||||||
switch (algorithm.name) {
|
switch (algorithm.name) {
|
||||||
|
|
|
@ -22,12 +22,12 @@ const {
|
||||||
ArrayPrototypePush,
|
ArrayPrototypePush,
|
||||||
ArrayPrototypeSlice,
|
ArrayPrototypeSlice,
|
||||||
ArrayPrototypeSplice,
|
ArrayPrototypeSplice,
|
||||||
Map,
|
|
||||||
MapPrototypeGet,
|
MapPrototypeGet,
|
||||||
MapPrototypeSet,
|
MapPrototypeSet,
|
||||||
MathRandom,
|
MathRandom,
|
||||||
ObjectFreeze,
|
ObjectFreeze,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
|
SafeMap,
|
||||||
SafeRegExp,
|
SafeRegExp,
|
||||||
Symbol,
|
Symbol,
|
||||||
StringFromCharCode,
|
StringFromCharCode,
|
||||||
|
@ -346,13 +346,15 @@ function formDataToBlob(formData) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QUOTE_CONTENT_PATTERN = new SafeRegExp(/^"([^"]*)"$/);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @returns {Map<string, string>}
|
* @returns {Map<string, string>}
|
||||||
*/
|
*/
|
||||||
function parseContentDisposition(value) {
|
function parseContentDisposition(value) {
|
||||||
/** @type {Map<string, string>} */
|
/** @type {Map<string, string>} */
|
||||||
const params = new Map();
|
const params = new SafeMap();
|
||||||
// Forced to do so for some Map constructor param mismatch
|
// Forced to do so for some Map constructor param mismatch
|
||||||
const values = ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1);
|
const values = ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1);
|
||||||
for (let i = 0; i < values.length; i++) {
|
for (let i = 0; i < values.length; i++) {
|
||||||
|
@ -361,7 +363,7 @@ function parseContentDisposition(value) {
|
||||||
MapPrototypeSet(
|
MapPrototypeSet(
|
||||||
params,
|
params,
|
||||||
entries[0],
|
entries[0],
|
||||||
StringPrototypeReplace(entries[1], /^"([^"]*)"$/, "$1"),
|
StringPrototypeReplace(entries[1], QUOTE_CONTENT_PATTERN, "$1"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,13 +42,13 @@ const {
|
||||||
PromisePrototypeThen,
|
PromisePrototypeThen,
|
||||||
PromisePrototypeCatch,
|
PromisePrototypeCatch,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeWeakMap,
|
||||||
String,
|
String,
|
||||||
StringPrototypeStartsWith,
|
StringPrototypeStartsWith,
|
||||||
StringPrototypeToLowerCase,
|
StringPrototypeToLowerCase,
|
||||||
TypeError,
|
TypeError,
|
||||||
Uint8Array,
|
Uint8Array,
|
||||||
Uint8ArrayPrototype,
|
Uint8ArrayPrototype,
|
||||||
WeakMap,
|
|
||||||
WeakMapPrototypeDelete,
|
WeakMapPrototypeDelete,
|
||||||
WeakMapPrototypeGet,
|
WeakMapPrototypeGet,
|
||||||
WeakMapPrototypeHas,
|
WeakMapPrototypeHas,
|
||||||
|
@ -62,7 +62,7 @@ const REQUEST_BODY_HEADER_NAMES = [
|
||||||
"content-type",
|
"content-type",
|
||||||
];
|
];
|
||||||
|
|
||||||
const requestBodyReaders = new WeakMap();
|
const requestBodyReaders = new SafeWeakMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{ method: string, url: string, headers: [string, string][], clientRid: number | null, hasBody: boolean }} args
|
* @param {{ method: string, url: string, headers: [string, string][], clientRid: number | null, hasBody: boolean }} args
|
||||||
|
|
|
@ -30,8 +30,8 @@ const {
|
||||||
MathCeil,
|
MathCeil,
|
||||||
SafeMap,
|
SafeMap,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeWeakMap,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
WeakMap,
|
|
||||||
} = primordials;
|
} = primordials;
|
||||||
import { pathFromURL } from "ext:deno_web/00_infra.js";
|
import { pathFromURL } from "ext:deno_web/00_infra.js";
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ const OUT_BUFFER = new Uint32Array(2);
|
||||||
const OUT_BUFFER_64 = new BigInt64Array(
|
const OUT_BUFFER_64 = new BigInt64Array(
|
||||||
TypedArrayPrototypeGetBuffer(OUT_BUFFER),
|
TypedArrayPrototypeGetBuffer(OUT_BUFFER),
|
||||||
);
|
);
|
||||||
const POINTER_TO_BUFFER_WEAK_MAP = new WeakMap();
|
const POINTER_TO_BUFFER_WEAK_MAP = new SafeWeakMap();
|
||||||
class UnsafePointer {
|
class UnsafePointer {
|
||||||
static create(value) {
|
static create(value) {
|
||||||
return ops.op_ffi_ptr_create(value);
|
return ops.op_ffi_ptr_create(value);
|
||||||
|
|
|
@ -47,8 +47,9 @@ const {
|
||||||
ArrayPrototypePush,
|
ArrayPrototypePush,
|
||||||
Error,
|
Error,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
|
PromisePrototypeCatch,
|
||||||
|
SafeSet,
|
||||||
SafeSetIterator,
|
SafeSetIterator,
|
||||||
Set,
|
|
||||||
SetPrototypeAdd,
|
SetPrototypeAdd,
|
||||||
SetPrototypeDelete,
|
SetPrototypeDelete,
|
||||||
SetPrototypeClear,
|
SetPrototypeClear,
|
||||||
|
@ -56,8 +57,6 @@ const {
|
||||||
StringPrototypeIncludes,
|
StringPrototypeIncludes,
|
||||||
StringPrototypeToLowerCase,
|
StringPrototypeToLowerCase,
|
||||||
StringPrototypeSplit,
|
StringPrototypeSplit,
|
||||||
SafeSet,
|
|
||||||
PromisePrototypeCatch,
|
|
||||||
Symbol,
|
Symbol,
|
||||||
SymbolAsyncIterator,
|
SymbolAsyncIterator,
|
||||||
TypeError,
|
TypeError,
|
||||||
|
@ -79,7 +78,7 @@ class HttpConn {
|
||||||
// that were created during lifecycle of this request.
|
// that were created during lifecycle of this request.
|
||||||
// When the connection is closed these resources should be closed
|
// When the connection is closed these resources should be closed
|
||||||
// as well.
|
// as well.
|
||||||
managedResources = new Set();
|
managedResources = new SafeSet();
|
||||||
|
|
||||||
constructor(rid, remoteAddr, localAddr) {
|
constructor(rid, remoteAddr, localAddr) {
|
||||||
this.#rid = rid;
|
this.#rid = rid;
|
||||||
|
|
|
@ -18,6 +18,7 @@ const {
|
||||||
JSONStringify,
|
JSONStringify,
|
||||||
NumberPrototypeToString,
|
NumberPrototypeToString,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
|
RegExpPrototypeTest,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
SafeRegExp,
|
SafeRegExp,
|
||||||
String,
|
String,
|
||||||
|
@ -26,6 +27,7 @@ const {
|
||||||
StringPrototypeMatch,
|
StringPrototypeMatch,
|
||||||
StringPrototypePadStart,
|
StringPrototypePadStart,
|
||||||
StringPrototypeReplace,
|
StringPrototypeReplace,
|
||||||
|
StringPrototypeReplaceAll,
|
||||||
StringPrototypeSlice,
|
StringPrototypeSlice,
|
||||||
StringPrototypeSubstring,
|
StringPrototypeSubstring,
|
||||||
StringPrototypeToLowerCase,
|
StringPrototypeToLowerCase,
|
||||||
|
@ -274,17 +276,24 @@ function addPaddingToBase64url(base64url) {
|
||||||
return base64url;
|
return base64url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BASE64URL_PATTERN = new SafeRegExp(/^[-_A-Z0-9]*?={0,2}$/i);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} base64url
|
* @param {string} base64url
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function convertBase64urlToBase64(base64url) {
|
function convertBase64urlToBase64(base64url) {
|
||||||
if (!/^[-_A-Z0-9]*?={0,2}$/i.test(base64url)) {
|
if (!RegExpPrototypeTest(BASE64URL_PATTERN, base64url)) {
|
||||||
// Contains characters not part of base64url spec.
|
// Contains characters not part of base64url spec.
|
||||||
throw new TypeError("Failed to decode base64url: invalid character");
|
throw new TypeError("Failed to decode base64url: invalid character");
|
||||||
}
|
}
|
||||||
return addPaddingToBase64url(base64url).replace(/\-/g, "+").replace(
|
return StringPrototypeReplaceAll(
|
||||||
/_/g,
|
StringPrototypeReplaceAll(
|
||||||
|
addPaddingToBase64url(base64url),
|
||||||
|
"-",
|
||||||
|
"+",
|
||||||
|
),
|
||||||
|
"_",
|
||||||
"/",
|
"/",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -295,9 +304,21 @@ function convertBase64urlToBase64(base64url) {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function forgivingBase64UrlEncode(data) {
|
function forgivingBase64UrlEncode(data) {
|
||||||
return forgivingBase64Encode(
|
return StringPrototypeReplaceAll(
|
||||||
typeof data === "string" ? new TextEncoder().encode(data) : data,
|
StringPrototypeReplaceAll(
|
||||||
).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
StringPrototypeReplaceAll(
|
||||||
|
forgivingBase64Encode(
|
||||||
|
typeof data === "string" ? new TextEncoder().encode(data) : data,
|
||||||
|
),
|
||||||
|
"=",
|
||||||
|
"",
|
||||||
|
),
|
||||||
|
"+",
|
||||||
|
"-",
|
||||||
|
),
|
||||||
|
"/",
|
||||||
|
"_",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
const primordials = globalThis.__bootstrap.primordials;
|
const primordials = globalThis.__bootstrap.primordials;
|
||||||
const {
|
const {
|
||||||
ArrayPrototypeIncludes,
|
ArrayPrototypeIncludes,
|
||||||
Map,
|
|
||||||
MapPrototypeGet,
|
MapPrototypeGet,
|
||||||
MapPrototypeHas,
|
MapPrototypeHas,
|
||||||
MapPrototypeSet,
|
MapPrototypeSet,
|
||||||
RegExpPrototypeTest,
|
RegExpPrototypeTest,
|
||||||
|
SafeMap,
|
||||||
SafeMapIterator,
|
SafeMapIterator,
|
||||||
StringPrototypeReplaceAll,
|
StringPrototypeReplaceAll,
|
||||||
StringPrototypeToLowerCase,
|
StringPrototypeToLowerCase,
|
||||||
|
@ -92,7 +92,7 @@ function parseMimeType(input) {
|
||||||
type: StringPrototypeToLowerCase(type),
|
type: StringPrototypeToLowerCase(type),
|
||||||
subtype: StringPrototypeToLowerCase(subtype),
|
subtype: StringPrototypeToLowerCase(subtype),
|
||||||
/** @type {Map<string, string>} */
|
/** @type {Map<string, string>} */
|
||||||
parameters: new Map(),
|
parameters: new SafeMap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// 11.
|
// 11.
|
||||||
|
|
|
@ -24,7 +24,6 @@ const {
|
||||||
DateNow,
|
DateNow,
|
||||||
Error,
|
Error,
|
||||||
FunctionPrototypeCall,
|
FunctionPrototypeCall,
|
||||||
Map,
|
|
||||||
MapPrototypeGet,
|
MapPrototypeGet,
|
||||||
MapPrototypeSet,
|
MapPrototypeSet,
|
||||||
ObjectCreate,
|
ObjectCreate,
|
||||||
|
@ -34,6 +33,7 @@ const {
|
||||||
ReflectDefineProperty,
|
ReflectDefineProperty,
|
||||||
ReflectHas,
|
ReflectHas,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeMap,
|
||||||
StringPrototypeStartsWith,
|
StringPrototypeStartsWith,
|
||||||
Symbol,
|
Symbol,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
|
@ -1443,7 +1443,7 @@ function defineEventHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this[_eventHandlers]) {
|
if (!this[_eventHandlers]) {
|
||||||
this[_eventHandlers] = new Map();
|
this[_eventHandlers] = new SafeMap();
|
||||||
}
|
}
|
||||||
let handlerWrapper = MapPrototypeGet(this[_eventHandlers], name);
|
let handlerWrapper = MapPrototypeGet(this[_eventHandlers], name);
|
||||||
if (handlerWrapper) {
|
if (handlerWrapper) {
|
||||||
|
|
|
@ -20,12 +20,12 @@ const {
|
||||||
DataViewPrototypeGetByteLength,
|
DataViewPrototypeGetByteLength,
|
||||||
DataViewPrototypeGetByteOffset,
|
DataViewPrototypeGetByteOffset,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
|
SafeWeakMap,
|
||||||
TypedArrayPrototypeGetBuffer,
|
TypedArrayPrototypeGetBuffer,
|
||||||
TypedArrayPrototypeGetByteOffset,
|
TypedArrayPrototypeGetByteOffset,
|
||||||
TypedArrayPrototypeGetLength,
|
TypedArrayPrototypeGetLength,
|
||||||
TypedArrayPrototypeGetSymbolToStringTag,
|
TypedArrayPrototypeGetSymbolToStringTag,
|
||||||
TypeErrorPrototype,
|
TypeErrorPrototype,
|
||||||
WeakMap,
|
|
||||||
WeakMapPrototypeSet,
|
WeakMapPrototypeSet,
|
||||||
Int8Array,
|
Int8Array,
|
||||||
Int16Array,
|
Int16Array,
|
||||||
|
@ -40,7 +40,7 @@ const {
|
||||||
Float64Array,
|
Float64Array,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
const objectCloneMemo = new WeakMap();
|
const objectCloneMemo = new SafeWeakMap();
|
||||||
|
|
||||||
function cloneArrayBuffer(
|
function cloneArrayBuffer(
|
||||||
srcBuffer,
|
srcBuffer,
|
||||||
|
|
|
@ -7,7 +7,6 @@ const {
|
||||||
ArrayPrototypePush,
|
ArrayPrototypePush,
|
||||||
ArrayPrototypeShift,
|
ArrayPrototypeShift,
|
||||||
FunctionPrototypeCall,
|
FunctionPrototypeCall,
|
||||||
Map,
|
|
||||||
MapPrototypeDelete,
|
MapPrototypeDelete,
|
||||||
MapPrototypeGet,
|
MapPrototypeGet,
|
||||||
MapPrototypeHas,
|
MapPrototypeHas,
|
||||||
|
@ -18,6 +17,7 @@ const {
|
||||||
NumberPOSITIVE_INFINITY,
|
NumberPOSITIVE_INFINITY,
|
||||||
PromisePrototypeThen,
|
PromisePrototypeThen,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeMap,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
TypedArrayPrototypeGetBuffer,
|
TypedArrayPrototypeGetBuffer,
|
||||||
TypeError,
|
TypeError,
|
||||||
|
@ -76,7 +76,7 @@ function handleTimerMacrotask() {
|
||||||
*
|
*
|
||||||
* @type {Map<number, { cancelRid: number, isRef: boolean, promiseId: number }>}
|
* @type {Map<number, { cancelRid: number, isRef: boolean, promiseId: number }>}
|
||||||
*/
|
*/
|
||||||
const activeTimers = new Map();
|
const activeTimers = new SafeMap();
|
||||||
|
|
||||||
let nextId = 1;
|
let nextId = 1;
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ import {
|
||||||
const primordials = globalThis.__bootstrap.primordials;
|
const primordials = globalThis.__bootstrap.primordials;
|
||||||
const {
|
const {
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeSet,
|
||||||
SafeSetIterator,
|
SafeSetIterator,
|
||||||
Set,
|
|
||||||
SetPrototypeAdd,
|
SetPrototypeAdd,
|
||||||
SetPrototypeDelete,
|
SetPrototypeDelete,
|
||||||
Symbol,
|
Symbol,
|
||||||
|
@ -69,7 +69,7 @@ class AbortSignal extends EventTarget {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this[abortAlgos] === null) {
|
if (this[abortAlgos] === null) {
|
||||||
this[abortAlgos] = new Set();
|
this[abortAlgos] = new SafeSet();
|
||||||
}
|
}
|
||||||
SetPrototypeAdd(this[abortAlgos], algorithm);
|
SetPrototypeAdd(this[abortAlgos], algorithm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ const {
|
||||||
DataViewPrototypeGetByteOffset,
|
DataViewPrototypeGetByteOffset,
|
||||||
Float32Array,
|
Float32Array,
|
||||||
Float64Array,
|
Float64Array,
|
||||||
FinalizationRegistry,
|
|
||||||
Int8Array,
|
Int8Array,
|
||||||
Int16Array,
|
Int16Array,
|
||||||
Int32Array,
|
Int32Array,
|
||||||
|
@ -56,7 +55,9 @@ const {
|
||||||
queueMicrotask,
|
queueMicrotask,
|
||||||
RangeError,
|
RangeError,
|
||||||
ReflectHas,
|
ReflectHas,
|
||||||
|
SafeFinalizationRegistry,
|
||||||
SafePromiseAll,
|
SafePromiseAll,
|
||||||
|
SafeWeakMap,
|
||||||
// TODO(lucacasonato): add SharedArrayBuffer to primordials
|
// TODO(lucacasonato): add SharedArrayBuffer to primordials
|
||||||
// SharedArrayBufferPrototype
|
// SharedArrayBufferPrototype
|
||||||
Symbol,
|
Symbol,
|
||||||
|
@ -73,7 +74,6 @@ const {
|
||||||
Uint16Array,
|
Uint16Array,
|
||||||
Uint32Array,
|
Uint32Array,
|
||||||
Uint8ClampedArray,
|
Uint8ClampedArray,
|
||||||
WeakMap,
|
|
||||||
WeakMapPrototypeGet,
|
WeakMapPrototypeGet,
|
||||||
WeakMapPrototypeHas,
|
WeakMapPrototypeHas,
|
||||||
WeakMapPrototypeSet,
|
WeakMapPrototypeSet,
|
||||||
|
@ -695,7 +695,7 @@ function isReadableStreamDisturbed(stream) {
|
||||||
const DEFAULT_CHUNK_SIZE = 64 * 1024; // 64 KiB
|
const DEFAULT_CHUNK_SIZE = 64 * 1024; // 64 KiB
|
||||||
|
|
||||||
// A finalization registry to clean up underlying resources that are GC'ed.
|
// 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);
|
core.tryClose(rid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4743,7 +4743,7 @@ webidl.configurePrototype(ByteLengthQueuingStrategy);
|
||||||
const ByteLengthQueuingStrategyPrototype = ByteLengthQueuingStrategy.prototype;
|
const ByteLengthQueuingStrategyPrototype = ByteLengthQueuingStrategy.prototype;
|
||||||
|
|
||||||
/** @type {WeakMap<typeof globalThis, (chunk: ArrayBufferView) => number>} */
|
/** @type {WeakMap<typeof globalThis, (chunk: ArrayBufferView) => number>} */
|
||||||
const byteSizeFunctionWeakMap = new WeakMap();
|
const byteSizeFunctionWeakMap = new SafeWeakMap();
|
||||||
|
|
||||||
function initializeByteLengthSizeFunction(globalObject) {
|
function initializeByteLengthSizeFunction(globalObject) {
|
||||||
if (WeakMapPrototypeHas(byteSizeFunctionWeakMap, globalObject)) {
|
if (WeakMapPrototypeHas(byteSizeFunctionWeakMap, globalObject)) {
|
||||||
|
@ -4800,7 +4800,7 @@ webidl.configurePrototype(CountQueuingStrategy);
|
||||||
const CountQueuingStrategyPrototype = CountQueuingStrategy.prototype;
|
const CountQueuingStrategyPrototype = CountQueuingStrategy.prototype;
|
||||||
|
|
||||||
/** @type {WeakMap<typeof globalThis, () => 1>} */
|
/** @type {WeakMap<typeof globalThis, () => 1>} */
|
||||||
const countSizeFunctionWeakMap = new WeakMap();
|
const countSizeFunctionWeakMap = new SafeWeakMap();
|
||||||
|
|
||||||
/** @param {typeof globalThis} globalObject */
|
/** @param {typeof globalThis} globalObject */
|
||||||
function initializeCountSizeFunction(globalObject) {
|
function initializeCountSizeFunction(globalObject) {
|
||||||
|
|
|
@ -27,13 +27,13 @@ const {
|
||||||
DataViewPrototypeGetByteOffset,
|
DataViewPrototypeGetByteOffset,
|
||||||
Date,
|
Date,
|
||||||
DatePrototypeGetTime,
|
DatePrototypeGetTime,
|
||||||
FinalizationRegistry,
|
|
||||||
MathMax,
|
MathMax,
|
||||||
MathMin,
|
MathMin,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
RegExpPrototypeTest,
|
RegExpPrototypeTest,
|
||||||
// TODO(lucacasonato): add SharedArrayBuffer to primordials
|
// TODO(lucacasonato): add SharedArrayBuffer to primordials
|
||||||
// SharedArrayBufferPrototype
|
// SharedArrayBufferPrototype
|
||||||
|
SafeFinalizationRegistry,
|
||||||
SafeRegExp,
|
SafeRegExp,
|
||||||
StringPrototypeCharAt,
|
StringPrototypeCharAt,
|
||||||
StringPrototypeToLowerCase,
|
StringPrototypeToLowerCase,
|
||||||
|
@ -549,7 +549,7 @@ webidl.converters["FilePropertyBag"] = webidl.createDictionaryConverter(
|
||||||
|
|
||||||
// A finalization registry to deallocate a blob part when its JS reference is
|
// A finalization registry to deallocate a blob part when its JS reference is
|
||||||
// garbage collected.
|
// garbage collected.
|
||||||
const registry = new FinalizationRegistry((uuid) => {
|
const registry = new SafeFinalizationRegistry((uuid) => {
|
||||||
ops.op_blob_remove_part(uuid);
|
ops.op_blob_remove_part(uuid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,12 @@ const {
|
||||||
ArrayPrototypePush,
|
ArrayPrototypePush,
|
||||||
ArrayPrototypeReduce,
|
ArrayPrototypeReduce,
|
||||||
FunctionPrototypeCall,
|
FunctionPrototypeCall,
|
||||||
Map,
|
|
||||||
MapPrototypeGet,
|
MapPrototypeGet,
|
||||||
MapPrototypeSet,
|
MapPrototypeSet,
|
||||||
ObjectDefineProperty,
|
ObjectDefineProperty,
|
||||||
queueMicrotask,
|
queueMicrotask,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeMap,
|
||||||
Symbol,
|
Symbol,
|
||||||
TypedArrayPrototypeSet,
|
TypedArrayPrototypeSet,
|
||||||
TypedArrayPrototypeGetBuffer,
|
TypedArrayPrototypeGetBuffer,
|
||||||
|
@ -273,7 +273,7 @@ class FileReader extends EventTarget {
|
||||||
webidl.assertBranded(this, FileReaderPrototype);
|
webidl.assertBranded(this, FileReaderPrototype);
|
||||||
|
|
||||||
if (!this[handlerSymbol]) {
|
if (!this[handlerSymbol]) {
|
||||||
this[handlerSymbol] = new Map();
|
this[handlerSymbol] = new SafeMap();
|
||||||
}
|
}
|
||||||
let handlerWrapper = MapPrototypeGet(this[handlerSymbol], name);
|
let handlerWrapper = MapPrototypeGet(this[handlerSymbol], name);
|
||||||
if (handlerWrapper) {
|
if (handlerWrapper) {
|
||||||
|
|
|
@ -8,11 +8,11 @@ const primordials = globalThis.__bootstrap.primordials;
|
||||||
const {
|
const {
|
||||||
Error,
|
Error,
|
||||||
ObjectDefineProperties,
|
ObjectDefineProperties,
|
||||||
|
SafeWeakMap,
|
||||||
Symbol,
|
Symbol,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
SymbolToStringTag,
|
SymbolToStringTag,
|
||||||
TypeError,
|
TypeError,
|
||||||
WeakMap,
|
|
||||||
WeakMapPrototypeGet,
|
WeakMapPrototypeGet,
|
||||||
WeakMapPrototypeSet,
|
WeakMapPrototypeSet,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
@ -206,7 +206,7 @@ ObjectDefineProperties(Location.prototype, {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const workerLocationUrls = new WeakMap();
|
const workerLocationUrls = new SafeWeakMap();
|
||||||
|
|
||||||
class WorkerLocation {
|
class WorkerLocation {
|
||||||
constructor(href = null, key = null) {
|
constructor(href = null, key = null) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ const {
|
||||||
ReflectOwnKeys,
|
ReflectOwnKeys,
|
||||||
RegExpPrototypeTest,
|
RegExpPrototypeTest,
|
||||||
SafeRegExp,
|
SafeRegExp,
|
||||||
Set,
|
SafeSet,
|
||||||
SetPrototypeEntries,
|
SetPrototypeEntries,
|
||||||
SetPrototypeForEach,
|
SetPrototypeForEach,
|
||||||
SetPrototypeKeys,
|
SetPrototypeKeys,
|
||||||
|
@ -752,7 +752,7 @@ function createDictionaryConverter(name, ...dictionaries) {
|
||||||
|
|
||||||
// https://heycam.github.io/webidl/#es-enumeration
|
// https://heycam.github.io/webidl/#es-enumeration
|
||||||
function createEnumConverter(name, values) {
|
function createEnumConverter(name, values) {
|
||||||
const E = new Set(values);
|
const E = new SafeSet(values);
|
||||||
|
|
||||||
return function (V, opts = {}) {
|
return function (V, opts = {}) {
|
||||||
const S = String(V);
|
const S = String(V);
|
||||||
|
|
|
@ -33,7 +33,7 @@ const {
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
PromisePrototypeThen,
|
PromisePrototypeThen,
|
||||||
RegExpPrototypeTest,
|
RegExpPrototypeTest,
|
||||||
Set,
|
SafeSet,
|
||||||
SetPrototypeGetSize,
|
SetPrototypeGetSize,
|
||||||
// TODO(lucacasonato): add SharedArrayBuffer to primordials
|
// TODO(lucacasonato): add SharedArrayBuffer to primordials
|
||||||
// SharedArrayBufferPrototype
|
// SharedArrayBufferPrototype
|
||||||
|
@ -223,7 +223,7 @@ class WebSocket extends EventTarget {
|
||||||
if (
|
if (
|
||||||
protocols.length !==
|
protocols.length !==
|
||||||
SetPrototypeGetSize(
|
SetPrototypeGetSize(
|
||||||
new Set(
|
new SafeSet(
|
||||||
ArrayPrototypeMap(protocols, (p) => StringPrototypeToLowerCase(p)),
|
ArrayPrototypeMap(protocols, (p) => StringPrototypeToLowerCase(p)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,7 +21,7 @@ const {
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
PromisePrototypeCatch,
|
PromisePrototypeCatch,
|
||||||
PromisePrototypeThen,
|
PromisePrototypeThen,
|
||||||
Set,
|
SafeSet,
|
||||||
SetPrototypeGetSize,
|
SetPrototypeGetSize,
|
||||||
StringPrototypeEndsWith,
|
StringPrototypeEndsWith,
|
||||||
StringPrototypeToLowerCase,
|
StringPrototypeToLowerCase,
|
||||||
|
@ -118,7 +118,7 @@ class WebSocketStream {
|
||||||
if (
|
if (
|
||||||
options.protocols.length !==
|
options.protocols.length !==
|
||||||
SetPrototypeGetSize(
|
SetPrototypeGetSize(
|
||||||
new Set(
|
new SafeSet(
|
||||||
ArrayPrototypeMap(
|
ArrayPrototypeMap(
|
||||||
options.protocols,
|
options.protocols,
|
||||||
(p) => StringPrototypeToLowerCase(p),
|
(p) => StringPrototypeToLowerCase(p),
|
||||||
|
|
|
@ -10,7 +10,6 @@ const {
|
||||||
ArrayPrototypeIncludes,
|
ArrayPrototypeIncludes,
|
||||||
ArrayPrototypeMap,
|
ArrayPrototypeMap,
|
||||||
ArrayPrototypeSlice,
|
ArrayPrototypeSlice,
|
||||||
Map,
|
|
||||||
MapPrototypeGet,
|
MapPrototypeGet,
|
||||||
MapPrototypeHas,
|
MapPrototypeHas,
|
||||||
MapPrototypeSet,
|
MapPrototypeSet,
|
||||||
|
@ -19,6 +18,7 @@ const {
|
||||||
PromiseReject,
|
PromiseReject,
|
||||||
ReflectHas,
|
ReflectHas,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
SafeMap,
|
||||||
Symbol,
|
Symbol,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
TypeError,
|
TypeError,
|
||||||
|
@ -113,7 +113,7 @@ class PermissionStatus extends EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Map<string, StatusCacheValue>} */
|
/** @type {Map<string, StatusCacheValue>} */
|
||||||
const statusCache = new Map();
|
const statusCache = new SafeMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Deno.PermissionDescriptor} desc
|
* @param {Deno.PermissionDescriptor} desc
|
||||||
|
|
|
@ -4,8 +4,9 @@ const core = globalThis.Deno.core;
|
||||||
const ops = core.ops;
|
const ops = core.ops;
|
||||||
const primordials = globalThis.__bootstrap.primordials;
|
const primordials = globalThis.__bootstrap.primordials;
|
||||||
const {
|
const {
|
||||||
|
SafeSet,
|
||||||
SafeSetIterator,
|
SafeSetIterator,
|
||||||
Set,
|
SetPrototypeAdd,
|
||||||
SetPrototypeDelete,
|
SetPrototypeDelete,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
TypeError,
|
TypeError,
|
||||||
|
@ -32,7 +33,7 @@ const signalData = {};
|
||||||
/** Gets the signal handlers and resource data of the given signal */
|
/** Gets the signal handlers and resource data of the given signal */
|
||||||
function getSignalData(signo) {
|
function getSignalData(signo) {
|
||||||
return signalData[signo] ??
|
return signalData[signo] ??
|
||||||
(signalData[signo] = { rid: undefined, listeners: new Set() });
|
(signalData[signo] = { rid: undefined, listeners: new SafeSet() });
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkSignalListenerType(listener) {
|
function checkSignalListenerType(listener) {
|
||||||
|
@ -47,7 +48,7 @@ function addSignalListener(signo, listener) {
|
||||||
checkSignalListenerType(listener);
|
checkSignalListenerType(listener);
|
||||||
|
|
||||||
const sigData = getSignalData(signo);
|
const sigData = getSignalData(signo);
|
||||||
sigData.listeners.add(listener);
|
SetPrototypeAdd(sigData.listeners, listener);
|
||||||
|
|
||||||
if (!sigData.rid) {
|
if (!sigData.rid) {
|
||||||
// If signal resource doesn't exist, create it.
|
// If signal resource doesn't exist, create it.
|
||||||
|
|
Loading…
Reference in a new issue