[bun.js] Implement process.exit (no callbacks yet)

This commit is contained in:
Jarred Sumner
2022-02-24 19:17:21 -08:00
parent 08c4f8b103
commit 0b7897f26c
2 changed files with 29 additions and 0 deletions

View File

@@ -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)));

View File

@@ -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,
});
}
}
};