Skip to content

fix(runtime): use more null proto objects again #25040

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

Merged
merged 6 commits into from
Sep 6, 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
6 changes: 5 additions & 1 deletion ext/console/01_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const colors = {

function defineColorAlias(target, alias) {
ObjectDefineProperty(colors, alias, {
__proto__: null,
get() {
return this[target];
},
Expand Down Expand Up @@ -3447,7 +3448,10 @@ function inspect(
function createFilteredInspectProxy({ object, keys, evaluate }) {
const obj = class {};
if (object.constructor?.name) {
ObjectDefineProperty(obj, "name", { value: object.constructor.name });
ObjectDefineProperty(obj, "name", {
__proto__: null,
value: object.constructor.name,
});
}

return new Proxy(new obj(), {
Expand Down
8 changes: 8 additions & 0 deletions ext/fetch/22_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
/** @type {PropertyDescriptorMap} */
const mixin = {
body: {
__proto__: null,
/**
* @returns {ReadableStream<Uint8Array> | null}
*/
Expand All @@ -278,6 +279,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
enumerable: true,
},
bodyUsed: {
__proto__: null,
/**
* @returns {boolean}
*/
Expand All @@ -292,6 +294,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
enumerable: true,
},
arrayBuffer: {
__proto__: null,
/** @returns {Promise<ArrayBuffer>} */
value: function arrayBuffer() {
return consumeBody(this, "ArrayBuffer");
Expand All @@ -301,6 +304,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
enumerable: true,
},
blob: {
__proto__: null,
/** @returns {Promise<Blob>} */
value: function blob() {
return consumeBody(this, "Blob");
Expand All @@ -310,6 +314,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
enumerable: true,
},
bytes: {
__proto__: null,
/** @returns {Promise<Uint8Array>} */
value: function bytes() {
return consumeBody(this, "bytes");
Expand All @@ -319,6 +324,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
enumerable: true,
},
formData: {
__proto__: null,
/** @returns {Promise<FormData>} */
value: function formData() {
return consumeBody(this, "FormData");
Expand All @@ -328,6 +334,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
enumerable: true,
},
json: {
__proto__: null,
/** @returns {Promise<any>} */
value: function json() {
return consumeBody(this, "JSON");
Expand All @@ -337,6 +344,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
enumerable: true,
},
text: {
__proto__: null,
/** @returns {Promise<string>} */
value: function text() {
return consumeBody(this, "text");
Expand Down
1 change: 1 addition & 0 deletions ext/fetch/22_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class HttpClient {
*/
constructor(rid) {
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
Expand Down
6 changes: 3 additions & 3 deletions ext/fetch/23_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ class Response {

webidl.configureInterface(Response);
ObjectDefineProperties(Response, {
json: { enumerable: true },
redirect: { enumerable: true },
error: { enumerable: true },
json: { __proto__: null, enumerable: true },
redirect: { __proto__: null, enumerable: true },
error: { __proto__: null, enumerable: true },
});
const ResponsePrototype = Response.prototype;
mixinBody(ResponsePrototype, _body, _mimeType);
Expand Down
3 changes: 3 additions & 0 deletions ext/fetch/27_eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,15 @@ const EventSourcePrototype = EventSource.prototype;

ObjectDefineProperties(EventSource, {
CONNECTING: {
__proto__: null,
value: 0,
},
OPEN: {
__proto__: null,
value: 1,
},
CLOSED: {
__proto__: null,
value: 2,
},
});
Expand Down
6 changes: 4 additions & 2 deletions ext/ffi/00_ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,11 @@ class DynamicLibrary {
this.symbols,
symbol,
{
__proto__: null,
configurable: false,
enumerable: true,
value,
writable: false,
value,
},
);
continue;
Expand All @@ -504,8 +505,10 @@ class DynamicLibrary {
this.symbols,
symbol,
{
__proto__: null,
configurable: false,
enumerable: true,
writable: false,
value: (...parameters) => {
if (isStructResult) {
const buffer = new Uint8Array(structSize);
Expand All @@ -527,7 +530,6 @@ class DynamicLibrary {
);
}
},
writable: false,
},
);
}
Expand Down
1 change: 1 addition & 0 deletions ext/fs/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ class FsFile {

constructor(rid, symbol) {
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
Expand Down
6 changes: 6 additions & 0 deletions ext/net/01_net.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ class Conn {
constructor(rid, remoteAddr, localAddr) {
if (internals.future) {
ObjectDefineProperty(this, "rid", {
__proto__: null,
enumerable: false,
value: undefined,
});
}
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
Expand Down Expand Up @@ -214,6 +216,7 @@ class TcpConn extends Conn {
constructor(rid, remoteAddr, localAddr) {
super(rid, remoteAddr, localAddr);
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
Expand Down Expand Up @@ -244,6 +247,7 @@ class UnixConn extends Conn {
constructor(rid, remoteAddr, localAddr) {
super(rid, remoteAddr, localAddr);
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
Expand All @@ -269,11 +273,13 @@ class Listener {
constructor(rid, addr) {
if (internals.future) {
ObjectDefineProperty(this, "rid", {
__proto__: null,
enumerable: false,
value: undefined,
});
}
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
Expand Down
2 changes: 2 additions & 0 deletions ext/net/02_tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TlsConn extends Conn {
constructor(rid, remoteAddr, localAddr) {
super(rid, remoteAddr, localAddr);
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
Expand Down Expand Up @@ -110,6 +111,7 @@ class TlsListener extends Listener {
constructor(rid, addr) {
super(rid, addr);
ObjectDefineProperty(this, internalRidSymbol, {
__proto__: null,
enumerable: false,
value: rid,
});
Expand Down
1 change: 1 addition & 0 deletions ext/node/benchmarks/child_process_ipc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if (process.env.CHILD) {
const start = performance.now();

const options = {
__proto__: null,
"stdio": ["inherit", "inherit", "inherit", "ipc"],
"env": { "CHILD": len.toString() },
};
Expand Down
4 changes: 2 additions & 2 deletions ext/node/polyfills/_brotli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class BrotliDecompress extends Transform {
#context;

// TODO(littledivy): use `options` argument
constructor(_options = {}) {
constructor(_options = { __proto__: null }) {
super({
// TODO(littledivy): use `encoding` argument
transform(chunk, _encoding, callback) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export class BrotliDecompress extends Transform {
export class BrotliCompress extends Transform {
#context;

constructor(options = {}) {
constructor(options = { __proto__: null }) {
super({
// TODO(littledivy): use `encoding` argument
transform(chunk, _encoding, callback) {
Expand Down
6 changes: 6 additions & 0 deletions ext/node/polyfills/_process/streams.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,26 @@ export function createWritableStdioStream(writer, name, warmup = false) {
stream.once("close", () => writer?.close());
ObjectDefineProperties(stream, {
columns: {
__proto__: null,
enumerable: true,
configurable: true,
get: () =>
writer?.isTerminal() ? Deno.consoleSize?.().columns : undefined,
},
rows: {
__proto__: null,
enumerable: true,
configurable: true,
get: () => writer?.isTerminal() ? Deno.consoleSize?.().rows : undefined,
},
isTTY: {
__proto__: null,
enumerable: true,
configurable: true,
get: () => writer?.isTerminal(),
},
getWindowSize: {
__proto__: null,
enumerable: true,
configurable: true,
value: () =>
Expand Down Expand Up @@ -203,6 +207,7 @@ export const initStdin = (warmup = false) => {
stdin.on("close", () => io.stdin?.close());
stdin.fd = io.stdin ? io.STDIN_RID : -1;
ObjectDefineProperty(stdin, "isTTY", {
__proto__: null,
enumerable: true,
configurable: true,
get() {
Expand All @@ -216,6 +221,7 @@ export const initStdin = (warmup = false) => {
return stdin;
};
ObjectDefineProperty(stdin, "isRaw", {
__proto__: null,
enumerable: true,
configurable: true,
get() {
Expand Down
2 changes: 1 addition & 1 deletion ext/node/polyfills/_util/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { clearTimeout, setTimeout } from "ext:deno_web/02_timers.js";
/** Resolve a Promise after a given amount of milliseconds. */
export function delay(
ms: number,
options: { signal?: AbortSignal } = {},
options: { signal?: AbortSignal } = { __proto__: null },
): Promise<void> {
const { signal } = options;
if (signal?.aborted) {
Expand Down
9 changes: 6 additions & 3 deletions ext/node/polyfills/_util/std_testing_diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ export function diffstr(A: string, B: string) {
);
}

function tokenize(string: string, { wordDiff = false } = {}): string[] {
function tokenize(
string: string,
{ wordDiff = false } = { __proto__: null },
): string[] {
if (wordDiff) {
// Split string on whitespace symbols
const tokens = StringPrototypeSplit(string, WHITESPACE_SYMBOL_PATTERN);
Expand Down Expand Up @@ -450,7 +453,7 @@ export function diffstr(A: string, B: string) {
*/
function createColor(
diffType: DiffType,
{ background = false } = {},
{ background = false } = { __proto__: null },
): (s: string) => string {
// TODO(@littledivy): Remove this when we can detect
// true color terminals.
Expand Down Expand Up @@ -484,7 +487,7 @@ function createSign(diffType: DiffType): string {

export function buildMessage(
diffResult: ReadonlyArray<DiffResult<string>>,
{ stringDiff = false } = {},
{ stringDiff = false } = { __proto__: null },
): string[] {
const messages: string[] = [], diffMessages: string[] = [];
ArrayPrototypePush(messages, "");
Expand Down
2 changes: 2 additions & 0 deletions ext/node/polyfills/string_decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,15 @@ StringDecoder.prototype.text = function text(

ObjectDefineProperties(StringDecoder.prototype, {
lastNeed: {
__proto__: null,
configurable: true,
enumerable: true,
get(this: StringDecoder): number {
return this[kMissingBytes];
},
},
lastTotal: {
__proto__: null,
configurable: true,
enumerable: true,
get(this: StringDecoder): number {
Expand Down
1 change: 1 addition & 0 deletions ext/node/polyfills/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function setTimeout(
}

ObjectDefineProperty(setTimeout, promisify.custom, {
__proto__: null,
value: (timeout: number, ...args: unknown[]) => {
return new Promise((cb) =>
setTimeout(cb, timeout, ...new SafeArrayIterator(args))
Expand Down
1 change: 1 addition & 0 deletions ext/node/polyfills/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export function inherits<T, U>(
);
}
ObjectDefineProperty(ctor, "super_", {
__proto__: null,
value: superCtor,
writable: true,
configurable: true,
Expand Down
11 changes: 7 additions & 4 deletions ext/node/polyfills/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const kParsingContext = Symbol("script parsing context");
export class Script {
#inner;

constructor(code, options = {}) {
constructor(code, options = { __proto__: null }) {
code = `${code}`;
if (typeof options === "string") {
options = { filename: options };
Expand Down Expand Up @@ -80,7 +80,7 @@ export class Script {
: undefined;
}

#runInContext(contextifiedObject, options = {}) {
#runInContext(contextifiedObject, options = { __proto__: null }) {
validateObject(options, "options");

let timeout = options.timeout;
Expand Down Expand Up @@ -181,7 +181,10 @@ function getContextOptions(options) {
}

let defaultContextNameIndex = 1;
export function createContext(contextObject = {}, options = {}) {
export function createContext(
contextObject = {},
options = { __proto__: null },
) {
if (isContext(contextObject)) {
return contextObject;
}
Expand Down Expand Up @@ -276,7 +279,7 @@ export function isContext(object) {
return op_vm_is_context(object);
}

export function compileFunction(code, params, options = {}) {
export function compileFunction(code, params, options = { __proto__: null }) {
validateString(code, "code");
if (params !== undefined) {
validateStringArray(params, "params");
Expand Down
Loading