From 210ae2ffb2ef960d795fd785b69ea11379590e4f Mon Sep 17 00:00:00 2001 From: zhiyuan <32867472+zhiyuang@users.noreply.github.com> Date: Thu, 20 Oct 2022 16:40:58 +0800 Subject: Fix Bun.serve error handler error param (#1359) --- src/bun.js/bindings/bindings.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/bun.js/bindings/bindings.cpp') diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 0cba2185d..d0de85849 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -2556,6 +2556,20 @@ void JSC__JSValue__getNameProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* a arg2->len = 0; } +JSC__JSValue JSC__JSValue__toError(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1) +{ + JSC::JSValue value = JSC::JSValue::decode(JSValue0); + if (JSC::Exception* jscException = JSC::jsDynamicCast(value)) { + if (JSC::ErrorInstance* error = JSC::jsDynamicCast(jscException->value())) { + return JSC::JSValue::encode(JSC::JSValue(error)); + } + } + if (JSC::ErrorInstance* error = JSC::jsDynamicCast(value)) { + return JSC::JSValue::encode(JSC::JSValue(error)); + } + return JSC::JSValue::encode(JSC::jsUndefined()); +} + void JSC__JSValue__toZigException(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigException* exception) { -- cgit v1.2.3