Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime): use more null proto objects #23921

Merged
merged 7 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/js/40_jupyter.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function enableJupyter() {
async function broadcast(
msgType,
content,
{ metadata = {}, buffers = [] } = {},
{ metadata = { __proto__: null }, buffers = [] } = { __proto__: null },
) {
await op_jupyter_broadcast(msgType, content, metadata, buffers);
}
Expand Down Expand Up @@ -400,7 +400,7 @@ function enableJupyter() {
if (options.update) {
messageType = "update_display_data";
}
let transient = {};
let transient = { __proto__: null };
if (options.display_id) {
transient = { display_id: options.display_id };
}
Expand Down
2 changes: 1 addition & 1 deletion cli/js/40_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function testInner(
nameOrFnOrOptions,
optionsOrFn,
maybeFn,
overrides = {},
overrides = { __proto__: null },
) {
// No-op if we're not running in `deno test` subcommand.
if (typeof op_register_test !== "function") {
Expand Down
8 changes: 4 additions & 4 deletions ext/console/01_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@ function cssToAnsi(css, prevCss = null) {
return ansi;
}

function inspectArgs(args, inspectOptions = {}) {
function inspectArgs(args, inspectOptions = { __proto__: null }) {
const ctx = {
...getDefaultInspectOptions(),
colors: inspectOptions.colors ?? !noColorStdout(),
Expand Down Expand Up @@ -3124,7 +3124,7 @@ class Console {
);
};

dir = (obj = undefined, options = {}) => {
dir = (obj = undefined, options = { __proto__: null }) => {
this.#printFunc(
inspectArgs([obj], {
...getConsoleInspectOptions(noColorStdout()),
Expand Down Expand Up @@ -3232,7 +3232,7 @@ class Console {
resultData = [...new SafeSetIterator(data)];
} else if (isMapObject) {
let idx = 0;
resultData = {};
resultData = { __proto__: null };

MapPrototypeForEach(data, (v, k) => {
resultData[idx] = { Key: k, Values: v };
Expand Down Expand Up @@ -3390,7 +3390,7 @@ const customInspect = SymbolFor("Deno.customInspect");

function inspect(
value,
inspectOptions = {},
inspectOptions = { __proto__: null },
) {
// Default options
const ctx = {
Expand Down
6 changes: 3 additions & 3 deletions ext/fetch/20_headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function checkForInvalidValueChars(value) {
return true;
}

let HEADER_NAME_CACHE = {};
let HEADER_NAME_CACHE = { __proto__: null };
let HEADER_CACHE_SIZE = 0;
const HEADER_NAME_CACHE_SIZE_BOUNDARY = 4096;
function checkHeaderNameForHttpTokenCodePoint(name) {
Expand All @@ -112,7 +112,7 @@ function checkHeaderNameForHttpTokenCodePoint(name) {
const valid = RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name);

if (HEADER_CACHE_SIZE > HEADER_NAME_CACHE_SIZE_BOUNDARY) {
HEADER_NAME_CACHE = {};
HEADER_NAME_CACHE = { __proto__: null };
HEADER_CACHE_SIZE = 0;
}
HEADER_CACHE_SIZE++;
Expand Down Expand Up @@ -241,7 +241,7 @@ class Headers {

// The order of steps are not similar to the ones suggested by the
// spec but produce the same result.
const seenHeaders = {};
const seenHeaders = { __proto__: null };
const entries = [];
for (let i = 0; i < list.length; ++i) {
const entry = list[i];
Expand Down
2 changes: 1 addition & 1 deletion ext/fetch/23_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class Request {
* @param {RequestInfo} input
* @param {RequestInit} init
*/
constructor(input, init = {}) {
constructor(input, init = { __proto__: null }) {
if (input === _brand) {
this[_brand] = _brand;
return;
Expand Down
2 changes: 1 addition & 1 deletion ext/fetch/23_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Response {
* @param {ResponseInit} init
* @returns {Response}
*/
static json(data = undefined, init = {}) {
static json(data = undefined, init = { __proto__: null }) {
const prefix = "Failed to execute 'Response.json'";
data = webidl.converters.any(data);
init = webidl.converters["ResponseInit_fast"](init, prefix, "Argument 2");
Expand Down
2 changes: 1 addition & 1 deletion ext/fetch/26_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function httpRedirectFetch(request, response, terminator) {
* @param {RequestInfo} input
* @param {RequestInit} init
*/
function fetch(input, init = {}) {
function fetch(input, init = { __proto__: null }) {
// There is an async dispatch later that causes a stack trace disconnect.
// We reconnect it by assigning the result of that dispatch to `opPromise`,
// awaiting `opPromise` in an inner function also named `fetch()` and
Expand Down
2 changes: 1 addition & 1 deletion ext/fetch/27_eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class EventSource extends EventTarget {
return this.#withCredentials;
}

constructor(url, eventSourceInitDict = {}) {
constructor(url, eventSourceInitDict = { __proto__: null }) {
super();
this[webidl.brand] = webidl.brand;
const prefix = "Failed to construct 'EventSource'";
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi/00_ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ const UnsafeCallbackPrototype = UnsafeCallback.prototype;

class DynamicLibrary {
#rid;
symbols = {};
symbols = { __proto__: null };

constructor(path, symbols) {
({ 0: this.#rid, 1: this.symbols } = op_ffi_load({ path, symbols }));
Expand Down
22 changes: 11 additions & 11 deletions ext/fs/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,31 @@ function chdir(directory) {
op_fs_chdir(pathFromURL(directory));
}

function makeTempDirSync(options = {}) {
function makeTempDirSync(options = { __proto__: null }) {
return op_fs_make_temp_dir_sync(
options.dir,
options.prefix,
options.suffix,
);
}

function makeTempDir(options = {}) {
function makeTempDir(options = { __proto__: null }) {
return op_fs_make_temp_dir_async(
options.dir,
options.prefix,
options.suffix,
);
}

function makeTempFileSync(options = {}) {
function makeTempFileSync(options = { __proto__: null }) {
return op_fs_make_temp_file_sync(
options.dir,
options.prefix,
options.suffix,
);
}

function makeTempFile(options = {}) {
function makeTempFile(options = { __proto__: null }) {
return op_fs_make_temp_file_async(
options.dir,
options.prefix,
Expand Down Expand Up @@ -245,7 +245,7 @@ function realPath(path) {

function removeSync(
path,
options = {},
options = { __proto__: null },
) {
op_fs_remove_sync(
pathFromURL(path),
Expand All @@ -255,7 +255,7 @@ function removeSync(

async function remove(
path,
options = {},
options = { __proto__: null },
) {
await op_fs_remove_async(
pathFromURL(path),
Expand Down Expand Up @@ -777,7 +777,7 @@ class FsFile {
return core.isTerminal(this.#rid);
}

setRaw(mode, options = {}) {
setRaw(mode, options = { __proto__: null }) {
const cbreak = !!(options.cbreak ?? false);
op_set_raw(this.#rid, mode, cbreak);
}
Expand Down Expand Up @@ -893,7 +893,7 @@ async function readTextFile(path, options) {
function writeFileSync(
path,
data,
options = {},
options = { __proto__: null },
) {
options.signal?.throwIfAborted();
op_fs_write_file_sync(
Expand All @@ -909,7 +909,7 @@ function writeFileSync(
async function writeFile(
path,
data,
options = {},
options = { __proto__: null },
) {
let cancelRid;
let abortHandler;
Expand Down Expand Up @@ -955,7 +955,7 @@ async function writeFile(
function writeTextFileSync(
path,
data,
options = {},
options = { __proto__: null },
) {
const encoder = new TextEncoder();
return writeFileSync(path, encoder.encode(data), options);
Expand All @@ -964,7 +964,7 @@ function writeTextFileSync(
function writeTextFile(
path,
data,
options = {},
options = { __proto__: null },
) {
if (ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, data)) {
return writeFile(
Expand Down
2 changes: 1 addition & 1 deletion ext/http/00_serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ function serve(arg1, arg2) {
throw new TypeError("A handler function must be provided.");
}
if (options === undefined) {
options = {};
options = { __proto__: null };
}

const wantsHttps = hasTlsKeyPairOptions(options);
Expand Down
2 changes: 1 addition & 1 deletion ext/http/02_websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const _ws = Symbol("[[associated_ws]]");
const websocketCvf = buildCaseInsensitiveCommaValueFinder("websocket");
const upgradeCvf = buildCaseInsensitiveCommaValueFinder("upgrade");

function upgradeWebSocket(request, options = {}) {
function upgradeWebSocket(request, options = { __proto__: null }) {
const inner = toInnerRequest(request);
const upgrade = request.headers.get("upgrade");
const upgradeHasWebSocketOption = upgrade !== null &&
Expand Down
2 changes: 1 addition & 1 deletion ext/io/12_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class Stdin {
return this.#readable;
}

setRaw(mode, options = {}) {
setRaw(mode, options = { __proto__: null }) {
const cbreak = !!(options.cbreak ?? false);
op_set_raw(this.#rid, mode, cbreak);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/kv/01_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Kv {
cursor?: string;
reverse?: boolean;
consistency?: Deno.KvConsistencyLevel;
} = {},
} = { __proto__: null },
): KvListIterator {
if (options.limit !== undefined && options.limit <= 0) {
throw new Error("limit must be positive");
Expand Down Expand Up @@ -340,7 +340,7 @@ class Kv {
finishMessageOps.clear();
}

watch(keys: Deno.KvKey[], options = {}) {
watch(keys: Deno.KvKey[], options = { __proto__: null }) {
const raw = options.raw ?? false;
const rid = op_kv_watch(this.#rid, keys);
const lastEntries: (Deno.KvEntryMaybe<unknown> | undefined)[] = ArrayFrom(
Expand Down
2 changes: 1 addition & 1 deletion ext/net/02_tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ async function startTls(
hostname = "127.0.0.1",
caCerts = [],
alpnProtocols = undefined,
} = {},
} = { __proto__: null },
) {
const { 0: rid, 1: localAddr, 2: remoteAddr } = op_tls_start({
rid: conn[internalRidSymbol],
Expand Down
12 changes: 6 additions & 6 deletions ext/web/02_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const _isTrusted = Symbol("[[isTrusted]]");
const _path = Symbol("[[path]]");

class Event {
constructor(type, eventInitDict = {}) {
constructor(type, eventInitDict = { __proto__: null }) {
// TODO(lucacasonato): remove when this interface is spec aligned
this[SymbolToStringTag] = "Event";
this[_canceledFlag] = false;
Expand Down Expand Up @@ -1095,7 +1095,7 @@ class ErrorEvent extends Event {
lineno = 0,
colno = 0,
error,
} = {},
} = { __proto__: null },
) {
super(type, {
bubbles: bubbles,
Expand Down Expand Up @@ -1164,7 +1164,7 @@ class CloseEvent extends Event {
wasClean = false,
code = 0,
reason = "",
} = {}) {
} = { __proto__: null }) {
super(type, {
bubbles: bubbles,
cancelable: cancelable,
Expand Down Expand Up @@ -1238,7 +1238,7 @@ const MessageEventPrototype = MessageEvent.prototype;
class CustomEvent extends Event {
#detail = null;

constructor(type, eventInitDict = {}) {
constructor(type, eventInitDict = { __proto__: null }) {
super(type, eventInitDict);
webidl.requiredArguments(
arguments.length,
Expand Down Expand Up @@ -1280,7 +1280,7 @@ ReflectDefineProperty(CustomEvent.prototype, "detail", {
// ProgressEvent could also be used in other DOM progress event emits.
// Current use is for FileReader.
class ProgressEvent extends Event {
constructor(type, eventInitDict = {}) {
constructor(type, eventInitDict = { __proto__: null }) {
super(type, eventInitDict);

this.lengthComputable = eventInitDict?.lengthComputable ?? false;
Expand Down Expand Up @@ -1329,7 +1329,7 @@ class PromiseRejectionEvent extends Event {
composed,
promise,
reason,
} = {},
} = { __proto__: null },
) {
super(type, {
bubbles: bubbles,
Expand Down
12 changes: 6 additions & 6 deletions ext/web/06_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -5274,7 +5274,7 @@ class ReadableStream {
"Argument 1",
);
} else {
options = {};
options = { __proto__: null };
}
if (options.mode === undefined) {
return acquireReadableStreamDefaultReader(this);
Expand All @@ -5290,7 +5290,7 @@ class ReadableStream {
* @param {PipeOptions=} options
* @returns {ReadableStream<T>}
*/
pipeThrough(transform, options = {}) {
pipeThrough(transform, options = { __proto__: null }) {
webidl.assertBranded(this, ReadableStreamPrototype);
const prefix = "Failed to execute 'pipeThrough' on 'ReadableStream'";
webidl.requiredArguments(arguments.length, 1, prefix);
Expand Down Expand Up @@ -5329,7 +5329,7 @@ class ReadableStream {
* @param {PipeOptions=} options
* @returns {Promise<void>}
*/
pipeTo(destination, options = {}) {
pipeTo(destination, options = { __proto__: null }) {
try {
webidl.assertBranded(this, ReadableStreamPrototype);
const prefix = "Failed to execute 'pipeTo' on 'ReadableStream'";
Expand Down Expand Up @@ -5567,7 +5567,7 @@ class ReadableStreamBYOBReader {
* @param {ReadableStreamBYOBReaderReadOptions} options
* @returns {Promise<ReadableStreamBYOBReadResult>}
*/
read(view, options = {}) {
read(view, options = { __proto__: null }) {
try {
webidl.assertBranded(this, ReadableStreamBYOBReaderPrototype);
const prefix = "Failed to execute 'read' on 'ReadableStreamBYOBReader'";
Expand Down Expand Up @@ -6151,8 +6151,8 @@ class TransformStream {
*/
constructor(
transformer = undefined,
writableStrategy = {},
readableStrategy = {},
writableStrategy = { __proto__: null },
readableStrategy = { __proto__: null },
) {
const prefix = "Failed to construct 'TransformStream'";
if (transformer !== undefined) {
Expand Down
Loading