diff options
author | 2023-09-21 05:48:40 -0700 | |
---|---|---|
committer | 2023-09-21 05:48:40 -0700 | |
commit | e1cf08b3a6fb33f0c90837178fc36caeacb346e5 (patch) | |
tree | b7c5a6a83d37799b0c24af737dc2d19cc9d8cba3 /src/bun.js/bindings/bindings.cpp | |
parent | 28f345346650dc94330b4a2cdcd1297df2916a39 (diff) | |
download | bun-e1cf08b3a6fb33f0c90837178fc36caeacb346e5.tar.gz bun-e1cf08b3a6fb33f0c90837178fc36caeacb346e5.tar.zst bun-e1cf08b3a6fb33f0c90837178fc36caeacb346e5.zip |
Fixes #5859jarred/5859
Diffstat (limited to 'src/bun.js/bindings/bindings.cpp')
-rw-r--r-- | src/bun.js/bindings/bindings.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
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, |