diff options
author | 2022-02-24 19:17:21 -0800 | |
---|---|---|
committer | 2022-02-24 19:17:21 -0800 | |
commit | 0b7897f26c35078cc3333ee03ceab9523da93f28 (patch) | |
tree | 0460944f0612c6a52eb04e4db0a1fe86b6001899 /src/javascript/jsc/bindings/Process.cpp | |
parent | 08c4f8b10387731979fa1cc67b593152f130f18c (diff) | |
download | bun-0b7897f26c35078cc3333ee03ceab9523da93f28.tar.gz bun-0b7897f26c35078cc3333ee03ceab9523da93f28.tar.zst bun-0b7897f26c35078cc3333ee03ceab9523da93f28.zip |
[bun.js] Implement `process.exit` (no callbacks yet)
Diffstat (limited to 'src/javascript/jsc/bindings/Process.cpp')
-rw-r--r-- | src/javascript/jsc/bindings/Process.cpp | 24 |
1 files changed, 24 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))); |