From 4071624eddfd253af566fd44c09fc78617458135 Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Sun, 25 Jan 2026 10:38:13 -0800 Subject: [PATCH] Update WebKit (#26381) ### What does this PR do? Updates WebKit to https://github.com/oven-sh/WebKit/commit/5b6a0ac49b6f0f505b7165850f1318a622652123 ### How did you verify your code works? --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner Co-authored-by: Claude Bot Co-authored-by: Claude Opus 4.5 --- cmake/targets/BuildBun.cmake | 4 +- cmake/tools/SetupWebKit.cmake | 2 +- misctools/cold-jsc-start.cpp | 2 +- src/bun.js/AsyncModule.zig | 2 +- src/bun.js/VirtualMachine.zig | 2 +- src/bun.js/api/JSBundler.zig | 2 +- src/bun.js/api/html_rewriter.zig | 4 +- src/bun.js/bindings/AnyPromise.zig | 2 +- src/bun.js/bindings/BunDebugger.cpp | 2 +- src/bun.js/bindings/BunObject.cpp | 6 +- src/bun.js/bindings/BunPlugin.cpp | 10 +-- src/bun.js/bindings/BunProcess.cpp | 12 +-- .../BunProcessReportObjectWindows.cpp | 2 +- src/bun.js/bindings/CallSite.cpp | 6 +- src/bun.js/bindings/CatchScopeBinding.cpp | 77 ------------------- src/bun.js/bindings/ErrorCode.cpp | 4 +- src/bun.js/bindings/ErrorStackTrace.cpp | 16 ++-- src/bun.js/bindings/FormatStackTraceForJS.cpp | 6 +- src/bun.js/bindings/JSBuffer.cpp | 2 +- src/bun.js/bindings/JSBundlerPlugin.cpp | 6 +- .../bindings/JSDOMExceptionHandling.cpp | 14 ++-- src/bun.js/bindings/JSDOMExceptionHandling.h | 6 +- src/bun.js/bindings/JSGlobalObject.zig | 2 +- src/bun.js/bindings/JSMockFunction.cpp | 8 +- src/bun.js/bindings/JSObject.zig | 2 +- src/bun.js/bindings/JSPromise.zig | 2 +- src/bun.js/bindings/JSPropertyIterator.zig | 4 +- src/bun.js/bindings/JSValue.zig | 14 ++-- src/bun.js/bindings/MimallocWTFMalloc.h | 12 +-- src/bun.js/bindings/NodeTimerObject.cpp | 2 +- src/bun.js/bindings/NodeVMModule.cpp | 2 +- src/bun.js/bindings/S3Error.cpp | 2 +- src/bun.js/bindings/StringBuilder.zig | 2 +- .../{CatchScope.zig => TopExceptionScope.zig} | 62 +++++++-------- .../bindings/TopExceptionScopeBinding.cpp | 77 +++++++++++++++++++ src/bun.js/bindings/ZigException.cpp | 6 +- src/bun.js/bindings/ZigGlobalObject.cpp | 22 +++--- src/bun.js/bindings/ZigGlobalObject.h | 2 +- src/bun.js/bindings/bindings.cpp | 38 ++++----- src/bun.js/bindings/headers-cpp.h | 14 ++-- src/bun.js/bindings/headers-handwritten.h | 4 +- src/bun.js/bindings/napi.cpp | 4 +- .../bindings/node/JSNodeHTTPServerSocket.cpp | 4 +- .../bindings/node/http/NodeHTTPParser.cpp | 10 +-- src/bun.js/bindings/sqlite/JSSQLStatement.cpp | 6 +- src/bun.js/bindings/v8/V8Object.cpp | 8 +- .../bindings/webcore/BroadcastChannel.cpp | 2 +- .../webcore/InternalWritableStream.cpp | 6 +- .../bindings/webcore/JSCallbackData.cpp | 2 +- src/bun.js/bindings/webcore/JSDOMPromise.cpp | 2 +- .../bindings/webcore/JSDOMPromiseDeferred.cpp | 16 ++-- .../bindings/webcore/JSDOMPromiseDeferred.h | 32 ++++---- .../bindings/webcore/JSEventEmitterCustom.cpp | 2 +- .../bindings/webcore/JSEventListener.cpp | 2 +- src/bun.js/bindings/webcore/MessageEvent.cpp | 4 +- src/bun.js/bindings/webcore/MessagePort.cpp | 2 +- .../bindings/webcore/ReadableStream.cpp | 8 +- .../ReadableStreamDefaultController.cpp | 8 +- .../webcore/SerializedScriptValue.cpp | 6 +- src/bun.js/bindings/webcore/WebSocket.cpp | 2 +- src/bun.js/event_loop.zig | 2 +- src/bun.js/jsc.zig | 4 +- src/bun.js/jsc/host_fn.zig | 4 +- src/bun.js/modules/BunTestModule.h | 10 +-- src/bun.js/modules/NodeModuleModule.cpp | 10 +-- src/bun.js/modules/NodeProcessModule.h | 6 +- src/bun.js/modules/NodeTTYModule.cpp | 2 +- src/bun.js/modules/NodeUtilTypesModule.cpp | 2 +- src/bun.js/modules/ObjectModule.cpp | 2 +- src/codegen/cppbind.ts | 2 +- src/codegen/generate-classes.ts | 2 +- 71 files changed, 320 insertions(+), 318 deletions(-) delete mode 100644 src/bun.js/bindings/CatchScopeBinding.cpp rename src/bun.js/bindings/{CatchScope.zig => TopExceptionScope.zig} (75%) create mode 100644 src/bun.js/bindings/TopExceptionScopeBinding.cpp diff --git a/cmake/targets/BuildBun.cmake b/cmake/targets/BuildBun.cmake index 26d798370f..64536cc26b 100644 --- a/cmake/targets/BuildBun.cmake +++ b/cmake/targets/BuildBun.cmake @@ -939,7 +939,7 @@ if(WIN32) endif() if(USE_MIMALLOC_AS_DEFAULT_ALLOCATOR) - target_compile_definitions(${bun} PRIVATE USE_MIMALLOC=1) + target_compile_definitions(${bun} PRIVATE USE_BUN_MIMALLOC=1) endif() target_compile_definitions(${bun} PRIVATE @@ -1253,6 +1253,7 @@ if(WIN32) target_link_libraries(${bun} PRIVATE ${WEBKIT_LIB_PATH}/WTF.lib ${WEBKIT_LIB_PATH}/JavaScriptCore.lib + ${WEBKIT_LIB_PATH}/bmalloc.lib ${WEBKIT_LIB_PATH}/sicudtd.lib ${WEBKIT_LIB_PATH}/sicuind.lib ${WEBKIT_LIB_PATH}/sicuucd.lib @@ -1261,6 +1262,7 @@ if(WIN32) target_link_libraries(${bun} PRIVATE ${WEBKIT_LIB_PATH}/WTF.lib ${WEBKIT_LIB_PATH}/JavaScriptCore.lib + ${WEBKIT_LIB_PATH}/bmalloc.lib ${WEBKIT_LIB_PATH}/sicudt.lib ${WEBKIT_LIB_PATH}/sicuin.lib ${WEBKIT_LIB_PATH}/sicuuc.lib diff --git a/cmake/tools/SetupWebKit.cmake b/cmake/tools/SetupWebKit.cmake index f276a0991a..a05db817b3 100644 --- a/cmake/tools/SetupWebKit.cmake +++ b/cmake/tools/SetupWebKit.cmake @@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use") option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading") if(NOT WEBKIT_VERSION) - set(WEBKIT_VERSION daf95b4b4574799ff22c8c4effd0dc6e864968a5) + set(WEBKIT_VERSION f151e5c43c3546da23c5c1e709452da25d47e168) endif() # Use preview build URL for Windows ARM64 until the fix is merged to main diff --git a/misctools/cold-jsc-start.cpp b/misctools/cold-jsc-start.cpp index 15f9789cbf..01575549ac 100644 --- a/misctools/cold-jsc-start.cpp +++ b/misctools/cold-jsc-start.cpp @@ -35,7 +35,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionWrite, (JSC::JSGlobalObject * globalObject, JSValue arg1 = callframe->argument(0); JSValue toWriteArg = callframe->argument(1); auto &vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); int32_t fd = STDOUT_FILENO; if (callframe->argumentCount() > 1) { diff --git a/src/bun.js/AsyncModule.zig b/src/bun.js/AsyncModule.zig index 054a9d0c4e..bce85737f6 100644 --- a/src/bun.js/AsyncModule.zig +++ b/src/bun.js/AsyncModule.zig @@ -417,7 +417,7 @@ pub const AsyncModule = struct { jsc.markBinding(@src()); var specifier = specifier_; var referrer = referrer_; - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(globalThis, @src()); defer { specifier.deref(); diff --git a/src/bun.js/VirtualMachine.zig b/src/bun.js/VirtualMachine.zig index 86ee29b136..8d70f6db23 100644 --- a/src/bun.js/VirtualMachine.zig +++ b/src/bun.js/VirtualMachine.zig @@ -543,7 +543,7 @@ fn wrapUnhandledRejectionErrorForUncaughtException(globalObject: *JSGlobalObject break :blk false; }) return reason; const reasonStr = blk: { - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(globalObject, @src()); defer scope.deinit(); defer if (scope.exception()) |_| scope.clearException(); diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index 3338c97c18..633139a074 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -1461,7 +1461,7 @@ pub const JSBundler = struct { error.JSTerminated => return error.JSTerminated, }; - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(globalThis, @src()); defer scope.deinit(); diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig index 8d168ceb6e..cae69291df 100644 --- a/src/bun.js/api/html_rewriter.zig +++ b/src/bun.js/api/html_rewriter.zig @@ -910,8 +910,8 @@ fn HandlerCallback( wrapper.deref(); } - // Use a CatchScope to properly handle exceptions from the JavaScript callback - var scope: bun.jsc.CatchScope = undefined; + // Use a TopExceptionScope to properly handle exceptions from the JavaScript callback + var scope: bun.jsc.TopExceptionScope = undefined; scope.init(this.global, @src()); defer scope.deinit(); diff --git a/src/bun.js/bindings/AnyPromise.zig b/src/bun.js/bindings/AnyPromise.zig index 9475b69cce..e5cd6430b2 100644 --- a/src/bun.js/bindings/AnyPromise.zig +++ b/src/bun.js/bindings/AnyPromise.zig @@ -73,7 +73,7 @@ pub const AnyPromise = union(enum) { } }; - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(globalObject, @src()); defer scope.deinit(); var ctx = Wrapper{ .args = args }; diff --git a/src/bun.js/bindings/BunDebugger.cpp b/src/bun.js/bindings/BunDebugger.cpp index f3fe73a76b..c0db82afce 100644 --- a/src/bun.js/bindings/BunDebugger.cpp +++ b/src/bun.js/bindings/BunDebugger.cpp @@ -578,7 +578,7 @@ extern "C" void Bun__startJSDebuggerThread(Zig::GlobalObject* debuggerGlobalObje debuggerScriptExecutionContext = debuggerGlobalObject->scriptExecutionContext(); JSC::VM& vm = debuggerGlobalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue defaultValue = debuggerGlobalObject->internalModuleRegistry()->requireId(debuggerGlobalObject, vm, InternalModuleRegistry::Field::InternalDebugger); scope.assertNoException(); JSFunction* debuggerDefaultFn = jsCast(defaultValue.asCell()); diff --git a/src/bun.js/bindings/BunObject.cpp b/src/bun.js/bindings/BunObject.cpp index 560fb14be4..c6d1dc56ea 100644 --- a/src/bun.js/bindings/BunObject.cpp +++ b/src/bun.js/bindings/BunObject.cpp @@ -1145,13 +1145,13 @@ static void exportBunObject(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC: for (const auto& propertyName : propertyNames) { exportNames.append(propertyName); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); // Yes, we have to call getters :( JSValue value = object->get(globalObject, propertyName); - if (catchScope.exception()) { - (void)catchScope.tryClearException(); + if (topExceptionScope.exception()) { + (void)topExceptionScope.tryClearException(); value = jsUndefined(); } exportValues.append(value); diff --git a/src/bun.js/bindings/BunPlugin.cpp b/src/bun.js/bindings/BunPlugin.cpp index 1ed7bcb428..c14c8bf33c 100644 --- a/src/bun.js/bindings/BunPlugin.cpp +++ b/src/bun.js/bindings/BunPlugin.cpp @@ -7,7 +7,7 @@ #include "helpers.h" #include "ZigGlobalObject.h" -#include +#include #include #include #include @@ -543,10 +543,10 @@ extern "C" JSC_DEFINE_HOST_FUNCTION(JSMock__jsModuleMock, (JSC::JSGlobalObject * if (url.isValid() && url.protocolIsFile()) { auto fromString = url.fileSystemPath(); BunString from = Bun::toString(fromString); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto result = JSValue::decode(Bun__resolveSyncWithSource(globalObject, JSValue::encode(specifierString), &from, true, false)); - if (catchScope.exception()) { - (void)catchScope.tryClearException(); + if (topExceptionScope.exception()) { + (void)topExceptionScope.tryClearException(); } if (result && result.isString()) { @@ -646,7 +646,7 @@ extern "C" JSC_DEFINE_HOST_FUNCTION(JSMock__jsModuleMock, (JSC::JSGlobalObject * for (auto& name : names) { // consistent with regular esm handling code - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue value = object->get(globalObject, name); if (scope.exception()) [[unlikely]] { (void)scope.tryClearException(); diff --git a/src/bun.js/bindings/BunProcess.cpp b/src/bun.js/bindings/BunProcess.cpp index 2c4dc2f2a2..b09a220fa3 100644 --- a/src/bun.js/bindings/BunProcess.cpp +++ b/src/bun.js/bindings/BunProcess.cpp @@ -15,7 +15,7 @@ #include "ErrorCode+List.h" #include "JavaScriptCore/ArgList.h" #include "JavaScriptCore/CallData.h" -#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/TopExceptionScope.h" #include "JavaScriptCore/JSCJSValue.h" #include "JavaScriptCore/JSCast.h" #include "JavaScriptCore/JSMap.h" @@ -1190,7 +1190,7 @@ extern "C" int Bun__handleUncaughtException(JSC::JSGlobalObject* lexicalGlobalOb // if there is an uncaughtExceptionCaptureCallback, call it and consider the exception handled auto capture = process->getUncaughtExceptionCaptureCallback(); if (!capture.isEmpty() && !capture.isUndefinedOrNull()) { - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); (void)call(lexicalGlobalObject, capture, args, "uncaughtExceptionCaptureCallback"_s); if (auto ex = scope.exception()) { (void)scope.tryClearException(); @@ -1254,7 +1254,7 @@ extern "C" JSC::EncodedJSValue Bun__noSideEffectsToString(JSC::VM& vm, JSC::JSGl extern "C" void Bun__promises__emitUnhandledRejectionWarning(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue reason, JSC::EncodedJSValue promise) { auto& vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto warning = JSC::createError(globalObject, "Unhandled promise rejection. This error originated either by " "throwing inside of an async function without a catch block, " "or by rejecting a promise which was not handled with .catch(). " @@ -1306,7 +1306,7 @@ extern "C" bool Bun__VM__allowRejectionHandledWarning(void* vm); extern "C" bool Bun__emitHandledPromiseEvent(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSValue promise) { - auto scope = DECLARE_CATCH_SCOPE(JSC::getVM(lexicalGlobalObject)); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(JSC::getVM(lexicalGlobalObject)); if (!lexicalGlobalObject->inherits(Zig::GlobalObject::info())) return false; auto* globalObject = jsCast(lexicalGlobalObject); @@ -2330,7 +2330,7 @@ extern "C" void Bun__ForceFileSinkToBeSynchronousForProcessObjectStdio(JSC::JSGl static JSValue constructStdioWriteStream(JSC::JSGlobalObject* globalObject, JSC::JSObject* processObject, int fd) { auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSC::JSFunction* getStdioWriteStream = JSC::JSFunction::create(vm, globalObject, processObjectInternalsGetStdioWriteStreamCodeGenerator(vm), globalObject); JSC::MarkedArgumentBuffer args; @@ -2393,7 +2393,7 @@ static JSValue constructStderr(VM& vm, JSObject* processObject) static JSValue constructStdin(VM& vm, JSObject* processObject) { auto* globalObject = processObject->globalObject(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSC::JSFunction* getStdinStream = JSC::JSFunction::create(vm, globalObject, processObjectInternalsGetStdinStreamCodeGenerator(vm), globalObject); JSC::MarkedArgumentBuffer args; args.append(processObject); diff --git a/src/bun.js/bindings/BunProcessReportObjectWindows.cpp b/src/bun.js/bindings/BunProcessReportObjectWindows.cpp index 6a433a8497..a62ab17e90 100644 --- a/src/bun.js/bindings/BunProcessReportObjectWindows.cpp +++ b/src/bun.js/bindings/BunProcessReportObjectWindows.cpp @@ -12,7 +12,7 @@ #include "JavaScriptCore/JSArray.h" #include "JavaScriptCore/ObjectConstructor.h" #include "JavaScriptCore/JSGlobalObject.h" -#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/TopExceptionScope.h" #include "JavaScriptCore/VM.h" #include "wtf/text/WTFString.h" #include "wtf/text/StringView.h" diff --git a/src/bun.js/bindings/CallSite.cpp b/src/bun.js/bindings/CallSite.cpp index 4fe20ab069..14cf1e9cc7 100644 --- a/src/bun.js/bindings/CallSite.cpp +++ b/src/bun.js/bindings/CallSite.cpp @@ -131,10 +131,10 @@ void CallSite::formatAsString(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WT } if (auto* object = thisValue.getObject()) { - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto className = object->calculatedClassName(object); - if (catchScope.exception()) { - (void)catchScope.tryClearException(); + if (topExceptionScope.exception()) { + (void)topExceptionScope.tryClearException(); } if (className.length() > 0) { diff --git a/src/bun.js/bindings/CatchScopeBinding.cpp b/src/bun.js/bindings/CatchScopeBinding.cpp deleted file mode 100644 index 28b57370ad..0000000000 --- a/src/bun.js/bindings/CatchScopeBinding.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include - -using JSC::CatchScope; - -#if ENABLE(EXCEPTION_SCOPE_VERIFICATION) -#define ExpectedCatchScopeSize 56 -#define ExpectedCatchScopeAlignment 8 -#else -#define ExpectedCatchScopeSize 8 -#define ExpectedCatchScopeAlignment 8 -#endif - -static_assert(sizeof(CatchScope) == ExpectedCatchScopeSize, "CatchScope.zig assumes CatchScope is 56 bytes"); -static_assert(alignof(CatchScope) == ExpectedCatchScopeAlignment, "CatchScope.zig assumes CatchScope is 8-byte aligned"); - -extern "C" void CatchScope__construct( - void* ptr, - JSC::JSGlobalObject* globalObject, - const char* function, - const char* file, - unsigned line, - size_t size, - size_t alignment) -{ - // validate that Zig is correct about what the size and alignment should be - ASSERT(size >= sizeof(CatchScope)); - ASSERT(alignment >= alignof(CatchScope)); - ASSERT((uintptr_t)ptr % alignment == 0); - -#if ENABLE(EXCEPTION_SCOPE_VERIFICATION) - new (ptr) JSC::CatchScope(JSC::getVM(globalObject), - JSC::ExceptionEventLocation { currentStackPointer(), function, file, line }); -#else - (void)function; - (void)file; - (void)line; - new (ptr) JSC::CatchScope(JSC::getVM(globalObject)); -#endif -} - -extern "C" JSC::Exception* CatchScope__pureException(void* ptr) -{ - ASSERT((uintptr_t)ptr % alignof(CatchScope) == 0); - return static_cast(ptr)->exception(); -} - -extern "C" JSC::Exception* CatchScope__exceptionIncludingTraps(void* ptr) -{ - ASSERT((uintptr_t)ptr % alignof(CatchScope) == 0); - auto* scope = static_cast(ptr); - // this is different than `return scope->exception()` because `RETURN_IF_EXCEPTION` also checks - // if there are traps that should throw an exception (like a termination request from another - // thread) - RETURN_IF_EXCEPTION(*scope, scope->exception()); - return nullptr; -} - -extern "C" void CatchScope__clearException(void* ptr) -{ - ASSERT((uintptr_t)ptr % alignof(CatchScope) == 0); - auto* scope = static_cast(ptr); - scope->clearException(); -} - -extern "C" void CatchScope__destruct(void* ptr) -{ - ASSERT((uintptr_t)ptr % alignof(CatchScope) == 0); - static_cast(ptr)->~CatchScope(); -} - -extern "C" void CatchScope__assertNoException(void* ptr) -{ - ASSERT((uintptr_t)ptr % alignof(CatchScope) == 0); - // this function assumes it should assert in all build modes, anything else would be confusing. - // Zig should only call CatchScope__assertNoException if it wants the assertion. - static_cast(ptr)->releaseAssertNoException(); -} diff --git a/src/bun.js/bindings/ErrorCode.cpp b/src/bun.js/bindings/ErrorCode.cpp index 3366f3afc8..08cf13f7c1 100644 --- a/src/bun.js/bindings/ErrorCode.cpp +++ b/src/bun.js/bindings/ErrorCode.cpp @@ -197,7 +197,7 @@ static Structure* createErrorStructure(JSC::VM& vm, JSGlobalObject* globalObject JSObject* ErrorCodeCache::createError(VM& vm, Zig::GlobalObject* globalObject, ErrorCode code, JSValue message, JSValue options) { - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto* cache = errorCache(globalObject); const auto& data = errors[static_cast(code)]; if (!cache->internalField(static_cast(code))) { @@ -346,7 +346,7 @@ void JSValueToStringSafe(JSC::JSGlobalObject* globalObject, WTF::StringBuilder& void determineSpecificType(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WTF::StringBuilder& builder, JSValue value) { - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); ASSERT(!value.isEmpty()); diff --git a/src/bun.js/bindings/ErrorStackTrace.cpp b/src/bun.js/bindings/ErrorStackTrace.cpp index 7607359268..b37a0e98e1 100644 --- a/src/bun.js/bindings/ErrorStackTrace.cpp +++ b/src/bun.js/bindings/ErrorStackTrace.cpp @@ -12,7 +12,7 @@ #include "JavaScriptCore/JSType.h" #include "wtf/text/OrdinalNumber.h" -#include +#include #include #include #include @@ -258,7 +258,7 @@ JSCStackTrace JSCStackTrace::getStackTraceForThrownValue(JSC::VM& vm, JSC::JSVal { const WTF::Vector* jscStackTrace = nullptr; - JSC::Exception* currentException = DECLARE_CATCH_SCOPE(vm).exception(); + JSC::Exception* currentException = DECLARE_TOP_EXCEPTION_SCOPE(vm).exception(); if (currentException && currentException->value() == thrownValue) { jscStackTrace = ¤tException->stack(); } else { @@ -631,7 +631,7 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSC:: // First try the "name" property. { WTF::String name; - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); PropertySlot slot(object, PropertySlot::InternalMethodType::VMInquiry, &vm); if (object->getOwnNonIndexPropertySlot(vm, object->structure(), vm.propertyNames->name, slot)) { if (!slot.isAccessor()) { @@ -644,17 +644,17 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSC:: } } } - if (catchScope.exception()) [[unlikely]] { - (void)catchScope.tryClearException(); + if (topExceptionScope.exception()) [[unlikely]] { + (void)topExceptionScope.tryClearException(); } } { // Then try the "displayName" property (what this does internally) - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); functionName = JSC::getCalculatedDisplayName(vm, object); - if (catchScope.exception()) [[unlikely]] { - (void)catchScope.tryClearException(); + if (topExceptionScope.exception()) [[unlikely]] { + (void)topExceptionScope.tryClearException(); } } diff --git a/src/bun.js/bindings/FormatStackTraceForJS.cpp b/src/bun.js/bindings/FormatStackTraceForJS.cpp index 8b61c797b2..dee8b43601 100644 --- a/src/bun.js/bindings/FormatStackTraceForJS.cpp +++ b/src/bun.js/bindings/FormatStackTraceForJS.cpp @@ -6,7 +6,7 @@ #include "JavaScriptCore/ArgList.h" #include "JavaScriptCore/CallData.h" -#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/TopExceptionScope.h" #include "JavaScriptCore/Error.h" #include "JavaScriptCore/ErrorInstance.h" #include "JavaScriptCore/ExceptionScope.h" @@ -125,7 +125,7 @@ static JSValue formatStackTraceToJSValueWithoutPrepareStackTrace(JSC::VM& vm, Zi prepareStackTrace = prepare; } } else { - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto* errorConstructor = lexicalGlobalObject->m_errorStructure.constructor(globalObject); prepareStackTrace = errorConstructor->getIfPropertyExists(lexicalGlobalObject, JSC::Identifier::fromString(vm, "prepareStackTrace"_s)); @@ -526,7 +526,7 @@ WTF::String computeErrorInfoWrapperToString(JSC::VM& vm, Vector& sta OrdinalNumber line = OrdinalNumber::fromOneBasedInt(line_in); OrdinalNumber column = OrdinalNumber::fromOneBasedInt(column_in); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); WTF::String result = computeErrorInfoToString(vm, stackTrace, line, column, sourceURL); if (scope.exception()) { // TODO: is this correct? vm.setOnComputeErrorInfo doesnt appear to properly handle a function that can throw diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index a39b7b65ff..be4674bd13 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -350,7 +350,7 @@ JSC::EncodedJSValue JSBuffer__bufferFromPointerAndLengthAndDeinit(JSC::JSGlobalO auto* globalObject = defaultGlobalObject(lexicalGlobalObject); auto* subclassStructure = globalObject->JSBufferSubclassStructure(); - auto scope = DECLARE_CATCH_SCOPE(lexicalGlobalObject->vm()); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(lexicalGlobalObject->vm()); if (length > 0) [[likely]] { ASSERT(bytesDeallocator); diff --git a/src/bun.js/bindings/JSBundlerPlugin.cpp b/src/bun.js/bindings/JSBundlerPlugin.cpp index 5315548f18..553a3ea292 100644 --- a/src/bun.js/bindings/JSBundlerPlugin.cpp +++ b/src/bun.js/bindings/JSBundlerPlugin.cpp @@ -4,7 +4,7 @@ #include "../../../packages/bun-native-bundler-plugin-api/bundler_plugin.h" #include "JavaScriptCore/CallData.h" #include "headers-handwritten.h" -#include +#include #include #include #include @@ -522,7 +522,7 @@ extern "C" void JSBundlerPlugin__matchOnLoad(Bun::JSBundlerPlugin* plugin, const if (callData.type == JSC::CallData::Type::None) [[unlikely]] return; - auto scope = DECLARE_CATCH_SCOPE(plugin->vm()); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(plugin->vm()); JSC::MarkedArgumentBuffer arguments; arguments.append(WRAP_BUNDLER_PLUGIN(context)); arguments.append(JSC::jsString(plugin->vm(), pathStr)); @@ -565,7 +565,7 @@ extern "C" void JSBundlerPlugin__matchOnResolve(Bun::JSBundlerPlugin* plugin, co if (callData.type == JSC::CallData::Type::None) [[unlikely]] return; - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSC::MarkedArgumentBuffer arguments; arguments.append(JSC::jsString(vm, pathStr)); arguments.append(JSC::jsString(vm, namespaceStringStr)); diff --git a/src/bun.js/bindings/JSDOMExceptionHandling.cpp b/src/bun.js/bindings/JSDOMExceptionHandling.cpp index b0d10ba810..ba0377efc9 100644 --- a/src/bun.js/bindings/JSDOMExceptionHandling.cpp +++ b/src/bun.js/bindings/JSDOMExceptionHandling.cpp @@ -47,10 +47,10 @@ void reportException(JSGlobalObject* lexicalGlobalObject, JSC::Exception* except if (vm.isTerminationException(exception)) return; - // We can declare a CatchScope here because we will clear the exception below if it's + // We can declare a TopExceptionScope here because we will clear the exception below if it's // not a TerminationException. If it's a TerminationException, it'll remain sticky in // the VM, but we have the check above to ensure that we do not re-enter this scope. - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); ErrorHandlingScope errorScope(lexicalGlobalObject->vm()); @@ -98,7 +98,7 @@ void reportException(JSGlobalObject* lexicalGlobalObject, JSValue exceptionValue reportException(lexicalGlobalObject, exception, cachedScript, fromModule); } -String retrieveErrorMessageWithoutName(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue exception, CatchScope& catchScope) +String retrieveErrorMessageWithoutName(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue exception, TopExceptionScope& topExceptionScope) { // FIXME: Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions // If this is a custom exception object, call toString on it to try and get a nice string representation for the exception. @@ -112,12 +112,12 @@ String retrieveErrorMessageWithoutName(JSGlobalObject& lexicalGlobalObject, VM& // We need to clear any new exception that may be thrown in the toString() call above. // reportException() is not supposed to be making new exceptions. - (void)catchScope.tryClearException(); + (void)topExceptionScope.tryClearException(); vm.clearLastException(); return errorMessage; } -String retrieveErrorMessage(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue exception, CatchScope& catchScope) +String retrieveErrorMessage(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue exception, TopExceptionScope& topExceptionScope) { // FIXME: Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions // If this is a custom exception object, call toString on it to try and get a nice string representation for the exception. @@ -129,7 +129,7 @@ String retrieveErrorMessage(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue // We need to clear any new exception that may be thrown in the toString() call above. // reportException() is not supposed to be making new exceptions. - (void)catchScope.tryClearException(); + (void)topExceptionScope.tryClearException(); vm.clearLastException(); return errorMessage; } @@ -137,7 +137,7 @@ String retrieveErrorMessage(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue void reportCurrentException(JSGlobalObject* lexicalGlobalObject) { auto& vm = JSC::getVM(lexicalGlobalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto* exception = scope.exception(); (void)scope.tryClearException(); reportException(lexicalGlobalObject, exception); diff --git a/src/bun.js/bindings/JSDOMExceptionHandling.h b/src/bun.js/bindings/JSDOMExceptionHandling.h index 7f04a6efde..e5699f6e02 100644 --- a/src/bun.js/bindings/JSDOMExceptionHandling.h +++ b/src/bun.js/bindings/JSDOMExceptionHandling.h @@ -29,7 +29,7 @@ #include namespace JSC { -class CatchScope; +class TopExceptionScope; } namespace WebCore { @@ -63,8 +63,8 @@ WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::JSGloba WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithThisTypeError(DeferredPromise&, ASCIILiteral interfaceName, ASCIILiteral operationName); WEBCORE_EXPORT JSC::EncodedJSValue rejectPromiseWithThisTypeError(JSC::JSGlobalObject&, ASCIILiteral interfaceName, ASCIILiteral operationName); -String retrieveErrorMessageWithoutName(JSC::JSGlobalObject&, JSC::VM&, JSC::JSValue exception, JSC::CatchScope&); -String retrieveErrorMessage(JSC::JSGlobalObject&, JSC::VM&, JSC::JSValue exception, JSC::CatchScope&); +String retrieveErrorMessageWithoutName(JSC::JSGlobalObject&, JSC::VM&, JSC::JSValue exception, JSC::TopExceptionScope&); +String retrieveErrorMessage(JSC::JSGlobalObject&, JSC::VM&, JSC::JSValue exception, JSC::TopExceptionScope&); WEBCORE_EXPORT void reportException(JSC::JSGlobalObject*, JSC::JSValue exception, CachedScript* = nullptr, bool = false); WEBCORE_EXPORT void reportException(JSC::JSGlobalObject*, JSC::Exception*, CachedScript* = nullptr, bool = false, ExceptionDetails* = nullptr); WEBCORE_EXPORT void reportExceptionIfJSDOMWindow(JSC::JSGlobalObject*, JSC::JSValue exception); diff --git a/src/bun.js/bindings/JSGlobalObject.zig b/src/bun.js/bindings/JSGlobalObject.zig index 6ce923f88e..25950dad6f 100644 --- a/src/bun.js/bindings/JSGlobalObject.zig +++ b/src/bun.js/bindings/JSGlobalObject.zig @@ -479,7 +479,7 @@ pub const JSGlobalObject = opaque { return JSC__JSGlobalObject__generateHeapSnapshot(this); } - // DEPRECATED - use CatchScope to check for exceptions and signal exceptions by returning JSError + // DEPRECATED - use TopExceptionScope to check for exceptions and signal exceptions by returning JSError pub fn hasException(this: *JSGlobalObject) bool { return JSGlobalObject__hasException(this); } diff --git a/src/bun.js/bindings/JSMockFunction.cpp b/src/bun.js/bindings/JSMockFunction.cpp index e7e9021cef..6456cff5b7 100644 --- a/src/bun.js/bindings/JSMockFunction.cpp +++ b/src/bun.js/bindings/JSMockFunction.cpp @@ -294,7 +294,7 @@ public: void copyNameAndLength(JSC::VM& vm, JSGlobalObject* global, JSC::JSValue value) { - auto catcher = DECLARE_CATCH_SCOPE(vm); + auto catcher = DECLARE_TOP_EXCEPTION_SCOPE(vm); WTF::String nameToUse; if (auto* fn = jsDynamicCast(value)) { nameToUse = fn->name(vm); @@ -931,15 +931,15 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionCall, (JSGlobalObject * lexicalGlobalObje setReturnValue(createMockResult(vm, globalObject, "incomplete"_s, jsUndefined())); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue returnValue = Bun::call(globalObject, result, callData, thisValue, args); - if (auto* exc = catchScope.exception()) { + if (auto* exc = topExceptionScope.exception()) { if (auto* returnValuesArray = fn->returnValues.get()) { returnValuesArray->putDirectIndex(globalObject, returnValueIndex, createMockResult(vm, globalObject, "throw"_s, exc->value())); fn->returnValues.set(vm, fn, returnValuesArray); - (void)catchScope.tryClearException(); + (void)topExceptionScope.tryClearException(); JSC::throwException(globalObject, scope, exc); return {}; } diff --git a/src/bun.js/bindings/JSObject.zig b/src/bun.js/bindings/JSObject.zig index ae9577e64e..38d8d1808f 100644 --- a/src/bun.js/bindings/JSObject.zig +++ b/src/bun.js/bindings/JSObject.zig @@ -140,7 +140,7 @@ pub const JSObject = opaque { // then the JSValue is zero. the function this ends up calling can return undefined // with an exception: // https://github.com/oven-sh/WebKit/blob/397dafc9721b8f8046f9448abb6dbc14efe096d3/Source/JavaScriptCore/runtime/JSObjectInlines.h#L112 - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(globalThis, @src()); defer scope.deinit(); const value = JSC__JSObject__getIndex(this, globalThis, i); diff --git a/src/bun.js/bindings/JSPromise.zig b/src/bun.js/bindings/JSPromise.zig index cfacd5f5f6..cf11d38987 100644 --- a/src/bun.js/bindings/JSPromise.zig +++ b/src/bun.js/bindings/JSPromise.zig @@ -190,7 +190,7 @@ pub const JSPromise = opaque { } }; - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(globalObject, @src()); defer scope.deinit(); var ctx = Wrapper{ .args = args }; diff --git a/src/bun.js/bindings/JSPropertyIterator.zig b/src/bun.js/bindings/JSPropertyIterator.zig index ab3cc81ca6..2336f0aea6 100644 --- a/src/bun.js/bindings/JSPropertyIterator.zig +++ b/src/bun.js/bindings/JSPropertyIterator.zig @@ -119,7 +119,7 @@ const JSPropertyIteratorImpl = opaque { pub const deinit = Bun__JSPropertyIterator__deinit; pub fn getNameAndValue(iter: *JSPropertyIteratorImpl, globalObject: *jsc.JSGlobalObject, object: *jsc.JSObject, propertyName: *bun.String, i: usize) bun.JSError!jsc.JSValue { - var scope: bun.jsc.CatchScope = undefined; + var scope: bun.jsc.TopExceptionScope = undefined; scope.init(globalObject, @src()); defer scope.deinit(); const value = Bun__JSPropertyIterator__getNameAndValue(iter, globalObject, object, propertyName, i); @@ -128,7 +128,7 @@ const JSPropertyIteratorImpl = opaque { } pub fn getNameAndValueNonObservable(iter: *JSPropertyIteratorImpl, globalObject: *jsc.JSGlobalObject, object: *jsc.JSObject, propertyName: *bun.String, i: usize) bun.JSError!jsc.JSValue { - var scope: bun.jsc.CatchScope = undefined; + var scope: bun.jsc.TopExceptionScope = undefined; scope.init(globalObject, @src()); defer scope.deinit(); const value = Bun__JSPropertyIterator__getNameAndValueNonObservable(iter, globalObject, object, propertyName, i); diff --git a/src/bun.js/bindings/JSValue.zig b/src/bun.js/bindings/JSValue.zig index 5bf2a1d788..1e9052cd14 100644 --- a/src/bun.js/bindings/JSValue.zig +++ b/src/bun.js/bindings/JSValue.zig @@ -1284,7 +1284,7 @@ pub const JSValue = enum(i64) { /// Unwraps Number, Boolean, String, and BigInt objects to their primitive forms. pub fn unwrapBoxedPrimitive(this: JSValue, global: *JSGlobalObject) JSError!JSValue { - var scope: CatchScope = undefined; + var scope: TopExceptionScope = undefined; scope.init(global, @src()); defer scope.deinit(); const result = JSC__JSValue__unwrapBoxedPrimitive(global, this); @@ -1399,7 +1399,7 @@ pub const JSValue = enum(i64) { extern fn JSC__JSValue__getPropertyValue(target: JSValue, global: *JSGlobalObject, ptr: [*]const u8, len: u32) JSValue; extern fn JSC__JSValue__getIfPropertyExistsFromPath(this: JSValue, global: *JSGlobalObject, path: JSValue) JSValue; pub fn getIfPropertyExistsFromPath(this: JSValue, global: *JSGlobalObject, path: JSValue) JSError!JSValue { - var scope: CatchScope = undefined; + var scope: TopExceptionScope = undefined; scope.init(global, @src()); defer scope.deinit(); const result = JSC__JSValue__getIfPropertyExistsFromPath(this, global, path); @@ -1428,7 +1428,7 @@ pub const JSValue = enum(i64) { } pub fn then2(this: JSValue, global: *JSGlobalObject, ctx: JSValue, resolve: *const jsc.JSHostFn, reject: *const jsc.JSHostFn) bun.JSTerminated!void { - var scope: CatchScope = undefined; + var scope: TopExceptionScope = undefined; scope.init(global, @src()); defer scope.deinit(); JSC__JSValue___then(this, global, ctx, resolve, reject); @@ -1436,7 +1436,7 @@ pub const JSValue = enum(i64) { } pub fn then(this: JSValue, global: *JSGlobalObject, ctx: ?*anyopaque, resolve: jsc.JSHostFnZig, reject: jsc.JSHostFnZig) bun.JSTerminated!void { - var scope: CatchScope = undefined; + var scope: TopExceptionScope = undefined; scope.init(global, @src()); defer scope.deinit(); this._then(global, JSValue.fromPtrAddress(@intFromPtr(ctx)), resolve, reject); @@ -1509,7 +1509,7 @@ pub const JSValue = enum(i64) { /// Get *own* property value (i.e. does not resolve property in the prototype chain) pub fn getOwn(this: JSValue, global: *JSGlobalObject, property_name: anytype) bun.JSError!?JSValue { var property_name_str = bun.String.init(property_name); - var scope: CatchScope = undefined; + var scope: TopExceptionScope = undefined; scope.init(global, @src()); defer scope.deinit(); const value = JSC__JSValue__getOwn(this, global, &property_name_str); @@ -1612,7 +1612,7 @@ pub const JSValue = enum(i64) { /// - .js_undefined /// - an empty string pub fn getStringish(this: JSValue, global: *JSGlobalObject, property: []const u8) bun.JSError!?bun.String { - var scope: CatchScope = undefined; + var scope: TopExceptionScope = undefined; scope.init(global, @src()); defer scope.deinit(); const prop = try get(this, global, property) orelse return null; @@ -2435,7 +2435,6 @@ const jsc = bun.jsc; const AnyPromise = jsc.AnyPromise; const ArrayBuffer = jsc.ArrayBuffer; const C_API = bun.jsc.C; -const CatchScope = jsc.CatchScope; const DOMURL = jsc.DOMURL; const JSArrayIterator = jsc.JSArrayIterator; const JSCell = jsc.JSCell; @@ -2444,6 +2443,7 @@ const JSInternalPromise = jsc.JSInternalPromise; const JSObject = jsc.JSObject; const JSPromise = jsc.JSPromise; const JSString = jsc.JSString; +const TopExceptionScope = jsc.TopExceptionScope; const VM = jsc.VM; const ZigException = jsc.ZigException; const ZigString = jsc.ZigString; diff --git a/src/bun.js/bindings/MimallocWTFMalloc.h b/src/bun.js/bindings/MimallocWTFMalloc.h index 32e43713ba..eb8771074c 100644 --- a/src/bun.js/bindings/MimallocWTFMalloc.h +++ b/src/bun.js/bindings/MimallocWTFMalloc.h @@ -10,7 +10,7 @@ namespace Bun { // For use with WTF types like WTF::Vector. struct MimallocMalloc { -#if USE(MIMALLOC) +#if USE(BUN_MIMALLOC) static constexpr std::size_t maxAlign = MI_MAX_ALIGN_SIZE; #else static constexpr std::size_t maxAlign = alignof(std::max_align_t); @@ -25,7 +25,7 @@ struct MimallocMalloc { static void* tryMalloc(std::size_t size) { -#if USE(MIMALLOC) +#if USE(BUN_MIMALLOC) return mi_malloc(size); #else return std::malloc(size); @@ -41,7 +41,7 @@ struct MimallocMalloc { static void* tryZeroedMalloc(std::size_t size) { -#if USE(MIMALLOC) +#if USE(BUN_MIMALLOC) return mi_zalloc(size); #else return std::calloc(size, 1); @@ -60,7 +60,7 @@ struct MimallocMalloc { ASSERT(alignment > 0); ASSERT((alignment & (alignment - 1)) == 0); // ensure power of two ASSERT(((alignment - 1) & size) == 0); // ensure size multiple of alignment -#if USE(MIMALLOC) +#if USE(BUN_MIMALLOC) return mi_malloc_aligned(size, alignment); #elif !OS(WINDOWS) return std::aligned_alloc(alignment, size); @@ -79,7 +79,7 @@ struct MimallocMalloc { static void* tryRealloc(void* p, std::size_t size) { -#if USE(MIMALLOC) +#if USE(BUN_MIMALLOC) return mi_realloc(p, size); #else return std::realloc(p, size); @@ -88,7 +88,7 @@ struct MimallocMalloc { static void free(void* p) { -#if USE(MIMALLOC) +#if USE(BUN_MIMALLOC) mi_free(p); #else std::free(p); diff --git a/src/bun.js/bindings/NodeTimerObject.cpp b/src/bun.js/bindings/NodeTimerObject.cpp index f6239ead09..08dca56050 100644 --- a/src/bun.js/bindings/NodeTimerObject.cpp +++ b/src/bun.js/bindings/NodeTimerObject.cpp @@ -19,7 +19,7 @@ using namespace JSC; static bool call(JSGlobalObject* globalObject, JSValue timerObject, JSValue callbackValue, JSValue argumentsValue) { auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue restoreAsyncContext {}; JSC::InternalFieldTuple* asyncContextData = nullptr; diff --git a/src/bun.js/bindings/NodeVMModule.cpp b/src/bun.js/bindings/NodeVMModule.cpp index c0bdd9dc66..ffa755f5c6 100644 --- a/src/bun.js/bindings/NodeVMModule.cpp +++ b/src/bun.js/bindings/NodeVMModule.cpp @@ -128,7 +128,7 @@ JSValue NodeVMModule::evaluate(JSGlobalObject* globalObject, uint32_t timeout, b if (vm.hasPendingTerminationException()) { vm.drainMicrotasksForGlobalObject(nodeVmGlobalObject); - DECLARE_CATCH_SCOPE(vm).clearException(); + DECLARE_TOP_EXCEPTION_SCOPE(vm).clearException(); vm.clearHasTerminationRequest(); if (getSigintReceived()) { setSigintReceived(false); diff --git a/src/bun.js/bindings/S3Error.cpp b/src/bun.js/bindings/S3Error.cpp index 31ddb1afc7..e16cca5fe0 100644 --- a/src/bun.js/bindings/S3Error.cpp +++ b/src/bun.js/bindings/S3Error.cpp @@ -27,7 +27,7 @@ SYSV_ABI JSC::EncodedJSValue S3Error__toErrorInstance(const S3Error* arg0, S3Error err = *arg0; auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); WTF::String message; if (err.message.tag != BunStringTag::Empty) { diff --git a/src/bun.js/bindings/StringBuilder.zig b/src/bun.js/bindings/StringBuilder.zig index a42e189a84..c0b332db48 100644 --- a/src/bun.js/bindings/StringBuilder.zig +++ b/src/bun.js/bindings/StringBuilder.zig @@ -67,7 +67,7 @@ extern fn StringBuilder__appendUChar(*anyopaque, c: u16) void; extern fn StringBuilder__appendQuotedJsonString(*anyopaque, str: String) void; pub fn toString(this: *StringBuilder, global: *JSGlobalObject) JSError!JSValue { - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(global, @src()); defer scope.deinit(); diff --git a/src/bun.js/bindings/CatchScope.zig b/src/bun.js/bindings/TopExceptionScope.zig similarity index 75% rename from src/bun.js/bindings/CatchScope.zig rename to src/bun.js/bindings/TopExceptionScope.zig index a685574b13..d0e0bc9470 100644 --- a/src/bun.js/bindings/CatchScope.zig +++ b/src/bun.js/bindings/TopExceptionScope.zig @@ -2,34 +2,34 @@ const size = if (Environment.allow_assert or Environment.enable_asan) 56 else 8; const alignment = 8; -/// Binding for JSC::CatchScope. This should be used rarely, only at translation boundaries between +/// Binding for JSC::TopExceptionScope. This should be used rarely, only at translation boundaries between /// JSC's exception checking and Zig's. Make sure not to move it after creation. Use this if you are /// making an external call that has no other way to indicate an exception. /// /// ```zig -/// // Declare a CatchScope surrounding the call that may throw an exception -/// var scope: CatchScope = undefined; +/// // Declare a TopExceptionScope surrounding the call that may throw an exception +/// var scope: TopExceptionScope = undefined; /// scope.init(global, @src()); /// defer scope.deinit(); /// /// const value: i32 = external_call(vm, foo, bar, baz); /// // Calling returnIfException() suffices to prove that we checked for an exception. -/// // This function's caller does not need to use a CatchScope or ThrowScope +/// // This function's caller does not need to use a TopExceptionScope or ThrowScope /// // because it can use Zig error unions. /// try scope.returnIfException(); /// return value; /// ``` -pub const CatchScope = struct { +pub const TopExceptionScope = struct { bytes: [size]u8 align(alignment), /// Pointer to `bytes`, set by `init()`, used to assert that the location did not change location: if (Environment.ci_assert) *u8 else void, pub fn init( - self: *CatchScope, + self: *TopExceptionScope, global: *jsc.JSGlobalObject, src: std.builtin.SourceLocation, ) void { - CatchScope__construct( + TopExceptionScope__construct( &self.bytes, global, src.fn_name, @@ -47,42 +47,42 @@ pub const CatchScope = struct { /// Generate a useful message including where the exception was thrown. /// Only intended to be called when there is a pending exception. - fn assertionFailure(self: *CatchScope, proof: *jsc.Exception) noreturn { + fn assertionFailure(self: *TopExceptionScope, proof: *jsc.Exception) noreturn { _ = proof; bun.assert(self.location == &self.bytes[0]); - CatchScope__assertNoException(&self.bytes); + TopExceptionScope__assertNoException(&self.bytes); @panic("assertionFailure called without a pending exception"); } - pub fn hasException(self: *CatchScope) bool { + pub fn hasException(self: *TopExceptionScope) bool { return self.exception() != null; } /// Get the thrown exception if it exists (like scope.exception() in C++) - pub fn exception(self: *CatchScope) ?*jsc.Exception { + pub fn exception(self: *TopExceptionScope) ?*jsc.Exception { if (comptime Environment.ci_assert) bun.assert(self.location == &self.bytes[0]); - return CatchScope__pureException(&self.bytes); + return TopExceptionScope__pureException(&self.bytes); } - pub fn clearException(self: *CatchScope) void { + pub fn clearException(self: *TopExceptionScope) void { if (comptime Environment.ci_assert) bun.assert(self.location == &self.bytes[0]); - return CatchScope__clearException(&self.bytes); + return TopExceptionScope__clearException(&self.bytes); } /// Get the thrown exception if it exists, or if an unhandled trap causes an exception to be thrown - pub fn exceptionIncludingTraps(self: *CatchScope) ?*jsc.Exception { + pub fn exceptionIncludingTraps(self: *TopExceptionScope) ?*jsc.Exception { if (comptime Environment.ci_assert) bun.assert(self.location == &self.bytes[0]); - return CatchScope__exceptionIncludingTraps(&self.bytes); + return TopExceptionScope__exceptionIncludingTraps(&self.bytes); } /// Intended for use with `try`. Returns if there is already a pending exception or if traps cause /// an exception to be thrown (this is the same as how RETURN_IF_EXCEPTION behaves in C++) - pub fn returnIfException(self: *CatchScope) !void { + pub fn returnIfException(self: *TopExceptionScope) !void { if (self.exceptionIncludingTraps() != null) return error.JSError; } /// Asserts there has not been any exception thrown. - pub fn assertNoException(self: *CatchScope) void { + pub fn assertNoException(self: *TopExceptionScope) void { if (comptime Environment.ci_assert) { if (self.exception()) |e| self.assertionFailure(e); } @@ -91,7 +91,7 @@ pub const CatchScope = struct { /// Asserts that there is or is not an exception according to the value of `should_have_exception`. /// Prefer over `assert(scope.hasException() == ...)` because if there is an unexpected exception, /// this function prints a trace of where it was thrown. - pub fn assertExceptionPresenceMatches(self: *CatchScope, should_have_exception: bool) void { + pub fn assertExceptionPresenceMatches(self: *TopExceptionScope, should_have_exception: bool) void { if (comptime Environment.ci_assert) { if (should_have_exception) { bun.assertf(self.hasException(), "Expected an exception to be thrown", .{}); @@ -104,7 +104,7 @@ pub const CatchScope = struct { /// If no exception, returns. /// If termination exception, returns JSTerminated (so you can `try`) /// If non-termination exception, assertion failure. - pub fn assertNoExceptionExceptTermination(self: *CatchScope) bun.JSTerminated!void { + pub fn assertNoExceptionExceptTermination(self: *TopExceptionScope) bun.JSTerminated!void { if (self.exception()) |e| { if (jsc.JSValue.fromCell(e).isTerminationException()) return error.JSTerminated @@ -114,15 +114,15 @@ pub const CatchScope = struct { } } - pub fn deinit(self: *CatchScope) void { + pub fn deinit(self: *TopExceptionScope) void { if (comptime Environment.ci_assert) bun.assert(self.location == &self.bytes[0]); - CatchScope__destruct(&self.bytes); + TopExceptionScope__destruct(&self.bytes); self.bytes = undefined; } }; -/// Limited subset of CatchScope functionality, for when you have a different way to detect -/// exceptions and you only need a CatchScope to prove that you are checking exceptions correctly. +/// Limited subset of TopExceptionScope functionality, for when you have a different way to detect +/// exceptions and you only need a TopExceptionScope to prove that you are checking exceptions correctly. /// Gated by `Environment.ci_assert`. /// /// ```zig @@ -139,7 +139,7 @@ pub const CatchScope = struct { /// return if (value == .zero) error.JSError else value; /// ``` pub const ExceptionValidationScope = struct { - scope: if (Environment.ci_assert) CatchScope else void, + scope: if (Environment.ci_assert) TopExceptionScope else void, pub fn init( self: *ExceptionValidationScope, @@ -184,7 +184,7 @@ pub const ExceptionValidationScope = struct { } }; -extern fn CatchScope__construct( +extern fn TopExceptionScope__construct( ptr: *align(alignment) [size]u8, global: *jsc.JSGlobalObject, function: [*:0]const u8, @@ -194,13 +194,13 @@ extern fn CatchScope__construct( alignment: usize, ) void; /// only returns exceptions that have already been thrown. does not check traps -extern fn CatchScope__pureException(ptr: *align(alignment) [size]u8) ?*jsc.Exception; -extern fn CatchScope__clearException(ptr: *align(alignment) [size]u8) void; +extern fn TopExceptionScope__pureException(ptr: *align(alignment) [size]u8) ?*jsc.Exception; +extern fn TopExceptionScope__clearException(ptr: *align(alignment) [size]u8) void; /// returns if an exception was already thrown, or if a trap (like another thread requesting /// termination) causes an exception to be thrown -extern fn CatchScope__exceptionIncludingTraps(ptr: *align(alignment) [size]u8) ?*jsc.Exception; -extern fn CatchScope__assertNoException(ptr: *align(alignment) [size]u8) void; -extern fn CatchScope__destruct(ptr: *align(alignment) [size]u8) void; +extern fn TopExceptionScope__exceptionIncludingTraps(ptr: *align(alignment) [size]u8) ?*jsc.Exception; +extern fn TopExceptionScope__assertNoException(ptr: *align(alignment) [size]u8) void; +extern fn TopExceptionScope__destruct(ptr: *align(alignment) [size]u8) void; const std = @import("std"); diff --git a/src/bun.js/bindings/TopExceptionScopeBinding.cpp b/src/bun.js/bindings/TopExceptionScopeBinding.cpp new file mode 100644 index 0000000000..19113d6fbb --- /dev/null +++ b/src/bun.js/bindings/TopExceptionScopeBinding.cpp @@ -0,0 +1,77 @@ +#include + +using JSC::TopExceptionScope; + +#if ENABLE(EXCEPTION_SCOPE_VERIFICATION) +#define ExpectedTopExceptionScopeSize 56 +#define ExpectedTopExceptionScopeAlignment 8 +#else +#define ExpectedTopExceptionScopeSize 8 +#define ExpectedTopExceptionScopeAlignment 8 +#endif + +static_assert(sizeof(TopExceptionScope) == ExpectedTopExceptionScopeSize, "TopExceptionScope.zig assumes TopExceptionScope is 56 bytes"); +static_assert(alignof(TopExceptionScope) == ExpectedTopExceptionScopeAlignment, "TopExceptionScope.zig assumes TopExceptionScope is 8-byte aligned"); + +extern "C" void TopExceptionScope__construct( + void* ptr, + JSC::JSGlobalObject* globalObject, + const char* function, + const char* file, + unsigned line, + size_t size, + size_t alignment) +{ + // validate that Zig is correct about what the size and alignment should be + ASSERT(size >= sizeof(TopExceptionScope)); + ASSERT(alignment >= alignof(TopExceptionScope)); + ASSERT((uintptr_t)ptr % alignment == 0); + +#if ENABLE(EXCEPTION_SCOPE_VERIFICATION) + new (ptr) JSC::TopExceptionScope(JSC::getVM(globalObject), + JSC::ExceptionEventLocation { currentStackPointer(), function, file, line }); +#else + (void)function; + (void)file; + (void)line; + new (ptr) JSC::TopExceptionScope(JSC::getVM(globalObject)); +#endif +} + +extern "C" JSC::Exception* TopExceptionScope__pureException(void* ptr) +{ + ASSERT((uintptr_t)ptr % alignof(TopExceptionScope) == 0); + return static_cast(ptr)->exception(); +} + +extern "C" JSC::Exception* TopExceptionScope__exceptionIncludingTraps(void* ptr) +{ + ASSERT((uintptr_t)ptr % alignof(TopExceptionScope) == 0); + auto* scope = static_cast(ptr); + // this is different than `return scope->exception()` because `RETURN_IF_EXCEPTION` also checks + // if there are traps that should throw an exception (like a termination request from another + // thread) + RETURN_IF_EXCEPTION(*scope, scope->exception()); + return nullptr; +} + +extern "C" void TopExceptionScope__clearException(void* ptr) +{ + ASSERT((uintptr_t)ptr % alignof(TopExceptionScope) == 0); + auto* scope = static_cast(ptr); + scope->clearException(); +} + +extern "C" void TopExceptionScope__destruct(void* ptr) +{ + ASSERT((uintptr_t)ptr % alignof(TopExceptionScope) == 0); + static_cast(ptr)->~TopExceptionScope(); +} + +extern "C" void TopExceptionScope__assertNoException(void* ptr) +{ + ASSERT((uintptr_t)ptr % alignof(TopExceptionScope) == 0); + // this function assumes it should assert in all build modes, anything else would be confusing. + // Zig should only call TopExceptionScope__assertNoException if it wants the assertion. + static_cast(ptr)->releaseAssertNoException(); +} diff --git a/src/bun.js/bindings/ZigException.cpp b/src/bun.js/bindings/ZigException.cpp index 69cc6d20a8..a1dc7ddec3 100644 --- a/src/bun.js/bindings/ZigException.cpp +++ b/src/bun.js/bindings/ZigException.cpp @@ -7,7 +7,7 @@ #include "root.h" #include "JavaScriptCore/ErrorType.h" -#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/TopExceptionScope.h" #include "JavaScriptCore/Exception.h" #include "ErrorCode+List.h" #include "ErrorCode.h" @@ -479,7 +479,7 @@ static void fromErrorInstance(ZigException& except, JSC::JSGlobalObject* global, { JSC::JSObject* obj = JSC::jsDynamicCast(val); auto& vm = JSC::getVM(global); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); bool getFromSourceURL = false; if (stackTrace != nullptr && stackTrace->size() > 0) { @@ -707,7 +707,7 @@ void exceptionFromString(ZigException& except, JSC::JSValue value, JSC::JSGlobal return; } - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); // Fallback case for when it's a user-defined ErrorLike-object that doesn't inherit from // ErrorInstance diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 74db88cf1f..2f8afa2d9b 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -7,7 +7,7 @@ #include "wtf/text/Base64.h" #include "JavaScriptCore/BuiltinNames.h" #include "JavaScriptCore/CallData.h" -#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/TopExceptionScope.h" #include "JavaScriptCore/ClassInfo.h" #include "JavaScriptCore/CodeBlock.h" #include "JavaScriptCore/Completion.h" @@ -1449,7 +1449,7 @@ JSC_DEFINE_HOST_FUNCTION(makeGetterTypeErrorForBuiltins, (JSGlobalObject * globa ASSERT(callFrame->argumentCount() == 2); VM& vm = globalObject->vm(); DeferTermination deferScope(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto interfaceName = callFrame->uncheckedArgument(0).getString(globalObject); scope.assertNoException(); @@ -1468,7 +1468,7 @@ JSC_DEFINE_HOST_FUNCTION(makeDOMExceptionForBuiltins, (JSGlobalObject * globalOb auto& vm = JSC::getVM(globalObject); DeferTermination deferScope(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto codeValue = callFrame->uncheckedArgument(0).getString(globalObject); scope.assertNoException(); @@ -1557,7 +1557,7 @@ extern "C" napi_env ZigGlobalObject__makeNapiEnvForFFI(Zig::GlobalObject* global JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotask, (JSGlobalObject * globalObject, CallFrame* callframe)) { auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto job = callframe->argument(0); if (!job || job.isUndefinedOrNull()) [[unlikely]] { @@ -1614,7 +1614,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotask, (JSGlobalObject * globalObj JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotaskVariadic, (JSGlobalObject * globalObject, CallFrame* callframe)) { auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto job = callframe->argument(0); if (!job || job.isUndefinedOrNull()) { @@ -1918,7 +1918,7 @@ void GlobalObject::finishCreation(VM& vm) m_JSBufferSubclassStructure.initLater( [](const Initializer& init) { - auto scope = DECLARE_CATCH_SCOPE(init.vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(init.vm); auto* globalObject = static_cast(init.owner); auto* baseStructure = globalObject->typedArrayStructureWithTypedArrayType(); JSC::Structure* subclassStructure = JSC::InternalFunction::createSubclassStructure(globalObject, globalObject->JSBufferConstructor(), baseStructure); @@ -1927,7 +1927,7 @@ void GlobalObject::finishCreation(VM& vm) }); m_JSResizableOrGrowableSharedBufferSubclassStructure.initLater( [](const Initializer& init) { - auto scope = DECLARE_CATCH_SCOPE(init.vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(init.vm); auto* globalObject = static_cast(init.owner); auto* baseStructure = globalObject->resizableOrGrowableSharedTypedArrayStructureWithTypedArrayType(); JSC::Structure* subclassStructure = JSC::InternalFunction::createSubclassStructure(globalObject, globalObject->JSBufferConstructor(), baseStructure); @@ -2685,7 +2685,7 @@ JSValue GlobalObject_getGlobalThis(VM& vm, JSObject* globalObject) void GlobalObject::addBuiltinGlobals(JSC::VM& vm) { - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); m_builtinInternalFunctions.initialize(*this); auto clientData = WebCore::clientData(vm); @@ -2835,7 +2835,7 @@ extern "C" [[ZIG_EXPORT(nothrow)]] void JSC__JSGlobalObject__addGc(JSC::JSGlobal uint8_t GlobalObject::drainMicrotasks() { auto& vm = this->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); if (auto* exception = scope.exception()) [[unlikely]] { if (vm.isTerminationException(exception)) [[unlikely]] { @@ -2969,7 +2969,7 @@ extern "C" void JSGlobalObject__clearTerminationException(JSC::JSGlobalObject* g // Clear the request for the termination exception to be thrown vm.clearHasTerminationRequest(); // In case it actually has been thrown, clear the exception itself as well - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); if (scope.exception() && vm.isTerminationException(scope.exception())) { (void)scope.tryClearException(); } @@ -3009,7 +3009,7 @@ extern "C" void Bun__handleRejectedPromise(Zig::GlobalObject* JSGlobalObject, JS void GlobalObject::handleRejectedPromises() { JSC::VM& virtual_machine = vm(); - auto scope = DECLARE_CATCH_SCOPE(virtual_machine); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(virtual_machine); while (auto* promise = m_aboutToBeNotifiedRejectedPromises.takeFirst(this)) { if (promise->isHandled()) continue; diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h index e92b385658..48a27659ab 100644 --- a/src/bun.js/bindings/ZigGlobalObject.h +++ b/src/bun.js/bindings/ZigGlobalObject.h @@ -46,7 +46,7 @@ struct node_module; #include "root.h" #include "headers-handwritten.h" -#include +#include #include #include #include diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 12eb49535a..4fbc573d34 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -10,7 +10,7 @@ #include "root.h" #include "JavaScriptCore/ErrorType.h" -#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/TopExceptionScope.h" #include "JavaScriptCore/Exception.h" #include "ErrorCode+List.h" #include "ErrorCode.h" @@ -2179,16 +2179,16 @@ extern "C" JSC::EncodedJSValue ZigString__toJSONObject(const ZigString* strPtr, } } - auto catchScope = DECLARE_CATCH_SCOPE(globalObject->vm()); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()); // JSONParseWithException does not propagate exceptions as expected. See #5859 JSValue result = JSONParse(globalObject, str); - if (!result && !catchScope.exception()) + if (!result && !topExceptionScope.exception()) scope.throwException(globalObject, createSyntaxError(globalObject, "Failed to parse JSON"_s)); - if (catchScope.exception()) { - auto* exception = catchScope.exception(); - catchScope.clearExceptionExceptTermination(); + if (topExceptionScope.exception()) { + auto* exception = topExceptionScope.exception(); + topExceptionScope.clearExceptionExceptTermination(); return JSC::JSValue::encode(exception->value()); } @@ -2216,7 +2216,7 @@ JSC::EncodedJSValue SystemError__toErrorInstance(const SystemError* arg0, JSC::J SystemError err = *arg0; auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); WTF::String message = WTF::emptyString(); if (err.message.tag != BunStringTag::Empty) { @@ -2921,7 +2921,7 @@ JSC::JSObject* JSC__JSString__toObject(JSC::JSString* arg0, JSC::JSGlobalObject* extern "C" JSC::JSInternalPromise* JSModuleLoader__import(JSC::JSGlobalObject* globalObject, const BunString* moduleNameStr) { auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto* promise = JSC::importModule(globalObject, JSC::Identifier::fromString(vm, moduleNameStr->toWTFString()), jsUndefined(), jsUndefined(), jsUndefined()); EXCEPTION_ASSERT(!!scope.exception() == !promise); @@ -3353,7 +3353,7 @@ JSC__JSModuleLoader__loadAndEvaluateModule(JSC::JSGlobalObject* globalObject, const BunString* arg1) { auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto name = makeAtomString(arg1->toWTFString()); auto* promise = JSC::loadAndEvaluateModule(globalObject, name, JSC::jsUndefined(), JSC::jsUndefined()); @@ -3372,7 +3372,7 @@ JSC__JSModuleLoader__loadAndEvaluateModule(JSC::JSGlobalObject* globalObject, void JSC__AnyPromise__wrap(JSC::JSGlobalObject* globalObject, EncodedJSValue encodedPromise, void* ctx, JSC::EncodedJSValue (*func)(void*, JSC::JSGlobalObject*)) { auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue promiseValue = JSC::JSValue::decode(encodedPromise); ASSERT(!promiseValue.isEmpty()); @@ -4455,7 +4455,7 @@ JSC::JSObject* JSC__JSValue__toObject(JSC::EncodedJSValue JSValue0, JSC::JSGloba bool JSC__JSValue__stringIncludes(JSC::EncodedJSValue value, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue other) { VM& vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); WTF::String stringToSearchIn = JSC::JSValue::decode(value).toWTFString(globalObject); RETURN_IF_EXCEPTION(scope, {}); @@ -5022,7 +5022,7 @@ static void JSC__JSValue__forEachPropertyImpl(JSC::EncodedJSValue JSValue0, JSC: } size_t prototypeCount = 0; - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSC::Structure* structure = object->structure(); bool fast = !nonIndexedOnly && canPerformFastPropertyEnumerationForIterationBun(structure); @@ -5293,7 +5293,7 @@ extern "C" [[ZIG_EXPORT(nothrow)]] bool JSC__isBigIntInInt64Range(JSC::EncodedJS return; auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSC::PropertyNameArrayBuilder properties(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Exclude); { @@ -5378,7 +5378,7 @@ bool JSC__JSValue__isInstanceOf(JSC::EncodedJSValue JSValue0, JSC::JSGlobalObjec { VM& vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue jsValue = JSValue::decode(JSValue0); JSValue jsValue1 = JSValue::decode(JSValue1); @@ -5897,22 +5897,22 @@ extern "C" EncodedJSValue JSArray__constructEmptyArray( extern "C" bool JSGlobalObject__hasException(JSC::JSGlobalObject* globalObject) { - return DECLARE_CATCH_SCOPE(globalObject->vm()).exception() != 0; + return DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()).exception() != 0; } extern "C" void JSGlobalObject__clearException(JSC::JSGlobalObject* globalObject) { - (void)DECLARE_CATCH_SCOPE(globalObject->vm()).tryClearException(); + (void)DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()).tryClearException(); } extern "C" bool JSGlobalObject__clearExceptionExceptTermination(JSC::JSGlobalObject* globalObject) { - return DECLARE_CATCH_SCOPE(globalObject->vm()).clearExceptionExceptTermination(); + return DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()).clearExceptionExceptTermination(); } extern "C" JSC::EncodedJSValue JSGlobalObject__tryTakeException(JSC::JSGlobalObject* globalObject) { - auto scope = DECLARE_CATCH_SCOPE(globalObject->vm()); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()); if (auto exception = scope.exception()) { (void)scope.tryClearException(); @@ -6012,7 +6012,7 @@ extern "C" EncodedJSValue Bun__JSObject__getCodePropertyVMInquiry(JSC::JSGlobalO } auto& vm = global->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); if (object->type() == JSC::ProxyObjectType) [[unlikely]] { return {}; } diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h index 50e4c3d7c4..9ccce1ec06 100644 --- a/src/bun.js/bindings/headers-cpp.h +++ b/src/bun.js/bindings/headers-cpp.h @@ -142,13 +142,13 @@ extern "C" const size_t JSC__VM_object_align_ = alignof(JSC::VM); extern "C" const size_t JSC__ThrowScope_object_size_ = sizeof(JSC::ThrowScope); extern "C" const size_t JSC__ThrowScope_object_align_ = alignof(JSC::ThrowScope); -#ifndef INCLUDED_JavaScriptCore_CatchScope_h -#define INCLUDED_JavaScriptCore_CatchScope_h -#include +#ifndef INCLUDED_JavaScriptCore_TopExceptionScope_h +#define INCLUDED_JavaScriptCore_TopExceptionScope_h +#include #endif -extern "C" const size_t JSC__CatchScope_object_size_ = sizeof(JSC::CatchScope); -extern "C" const size_t JSC__CatchScope_object_align_ = alignof(JSC::CatchScope); +extern "C" const size_t JSC__TopExceptionScope_object_size_ = sizeof(JSC::TopExceptionScope); +extern "C" const size_t JSC__TopExceptionScope_object_align_ = alignof(JSC::TopExceptionScope); #ifndef INCLUDED__ZigGlobalObject_h_ #define INCLUDED__ZigGlobalObject_h_ @@ -190,6 +190,6 @@ extern "C" const size_t Bun__Timer_object_align_ = alignof(Bun__Timer); extern "C" const size_t Bun__BodyValueBufferer_object_size_ = sizeof(Bun__BodyValueBufferer); extern "C" const size_t Bun__BodyValueBufferer_object_align_ = alignof(Bun__BodyValueBufferer); -const size_t sizes[39] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::DOMFormData), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(JSC::JSModuleLoader), sizeof(WebCore::AbortSignal), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(JSC::JSMap), sizeof(JSC::JSValue), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(FFI__ptr), sizeof(Reader__u8), sizeof(Reader__u16), sizeof(Reader__u32), sizeof(Reader__ptr), sizeof(Reader__i8), sizeof(Reader__i16), sizeof(Reader__i32), sizeof(Reader__f32), sizeof(Reader__f64), sizeof(Reader__i64), sizeof(Reader__u64), sizeof(Reader__intptr), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink), sizeof(FileSink), sizeof(FileSink)}; +const size_t sizes[39] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::DOMFormData), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(JSC::JSModuleLoader), sizeof(WebCore::AbortSignal), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(JSC::JSMap), sizeof(JSC::JSValue), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::TopExceptionScope), sizeof(FFI__ptr), sizeof(Reader__u8), sizeof(Reader__u16), sizeof(Reader__u32), sizeof(Reader__ptr), sizeof(Reader__i8), sizeof(Reader__i16), sizeof(Reader__i32), sizeof(Reader__f32), sizeof(Reader__f64), sizeof(Reader__i64), sizeof(Reader__u64), sizeof(Reader__intptr), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink), sizeof(FileSink), sizeof(FileSink)}; -const size_t aligns[39] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::DOMFormData), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(JSC::JSModuleLoader), alignof(WebCore::AbortSignal), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(JSC::JSMap), alignof(JSC::JSValue), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(FFI__ptr), alignof(Reader__u8), alignof(Reader__u16), alignof(Reader__u32), alignof(Reader__ptr), alignof(Reader__i8), alignof(Reader__i16), alignof(Reader__i32), alignof(Reader__f32), alignof(Reader__f64), alignof(Reader__i64), alignof(Reader__u64), alignof(Reader__intptr), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink), alignof(FileSink), alignof(FileSink)}; +const size_t aligns[39] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::DOMFormData), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(JSC::JSModuleLoader), alignof(WebCore::AbortSignal), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(JSC::JSMap), alignof(JSC::JSValue), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::TopExceptionScope), alignof(FFI__ptr), alignof(Reader__u8), alignof(Reader__u16), alignof(Reader__u32), alignof(Reader__ptr), alignof(Reader__i8), alignof(Reader__i16), alignof(Reader__i32), alignof(Reader__f32), alignof(Reader__f64), alignof(Reader__i64), alignof(Reader__u64), alignof(Reader__intptr), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink), alignof(FileSink), alignof(FileSink)}; diff --git a/src/bun.js/bindings/headers-handwritten.h b/src/bun.js/bindings/headers-handwritten.h index 546d804181..a641c372fa 100644 --- a/src/bun.js/bindings/headers-handwritten.h +++ b/src/bun.js/bindings/headers-handwritten.h @@ -483,13 +483,13 @@ ALWAYS_INLINE void BunString::deref() #endif // HEADERS_HANDWRITTEN #if ASSERT_ENABLED -#define ASSERT_NO_PENDING_EXCEPTION(globalObject) DECLARE_CATCH_SCOPE(globalObject->vm()).assertNoExceptionExceptTermination() +#define ASSERT_NO_PENDING_EXCEPTION(globalObject) DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()).assertNoExceptionExceptTermination() #else #define ASSERT_NO_PENDING_EXCEPTION(globalObject) void() #endif #if ASSERT_ENABLED -#define ASSERT_PENDING_EXCEPTION(globalObject) EXCEPTION_ASSERT(!!DECLARE_CATCH_SCOPE(globalObject->vm()).exception()); +#define ASSERT_PENDING_EXCEPTION(globalObject) EXCEPTION_ASSERT(!!DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()).exception()); #else #define ASSERT_PENDING_EXCEPTION(globalObject) void() #endif diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp index 884f3c4535..aa3419a65b 100644 --- a/src/bun.js/bindings/napi.cpp +++ b/src/bun.js/bindings/napi.cpp @@ -1308,7 +1308,7 @@ extern "C" napi_status napi_is_exception_pending(napi_env env, bool* result) if (globalObject) { auto& vm = JSC::getVM(globalObject); // Use a catch scope instead of throw scope for safety during cleanup - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); *result = scope.exception() != nullptr; } } @@ -1327,7 +1327,7 @@ extern "C" napi_status napi_get_and_clear_last_exception(napi_env env, } auto globalObject = toJS(env); - auto scope = DECLARE_CATCH_SCOPE(JSC::getVM(globalObject)); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(JSC::getVM(globalObject)); if (scope.exception()) [[unlikely]] { *result = toNapi(JSValue(scope.exception()->value()), globalObject); } else if (std::optional pending = env->pendingException()) { diff --git a/src/bun.js/bindings/node/JSNodeHTTPServerSocket.cpp b/src/bun.js/bindings/node/JSNodeHTTPServerSocket.cpp index a83540e486..4f7def480e 100644 --- a/src/bun.js/bindings/node/JSNodeHTTPServerSocket.cpp +++ b/src/bun.js/bindings/node/JSNodeHTTPServerSocket.cpp @@ -190,7 +190,7 @@ void JSNodeHTTPServerSocket::onDrain() auto bufferedSize = this->streamBuffer.bufferedSize(); if (bufferedSize > 0) { auto* globalObject = defaultGlobalObject(this->globalObject()); - auto scope = DECLARE_CATCH_SCOPE(globalObject->vm()); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()); us_socket_buffered_js_write(this->socket, this->is_ssl, this->ended, &this->streamBuffer, globalObject, JSValue::encode(JSC::jsUndefined()), JSValue::encode(JSC::jsUndefined())); if (scope.exception()) { globalObject->reportUncaughtExceptionAtEventLoop(globalObject, scope.exception()); @@ -241,7 +241,7 @@ void JSNodeHTTPServerSocket::onData(const char* data, int length, bool last) WebCore::ScriptExecutionContext* scriptExecutionContext = globalObject->scriptExecutionContext(); if (scriptExecutionContext) { - auto scope = DECLARE_CATCH_SCOPE(globalObject->vm()); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()); JSC::JSUint8Array* buffer = WebCore::createBuffer(globalObject, std::span(reinterpret_cast(data), length)); auto chunk = JSC::JSValue(buffer); if (scope.exception()) { diff --git a/src/bun.js/bindings/node/http/NodeHTTPParser.cpp b/src/bun.js/bindings/node/http/NodeHTTPParser.cpp index d0babb741e..a49e47648a 100644 --- a/src/bun.js/bindings/node/http/NodeHTTPParser.cpp +++ b/src/bun.js/bindings/node/http/NodeHTTPParser.cpp @@ -315,7 +315,7 @@ int HTTPParser::onMessageBegin() { JSGlobalObject* globalObject = m_globalObject; auto& vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSHTTPParser* thisParser = m_thisParser; @@ -379,7 +379,7 @@ int HTTPParser::onHeaderField(const char* at, size_t length) { JSGlobalObject* globalObject = m_globalObject; auto& vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); int rv = trackHeader(length); if (rv != 0) { @@ -452,7 +452,7 @@ int HTTPParser::onHeadersComplete() { JSGlobalObject* globalObject = m_globalObject; auto& vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSHTTPParser* thisParser = m_thisParser; m_headersCompleted = true; @@ -540,7 +540,7 @@ int HTTPParser::onBody(const char* at, size_t length) JSGlobalObject* lexicalGlobalObject = m_globalObject; auto* globalObject = defaultGlobalObject(lexicalGlobalObject); auto& vm = lexicalGlobalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue onBodyCallback = m_thisParser->get(lexicalGlobalObject, Identifier::from(vm, kOnBody)); RETURN_IF_EXCEPTION(scope, 0); @@ -571,7 +571,7 @@ int HTTPParser::onMessageComplete() { JSGlobalObject* globalObject = m_globalObject; auto& vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSHTTPParser* thisParser = m_thisParser; if (JSConnectionsList* connections = m_connectionsList.get()) { diff --git a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp index ac9948c7d8..118ed257ea 100644 --- a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp +++ b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp @@ -1659,10 +1659,10 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementOpenStatementFunction, (JSC::JSGlobalObje #endif initializeSQLite(); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); String path = pathValue.toWTFString(lexicalGlobalObject); - RETURN_IF_EXCEPTION(catchScope, JSValue::encode(jsUndefined())); - (void)catchScope.tryClearException(); + RETURN_IF_EXCEPTION(topExceptionScope, JSValue::encode(jsUndefined())); + (void)topExceptionScope.tryClearException(); int openFlags = DEFAULT_SQLITE_FLAGS; if (callFrame->argumentCount() > 1) { JSValue flags = callFrame->argument(1); diff --git a/src/bun.js/bindings/v8/V8Object.cpp b/src/bun.js/bindings/v8/V8Object.cpp index ab6456fd1e..3ae7cab0d1 100644 --- a/src/bun.js/bindings/v8/V8Object.cpp +++ b/src/bun.js/bindings/v8/V8Object.cpp @@ -45,7 +45,7 @@ Maybe Object::Set(Local context, Local key, Local v JSValue v = value->localToJSValue(); auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); PutPropertySlot slot(object, false); Identifier identifier = k.toPropertyKey(globalObject); @@ -65,7 +65,7 @@ Maybe Object::Set(Local context, uint32_t index, Local val JSValue v = value->localToJSValue(); auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); // TODO: investigate if we should use the return value (seems like not) bool success = object->methodTable()->putByIndex(object, globalObject, index, v, false); @@ -82,7 +82,7 @@ MaybeLocal Object::Get(Local context, Local key) JSValue k = key->localToJSValue(); auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); Identifier identifier = k.toPropertyKey(globalObject); RETURN_IF_EXCEPTION(scope, MaybeLocal()); @@ -102,7 +102,7 @@ MaybeLocal Object::Get(Local context, uint32_t index) JSObject* object = localToObjectPointer(); auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue result = object->get(globalObject, index); if (scope.exception()) [[unlikely]] { diff --git a/src/bun.js/bindings/webcore/BroadcastChannel.cpp b/src/bun.js/bindings/webcore/BroadcastChannel.cpp index f0b3ebbbb5..9302f6554d 100644 --- a/src/bun.js/bindings/webcore/BroadcastChannel.cpp +++ b/src/bun.js/bindings/webcore/BroadcastChannel.cpp @@ -265,7 +265,7 @@ void BroadcastChannel::dispatchMessage(Ref&& message) return; auto& vm = JSC::getVM(globalObject); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); Vector> dummyPorts; auto event = MessageEvent::create(*globalObject, WTF::move(message), {}, {}, nullptr, WTF::move(dummyPorts)); if (scope.exception()) [[unlikely]] { diff --git a/src/bun.js/bindings/webcore/InternalWritableStream.cpp b/src/bun.js/bindings/webcore/InternalWritableStream.cpp index ab2a8ec27b..b45443f25a 100644 --- a/src/bun.js/bindings/webcore/InternalWritableStream.cpp +++ b/src/bun.js/bindings/webcore/InternalWritableStream.cpp @@ -36,7 +36,7 @@ static ExceptionOr invokeWritableStreamFunction(JSC::JSGlobalObjec JSC::VM& vm = globalObject.vm(); JSC::JSLockHolder lock(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto function = globalObject.get(&globalObject, identifier); ASSERT(function.isCallable()); @@ -79,7 +79,7 @@ bool InternalWritableStream::locked() const if (!globalObject) return false; - auto scope = DECLARE_CATCH_SCOPE(globalObject->vm()); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()); auto* clientData = static_cast(globalObject->vm().clientData); auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().isWritableStreamLockedPrivateName(); @@ -99,7 +99,7 @@ void InternalWritableStream::lock() if (!globalObject) return; - auto scope = DECLARE_CATCH_SCOPE(globalObject->vm()); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(globalObject->vm()); auto* clientData = static_cast(globalObject->vm().clientData); auto& privateName = clientData->builtinFunctions().writableStreamInternalsBuiltins().acquireWritableStreamDefaultWriterPrivateName(); diff --git a/src/bun.js/bindings/webcore/JSCallbackData.cpp b/src/bun.js/bindings/webcore/JSCallbackData.cpp index c97b045371..b5ba3dd293 100644 --- a/src/bun.js/bindings/webcore/JSCallbackData.cpp +++ b/src/bun.js/bindings/webcore/JSCallbackData.cpp @@ -48,7 +48,7 @@ JSValue JSCallbackData::invokeCallback(VM& vm, JSObject* callback, JSValue thisV // https://webidl.spec.whatwg.org/#ref-for-prepare-to-run-script makes callback's [[Realm]] a running JavaScript execution context, // which is used for creating TypeError objects: https://tc39.es/ecma262/#sec-ecmascript-function-objects-call-thisargument-argumentslist (step 4). JSGlobalObject* lexicalGlobalObject = callback->globalObject(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue function; CallData callData; diff --git a/src/bun.js/bindings/webcore/JSDOMPromise.cpp b/src/bun.js/bindings/webcore/JSDOMPromise.cpp index 56dd702a27..34f634281e 100644 --- a/src/bun.js/bindings/webcore/JSDOMPromise.cpp +++ b/src/bun.js/bindings/webcore/JSDOMPromise.cpp @@ -29,7 +29,7 @@ // #include "DOMWindow.h" // #include "JSDOMWindow.h" #include -#include +#include #include #include #include diff --git a/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp b/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp index aec764b49e..730b6b2dce 100644 --- a/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp +++ b/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp @@ -152,7 +152,7 @@ void DeferredPromise::reject(Exception exception, RejectAsHandled rejectAsHandle auto& lexicalGlobalObject = *m_globalObject; JSC::VM& vm = lexicalGlobalObject.vm(); JSC::JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); if (exception.code() == ExistingExceptionError) { EXCEPTION_ASSERT(scope.exception()); @@ -187,7 +187,7 @@ void DeferredPromise::reject(ExceptionCode ec, const String& message, RejectAsHa auto& lexicalGlobalObject = *m_globalObject; JSC::VM& vm = lexicalGlobalObject.vm(); JSC::JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); if (ec == ExistingExceptionError) { EXCEPTION_ASSERT(scope.exception()); @@ -223,14 +223,14 @@ void DeferredPromise::reject(const JSC::PrivateName& privateName, RejectAsHandle reject(*lexicalGlobalObject, JSC::Symbol::create(lexicalGlobalObject->vm(), privateName.uid()), rejectAsHandled); } -void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSPromise& promise, JSC::CatchScope& catchScope) +void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSPromise& promise, JSC::TopExceptionScope& topExceptionScope) { UNUSED_PARAM(lexicalGlobalObject); - if (!catchScope.exception()) [[likely]] + if (!topExceptionScope.exception()) [[likely]] return; - JSValue error = catchScope.exception()->value(); - (void)catchScope.tryClearException(); + JSValue error = topExceptionScope.exception()->value(); + (void)topExceptionScope.tryClearException(); DeferredPromise::create(globalObject, promise)->reject(error); } @@ -276,7 +276,7 @@ void fulfillPromiseWithArrayBuffer(Ref&& promise, const void* d fulfillPromiseWithArrayBuffer(WTF::move(promise), ArrayBuffer::tryCreate({ reinterpret_cast(data), length }).get()); } -bool DeferredPromise::handleTerminationExceptionIfNeeded(CatchScope& scope, JSDOMGlobalObject& lexicalGlobalObject) +bool DeferredPromise::handleTerminationExceptionIfNeeded(TopExceptionScope& scope, JSDOMGlobalObject& lexicalGlobalObject) { auto* exception = scope.exception(); VM& vm = scope.vm(); @@ -284,7 +284,7 @@ bool DeferredPromise::handleTerminationExceptionIfNeeded(CatchScope& scope, JSDO return !!exception && vm.isTerminationException(exception); } -void DeferredPromise::handleUncaughtException(CatchScope& scope, JSDOMGlobalObject& lexicalGlobalObject) +void DeferredPromise::handleUncaughtException(TopExceptionScope& scope, JSDOMGlobalObject& lexicalGlobalObject) { auto* exception = scope.exception(); handleTerminationExceptionIfNeeded(scope, lexicalGlobalObject); diff --git a/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.h b/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.h index 67f58839be..bc94d1efc6 100644 --- a/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.h +++ b/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.h @@ -29,7 +29,7 @@ #include "JSDOMConvert.h" #include "JSDOMGuardedObject.h" #include "ScriptExecutionContext.h" -#include +#include #include namespace WebCore { @@ -77,7 +77,7 @@ public: JSC::JSGlobalObject* lexicalGlobalObject = globalObject(); auto& vm = lexicalGlobalObject->vm(); JSC::JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value_js = toJS(*lexicalGlobalObject, *globalObject(), std::forward(value)); DEFERRED_PROMISE_HANDLE_AND_RETURN_IF_EXCEPTION(scope, lexicalGlobalObject); resolve(*lexicalGlobalObject, value_js); @@ -119,7 +119,7 @@ public: JSC::JSGlobalObject* lexicalGlobalObject = globalObject(); auto& vm = lexicalGlobalObject->vm(); JSC::JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value_js = toJSNewlyCreated(*lexicalGlobalObject, *globalObject(), std::forward(value)); DEFERRED_PROMISE_HANDLE_AND_RETURN_IF_EXCEPTION(scope, lexicalGlobalObject); resolve(*lexicalGlobalObject, value_js); @@ -136,7 +136,7 @@ public: auto* lexicalGlobalObject = globalObject(); auto& vm = lexicalGlobalObject->vm(); JSC::JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value_js = toJSNewlyCreated(*lexicalGlobalObject, *globalObject(), createValue(*globalObject()->scriptExecutionContext())); DEFERRED_PROMISE_HANDLE_AND_RETURN_IF_EXCEPTION(scope, lexicalGlobalObject); resolve(*lexicalGlobalObject, value_js); @@ -153,7 +153,7 @@ public: JSC::JSGlobalObject* lexicalGlobalObject = globalObject(); auto& vm = lexicalGlobalObject->vm(); JSC::JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value_js = toJS(*lexicalGlobalObject, *globalObject(), std::forward(value)); DEFERRED_PROMISE_HANDLE_AND_RETURN_IF_EXCEPTION(scope, lexicalGlobalObject); reject(*lexicalGlobalObject, value_js, rejectAsHandled); @@ -177,7 +177,7 @@ public: auto* lexicalGlobalObject = globalObject(); auto& vm = lexicalGlobalObject->vm(); JSC::JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value_js = callback(*globalObject()); DEFERRED_PROMISE_HANDLE_AND_RETURN_IF_EXCEPTION(scope, lexicalGlobalObject); resolve(*lexicalGlobalObject, value_js); @@ -194,7 +194,7 @@ public: auto* lexicalGlobalObject = globalObject(); auto& vm = lexicalGlobalObject->vm(); JSC::JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value_js = callback(*globalObject()); DEFERRED_PROMISE_HANDLE_AND_RETURN_IF_EXCEPTION(scope, lexicalGlobalObject); reject(*lexicalGlobalObject, value_js, rejectAsHandled); @@ -226,8 +226,8 @@ private: callFunction(lexicalGlobalObject, rejectAsHandled == RejectAsHandled::Yes ? ResolveMode::RejectAsHandled : ResolveMode::Reject, resolution); } - bool handleTerminationExceptionIfNeeded(JSC::CatchScope&, JSDOMGlobalObject& lexicalGlobalObject); - void handleUncaughtException(JSC::CatchScope&, JSDOMGlobalObject& lexicalGlobalObject); + bool handleTerminationExceptionIfNeeded(JSC::TopExceptionScope&, JSDOMGlobalObject& lexicalGlobalObject); + void handleUncaughtException(JSC::TopExceptionScope&, JSDOMGlobalObject& lexicalGlobalObject); Mode m_mode; }; @@ -340,7 +340,7 @@ public: void fulfillPromiseWithJSON(Ref&&, const String&); void fulfillPromiseWithArrayBuffer(Ref&&, ArrayBuffer*); void fulfillPromiseWithArrayBuffer(Ref&&, const void*, size_t); -WEBCORE_EXPORT void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject&, JSDOMGlobalObject&, JSC::JSPromise&, JSC::CatchScope&); +WEBCORE_EXPORT void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject&, JSDOMGlobalObject&, JSC::JSPromise&, JSC::TopExceptionScope&); enum class RejectedPromiseWithTypeErrorCause { NativeGetter, InvalidThis }; @@ -352,7 +352,7 @@ template inline JSC::JSValue callPromiseFunction(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame) { auto& vm = JSC::getVM(&lexicalGlobalObject); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto& globalObject = *JSC::jsSecureCast(&lexicalGlobalObject); auto* promise = JSC::JSPromise::create(vm, globalObject.promiseStructure()); @@ -360,10 +360,10 @@ inline JSC::JSValue callPromiseFunction(JSC::JSGlobalObject& lexicalGlobalObject promiseFunction(lexicalGlobalObject, callFrame, DeferredPromise::create(globalObject, *promise)); - rejectPromiseWithExceptionIfAny(lexicalGlobalObject, globalObject, *promise, catchScope); + rejectPromiseWithExceptionIfAny(lexicalGlobalObject, globalObject, *promise, topExceptionScope); // FIXME: We could have error since any JS call can throw stack-overflow errors. // https://bugs.webkit.org/show_bug.cgi?id=203402 - RETURN_IF_EXCEPTION(catchScope, JSC::jsUndefined()); + RETURN_IF_EXCEPTION(topExceptionScope, JSC::jsUndefined()); return promise; } @@ -371,7 +371,7 @@ template inline JSC::JSValue callPromiseFunction(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, PromiseFunctor functor) { auto& vm = JSC::getVM(&lexicalGlobalObject); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto& globalObject = *JSC::jsSecureCast(&lexicalGlobalObject); auto* promise = JSC::JSPromise::create(vm, globalObject.promiseStructure()); @@ -379,10 +379,10 @@ inline JSC::JSValue callPromiseFunction(JSC::JSGlobalObject& lexicalGlobalObject functor(lexicalGlobalObject, callFrame, DeferredPromise::create(globalObject, *promise)); - rejectPromiseWithExceptionIfAny(lexicalGlobalObject, globalObject, *promise, catchScope); + rejectPromiseWithExceptionIfAny(lexicalGlobalObject, globalObject, *promise, topExceptionScope); // FIXME: We could have error since any JS call can throw stack-overflow errors. // https://bugs.webkit.org/show_bug.cgi?id=203402 - RETURN_IF_EXCEPTION(catchScope, JSC::jsUndefined()); + RETURN_IF_EXCEPTION(topExceptionScope, JSC::jsUndefined()); return promise; } diff --git a/src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp b/src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp index 41a6b956a0..e1e1614b31 100644 --- a/src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp +++ b/src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp @@ -66,7 +66,7 @@ JSEventEmitter* jsEventEmitterCastFast(VM& vm, JSC::JSGlobalObject* lexicalGloba } // TODO: properly propagate exception upwards (^ getIfPropertyExists) - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto* globalObject = static_cast(lexicalGlobalObject); auto impl = EventEmitter::create(*globalObject->scriptExecutionContext()); impl->setThisObject(thisObject); diff --git a/src/bun.js/bindings/webcore/JSEventListener.cpp b/src/bun.js/bindings/webcore/JSEventListener.cpp index b4f61be1c5..b9e519619a 100644 --- a/src/bun.js/bindings/webcore/JSEventListener.cpp +++ b/src/bun.js/bindings/webcore/JSEventListener.cpp @@ -147,7 +147,7 @@ void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext VM& vm = scriptExecutionContext.vm(); JSLockHolder lock(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); // See https://dom.spec.whatwg.org/#dispatching-events spec on calling handleEvent. // "If this throws an exception, report the exception." It should not propagate the diff --git a/src/bun.js/bindings/webcore/MessageEvent.cpp b/src/bun.js/bindings/webcore/MessageEvent.cpp index 113a7eb210..05125e8651 100644 --- a/src/bun.js/bindings/webcore/MessageEvent.cpp +++ b/src/bun.js/bindings/webcore/MessageEvent.cpp @@ -96,12 +96,12 @@ auto MessageEvent::create(JSC::JSGlobalObject& globalObject, Ref locker(vm.apiLock()); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); bool didFail = false; auto deserialized = data->deserialize(globalObject, &globalObject, ports, SerializationErrorMode::NonThrowing, &didFail); - if (catchScope.exception()) [[unlikely]] + if (topExceptionScope.exception()) [[unlikely]] deserialized = jsUndefined(); JSC::Strong strongData(vm, deserialized); diff --git a/src/bun.js/bindings/webcore/MessagePort.cpp b/src/bun.js/bindings/webcore/MessagePort.cpp index 8cdca2d979..4290583aeb 100644 --- a/src/bun.js/bindings/webcore/MessagePort.cpp +++ b/src/bun.js/bindings/webcore/MessagePort.cpp @@ -265,7 +265,7 @@ void MessagePort::dispatchMessages() ASSERT(context->isContextThread()); auto* globalObject = defaultGlobalObject(context->globalObject()); Ref vm = globalObject->vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); for (auto& message : messages) { // close() in Worker onmessage handler should prevent next message from dispatching. diff --git a/src/bun.js/bindings/webcore/ReadableStream.cpp b/src/bun.js/bindings/webcore/ReadableStream.cpp index f7efa38ace..ef0a2cd6a0 100644 --- a/src/bun.js/bindings/webcore/ReadableStream.cpp +++ b/src/bun.js/bindings/webcore/ReadableStream.cpp @@ -117,7 +117,7 @@ static inline std::optional invokeReadableStreamFunction(JSC::JSGl auto function = lexicalGlobalObject.get(&lexicalGlobalObject, identifier); ASSERT(function.isCallable()); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto callData = JSC::getCallData(function); auto result = call(&lexicalGlobalObject, function, callData, thisValue, arguments); EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException()); @@ -174,7 +174,7 @@ void ReadableStream::cancel(const Exception& exception) auto& vm = lexicalGlobalObject.vm(); JSC::JSLockHolder lock(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value = createDOMException(&lexicalGlobalObject, exception.code(), exception.message()); if (scope.exception()) [[unlikely]] { ASSERT(vm.hasPendingTerminationException()); @@ -195,7 +195,7 @@ void ReadableStream::cancel(WebCore::JSDOMGlobalObject& globalObject, JSReadable auto& vm = globalObject.vm(); JSC::JSLockHolder lock(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value = createDOMException(&globalObject, exception.code(), exception.message()); if (scope.exception()) [[unlikely]] { ASSERT(vm.hasPendingTerminationException()); @@ -219,7 +219,7 @@ static inline bool checkReadableStream(JSDOMGlobalObject& globalObject, JSReadab ASSERT(!arguments.hasOverflowed()); auto& vm = lexicalGlobalObject.vm(); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto callData = JSC::getCallData(function); ASSERT(callData.type != JSC::CallData::Type::None); diff --git a/src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp b/src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp index 77d99afb6e..ca3c275425 100644 --- a/src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp +++ b/src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp @@ -31,7 +31,7 @@ #include "ReadableStreamDefaultController.h" #include "WebCoreJSClientData.h" -#include +#include #include #include #include @@ -44,7 +44,7 @@ static bool invokeReadableStreamDefaultControllerFunction(JSC::JSGlobalObject& l JSC::VM& vm = lexicalGlobalObject.vm(); JSC::JSLockHolder lock(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto function = lexicalGlobalObject.get(&lexicalGlobalObject, identifier); EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException()); @@ -74,7 +74,7 @@ void ReadableStreamDefaultController::error(const Exception& exception) JSC::JSGlobalObject& lexicalGlobalObject = this->globalObject(); auto& vm = lexicalGlobalObject.vm(); JSC::JSLockHolder lock(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto value = createDOMException(&lexicalGlobalObject, exception.code(), exception.message()); if (scope.exception()) [[unlikely]] { @@ -141,7 +141,7 @@ bool ReadableStreamDefaultController::enqueue(RefPtr&& buffer) JSC::JSGlobalObject& lexicalGlobalObject = this->globalObject(); auto& vm = lexicalGlobalObject.vm(); JSC::JSLockHolder lock(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto length = buffer->byteLength(); auto value = JSC::JSUint8Array::create(&lexicalGlobalObject, lexicalGlobalObject.typedArrayStructureWithTypedArrayType(), WTF::move(buffer), 0, length); diff --git a/src/bun.js/bindings/webcore/SerializedScriptValue.cpp b/src/bun.js/bindings/webcore/SerializedScriptValue.cpp index 56b2b2b7f6..a0746d530b 100644 --- a/src/bun.js/bindings/webcore/SerializedScriptValue.cpp +++ b/src/bun.js/bindings/webcore/SerializedScriptValue.cpp @@ -67,7 +67,7 @@ #include #include #include -#include +#include #include #include #include @@ -6147,7 +6147,7 @@ RefPtr SerializedScriptValue::create(JSContextRef originC JSGlobalObject* lexicalGlobalObject = toJS(originContext); auto& vm = JSC::getVM(lexicalGlobalObject); JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue value = toJS(lexicalGlobalObject, apiValue); auto serializedValue = SerializedScriptValue::create(*lexicalGlobalObject, value); @@ -6379,7 +6379,7 @@ JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, J JSGlobalObject* lexicalGlobalObject = toJS(destinationContext); auto& vm = JSC::getVM(lexicalGlobalObject); JSLockHolder locker(vm); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue value = deserialize(*lexicalGlobalObject, lexicalGlobalObject); if (scope.exception()) [[unlikely]] { diff --git a/src/bun.js/bindings/webcore/WebSocket.cpp b/src/bun.js/bindings/webcore/WebSocket.cpp index c1207d41c4..67d994b077 100644 --- a/src/bun.js/bindings/webcore/WebSocket.cpp +++ b/src/bun.js/bindings/webcore/WebSocket.cpp @@ -1343,7 +1343,7 @@ void WebSocket::didReceiveBinaryData(const AtomString& eventName, const std::spa if (this->hasEventListeners(eventName)) { // the main reason for dispatching on a separate tick is to handle when you haven't yet attached an event listener this->incPendingActivityCount(); - auto scope = DECLARE_CATCH_SCOPE(scriptExecutionContext()->vm()); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(scriptExecutionContext()->vm()); JSUint8Array* buffer = createBuffer(scriptExecutionContext()->jsGlobalObject(), binaryData); if (!buffer || scope.exception()) [[unlikely]] { diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index cd017e7fb3..a922b6b38a 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -476,7 +476,7 @@ pub fn processGCTimer(this: *EventLoop) void { pub fn tick(this: *EventLoop) void { jsc.markBinding(@src()); - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(this.global, @src()); defer scope.deinit(); this.entered_event_loop_count += 1; diff --git a/src/bun.js/jsc.zig b/src/bun.js/jsc.zig index b4f8cc51ab..ca434864f3 100644 --- a/src/bun.js/jsc.zig +++ b/src/bun.js/jsc.zig @@ -81,8 +81,8 @@ pub const Weak = @import("./Weak.zig").Weak; pub const WeakRefType = @import("./Weak.zig").WeakRefType; pub const Exception = @import("./bindings/Exception.zig").Exception; pub const SourceProvider = @import("./bindings/SourceProvider.zig").SourceProvider; -pub const CatchScope = @import("./bindings/CatchScope.zig").CatchScope; -pub const ExceptionValidationScope = @import("./bindings/CatchScope.zig").ExceptionValidationScope; +pub const TopExceptionScope = @import("./bindings/TopExceptionScope.zig").TopExceptionScope; +pub const ExceptionValidationScope = @import("./bindings/TopExceptionScope.zig").ExceptionValidationScope; pub const MarkedArgumentBuffer = @import("./bindings/MarkedArgumentBuffer.zig").MarkedArgumentBuffer; pub const RegularExpression = @import("./bindings/RegularExpression.zig").RegularExpression; diff --git a/src/bun.js/jsc/host_fn.zig b/src/bun.js/jsc/host_fn.zig index 738080a0f5..d5c5d4d0b1 100644 --- a/src/bun.js/jsc/host_fn.zig +++ b/src/bun.js/jsc/host_fn.zig @@ -107,7 +107,7 @@ pub fn toJSHostCall( /// The wrapped function must return an empty JSValue if and only if it has thrown an exception. /// If your function does not follow this pattern (if it can return empty without an exception, or /// throw an exception and return non-empty), either fix the function or write a custom wrapper with -/// CatchScope. +/// TopExceptionScope. pub fn fromJSHostCall( globalThis: *JSGlobalObject, /// For attributing thrown exceptions @@ -132,7 +132,7 @@ pub fn fromJSHostCallGeneric( comptime function: anytype, args: std.meta.ArgsTuple(@TypeOf(function)), ) error{JSError}!@typeInfo(@TypeOf(function)).@"fn".return_type.? { - var scope: jsc.CatchScope = undefined; + var scope: jsc.TopExceptionScope = undefined; scope.init(globalThis, src); defer scope.deinit(); diff --git a/src/bun.js/modules/BunTestModule.h b/src/bun.js/modules/BunTestModule.h index 5132416d88..4d2038d261 100644 --- a/src/bun.js/modules/BunTestModule.h +++ b/src/bun.js/modules/BunTestModule.h @@ -8,7 +8,7 @@ void generateNativeModule_BunTest( { auto& vm = JSC::getVM(lexicalGlobalObject); auto globalObject = jsCast(lexicalGlobalObject); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSObject* object = globalObject->lazyTestModuleObject(); @@ -19,16 +19,16 @@ void generateNativeModule_BunTest( // Also export all properties as named exports JSC::PropertyNameArrayBuilder properties(vm, JSC::PropertyNameMode::Strings, JSC::PrivateSymbolMode::Exclude); object->methodTable()->getOwnPropertyNames(object, lexicalGlobalObject, properties, JSC::DontEnumPropertiesMode::Exclude); - if (catchScope.exception()) [[unlikely]] { - (void)catchScope.tryClearException(); + if (topExceptionScope.exception()) [[unlikely]] { + (void)topExceptionScope.tryClearException(); return; } for (auto& property : properties.releaseData()->propertyNameVector()) { JSC::PropertySlot slot(object, JSC::PropertySlot::InternalMethodType::Get); auto ownPropertySlot = object->methodTable()->getOwnPropertySlot(object, lexicalGlobalObject, property, slot); - if (catchScope.exception()) [[unlikely]] { - (void)catchScope.tryClearException(); + if (topExceptionScope.exception()) [[unlikely]] { + (void)topExceptionScope.tryClearException(); } if (ownPropertySlot) { exportNames.append(property); diff --git a/src/bun.js/modules/NodeModuleModule.cpp b/src/bun.js/modules/NodeModuleModule.cpp index bd9c52c148..fd49baf2f3 100644 --- a/src/bun.js/modules/NodeModuleModule.cpp +++ b/src/bun.js/modules/NodeModuleModule.cpp @@ -1150,12 +1150,12 @@ void generateNativeModule_NodeModule(JSC::JSGlobalObject* lexicalGlobalObject, { Zig::GlobalObject* globalObject = defaultGlobalObject(lexicalGlobalObject); auto& vm = JSC::getVM(globalObject); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); auto* constructor = globalObject->m_nodeModuleConstructor.getInitializedOnMainThread(globalObject); if (constructor->hasNonReifiedStaticProperties()) { constructor->reifyAllStaticProperties(globalObject); - if (catchScope.exception()) { - (void)catchScope.tryClearException(); + if (topExceptionScope.exception()) { + (void)topExceptionScope.tryClearException(); } } @@ -1170,9 +1170,9 @@ void generateNativeModule_NodeModule(JSC::JSGlobalObject* lexicalGlobalObject, const auto& property = Identifier::fromString(vm, entry.m_key); JSValue value = constructor->get(globalObject, property); - if (catchScope.exception()) [[unlikely]] { + if (topExceptionScope.exception()) [[unlikely]] { value = {}; - (void)catchScope.tryClearException(); + (void)topExceptionScope.tryClearException(); } exportNames.append(property); diff --git a/src/bun.js/modules/NodeProcessModule.h b/src/bun.js/modules/NodeProcessModule.h index 8ad1750d86..6a0ce5818f 100644 --- a/src/bun.js/modules/NodeProcessModule.h +++ b/src/bun.js/modules/NodeProcessModule.h @@ -33,11 +33,11 @@ DEFINE_NATIVE_MODULE(NodeProcess) } exportNames.append(entry); - auto catchScope = DECLARE_CATCH_SCOPE(vm); + auto topExceptionScope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue result = process->get(globalObject, entry); - if (catchScope.exception()) { + if (topExceptionScope.exception()) { result = jsUndefined(); - (void)catchScope.tryClearException(); + (void)topExceptionScope.tryClearException(); } exportValues.append(result); diff --git a/src/bun.js/modules/NodeTTYModule.cpp b/src/bun.js/modules/NodeTTYModule.cpp index 3ea4c15316..b5a870a4a4 100644 --- a/src/bun.js/modules/NodeTTYModule.cpp +++ b/src/bun.js/modules/NodeTTYModule.cpp @@ -13,7 +13,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionTty_isatty, (JSGlobalObject * globalObject, C return JSValue::encode(jsBoolean(false)); } - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); int fd = callFrame->argument(0).toInt32(globalObject); RETURN_IF_EXCEPTION(scope, {}); diff --git a/src/bun.js/modules/NodeUtilTypesModule.cpp b/src/bun.js/modules/NodeUtilTypesModule.cpp index 5dc76db0a0..22e489b0b0 100644 --- a/src/bun.js/modules/NodeUtilTypesModule.cpp +++ b/src/bun.js/modules/NodeUtilTypesModule.cpp @@ -1,7 +1,7 @@ #include "BunClientData.h" #include "JSDOMWrapper.h" #include "JSEventTarget.h" -#include "JavaScriptCore/CatchScope.h" +#include "JavaScriptCore/TopExceptionScope.h" #include "_NativeModule.h" #include "napi_external.h" diff --git a/src/bun.js/modules/ObjectModule.cpp b/src/bun.js/modules/ObjectModule.cpp index 3f243e5a0c..442e1e4f7a 100644 --- a/src/bun.js/modules/ObjectModule.cpp +++ b/src/bun.js/modules/ObjectModule.cpp @@ -24,7 +24,7 @@ generateObjectModuleSourceCode(JSC::JSGlobalObject* globalObject, for (auto& entry : properties.releaseData()->propertyNameVector()) { exportNames.append(entry); - auto scope = DECLARE_CATCH_SCOPE(vm); + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm); JSValue value = object->get(globalObject, entry); if (scope.exception()) [[unlikely]] { (void)scope.tryClearException(); diff --git a/src/codegen/cppbind.ts b/src/codegen/cppbind.ts index fdbf44bb82..40d68c6527 100644 --- a/src/codegen/cppbind.ts +++ b/src/codegen/cppbind.ts @@ -670,7 +670,7 @@ function generateZigFn( resultBindings.push( `pub fn ${formatZigName(fn.name)}(${generateZigParameterList(fn.parameters, globalThisArg)}) error{JSError}!${returnType} {`, ` if (comptime Environment.ci_assert) {`, - ` var scope: jsc.CatchScope = undefined;`, + ` var scope: jsc.TopExceptionScope = undefined;`, ` scope.init(${formatZigName(globalThisArg.name)}, @src());`, ` defer scope.deinit();`, ``, diff --git a/src/codegen/generate-classes.ts b/src/codegen/generate-classes.ts index 1edfb6d7ba..74ce3b7422 100644 --- a/src/codegen/generate-classes.ts +++ b/src/codegen/generate-classes.ts @@ -1305,7 +1305,7 @@ JSC_DEFINE_HOST_FUNCTION(${symbolName(typeName, name)}Callback, (JSGlobalObject JSC::EncodedJSValue result = ${symbolName(typeName, fn)}(thisObject->wrapped(), lexicalGlobalObject, callFrame${proto[name].passThis ? ", JSValue::encode(thisObject)" : ""}); - ASSERT_WITH_MESSAGE(!JSValue::decode(result).isEmpty() or DECLARE_CATCH_SCOPE(vm).exception() != 0, \"${typeName}.${proto[name].fn} returned an empty value without an exception\"); + ASSERT_WITH_MESSAGE(!JSValue::decode(result).isEmpty() or DECLARE_TOP_EXCEPTION_SCOPE(vm).exception() != 0, \"${typeName}.${proto[name].fn} returned an empty value without an exception\"); ${ !proto[name].DOMJIT