mirror of
https://github.com/denoland/deno.git
synced 2025-03-10 06:07:03 -04:00
fix(node): instantiating process class without new (#23865)
Popular test runners like Jest instantiate a new `Process` object themselves and expect the class constructor to be callable without the `new` keyword. This PR refactors our `Process` class implementation from a proper ES2015 class to an ES5-style class which can be invoked both with and without the `new` keyword like in Node. Fixes https://github.com/denoland/deno/issues/23863
This commit is contained in:
parent
eec8800513
commit
3d3b9a7566
2 changed files with 292 additions and 273 deletions
|
@ -311,6 +311,8 @@ if (!isWindows) {
|
||||||
|
|
||||||
export { geteuid, getgid, getuid };
|
export { geteuid, getgid, getuid };
|
||||||
|
|
||||||
|
const ALLOWED_FLAGS = buildAllowedFlags();
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
function uncaughtExceptionHandler(err: any, origin: string) {
|
function uncaughtExceptionHandler(err: any, origin: string) {
|
||||||
// The origin parameter can be 'unhandledRejection' or 'uncaughtException'
|
// The origin parameter can be 'unhandledRejection' or 'uncaughtException'
|
||||||
|
@ -326,13 +328,21 @@ function uncaughtExceptionHandler(err: any, origin: string) {
|
||||||
|
|
||||||
let execPath: string | null = null;
|
let execPath: string | null = null;
|
||||||
|
|
||||||
class Process extends EventEmitter {
|
// The process class needs to be an ES5 class because it can be instantiated
|
||||||
constructor() {
|
// in Node without the `new` keyword. It's not a true class in Node. Popular
|
||||||
super();
|
// test runners like Jest rely on this.
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
function Process(this: any) {
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
if (!(this instanceof Process)) return new (Process as any)();
|
||||||
|
|
||||||
|
EventEmitter.call(this);
|
||||||
}
|
}
|
||||||
|
Process.prototype = Object.create(EventEmitter.prototype);
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processrelease */
|
/** https://nodejs.org/api/process.html#processrelease */
|
||||||
get release() {
|
Object.defineProperty(Process.prototype, "release", {
|
||||||
|
get() {
|
||||||
return {
|
return {
|
||||||
name: "node",
|
name: "node",
|
||||||
sourceUrl:
|
sourceUrl:
|
||||||
|
@ -340,109 +350,115 @@ class Process extends EventEmitter {
|
||||||
headersUrl:
|
headersUrl:
|
||||||
`https://nodejs.org/download/release/${version}/node-${version}-headers.tar.gz`,
|
`https://nodejs.org/download/release/${version}/node-${version}-headers.tar.gz`,
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_arch */
|
/** https://nodejs.org/api/process.html#process_process_arch */
|
||||||
get arch() {
|
Object.defineProperty(Process.prototype, "arch", {
|
||||||
|
get() {
|
||||||
return arch;
|
return arch;
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
get report() {
|
Object.defineProperty(Process.prototype, "report", {
|
||||||
|
get() {
|
||||||
return report;
|
return report;
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
get title() {
|
Object.defineProperty(Process.prototype, "title", {
|
||||||
|
get() {
|
||||||
return "deno";
|
return "deno";
|
||||||
}
|
},
|
||||||
|
set(_value) {
|
||||||
set title(_value) {
|
|
||||||
// NOTE(bartlomieju): this is a noop. Node.js doesn't guarantee that the
|
// NOTE(bartlomieju): this is a noop. Node.js doesn't guarantee that the
|
||||||
// process name will be properly set and visible from other tools anyway.
|
// process name will be properly set and visible from other tools anyway.
|
||||||
// Might revisit in the future.
|
// Might revisit in the future.
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://nodejs.org/api/process.html#process_process_argv
|
* https://nodejs.org/api/process.html#process_process_argv
|
||||||
* Read permissions are required in order to get the executable route
|
* Read permissions are required in order to get the executable route
|
||||||
*/
|
*/
|
||||||
argv = argv;
|
Process.prototype.argv = argv;
|
||||||
|
|
||||||
get argv0() {
|
Object.defineProperty(Process.prototype, "argv0", {
|
||||||
|
get() {
|
||||||
return argv0;
|
return argv0;
|
||||||
}
|
},
|
||||||
|
set(_val) {},
|
||||||
set argv0(_val) {}
|
});
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_chdir_directory */
|
/** https://nodejs.org/api/process.html#process_process_chdir_directory */
|
||||||
chdir = chdir;
|
Process.prototype.chdir = chdir;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processconfig */
|
/** https://nodejs.org/api/process.html#processconfig */
|
||||||
config = {
|
Process.prototype.config = {
|
||||||
target_defaults: {},
|
target_defaults: {},
|
||||||
variables: {},
|
variables: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_cwd */
|
/** https://nodejs.org/api/process.html#process_process_cwd */
|
||||||
cwd = cwd;
|
Process.prototype.cwd = cwd;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://nodejs.org/api/process.html#process_process_env
|
* https://nodejs.org/api/process.html#process_process_env
|
||||||
* Requires env permissions
|
* Requires env permissions
|
||||||
*/
|
*/
|
||||||
env = env;
|
Process.prototype.env = env;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_execargv */
|
/** https://nodejs.org/api/process.html#process_process_execargv */
|
||||||
execArgv: string[] = [];
|
Process.prototype.execArgv = [];
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_exit_code */
|
/** https://nodejs.org/api/process.html#process_process_exit_code */
|
||||||
exit = exit;
|
Process.prototype.exit = exit;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processabort */
|
/** https://nodejs.org/api/process.html#processabort */
|
||||||
abort = abort;
|
Process.prototype.abort = abort;
|
||||||
|
|
||||||
// Undocumented Node API that is used by `signal-exit` which in turn
|
// Undocumented Node API that is used by `signal-exit` which in turn
|
||||||
// is used by `node-tap`. It was marked for removal a couple of years
|
// is used by `node-tap`. It was marked for removal a couple of years
|
||||||
// ago. See https://github.com/nodejs/node/blob/6a6b3c54022104cc110ab09044a2a0cecb8988e7/lib/internal/bootstrap/node.js#L172
|
// ago. See https://github.com/nodejs/node/blob/6a6b3c54022104cc110ab09044a2a0cecb8988e7/lib/internal/bootstrap/node.js#L172
|
||||||
reallyExit = (code: number) => {
|
Process.prototype.reallyExit = (code: number) => {
|
||||||
return Deno.exit(code || 0);
|
return Deno.exit(code || 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
_exiting = _exiting;
|
Process.prototype._exiting = _exiting;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processexitcode_1 */
|
/** https://nodejs.org/api/process.html#processexitcode_1 */
|
||||||
get exitCode() {
|
Object.defineProperty(Process.prototype, "exitCode", {
|
||||||
|
get() {
|
||||||
return globalProcessExitCode;
|
return globalProcessExitCode;
|
||||||
}
|
},
|
||||||
|
set(code: number | undefined) {
|
||||||
set exitCode(code: number | undefined) {
|
|
||||||
globalProcessExitCode = code;
|
globalProcessExitCode = code;
|
||||||
code = parseInt(code) || 0;
|
code = parseInt(code) || 0;
|
||||||
if (!isNaN(code)) {
|
if (!isNaN(code)) {
|
||||||
op_set_exit_code(code);
|
op_set_exit_code(code);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Typed as any to avoid importing "module" module for types
|
// Typed as any to avoid importing "module" module for types
|
||||||
// deno-lint-ignore no-explicit-any
|
Process.prototype.mainModule = undefined;
|
||||||
mainModule: any = undefined;
|
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_nexttick_callback_args */
|
/** https://nodejs.org/api/process.html#process_process_nexttick_callback_args */
|
||||||
nextTick = _nextTick;
|
Process.prototype.nextTick = _nextTick;
|
||||||
|
|
||||||
dlopen = dlopen;
|
Process.prototype.dlopen = dlopen;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_events */
|
/** https://nodejs.org/api/process.html#process_process_events */
|
||||||
override on(event: "exit", listener: (code: number) => void): this;
|
Process.prototype.on = function (
|
||||||
override on(
|
|
||||||
event: typeof notImplementedEvents[number],
|
|
||||||
// deno-lint-ignore ban-types
|
|
||||||
listener: Function,
|
|
||||||
): this;
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
override on(event: string, listener: (...args: any[]) => void): this {
|
this: any,
|
||||||
|
event: string,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
listener: (...args: any[]) => void,
|
||||||
|
) {
|
||||||
if (notImplementedEvents.includes(event)) {
|
if (notImplementedEvents.includes(event)) {
|
||||||
warnNotImplemented(`process.on("${event}")`);
|
warnNotImplemented(`process.on("${event}")`);
|
||||||
super.on(event, listener);
|
EventEmitter.prototype.on.call(this, event, listener);
|
||||||
} else if (event.startsWith("SIG")) {
|
} else if (event.startsWith("SIG")) {
|
||||||
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
|
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
|
||||||
// Ignores SIGBREAK if the platform is not windows.
|
// Ignores SIGBREAK if the platform is not windows.
|
||||||
|
@ -452,23 +468,22 @@ class Process extends EventEmitter {
|
||||||
Deno.addSignalListener(event as Deno.Signal, listener);
|
Deno.addSignalListener(event as Deno.Signal, listener);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.on(event, listener);
|
EventEmitter.prototype.on.call(this, event, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
override off(event: "exit", listener: (code: number) => void): this;
|
Process.prototype.off = function (
|
||||||
override off(
|
|
||||||
event: typeof notImplementedEvents[number],
|
|
||||||
// deno-lint-ignore ban-types
|
|
||||||
listener: Function,
|
|
||||||
): this;
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
override off(event: string, listener: (...args: any[]) => void): this {
|
this: any,
|
||||||
|
event: string,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
listener: (...args: any[]) => void,
|
||||||
|
) {
|
||||||
if (notImplementedEvents.includes(event)) {
|
if (notImplementedEvents.includes(event)) {
|
||||||
warnNotImplemented(`process.off("${event}")`);
|
warnNotImplemented(`process.off("${event}")`);
|
||||||
super.off(event, listener);
|
EventEmitter.prototype.off.call(this, event, listener);
|
||||||
} else if (event.startsWith("SIG")) {
|
} else if (event.startsWith("SIG")) {
|
||||||
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
|
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
|
||||||
// Ignores SIGBREAK if the platform is not windows.
|
// Ignores SIGBREAK if the platform is not windows.
|
||||||
|
@ -478,14 +493,19 @@ class Process extends EventEmitter {
|
||||||
Deno.removeSignalListener(event as Deno.Signal, listener);
|
Deno.removeSignalListener(event as Deno.Signal, listener);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.off(event, listener);
|
EventEmitter.prototype.off.call(this, event, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Process.prototype.emit = function (
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
override emit(event: string, ...args: any[]): boolean {
|
this: any,
|
||||||
|
event: string,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
...args: any[]
|
||||||
|
): boolean {
|
||||||
if (event.startsWith("SIG")) {
|
if (event.startsWith("SIG")) {
|
||||||
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
|
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
|
||||||
// Ignores SIGBREAK if the platform is not windows.
|
// Ignores SIGBREAK if the platform is not windows.
|
||||||
|
@ -493,29 +513,22 @@ class Process extends EventEmitter {
|
||||||
Deno.kill(Deno.pid, event as Deno.Signal);
|
Deno.kill(Deno.pid, event as Deno.Signal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return super.emit(event, ...args);
|
return EventEmitter.prototype.emit.call(this, event, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
|
|
||||||
override prependListener(
|
Process.prototype.prependListener = function (
|
||||||
event: "exit",
|
// deno-lint-ignore no-explicit-any
|
||||||
listener: (code: number) => void,
|
this: any,
|
||||||
): this;
|
|
||||||
override prependListener(
|
|
||||||
event: typeof notImplementedEvents[number],
|
|
||||||
// deno-lint-ignore ban-types
|
|
||||||
listener: Function,
|
|
||||||
): this;
|
|
||||||
override prependListener(
|
|
||||||
event: string,
|
event: string,
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
listener: (...args: any[]) => void,
|
listener: (...args: any[]) => void,
|
||||||
): this {
|
) {
|
||||||
if (notImplementedEvents.includes(event)) {
|
if (notImplementedEvents.includes(event)) {
|
||||||
warnNotImplemented(`process.prependListener("${event}")`);
|
warnNotImplemented(`process.prependListener("${event}")`);
|
||||||
super.prependListener(event, listener);
|
EventEmitter.prototype.prependListener.call(this, event, listener);
|
||||||
} else if (event.startsWith("SIG")) {
|
} else if (event.startsWith("SIG")) {
|
||||||
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
|
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
|
||||||
// Ignores SIGBREAK if the platform is not windows.
|
// Ignores SIGBREAK if the platform is not windows.
|
||||||
|
@ -523,71 +536,65 @@ class Process extends EventEmitter {
|
||||||
Deno.addSignalListener(event as Deno.Signal, listener);
|
Deno.addSignalListener(event as Deno.Signal, listener);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.prependListener(event, listener);
|
EventEmitter.prototype.prependListener.call(this, event, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_pid */
|
/** https://nodejs.org/api/process.html#process_process_pid */
|
||||||
get pid() {
|
Object.defineProperty(Process.prototype, "pid", {
|
||||||
|
get() {
|
||||||
return pid;
|
return pid;
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processppid */
|
/** https://nodejs.org/api/process.html#processppid */
|
||||||
get ppid() {
|
Object.defineProperty(Process.prototype, "ppid", {
|
||||||
|
get() {
|
||||||
return Deno.ppid;
|
return Deno.ppid;
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_platform */
|
/** https://nodejs.org/api/process.html#process_process_platform */
|
||||||
get platform() {
|
Object.defineProperty(Process.prototype, "platform", {
|
||||||
|
get() {
|
||||||
return platform;
|
return platform;
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// https://nodejs.org/api/process.html#processsetsourcemapsenabledval
|
// https://nodejs.org/api/process.html#processsetsourcemapsenabledval
|
||||||
setSourceMapsEnabled(_val: boolean) {
|
Process.prototype.setSourceMapsEnabled = (_val: boolean) => {
|
||||||
// This is a no-op in Deno. Source maps are always enabled.
|
// This is a no-op in Deno. Source maps are always enabled.
|
||||||
// TODO(@satyarohith): support disabling source maps if needed.
|
// TODO(@satyarohith): support disabling source maps if needed.
|
||||||
}
|
};
|
||||||
|
|
||||||
override addListener(event: "exit", listener: (code: number) => void): this;
|
Process.prototype.addListener = function (
|
||||||
override addListener(
|
// deno-lint-ignore no-explicit-any
|
||||||
event: typeof notImplementedEvents[number],
|
this: any,
|
||||||
// deno-lint-ignore ban-types
|
|
||||||
listener: Function,
|
|
||||||
): this;
|
|
||||||
override addListener(
|
|
||||||
event: string,
|
event: string,
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
listener: (...args: any[]) => void,
|
listener: (...args: any[]) => void,
|
||||||
): this {
|
) {
|
||||||
if (notImplementedEvents.includes(event)) {
|
if (notImplementedEvents.includes(event)) {
|
||||||
warnNotImplemented(`process.addListener("${event}")`);
|
warnNotImplemented(`process.addListener("${event}")`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.on(event, listener);
|
return this.on(event, listener);
|
||||||
}
|
};
|
||||||
|
|
||||||
override removeListener(
|
Process.prototype.removeListener = function (
|
||||||
event: "exit",
|
|
||||||
listener: (code: number) => void,
|
|
||||||
): this;
|
|
||||||
override removeListener(
|
|
||||||
event: typeof notImplementedEvents[number],
|
|
||||||
// deno-lint-ignore ban-types
|
|
||||||
listener: Function,
|
|
||||||
): this;
|
|
||||||
override removeListener(
|
|
||||||
event: string,
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
|
this: any,
|
||||||
|
event: string, // deno-lint-ignore no-explicit-any
|
||||||
listener: (...args: any[]) => void,
|
listener: (...args: any[]) => void,
|
||||||
): this {
|
) {
|
||||||
if (notImplementedEvents.includes(event)) {
|
if (notImplementedEvents.includes(event)) {
|
||||||
warnNotImplemented(`process.removeListener("${event}")`);
|
warnNotImplemented(`process.removeListener("${event}")`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.off(event, listener);
|
return this.off(event, listener);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current high-resolution real time in a [seconds, nanoseconds]
|
* Returns the current high-resolution real time in a [seconds, nanoseconds]
|
||||||
|
@ -602,92 +609,94 @@ class Process extends EventEmitter {
|
||||||
* These times are relative to an arbitrary time in the past, and not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals.
|
* These times are relative to an arbitrary time in the past, and not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals.
|
||||||
* https://nodejs.org/api/process.html#process_process_hrtime_time
|
* https://nodejs.org/api/process.html#process_process_hrtime_time
|
||||||
*/
|
*/
|
||||||
hrtime = hrtime;
|
Process.prototype.hrtime = hrtime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*
|
*
|
||||||
* NodeJS internal, use process.kill instead
|
* NodeJS internal, use process.kill instead
|
||||||
*/
|
*/
|
||||||
_kill = _kill;
|
Process.prototype._kill = _kill;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processkillpid-signal */
|
/** https://nodejs.org/api/process.html#processkillpid-signal */
|
||||||
kill = kill;
|
Process.prototype.kill = kill;
|
||||||
|
|
||||||
memoryUsage = memoryUsage;
|
Process.prototype.memoryUsage = memoryUsage;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_stderr */
|
/** https://nodejs.org/api/process.html#process_process_stderr */
|
||||||
stderr = stderr;
|
Process.prototype.stderr = stderr;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_stdin */
|
/** https://nodejs.org/api/process.html#process_process_stdin */
|
||||||
stdin = stdin;
|
Process.prototype.stdin = stdin;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_stdout */
|
/** https://nodejs.org/api/process.html#process_process_stdout */
|
||||||
stdout = stdout;
|
Process.prototype.stdout = stdout;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_version */
|
/** https://nodejs.org/api/process.html#process_process_version */
|
||||||
version = version;
|
Process.prototype.version = version;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_versions */
|
/** https://nodejs.org/api/process.html#process_process_versions */
|
||||||
versions = versions;
|
Process.prototype.versions = versions;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process_emitwarning_warning_options */
|
/** https://nodejs.org/api/process.html#process_process_emitwarning_warning_options */
|
||||||
emitWarning = emitWarning;
|
Process.prototype.emitWarning = emitWarning;
|
||||||
|
|
||||||
binding(name: BindingName) {
|
Process.prototype.binding = (name: BindingName) => {
|
||||||
return getBinding(name);
|
return getBinding(name);
|
||||||
}
|
};
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processumaskmask */
|
/** https://nodejs.org/api/process.html#processumaskmask */
|
||||||
umask() {
|
Process.prototype.umask = () => {
|
||||||
// Always return the system default umask value.
|
// Always return the system default umask value.
|
||||||
// We don't use Deno.umask here because it has a race
|
// We don't use Deno.umask here because it has a race
|
||||||
// condition bug.
|
// condition bug.
|
||||||
// See https://github.com/denoland/deno_std/issues/1893#issuecomment-1032897779
|
// See https://github.com/denoland/deno_std/issues/1893#issuecomment-1032897779
|
||||||
return 0o22;
|
return 0o22;
|
||||||
}
|
};
|
||||||
|
|
||||||
/** This method is removed on Windows */
|
/** This method is removed on Windows */
|
||||||
getgid = getgid;
|
Process.prototype.getgid = getgid;
|
||||||
|
|
||||||
/** This method is removed on Windows */
|
/** This method is removed on Windows */
|
||||||
getuid = getuid;
|
Process.prototype.getuid = getuid;
|
||||||
|
|
||||||
/** This method is removed on Windows */
|
/** This method is removed on Windows */
|
||||||
geteuid = geteuid;
|
Process.prototype.geteuid = geteuid;
|
||||||
|
|
||||||
// TODO(kt3k): Implement this when we added -e option to node compat mode
|
// TODO(kt3k): Implement this when we added -e option to node compat mode
|
||||||
_eval: string | undefined = undefined;
|
Process.prototype._eval = undefined;
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processexecpath */
|
/** https://nodejs.org/api/process.html#processexecpath */
|
||||||
get execPath() {
|
|
||||||
|
Object.defineProperty(Process.prototype, "execPath", {
|
||||||
|
get() {
|
||||||
if (execPath) {
|
if (execPath) {
|
||||||
return execPath;
|
return execPath;
|
||||||
}
|
}
|
||||||
execPath = Deno.execPath();
|
execPath = Deno.execPath();
|
||||||
return execPath;
|
return execPath;
|
||||||
}
|
},
|
||||||
|
set(path: string) {
|
||||||
set execPath(path: string) {
|
|
||||||
execPath = path;
|
execPath = path;
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#processuptime */
|
/** https://nodejs.org/api/process.html#processuptime */
|
||||||
uptime() {
|
Process.prototype.uptime = () => {
|
||||||
return Number((performance.now() / 1000).toFixed(9));
|
return Number((performance.now() / 1000).toFixed(9));
|
||||||
}
|
};
|
||||||
|
|
||||||
#allowedFlags = buildAllowedFlags();
|
|
||||||
/** https://nodejs.org/api/process.html#processallowednodeenvironmentflags */
|
/** https://nodejs.org/api/process.html#processallowednodeenvironmentflags */
|
||||||
get allowedNodeEnvironmentFlags() {
|
Object.defineProperty(Process.prototype, "allowedNodeEnvironmentFlags", {
|
||||||
return this.#allowedFlags;
|
get() {
|
||||||
}
|
return ALLOWED_FLAGS;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
features = { inspector: false };
|
Process.prototype.features = { inspector: false };
|
||||||
|
|
||||||
// TODO(kt3k): Get the value from --no-deprecation flag.
|
// TODO(kt3k): Get the value from --no-deprecation flag.
|
||||||
noDeprecation = false;
|
Process.prototype.noDeprecation = false;
|
||||||
}
|
|
||||||
|
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
delete Process.prototype.getgid;
|
delete Process.prototype.getgid;
|
||||||
|
@ -696,6 +705,7 @@ if (isWindows) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** https://nodejs.org/api/process.html#process_process */
|
/** https://nodejs.org/api/process.html#process_process */
|
||||||
|
// @ts-ignore TS doesn't work well with ES5 classes
|
||||||
const process = new Process();
|
const process = new Process();
|
||||||
|
|
||||||
Object.defineProperty(process, Symbol.toStringTag, {
|
Object.defineProperty(process, Symbol.toStringTag, {
|
||||||
|
|
|
@ -1094,3 +1094,12 @@ Deno.test({
|
||||||
assert(v >= 0);
|
assert(v >= 0);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test for https://github.com/denoland/deno/issues/23863
|
||||||
|
Deno.test({
|
||||||
|
name: "instantiate process constructor without 'new' keyword",
|
||||||
|
fn() {
|
||||||
|
// This would throw
|
||||||
|
process.constructor.call({});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue