summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/process.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/process.ts')
-rw-r--r--ext/node/polyfills/process.ts45
1 files changed, 31 insertions, 14 deletions
diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts
index 9e7c29be7..828b4c660 100644
--- a/ext/node/polyfills/process.ts
+++ b/ext/node/polyfills/process.ts
@@ -2,6 +2,7 @@
// Copyright Joyent, Inc. and Node.js contributors. All rights reserved. MIT license.
const internals = globalThis.__bootstrap.internals;
+import { core } from "internal:deno_node/polyfills/_core.ts";
import {
notImplemented,
warnNotImplemented,
@@ -32,8 +33,11 @@ import {
stdin as stdin_,
stdout as stdout_,
} from "internal:deno_node/polyfills/_process/streams.mjs";
-import { core } from "internal:deno_node/polyfills/_core.ts";
-import { processTicksAndRejections } from "internal:deno_node/polyfills/_next_tick.ts";
+import {
+ processTicksAndRejections,
+ runNextTicks,
+} from "internal:deno_node/polyfills/_next_tick.ts";
+import { isWindows } from "internal:deno_node/polyfills/_util/os.ts";
// TODO(kt3k): This should be set at start up time
export let arch = "";
@@ -71,10 +75,19 @@ const notImplementedEvents = [
"worker",
];
-export const argv = [];
+export const argv: string[] = [];
// Overwrites the 1st item with getter.
-Object.defineProperty(argv, "0", { get: Deno.execPath });
+// TODO(bartlomieju): added "configurable: true" to make this work for binary
+// commands, but that is probably a wrong solution
+// TODO(bartlomieju): move the configuration for all "argv" to
+// "internals.__bootstrapNodeProcess"
+Object.defineProperty(argv, "0", {
+ get: () => {
+ return Deno.execPath();
+ },
+ configurable: true,
+});
// Overwrites the 2st item with getter.
Object.defineProperty(argv, "1", {
get: () => {
@@ -86,13 +99,6 @@ Object.defineProperty(argv, "1", {
},
});
-// TODO(kt3k): Set the rest of args at start up time instead of defining
-// random number of getters.
-for (let i = 0; i < 30; i++) {
- const j = i;
- Object.defineProperty(argv, j + 2, { get: () => Deno.args[j] });
-}
-
/** https://nodejs.org/api/process.html#process_process_exit_code */
export const exit = (code?: number | string) => {
if (code || code === 0) {
@@ -681,9 +687,18 @@ addReadOnlyProcessAlias("throwDeprecation", "--throw-deprecation");
export const removeListener = process.removeListener;
export const removeAllListeners = process.removeAllListeners;
-// FIXME(bartlomieju): currently it's not called
-// only call this from runtime's main.js
-internals.__bootstrapNodeProcess = function () {
+// Should be called only once, in `runtime/js/99_main.js` when the runtime is
+// bootstrapped.
+internals.__bootstrapNodeProcess = function (args: string[]) {
+ for (let i = 0; i < args.length; i++) {
+ argv[i + 2] = args[i];
+ }
+
+ core.setNextTickCallback(processTicksAndRejections);
+ core.setMacrotaskCallback(runNextTicks);
+
+ // TODO(bartlomieju): this is buggy, see https://github.com/denoland/deno/issues/16928
+ // We should use a specialized API in 99_main.js instead
globalThis.addEventListener("unhandledrejection", (event) => {
if (process.listenerCount("unhandledRejection") === 0) {
// The Node.js default behavior is to raise an uncaught exception if
@@ -724,6 +739,8 @@ internals.__bootstrapNodeProcess = function () {
process.emit("exit", process.exitCode || 0);
}
});
+
+ delete internals.__bootstrapNodeProcess;
};
export default process;