diff options
| -rw-r--r-- | packages/bun-types/globals.d.ts | 5 | ||||
| -rw-r--r-- | src/bun.js/bindings/Process.cpp | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts index c99dcd129..9802da101 100644 --- a/packages/bun-types/globals.d.ts +++ b/packages/bun-types/globals.d.ts @@ -354,6 +354,11 @@ interface Process { stdin: import("stream").Duplex & { isTTY: boolean }; stdout: import("stream").Writable & { isTTY: boolean }; stderr: import("stream").Writable & { isTTY: boolean }; + + /** + * exit the process with a fatal exception, sending SIGABRT + */ + abort(): never; } declare var process: Process; diff --git a/src/bun.js/bindings/Process.cpp b/src/bun.js/bindings/Process.cpp index 4371eb8df..a72990ed8 100644 --- a/src/bun.js/bindings/Process.cpp +++ b/src/bun.js/bindings/Process.cpp @@ -489,6 +489,12 @@ Process::~Process() } } +JSC_DEFINE_HOST_FUNCTION(Process_functionAbort, (JSGlobalObject * globalObject, CallFrame*)) +{ + abort(); + __builtin_unreachable(); +} + void Process::finishCreation(JSC::VM& vm) { Base::finishCreation(vm); @@ -598,6 +604,9 @@ void Process::finishCreation(JSC::VM& vm) this->putDirectCustomAccessor(vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "stdin"_s)), JSC::CustomGetterSetter::create(vm, Process_lazyStdinGetter, Process_defaultSetter), 0); + + this->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(this->vm(), "abort"_s), + 0, Process_functionAbort, ImplementationVisibility::Public, NoIntrinsic, 0); } const JSC::ClassInfo Process::s_info = { "Process"_s, &Base::s_info, nullptr, nullptr, |
