From e1cf08b3a6fb33f0c90837178fc36caeacb346e5 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 21 Sep 2023 05:48:40 -0700 Subject: Fixes #5859 --- src/bun.js/bindings/bindings.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (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 47ef36aea..bff5640ef 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -1396,15 +1396,22 @@ BunString WebCore__DOMURL__fileSystemPath(WebCore__DOMURL* arg0) extern "C" JSC__JSValue ZigString__toJSONObject(const ZigString* strPtr, JSC::JSGlobalObject* globalObject) { auto str = Zig::toString(*strPtr); - auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); - auto scope = DECLARE_CATCH_SCOPE(globalObject->vm()); - JSValue result = JSONParseWithException(globalObject, str); - if (auto* exception = scope.exception()) { + auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); + + // JSONParseWithException does not propagate exceptions as expected. See #5859 + JSValue result = JSONParse(globalObject, str); + + if (!result && !scope.exception()) { + scope.throwException(globalObject, createSyntaxError(globalObject, "Failed to parse JSON"_s)); + } + + if (scope.exception()) { + auto* exception = scope.exception(); scope.clearException(); - RELEASE_AND_RETURN(throwScope, JSC::JSValue::encode(exception->value())); + return JSC::JSValue::encode(exception); } - RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); + return JSValue::encode(result); } JSC__JSValue SystemError__toErrorInstance(const SystemError* arg0, -- cgit v1.2.3