diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/javascript/jsc/bindings/Process.cpp | 24 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/exports.zig | 5 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/javascript/jsc/bindings/Process.cpp b/src/javascript/jsc/bindings/Process.cpp index a6de63f8c..c61bd5db7 100644 --- a/src/javascript/jsc/bindings/Process.cpp +++ b/src/javascript/jsc/bindings/Process.cpp @@ -103,6 +103,20 @@ static JSC_DEFINE_HOST_FUNCTION(Process_functionNextTick, return JSC::JSValue::encode(JSC::jsUndefined()); } +static JSC_DECLARE_HOST_FUNCTION(Process_functionExit); +static JSC_DEFINE_HOST_FUNCTION(Process_functionExit, + (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) +{ + if (callFrame->argumentCount() == 0) { + // TODO: exitCode + Bun__Process__exit(globalObject, 0); + } else { + Bun__Process__exit(globalObject, callFrame->argument(0).toInt32(globalObject)); + } + + return JSC::JSValue::encode(JSC::jsUndefined()); +} + static JSC_DECLARE_HOST_FUNCTION(Process_functionChdir); static JSC_DEFINE_HOST_FUNCTION(Process_functionChdir, @@ -123,6 +137,8 @@ static JSC_DEFINE_HOST_FUNCTION(Process_functionChdir, return JSValue::encode(JSC::jsUndefined()); } + scope.release(); + return JSC::JSValue::encode(result); } @@ -162,6 +178,11 @@ void Process::finishCreation(JSC::VM& vm) WTF::String("chdir"), Process_functionChdir), 0); + this->putDirect(vm, JSC::Identifier::fromString(vm, "exit"_s), + JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 0, + WTF::String("exit"), Process_functionExit), + 0); + putDirectCustomAccessor( vm, clientData->builtinNames().versionsPublicName(), JSC::CustomGetterSetter::create(vm, Process_getVersionsLazy, Process_setVersionsLazy), 0); @@ -169,6 +190,9 @@ void Process::finishCreation(JSC::VM& vm) this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "browser"), JSC::JSValue(false)); + this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "exitCode"), + JSC::JSValue(JSC::jsNumber(0))); + this->putDirect(this->vm(), clientData->builtinNames().versionPublicName(), JSC::jsString(this->vm(), WTF::String(Bun__version))); diff --git a/src/javascript/jsc/bindings/exports.zig b/src/javascript/jsc/bindings/exports.zig index c18482641..c7e98077c 100644 --- a/src/javascript/jsc/bindings/exports.zig +++ b/src/javascript/jsc/bindings/exports.zig @@ -344,6 +344,7 @@ pub const Process = extern struct { pub const getArgv = JSC.Node.Process.getArgv; pub const getCwd = JSC.Node.Process.getCwd; pub const setCwd = JSC.Node.Process.setCwd; + pub const exit = JSC.Node.Process.exit; pub const Export = shim.exportFunctions(.{ .@"getTitle" = getTitle, @@ -351,6 +352,7 @@ pub const Process = extern struct { .@"getArgv" = getArgv, .@"getCwd" = getCwd, .@"setCwd" = setCwd, + .@"exit" = exit, }); comptime { @@ -370,6 +372,9 @@ pub const Process = extern struct { @export(setCwd, .{ .name = Export[4].symbol_name, }); + @export(exit, .{ + .name = Export[5].symbol_name, + }); } } }; |