From 69be630aeaef9887dd487fec937063a7967ae098 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 22 May 2025 21:12:43 -0700 Subject: [PATCH] WebKit Upgrade (#19839) Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Ben Grant Co-authored-by: 190n <7763597+190n@users.noreply.github.com> --- cmake/tools/SetupWebKit.cmake | 2 +- src/bake/BakeGlobalObject.cpp | 4 +- src/bake/BakeProduction.cpp | 2 +- src/bun.js/bindings/AsyncContextFrame.cpp | 4 +- src/bun.js/bindings/Base64Helpers.cpp | 4 +- src/bun.js/bindings/BunObject.cpp | 22 +- src/bun.js/bindings/BunPlugin.cpp | 4 +- src/bun.js/bindings/BunProcess.cpp | 26 +- src/bun.js/bindings/BunString.cpp | 38 +-- src/bun.js/bindings/ConsoleObject.cpp | 2 +- src/bun.js/bindings/Cookie.cpp | 6 +- src/bun.js/bindings/ErrorCode.cpp | 4 +- src/bun.js/bindings/ErrorStackTrace.cpp | 10 +- src/bun.js/bindings/GCDefferalContext.h | 2 +- src/bun.js/bindings/HTMLEntryPoint.cpp | 8 +- src/bun.js/bindings/ImportMetaObject.cpp | 26 +- .../bindings/InternalModuleRegistry.cpp | 2 +- src/bun.js/bindings/JSBuffer.cpp | 228 ++++++++++-------- src/bun.js/bindings/JSBufferEncodingType.cpp | 2 +- src/bun.js/bindings/JSBufferList.cpp | 30 +-- src/bun.js/bindings/JSBufferList.h | 4 +- src/bun.js/bindings/JSBundlerPlugin.cpp | 20 +- src/bun.js/bindings/JSCommonJSExtensions.cpp | 4 +- src/bun.js/bindings/JSCommonJSModule.cpp | 61 ++--- .../bindings/JSDOMExceptionHandling.cpp | 2 +- src/bun.js/bindings/JSDOMExceptionHandling.h | 6 +- src/bun.js/bindings/JSDOMFile.cpp | 2 +- src/bun.js/bindings/JSDOMWrapperCache.h | 2 +- .../bindings/JSEnvironmentVariableMap.cpp | 18 +- src/bun.js/bindings/JSFFIFunction.cpp | 20 +- src/bun.js/bindings/JSMockFunction.cpp | 24 +- src/bun.js/bindings/JSPropertyIterator.cpp | 8 +- src/bun.js/bindings/JSStringDecoder.cpp | 14 +- src/bun.js/bindings/JSValue.zig | 55 ++--- src/bun.js/bindings/JSX509Certificate.cpp | 6 +- .../bindings/JSX509CertificatePrototype.cpp | 52 ++-- src/bun.js/bindings/ModuleLoader.cpp | 17 +- src/bun.js/bindings/NodeDirent.cpp | 6 +- src/bun.js/bindings/NodeHTTP.cpp | 14 +- src/bun.js/bindings/NodeTimerObject.cpp | 4 +- src/bun.js/bindings/NodeVM.cpp | 34 +-- src/bun.js/bindings/ObjectBindings.cpp | 6 +- src/bun.js/bindings/ProcessBindingTTYWrap.cpp | 4 +- src/bun.js/bindings/ProcessBindingUV.cpp | 2 +- src/bun.js/bindings/SQLClient.cpp | 20 +- src/bun.js/bindings/Uint8Array.cpp | 4 +- src/bun.js/bindings/Weak.cpp | 2 +- src/bun.js/bindings/ZigGlobalObject.cpp | 105 ++++---- src/bun.js/bindings/bindings.cpp | 92 +++---- src/bun.js/bindings/c-bindings.cpp | 6 +- src/bun.js/bindings/debug-helpers.h | 2 +- .../bindings/decodeURIComponentSIMD.cpp | 2 +- src/bun.js/bindings/helpers.h | 27 ++- src/bun.js/bindings/napi.cpp | 36 +-- src/bun.js/bindings/napi.h | 2 +- src/bun.js/bindings/node/NodeTimers.cpp | 10 +- .../node/crypto/CryptoGenDhKeyPair.cpp | 4 +- .../bindings/node/crypto/CryptoPrimes.cpp | 8 +- .../bindings/node/crypto/CryptoSignJob.cpp | 2 +- .../bindings/node/crypto/CryptoUtil.cpp | 4 +- .../node/crypto/DiffieHellmanFunctions.h | 16 +- .../node/crypto/JSCipherConstructor.cpp | 4 +- .../bindings/node/crypto/JSDiffieHellman.cpp | 2 +- .../JSDiffieHellmanGroupConstructor.cpp | 2 +- src/bun.js/bindings/node/crypto/JSHash.cpp | 2 +- src/bun.js/bindings/node/crypto/JSHmac.cpp | 2 +- .../node/crypto/JSKeyObjectConstructor.cpp | 2 +- src/bun.js/bindings/node/crypto/JSSign.cpp | 8 +- src/bun.js/bindings/node/crypto/JSVerify.cpp | 6 +- src/bun.js/bindings/node/crypto/KeyObject.cpp | 6 +- src/bun.js/bindings/root.h | 3 + src/bun.js/bindings/sqlite/JSSQLStatement.cpp | 120 ++++----- .../bindings/webcore/BroadcastChannel.cpp | 2 +- src/bun.js/bindings/webcore/BufferSource.h | 2 +- src/bun.js/bindings/webcore/EventContext.cpp | 2 +- src/bun.js/bindings/webcore/EventEmitter.cpp | 14 +- .../bindings/webcore/EventListenerMap.cpp | 2 +- src/bun.js/bindings/webcore/EventPath.cpp | 14 +- src/bun.js/bindings/webcore/EventTarget.cpp | 8 +- src/bun.js/bindings/webcore/HTTPParsers.cpp | 2 +- .../webcore/IdentifierEventListenerMap.cpp | 2 +- .../webcore/InternalWritableStream.cpp | 4 +- .../bindings/webcore/JSAbortController.cpp | 4 +- src/bun.js/bindings/webcore/JSAbortSignal.cpp | 10 +- .../bindings/webcore/JSAbortSignalCustom.cpp | 10 +- .../webcore/JSAddEventListenerOptions.cpp | 2 +- .../bindings/webcore/JSBroadcastChannel.cpp | 10 +- .../webcore/JSByteLengthQueuingStrategy.cpp | 2 +- .../bindings/webcore/JSCallbackData.cpp | 4 +- src/bun.js/bindings/webcore/JSCloseEvent.cpp | 6 +- src/bun.js/bindings/webcore/JSCookie.cpp | 52 ++-- src/bun.js/bindings/webcore/JSCookieMap.cpp | 6 +- .../webcore/JSCountQueuingStrategy.cpp | 2 +- src/bun.js/bindings/webcore/JSCustomEvent.cpp | 8 +- src/bun.js/bindings/webcore/JSDOMAttribute.h | 6 +- .../webcore/JSDOMBuiltinConstructor.h | 6 +- .../bindings/webcore/JSDOMConvertBase.h | 12 +- .../webcore/JSDOMConvertBufferSource.h | 2 +- .../webcore/JSDOMConvertEnumeration.h | 2 +- .../webcore/JSDOMConvertEventListener.h | 2 +- .../bindings/webcore/JSDOMConvertInterface.h | 2 +- .../bindings/webcore/JSDOMConvertNumbers.h | 14 +- .../bindings/webcore/JSDOMConvertRecord.h | 2 +- .../bindings/webcore/JSDOMConvertSequences.h | 10 +- .../bindings/webcore/JSDOMConvertStrings.cpp | 10 +- .../bindings/webcore/JSDOMException.cpp | 2 +- src/bun.js/bindings/webcore/JSDOMFormData.cpp | 14 +- src/bun.js/bindings/webcore/JSDOMIterator.h | 4 +- .../bindings/webcore/JSDOMOperation.cpp | 6 +- src/bun.js/bindings/webcore/JSDOMOperation.h | 2 +- .../webcore/JSDOMOperationReturningPromise.h | 5 +- .../bindings/webcore/JSDOMPromiseDeferred.cpp | 10 +- .../bindings/webcore/JSDOMPromiseDeferred.h | 4 +- src/bun.js/bindings/webcore/JSDOMURL.cpp | 14 +- src/bun.js/bindings/webcore/JSErrorEvent.cpp | 6 +- src/bun.js/bindings/webcore/JSEvent.cpp | 8 +- .../bindings/webcore/JSEventEmitter.cpp | 34 +-- .../bindings/webcore/JSEventEmitterCustom.cpp | 4 +- .../bindings/webcore/JSEventEmitterCustom.h | 3 +- src/bun.js/bindings/webcore/JSEventInit.cpp | 2 +- .../bindings/webcore/JSEventListener.cpp | 8 +- .../webcore/JSEventListenerOptions.cpp | 2 +- .../bindings/webcore/JSEventModifierInit.cpp | 2 +- src/bun.js/bindings/webcore/JSEventTarget.cpp | 12 +- .../bindings/webcore/JSEventTargetCustom.h | 3 +- .../bindings/webcore/JSEventTargetNode.cpp | 2 +- .../bindings/webcore/JSFetchHeaders.cpp | 22 +- src/bun.js/bindings/webcore/JSMIMEParams.cpp | 18 +- src/bun.js/bindings/webcore/JSMIMEType.cpp | 16 +- .../bindings/webcore/JSMessageChannel.cpp | 4 +- .../bindings/webcore/JSMessageEvent.cpp | 8 +- src/bun.js/bindings/webcore/JSMessagePort.cpp | 6 +- src/bun.js/bindings/webcore/JSPerformance.cpp | 14 +- .../bindings/webcore/JSPerformanceEntry.cpp | 2 +- .../bindings/webcore/JSPerformanceMark.cpp | 6 +- .../webcore/JSPerformanceMarkOptions.cpp | 2 +- .../bindings/webcore/JSPerformanceMeasure.cpp | 2 +- .../webcore/JSPerformanceMeasureOptions.cpp | 2 +- .../webcore/JSPerformanceObserver.cpp | 10 +- .../webcore/JSPerformanceObserverCustom.cpp | 2 +- .../JSPerformanceObserverEntryList.cpp | 6 +- .../webcore/JSPerformanceResourceTiming.cpp | 2 +- .../webcore/JSPerformanceServerTiming.cpp | 2 +- .../bindings/webcore/JSPerformanceTiming.cpp | 2 +- .../JSReadableByteStreamController.cpp | 2 +- .../bindings/webcore/JSReadableStream.cpp | 2 +- .../webcore/JSReadableStreamBYOBReader.cpp | 2 +- .../webcore/JSReadableStreamBYOBRequest.cpp | 2 +- .../JSReadableStreamDefaultController.cpp | 2 +- .../webcore/JSReadableStreamDefaultReader.cpp | 2 +- .../bindings/webcore/JSReadableStreamSink.cpp | 4 +- .../webcore/JSReadableStreamSource.cpp | 2 +- .../webcore/JSStructuredSerializeOptions.cpp | 2 +- .../bindings/webcore/JSTextDecoderStream.cpp | 2 +- src/bun.js/bindings/webcore/JSTextEncoder.cpp | 10 +- .../bindings/webcore/JSTextEncoderStream.cpp | 2 +- .../bindings/webcore/JSTransformStream.cpp | 2 +- .../JSTransformStreamDefaultController.cpp | 2 +- .../bindings/webcore/JSURLSearchParams.cpp | 16 +- src/bun.js/bindings/webcore/JSWebSocket.cpp | 12 +- src/bun.js/bindings/webcore/JSWorker.cpp | 10 +- .../bindings/webcore/JSWorkerOptions.cpp | 2 +- .../bindings/webcore/JSWritableStream.cpp | 2 +- .../JSWritableStreamDefaultController.cpp | 2 +- .../webcore/JSWritableStreamDefaultWriter.cpp | 2 +- .../bindings/webcore/JSWritableStreamSink.cpp | 6 +- src/bun.js/bindings/webcore/MessageEvent.cpp | 2 +- src/bun.js/bindings/webcore/MessagePort.cpp | 2 +- .../bindings/webcore/ReadableStream.cpp | 4 +- .../ReadableStreamDefaultController.cpp | 4 +- .../webcore/SerializedScriptValue.cpp | 60 ++--- .../webcore/WebCoreTypedArrayController.cpp | 2 +- src/bun.js/bindings/webcore/WebSocket.cpp | 10 +- src/bun.js/bindings/webcore/Worker.cpp | 2 +- .../bindings/webcrypto/JSAesCbcCfbParams.cpp | 2 +- .../bindings/webcrypto/JSAesCtrParams.cpp | 2 +- .../bindings/webcrypto/JSAesGcmParams.cpp | 2 +- .../bindings/webcrypto/JSAesKeyParams.cpp | 2 +- .../webcrypto/JSCryptoAesKeyAlgorithm.cpp | 2 +- .../webcrypto/JSCryptoAlgorithmParameters.cpp | 2 +- .../webcrypto/JSCryptoEcKeyAlgorithm.cpp | 2 +- .../webcrypto/JSCryptoHmacKeyAlgorithm.cpp | 2 +- src/bun.js/bindings/webcrypto/JSCryptoKey.cpp | 6 +- .../webcrypto/JSCryptoKeyAlgorithm.cpp | 2 +- .../bindings/webcrypto/JSCryptoKeyPair.cpp | 2 +- .../bindings/webcrypto/JSCryptoKeyUsage.cpp | 2 +- .../JSCryptoRsaHashedKeyAlgorithm.cpp | 2 +- .../webcrypto/JSCryptoRsaKeyAlgorithm.cpp | 2 +- .../bindings/webcrypto/JSEcKeyParams.cpp | 2 +- .../webcrypto/JSEcdhKeyDeriveParams.cpp | 2 +- .../bindings/webcrypto/JSEcdsaParams.cpp | 2 +- .../bindings/webcrypto/JSHkdfParams.cpp | 2 +- .../bindings/webcrypto/JSHmacKeyParams.cpp | 2 +- .../bindings/webcrypto/JSJsonWebKey.cpp | 2 +- .../bindings/webcrypto/JSPbkdf2Params.cpp | 2 +- .../webcrypto/JSRsaHashedImportParams.cpp | 2 +- .../webcrypto/JSRsaHashedKeyGenParams.cpp | 2 +- .../bindings/webcrypto/JSRsaKeyGenParams.cpp | 2 +- .../bindings/webcrypto/JSRsaOaepParams.cpp | 2 +- .../webcrypto/JSRsaOtherPrimesInfo.cpp | 2 +- .../bindings/webcrypto/JSRsaPssParams.cpp | 2 +- .../bindings/webcrypto/JSSubtleCrypto.cpp | 32 +-- .../bindings/webcrypto/SubtleCrypto.cpp | 6 +- src/bun.js/modules/BunJSCModule.h | 6 +- src/bun.js/modules/NodeBufferModule.h | 8 +- src/bun.js/modules/NodeModuleModule.cpp | 4 +- src/bun.js/modules/NodeUtilTypesModule.cpp | 2 +- src/codegen/bindgen.ts | 4 +- src/codegen/generate-classes.ts | 22 +- src/codegen/generate-jssink.ts | 4 +- src/io/io_darwin.cpp | 6 +- src/js/builtins/BunBuiltinNames.h | 2 +- test/js/node/buffer.test.js | 16 ++ 213 files changed, 1126 insertions(+), 1039 deletions(-) diff --git a/cmake/tools/SetupWebKit.cmake b/cmake/tools/SetupWebKit.cmake index ad92845801..d48552420b 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 eda8b0fb4fb1aa23db9c2b00933df8b58bcdd289) + set(WEBKIT_VERSION 754692aa9c30218d1e81444670f5e4649426b157) endif() string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX) diff --git a/src/bake/BakeGlobalObject.cpp b/src/bake/BakeGlobalObject.cpp index b482b0214b..33f44c737b 100644 --- a/src/bake/BakeGlobalObject.cpp +++ b/src/bake/BakeGlobalObject.cpp @@ -104,11 +104,11 @@ JSC::JSInternalPromise* bakeModuleLoaderFetch(JSC::JSGlobalObject* globalObject, auto& vm = JSC::getVM(globalObject); auto scope = DECLARE_THROW_SCOPE(vm); auto moduleKey = key.toWTFString(globalObject); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return rejectedInternalPromise(globalObject, scope.exception()->value()); if (moduleKey.startsWith("bake:/"_s)) { - if (LIKELY(global->m_perThreadData)) { + if (global->m_perThreadData) [[likely]] { BunString source = BakeProdLoad(global->m_perThreadData, Bun::toString(moduleKey)); if (source.tag != BunStringTag::Dead) { JSC::SourceOrigin origin = JSC::SourceOrigin(WTF::URL(moduleKey)); diff --git a/src/bake/BakeProduction.cpp b/src/bake/BakeProduction.cpp index 5d2a867200..d6c05b4779 100644 --- a/src/bake/BakeProduction.cpp +++ b/src/bake/BakeProduction.cpp @@ -40,7 +40,7 @@ extern "C" JSC::JSPromise* BakeRenderRoutesForProdStatic( NakedPtr returnedException = nullptr; auto result = JSC::profiledCall(global, JSC::ProfilingReason::API, cb, callData, JSC::jsUndefined(), args, returnedException); - if (UNLIKELY(returnedException)) { + if (returnedException) [[unlikely]] { // This should be impossible because it returns a promise. return JSC::JSPromise::rejectedPromise(global, returnedException->value()); } diff --git a/src/bun.js/bindings/AsyncContextFrame.cpp b/src/bun.js/bindings/AsyncContextFrame.cpp index c9ceac6b06..3fcca2555b 100644 --- a/src/bun.js/bindings/AsyncContextFrame.cpp +++ b/src/bun.js/bindings/AsyncContextFrame.cpp @@ -97,7 +97,7 @@ extern "C" JSC::EncodedJSValue AsyncContextFrame__withAsyncContextIfNeeded(JSGlo // } JSValue AsyncContextFrame::call(JSGlobalObject* global, JSValue functionObject, JSValue thisValue, const ArgList& args) { - if (LIKELY(!global->isAsyncContextTrackingEnabled())) { + if (!global->isAsyncContextTrackingEnabled()) [[likely]] { return JSC::profiledCall(global, ProfilingReason::API, functionObject, JSC::getCallData(functionObject), thisValue, args); } @@ -105,7 +105,7 @@ JSValue AsyncContextFrame::call(JSGlobalObject* global, JSValue functionObject, } JSValue AsyncContextFrame::call(JSGlobalObject* global, JSValue functionObject, JSValue thisValue, const ArgList& args, NakedPtr& returnedException) { - if (LIKELY(!global->isAsyncContextTrackingEnabled())) { + if (!global->isAsyncContextTrackingEnabled()) [[likely]] { return JSC::profiledCall(global, ProfilingReason::API, functionObject, JSC::getCallData(functionObject), thisValue, args, returnedException); } diff --git a/src/bun.js/bindings/Base64Helpers.cpp b/src/bun.js/bindings/Base64Helpers.cpp index c0088a5830..d7996921d7 100644 --- a/src/bun.js/bindings/Base64Helpers.cpp +++ b/src/bun.js/bindings/Base64Helpers.cpp @@ -20,7 +20,7 @@ ExceptionOr atob(const String& encodedString) size_t expected_length = simdutf::latin1_length_from_utf16(span.size()); std::span ptr; WTF::String convertedString = WTF::String::tryCreateUninitialized(expected_length, ptr); - if (UNLIKELY(convertedString.isNull())) { + if (convertedString.isNull()) [[unlikely]] { return WebCore::Exception { OutOfMemoryError }; } @@ -36,7 +36,7 @@ ExceptionOr atob(const String& encodedString) size_t result_length = simdutf::maximal_binary_length_from_base64(reinterpret_cast(span.data()), encodedString.length()); std::span ptr; WTF::String outString = WTF::String::tryCreateUninitialized(result_length, ptr); - if (UNLIKELY(outString.isNull())) { + if (outString.isNull()) [[unlikely]] { return WebCore::Exception { OutOfMemoryError }; } auto result = simdutf::base64_to_binary(reinterpret_cast(span.data()), span.size(), reinterpret_cast(ptr.data()), simdutf::base64_default); diff --git a/src/bun.js/bindings/BunObject.cpp b/src/bun.js/bindings/BunObject.cpp index 49ed4f5153..8f24d751b3 100644 --- a/src/bun.js/bindings/BunObject.cpp +++ b/src/bun.js/bindings/BunObject.cpp @@ -103,7 +103,7 @@ static inline JSC::EncodedJSValue flattenArrayOfBuffersIntoArrayBufferOrUint8Arr auto throwScope = DECLARE_THROW_SCOPE(vm); auto array = JSC::jsDynamicCast(arrayValue); - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { throwTypeError(lexicalGlobalObject, throwScope, "Argument must be an array"_s); return {}; } @@ -133,7 +133,7 @@ static inline JSC::EncodedJSValue flattenArrayOfBuffersIntoArrayBufferOrUint8Arr // This is a small optimization MarkedArgumentBuffer args; args.ensureCapacity(arrayLength); - if (UNLIKELY(args.hasOverflowed())) { + if (args.hasOverflowed()) [[unlikely]] { throwOutOfMemoryError(lexicalGlobalObject, throwScope); return {}; } @@ -143,7 +143,7 @@ static inline JSC::EncodedJSValue flattenArrayOfBuffersIntoArrayBufferOrUint8Arr RETURN_IF_EXCEPTION(throwScope, {}); if (auto* typedArray = JSC::jsDynamicCast(element)) { - if (UNLIKELY(typedArray->isDetached())) { + if (typedArray->isDetached()) [[unlikely]] { return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject, "Cannot validate on a detached buffer"_s); } size_t current = typedArray->byteLength(); @@ -155,7 +155,7 @@ static inline JSC::EncodedJSValue flattenArrayOfBuffersIntoArrayBufferOrUint8Arr } } else if (auto* arrayBuffer = JSC::jsDynamicCast(element)) { auto* impl = arrayBuffer->impl(); - if (UNLIKELY(!impl)) { + if (!impl) [[unlikely]] { return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject, "Cannot validate on a detached buffer"_s); } @@ -179,7 +179,7 @@ static inline JSC::EncodedJSValue flattenArrayOfBuffersIntoArrayBufferOrUint8Arr } auto buffer = JSC::ArrayBuffer::tryCreateUninitialized(byteLength, 1); - if (UNLIKELY(!buffer)) { + if (!buffer) [[unlikely]] { throwTypeError(lexicalGlobalObject, throwScope, "Failed to allocate ArrayBuffer"_s); return {}; } @@ -239,7 +239,7 @@ JSC_DEFINE_HOST_FUNCTION(functionConcatTypedArrays, (JSGlobalObject * globalObje auto& vm = JSC::getVM(globalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(callFrame->argumentCount() < 1)) { + if (callFrame->argumentCount() < 1) [[unlikely]] { throwTypeError(globalObject, throwScope, "Expected at least one argument"_s); return {}; } @@ -351,7 +351,7 @@ static JSValue constructBunShell(VM& vm, JSObject* bunObject) JSC::JSValue shell = JSC::call(globalObject, createShellFn, args, "BunShell"_s); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(!shell.isObject())) { + if (!shell.isObject()) [[unlikely]] { throwTypeError(globalObject, scope, "Internal error: BunShell constructor did not return an object"_s); return {}; } @@ -359,7 +359,7 @@ static JSValue constructBunShell(VM& vm, JSObject* bunObject) auto* bunShell = shell.getObject(); auto ShellError = bunShell->get(globalObject, JSC::Identifier::fromString(vm, "ShellError"_s)); - if (UNLIKELY(!ShellError.isObject())) { + if (!ShellError.isObject()) [[unlikely]] { throwTypeError(globalObject, scope, "Internal error: BunShell.ShellError is not an object"_s); return {}; } @@ -644,7 +644,7 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj } /// cannot turn non-`file://` URLs into file paths - if (UNLIKELY(!url.protocolIsFile())) { + if (!url.protocolIsFile()) [[unlikely]] { Bun::ERR::INVALID_URL_SCHEME(scope, globalObject, "file"_s); return {}; } @@ -655,7 +655,7 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj #if !OS(WINDOWS) // file://host/path is illegal if `host` is not `localhost`. // Should be `file:///` instead - if (UNLIKELY(url.host().length() > 0 && url.host() != "localhost"_s)) { + if (url.host().length() > 0 && url.host() != "localhost"_s) [[unlikely]] { #if OS(DARWIN) Bun::ERR::INVALID_FILE_URL_HOST(scope, globalObject, "darwin"_s); @@ -918,7 +918,7 @@ void generateNativeModule_BunObject(JSC::JSGlobalObject* lexicalGlobalObject, auto* object = globalObject->bunObject(); // :'( - if (LIKELY(object->hasNonReifiedStaticProperties())) { + if (object->hasNonReifiedStaticProperties()) [[likely]] { object->reifyAllStaticProperties(lexicalGlobalObject); } diff --git a/src/bun.js/bindings/BunPlugin.cpp b/src/bun.js/bindings/BunPlugin.cpp index 1fb8fed838..de64d26307 100644 --- a/src/bun.js/bindings/BunPlugin.cpp +++ b/src/bun.js/bindings/BunPlugin.cpp @@ -489,7 +489,7 @@ extern "C" JSC_DEFINE_HOST_FUNCTION(JSMock__jsModuleMock, (JSC::JSGlobalObject * auto& vm = JSC::getVM(lexicalGlobalObject); Zig::GlobalObject* globalObject = defaultGlobalObject(lexicalGlobalObject); auto scope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(!globalObject)) { + if (!globalObject) [[unlikely]] { scope.throwException(lexicalGlobalObject, JSC::createTypeError(lexicalGlobalObject, "Cannot run mock from a different global context"_s)); return {}; } @@ -783,7 +783,7 @@ EncodedJSValue BunPlugin::OnResolve::run(JSC::JSGlobalObject* globalObject, BunS continue; } auto* function = callbacks[i].get(); - if (UNLIKELY(!function)) { + if (!function) [[unlikely]] { continue; } diff --git a/src/bun.js/bindings/BunProcess.cpp b/src/bun.js/bindings/BunProcess.cpp index 87a14c5c5c..b70b4c00bc 100644 --- a/src/bun.js/bindings/BunProcess.cpp +++ b/src/bun.js/bindings/BunProcess.cpp @@ -387,7 +387,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb JSC::JSValue moduleValue = callFrame->uncheckedArgument(0); JSC::JSObject* moduleObject = jsDynamicCast(moduleValue); - if (UNLIKELY(!moduleObject)) { + if (!moduleObject) [[unlikely]] { JSC::throwTypeError(globalObject, scope, "dlopen requires an object as first argument"_s); return {}; } @@ -395,7 +395,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb JSValue exports = moduleObject->getIfPropertyExists(globalObject, builtinNames(vm).exportsPublicName()); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(!exports)) { + if (!exports) [[unlikely]] { JSC::throwTypeError(globalObject, scope, "dlopen requires an object with an exports property"_s); return {}; } @@ -487,7 +487,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb { auto utf8_filename = filename.tryGetUTF8(ConversionMode::LenientConversion); - if (UNLIKELY(!utf8_filename)) { + if (!utf8_filename) [[unlikely]] { JSC::throwTypeError(globalObject, scope, "process.dlopen requires a valid UTF-8 string for the filename"_s); return {}; } @@ -594,7 +594,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb dlclose(handle); #endif - if (LIKELY(!scope.exception())) { + if (!scope.exception()) [[likely]] { JSC::throwTypeError(globalObject, scope, "symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?"_s); } return {}; @@ -843,7 +843,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionHRTime, (JSC::JSGlobalObject * globalOb } } - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { JSC::throwOutOfMemoryError(globalObject, throwScope); return {}; } @@ -1052,11 +1052,11 @@ void signalHandler(uv_signal_t* signal, int signalNumber) #endif { #if OS(WINDOWS) - if (UNLIKELY(signalNumberToNameMap->find(signalNumber) == signalNumberToNameMap->end())) + if (signalNumberToNameMap->find(signalNumber) == signalNumberToNameMap->end()) [[unlikely]] return; auto* context = ScriptExecutionContext::getMainThreadScriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return; // signal handlers can be run on any thread context->postTaskConcurrently([signalNumber](ScriptExecutionContext& context) { @@ -1297,7 +1297,7 @@ static void onDidChangeListeners(EventEmitter& eventEmitter, const Identifier& e signalNumber, &signalHandler); - if (UNLIKELY(!signal_handle.handle)) + if (!signal_handle.handle) [[unlikely]] return; #endif @@ -2739,7 +2739,7 @@ static Process* getProcessObject(JSC::JSGlobalObject* lexicalGlobalObject, JSVal Process* process = jsDynamicCast(thisValue); // Handle "var memoryUsage = process.memoryUsage; memoryUsage()" - if (UNLIKELY(!process)) { + if (!process) [[unlikely]] { // Handle calling this function from inside a node:vm Zig::GlobalObject* zigGlobalObject = defaultGlobalObject(lexicalGlobalObject); @@ -2828,14 +2828,14 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionCpuUsage, (JSC::JSGlobalObject * global JSValue comparatorValue = callFrame->argument(0); if (!comparatorValue.isUndefined()) { JSC::JSObject* comparator = comparatorValue.getObject(); - if (UNLIKELY(!comparator)) { + if (!comparator) [[unlikely]] { return Bun::ERR::INVALID_ARG_TYPE(throwScope, globalObject, "prevValue"_s, "object"_s, comparatorValue); } JSValue userValue; JSValue systemValue; - if (LIKELY(comparator->structureID() == cpuUsageStructure->id())) { + if (comparator->structureID() == cpuUsageStructure->id()) [[likely]] { userValue = comparator->getDirect(0); systemValue = comparator->getDirect(1); } else { @@ -2977,7 +2977,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionMemoryUsage, (JSC::JSGlobalObject * glo } JSC::JSObject* result = JSC::constructEmptyObject(vm, process->memoryUsageStructure()); - if (UNLIKELY(throwScope.exception())) { + if (throwScope.exception()) [[unlikely]] { return {}; } @@ -3047,7 +3047,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionOpenStdin, (JSGlobalObject * globalObje RETURN_IF_EXCEPTION(throwScope, {}); if (!resumeValue.isUndefinedOrNull()) { auto resumeFunction = jsDynamicCast(resumeValue); - if (UNLIKELY(!resumeFunction)) { + if (!resumeFunction) [[unlikely]] { throwTypeError(globalObject, throwScope, "stdin.resume is not a function"_s); return {}; } diff --git a/src/bun.js/bindings/BunString.cpp b/src/bun.js/bindings/BunString.cpp index b58b5312af..6cd88f9c8d 100644 --- a/src/bun.js/bindings/BunString.cpp +++ b/src/bun.js/bindings/BunString.cpp @@ -70,7 +70,12 @@ extern "C" BunString BunString__createAtom(const char* bytes, size_t length) ASSERT(simdutf::validate_ascii(bytes, length)); auto atom = tryMakeAtomString(String(StringImpl::createWithoutCopying({ bytes, length }))); atom.impl()->ref(); +// Ignore the warning about returning a stack address +// This is safe because we've ref'd the atom.impl() which will keep it alive +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-stack-address" return { BunStringTag::WTFStringImpl, { .wtf = atom.impl() } }; +#pragma clang diagnostic pop } extern "C" BunString BunString__tryCreateAtom(const char* bytes, size_t length) @@ -80,7 +85,12 @@ extern "C" BunString BunString__tryCreateAtom(const char* bytes, size_t length) if (atom.isNull()) return { BunStringTag::Dead, {} }; atom.impl()->ref(); + // Ignore the warning about returning a stack address +// This is safe because we've ref'd the atom.impl() which will keep it alive +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-stack-address" return { BunStringTag::WTFStringImpl, { .wtf = atom.impl() } }; +#pragma clang diagnostic pop } return { BunStringTag::Dead, {} }; @@ -98,7 +108,7 @@ extern "C" JSC::EncodedJSValue BunString__createUTF8ForJS(JSC::JSGlobalObject* g } auto str = WTF::String::fromUTF8ReplacingInvalidSequences(std::span { reinterpret_cast(ptr), length }); - if (UNLIKELY(str.isNull())) { + if (str.isNull()) [[unlikely]] { throwOutOfMemoryError(globalObject, scope); return JSC::EncodedJSValue(); } @@ -110,11 +120,11 @@ extern "C" JSC::EncodedJSValue BunString__transferToJS(BunString* bunString, JSC auto& vm = JSC::getVM(globalObject); auto scope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(bunString->tag == BunStringTag::Empty || bunString->tag == BunStringTag::Dead)) { + if (bunString->tag == BunStringTag::Empty || bunString->tag == BunStringTag::Dead) [[unlikely]] { return JSValue::encode(JSC::jsEmptyString(vm)); } - if (LIKELY(bunString->tag == BunStringTag::WTFStringImpl)) { + if (bunString->tag == BunStringTag::WTFStringImpl) [[likely]] { #if ASSERT_ENABLED unsigned refCount = bunString->impl.wtf->refCount(); ASSERT(refCount > 0 && !bunString->impl.wtf->isEmpty()); @@ -180,10 +190,10 @@ BunString toString(const char* bytes, size_t length) BunString fromJS(JSC::JSGlobalObject* globalObject, JSValue value) { WTF::String str = value.toWTFString(globalObject); - if (UNLIKELY(str.isNull())) { + if (str.isNull()) [[unlikely]] { return { BunStringTag::Dead }; } - if (UNLIKELY(str.length() == 0)) { + if (str.length() == 0) [[unlikely]] { return { BunStringTag::Empty }; } @@ -210,10 +220,10 @@ BunString toString(JSC::JSGlobalObject* globalObject, JSValue value) BunString toStringRef(JSC::JSGlobalObject* globalObject, JSValue value) { auto str = value.toWTFString(globalObject); - if (UNLIKELY(str.isNull())) { + if (str.isNull()) [[unlikely]] { return { BunStringTag::Dead }; } - if (UNLIKELY(str.length() == 0)) { + if (str.length() == 0) [[unlikely]] { return { BunStringTag::Empty }; } @@ -292,7 +302,7 @@ extern "C" BunString BunString__fromUTF16Unitialized(size_t length) ASSERT(length > 0); std::span ptr; auto impl = WTF::StringImpl::tryCreateUninitialized(length, ptr); - if (UNLIKELY(!impl)) { + if (!impl) [[unlikely]] { return { .tag = BunStringTag::Dead }; } return { BunStringTag::WTFStringImpl, { .wtf = impl.leakRef() } }; @@ -303,7 +313,7 @@ extern "C" BunString BunString__fromLatin1Unitialized(size_t length) ASSERT(length > 0); std::span ptr; auto impl = WTF::StringImpl::tryCreateUninitialized(length, ptr); - if (UNLIKELY(!impl)) { + if (!impl) [[unlikely]] { return { .tag = BunStringTag::Dead }; } return { BunStringTag::WTFStringImpl, { .wtf = impl.leakRef() } }; @@ -316,7 +326,7 @@ extern "C" BunString BunString__fromUTF8(const char* bytes, size_t length) size_t u16Length = simdutf::utf16_length_from_utf8(bytes, length); std::span ptr; auto impl = WTF::StringImpl::tryCreateUninitialized(static_cast(u16Length), ptr); - if (UNLIKELY(!impl)) { + if (!impl) [[unlikely]] { return { .tag = BunStringTag::Dead }; } RELEASE_ASSERT(simdutf::convert_utf8_to_utf16(bytes, length, ptr.data()) == u16Length); @@ -324,7 +334,7 @@ extern "C" BunString BunString__fromUTF8(const char* bytes, size_t length) } auto str = WTF::String::fromUTF8ReplacingInvalidSequences(std::span { reinterpret_cast(bytes), length }); - if (UNLIKELY(str.isNull())) { + if (str.isNull()) [[unlikely]] { return { .tag = BunStringTag::Dead }; } auto impl = str.releaseImpl(); @@ -336,7 +346,7 @@ extern "C" BunString BunString__fromLatin1(const char* bytes, size_t length) ASSERT(length > 0); std::span ptr; auto impl = WTF::StringImpl::tryCreateUninitialized(length, ptr); - if (UNLIKELY(!impl)) { + if (!impl) [[unlikely]] { return { .tag = BunStringTag::Dead }; } memcpy(ptr.data(), bytes, length); @@ -351,7 +361,7 @@ extern "C" BunString BunString__fromUTF16ToLatin1(const char16_t* bytes, size_t size_t outLength = simdutf::latin1_length_from_utf16(length); std::span ptr; auto impl = WTF::StringImpl::tryCreateUninitialized(outLength, ptr); - if (UNLIKELY(!impl)) { + if (!impl) [[unlikely]] { return { BunStringTag::Dead }; } @@ -365,7 +375,7 @@ extern "C" BunString BunString__fromUTF16(const char16_t* bytes, size_t length) ASSERT(length > 0); std::span ptr; auto impl = WTF::StringImpl::tryCreateUninitialized(length, ptr); - if (UNLIKELY(!impl)) { + if (!impl) [[unlikely]] { return { .tag = BunStringTag::Dead }; } memcpy(ptr.data(), bytes, length * sizeof(char16_t)); diff --git a/src/bun.js/bindings/ConsoleObject.cpp b/src/bun.js/bindings/ConsoleObject.cpp index 7bd750f6bd..beecfc84a1 100644 --- a/src/bun.js/bindings/ConsoleObject.cpp +++ b/src/bun.js/bindings/ConsoleObject.cpp @@ -49,7 +49,7 @@ void ConsoleObject::messageWithTypeAndLevel(MessageType type, MessageLevel level jsArgs[i] = JSC::JSValue::encode(val); } - if (UNLIKELY(type == MessageType::Table && count >= 2 && !args->argumentAt(1).isUndefined() && (!args->argumentAt(1).isCell() || args->argumentAt(1).asCell()->type() != JSC::JSType::ArrayType))) { + if (type == MessageType::Table && count >= 2 && !args->argumentAt(1).isUndefined() && (!args->argumentAt(1).isCell() || args->argumentAt(1).asCell()->type() != JSC::JSType::ArrayType)) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); JSC::throwTypeError(globalObject, scope, "The \"properties\" argument must be an instance of Array."_s); return; diff --git a/src/bun.js/bindings/Cookie.cpp b/src/bun.js/bindings/Cookie.cpp index c4e08d6591..46d348adfe 100644 --- a/src/bun.js/bindings/Cookie.cpp +++ b/src/bun.js/bindings/Cookie.cpp @@ -72,7 +72,7 @@ String Cookie::serialize(JSC::VM& vm, const std::span> cookies ExceptionOr> Cookie::parse(StringView cookieString) { // RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='. - if (UNLIKELY(cookieString.length() < 2)) { + if (cookieString.length() < 2) [[unlikely]] { return Exception { TypeError, "Invalid cookie string: empty"_s }; } @@ -81,7 +81,7 @@ ExceptionOr> Cookie::parse(StringView cookieString) StringView cookiePair = firstSemicolonPos == notFound ? cookieString : cookieString.substring(0, firstSemicolonPos); size_t firstEqualsPos = cookiePair.find('='); - if (UNLIKELY(firstEqualsPos == notFound)) { + if (firstEqualsPos == notFound) [[unlikely]] { return Exception { TypeError, "Invalid cookie string: no '=' found"_s }; } @@ -130,7 +130,7 @@ ExceptionOr> Cookie::parse(StringView cookieString) if (!attributeValue.isEmpty() && attributeValue.startsWith('/')) path = attributeValue; } else if (attributeName == "expires"_s && !hasMaxAge && !attributeValue.isEmpty()) { - if (UNLIKELY(!attributeValue.is8Bit())) { + if (!attributeValue.is8Bit()) [[unlikely]] { auto asLatin1 = attributeValue.latin1(); if (auto parsed = WTF::parseDate({ reinterpret_cast(asLatin1.data()), asLatin1.length() })) { expires = static_cast(parsed); diff --git a/src/bun.js/bindings/ErrorCode.cpp b/src/bun.js/bindings/ErrorCode.cpp index 5fcbed16fc..5df3e591ff 100644 --- a/src/bun.js/bindings/ErrorCode.cpp +++ b/src/bun.js/bindings/ErrorCode.cpp @@ -403,7 +403,7 @@ void determineSpecificType(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WTF:: view = str->substring(0, 25); } builder.append("type string ("_s); - if (UNLIKELY(needsEscape)) { + if (needsEscape) [[unlikely]] { builder.append('"'); if (view.is8Bit()) { const auto span = view.span(); @@ -431,7 +431,7 @@ void determineSpecificType(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WTF:: if (needsEllipsis) { builder.append("..."_s); } - if (UNLIKELY(needsEscape)) { + if (needsEscape) [[unlikely]] { builder.append('"'); } else { builder.append('\''); diff --git a/src/bun.js/bindings/ErrorStackTrace.cpp b/src/bun.js/bindings/ErrorStackTrace.cpp index 674ad768fc..a2d0b46ec7 100644 --- a/src/bun.js/bindings/ErrorStackTrace.cpp +++ b/src/bun.js/bindings/ErrorStackTrace.cpp @@ -496,7 +496,7 @@ String sourceURL(const JSC::SourceOrigin& origin) String sourceURL(JSC::SourceProvider* sourceProvider) { - if (UNLIKELY(!sourceProvider)) { + if (!sourceProvider) [[unlikely]] { return String(); } @@ -531,7 +531,7 @@ String sourceURL(JSC::CodeBlock& codeBlock) String sourceURL(JSC::CodeBlock* codeBlock) { - if (UNLIKELY(!codeBlock)) { + if (!codeBlock) [[unlikely]] { return String(); } @@ -544,7 +544,7 @@ String sourceURL(JSC::VM& vm, const JSC::StackFrame& frame) return "[wasm code]"_s; } - if (UNLIKELY(!frame.hasLineAndColumnInfo())) { + if (!frame.hasLineAndColumnInfo()) [[unlikely]] { return "[native code]"_s; } @@ -627,7 +627,7 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSC:: } } } - if (UNLIKELY(catchScope.exception())) { + if (catchScope.exception()) [[unlikely]] { catchScope.clearException(); } } @@ -636,7 +636,7 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSC:: // Then try the "displayName" property (what this does internally) auto catchScope = DECLARE_CATCH_SCOPE(vm); functionName = JSC::getCalculatedDisplayName(vm, object); - if (UNLIKELY(catchScope.exception())) { + if (catchScope.exception()) [[unlikely]] { catchScope.clearException(); } } diff --git a/src/bun.js/bindings/GCDefferalContext.h b/src/bun.js/bindings/GCDefferalContext.h index 802f63033e..0614778a90 100644 --- a/src/bun.js/bindings/GCDefferalContext.h +++ b/src/bun.js/bindings/GCDefferalContext.h @@ -14,7 +14,7 @@ ALWAYS_INLINE GCDeferralContext::~GCDeferralContext() if constexpr (validateDFGDoesGC) m_vm.verifyCanGC(); - if (UNLIKELY(m_shouldGC)) + if (m_shouldGC) [[unlikely]] m_vm.heap.collectIfNecessaryOrDefer(); } diff --git a/src/bun.js/bindings/HTMLEntryPoint.cpp b/src/bun.js/bindings/HTMLEntryPoint.cpp index c805fea3f0..e6b6042c98 100644 --- a/src/bun.js/bindings/HTMLEntryPoint.cpp +++ b/src/bun.js/bindings/HTMLEntryPoint.cpp @@ -16,23 +16,23 @@ extern "C" JSInternalPromise* Bun__loadHTMLEntryPoint(Zig::GlobalObject* globalO JSInternalPromise* promise = JSInternalPromise::create(vm, globalObject->internalPromiseStructure()); JSValue htmlModule = globalObject->internalModuleRegistry()->requireId(globalObject, vm, InternalModuleRegistry::InternalHtml); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { return promise->rejectWithCaughtException(globalObject, scope); } JSObject* htmlModuleObject = htmlModule.getObject(); - if (UNLIKELY(!htmlModuleObject)) { + if (!htmlModuleObject) [[unlikely]] { BUN_PANIC("Failed to load HTML entry point"); } MarkedArgumentBuffer args; JSValue result = JSC::call(globalObject, htmlModuleObject, args, "Failed to load HTML entry point"_s); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { return promise->rejectWithCaughtException(globalObject, scope); } promise = jsDynamicCast(result); - if (UNLIKELY(!promise)) { + if (!promise) [[unlikely]] { BUN_PANIC("Failed to load HTML entry point"); } return promise; diff --git a/src/bun.js/bindings/ImportMetaObject.cpp b/src/bun.js/bindings/ImportMetaObject.cpp index 7062e14820..8951c85d42 100644 --- a/src/bun.js/bindings/ImportMetaObject.cpp +++ b/src/bun.js/bindings/ImportMetaObject.cpp @@ -238,7 +238,7 @@ extern "C" JSC::EncodedJSValue functionImportMeta__resolveSync(JSC::JSGlobalObje from = JSC::JSValue::encode(thisValue); } else { JSC::JSObject* thisObject = JSC::jsDynamicCast(thisValue); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); JSC::throwTypeError(globalObject, scope, "import.meta.resolveSync must be bound to an import.meta object"_s); return {}; @@ -302,10 +302,10 @@ extern "C" JSC::EncodedJSValue functionImportMeta__resolveSyncPrivate(JSC::JSGlo } if (!isESM) { - if (LIKELY(globalObject)) { - if (UNLIKELY(globalObject->hasOverriddenModuleResolveFilenameFunction)) { + if (globalObject) [[likely]] { + if (globalObject->hasOverriddenModuleResolveFilenameFunction) [[unlikely]] { auto overrideHandler = jsCast(globalObject->m_moduleResolveFilenameFunction.getInitializedOnMainThread(globalObject)); - if (LIKELY(overrideHandler)) { + if (overrideHandler) [[likely]] { ASSERT(overrideHandler->isCallable()); JSValue parentModuleObject = globalObject->requireMap()->get(globalObject, from); @@ -436,7 +436,7 @@ JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve, if (!from) { auto* thisObject = JSC::jsDynamicCast(thisValue); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); JSC::throwTypeError(globalObject, scope, "import.meta.resolve must be bound to an import.meta object"_s); RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::JSValue {})); @@ -445,7 +445,7 @@ JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve, auto clientData = WebCore::clientData(vm); JSValue pathProperty = thisObject->getIfPropertyExists(globalObject, clientData->builtinNames().pathPublicName()); - if (LIKELY(pathProperty && pathProperty.isString())) { + if (pathProperty && pathProperty.isString()) [[likely]] { from = pathProperty; } else { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); @@ -476,7 +476,7 @@ JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve, } // In Node.js, `node:doesnotexist` resolves to `node:doesnotexist` - if (UNLIKELY(specifier.startsWith("node:"_s)) || UNLIKELY(specifier.startsWith("bun:"_s))) { + if (specifier.startsWith("node:"_s) || specifier.startsWith("bun:"_s)) [[unlikely]] { return JSValue::encode(jsString(vm, specifier)); } @@ -502,7 +502,7 @@ JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve, JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_url, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName)) { ImportMetaObject* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); return JSValue::encode(thisObject->urlProperty.getInitializedOnMainThread(thisObject)); @@ -511,7 +511,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_url, (JSGlobalObject * globalO JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_dir, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName)) { ImportMetaObject* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); return JSValue::encode(thisObject->dirProperty.getInitializedOnMainThread(thisObject)); @@ -520,7 +520,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_dir, (JSGlobalObject * globalO JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_file, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName)) { ImportMetaObject* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); return JSValue::encode(thisObject->fileProperty.getInitializedOnMainThread(thisObject)); @@ -529,7 +529,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_file, (JSGlobalObject * global JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_path, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName)) { ImportMetaObject* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); return JSValue::encode(thisObject->pathProperty.getInitializedOnMainThread(thisObject)); @@ -538,7 +538,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_path, (JSGlobalObject * global JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_require, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName)) { ImportMetaObject* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); return JSValue::encode(thisObject->requireProperty.getInitializedOnMainThread(thisObject)); @@ -549,7 +549,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_require, (JSGlobalObject * glo JSC_DEFINE_CUSTOM_SETTER(jsImportMetaObjectSetter_require, (JSGlobalObject * jsGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName propertyName)) { ImportMetaObject* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return false; JSValue value = JSValue::decode(encodedValue); diff --git a/src/bun.js/bindings/InternalModuleRegistry.cpp b/src/bun.js/bindings/InternalModuleRegistry.cpp index e5ceda2a96..c4cdb915b4 100644 --- a/src/bun.js/bindings/InternalModuleRegistry.cpp +++ b/src/bun.js/bindings/InternalModuleRegistry.cpp @@ -55,7 +55,7 @@ JSC::JSValue generateModule(JSC::JSGlobalObject* globalObject, JSC::VM& vm, cons static_cast(globalObject)); RETURN_IF_EXCEPTION(throwScope, {}); - if (UNLIKELY(globalObject->hasDebugger() && globalObject->debugger()->isInteractivelyDebugging())) { + if (globalObject->hasDebugger() && globalObject->debugger()->isInteractivelyDebugging()) [[unlikely]] { globalObject->debugger()->sourceParsed(globalObject, source.provider(), -1, ""_s); } diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index 2e6479a4f7..8ae40a02fc 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -86,6 +86,8 @@ extern "C" BunString Bun__inspect_singleline(JSC::JSGlobalObject* globalObject, using namespace JSC; using namespace WebCore; +static_assert(std::is_same_v, "all Buffer BigInt functions assume bigint digits are 64 bits"); + JSC_DECLARE_HOST_FUNCTION(constructJSBuffer); JSC_DECLARE_HOST_FUNCTION(callJSBuffer); @@ -162,7 +164,7 @@ std::optional byteLength(JSC::JSString* str, JSC::JSGlobalObject* lexica case WebCore::BufferEncodingType::base64url: { int64_t length = str->length(); const auto view = str->view(lexicalGlobalObject); - if (UNLIKELY(view->isNull())) { + if (view->isNull()) [[unlikely]] { return std::nullopt; } @@ -194,7 +196,7 @@ std::optional byteLength(JSC::JSString* str, JSC::JSGlobalObject* lexica case WebCore::BufferEncodingType::utf8: { const auto view = str->view(lexicalGlobalObject); - if (UNLIKELY(view->isNull())) { + if (view->isNull()) [[unlikely]] { return std::nullopt; } @@ -227,7 +229,7 @@ static JSUint8Array* allocBuffer(JSC::JSGlobalObject* lexicalGlobalObject, size_ auto* uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, subclassStructure, byteLength); #if ASSERT_ENABLED - if (UNLIKELY(!uint8Array)) { + if (!uint8Array) [[unlikely]] { // it should have thrown an exception already ASSERT(throwScope.exception()); } @@ -247,7 +249,7 @@ static JSUint8Array* allocBufferUnsafe(JSC::JSGlobalObject* lexicalGlobalObject, auto* result = createUninitializedBuffer(lexicalGlobalObject, byteLength); #if ASSERT_ENABLED - if (UNLIKELY(!result)) { + if (!result) [[unlikely]] { // it should have thrown an exception already ASSERT(throwScope.exception()); } @@ -281,7 +283,7 @@ static WebCore::BufferEncodingType parseEncoding(JSC::ThrowScope& scope, JSC::JS const auto& view = arg_->view(lexicalGlobalObject); std::optional encoded = parseEnumerationFromView(view); - if (UNLIKELY(!encoded)) { + if (!encoded) [[unlikely]] { if (validateUnknown) { Bun::V::validateString(scope, lexicalGlobalObject, arg, "encoding"_s); RETURN_IF_EXCEPTION(scope, WebCore::BufferEncodingType::utf8); @@ -295,19 +297,25 @@ static WebCore::BufferEncodingType parseEncoding(JSC::ThrowScope& scope, JSC::JS uint32_t validateOffset(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, JSC::JSValue name, uint32_t min, uint32_t max) { - if (UNLIKELY(!value.isNumber())) return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value); + if (!value.isNumber()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value); auto value_num = value.asNumber(); - if (UNLIKELY(std::fmod(value_num, 1.0) != 0)) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, "an integer"_s, value); - if (UNLIKELY(value_num < min || value_num > max)) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, min, max, value); + if (std::fmod(value_num, 1.0) != 0) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, "an integer"_s, value); + if (value_num < min || value_num > max) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, min, max, value); uint32_t result = JSC::toInt32(value_num); return result; } uint32_t validateOffset(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, WTF::ASCIILiteral name, uint32_t min, uint32_t max) { - if (UNLIKELY(!value.isNumber())) return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value); + if (!value.isNumber()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value); auto value_num = value.asNumber(); - if (UNLIKELY(std::fmod(value_num, 1.0) != 0)) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, "an integer"_s, value); - if (UNLIKELY(value_num < min || value_num > max)) return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, min, max, value); + if (std::fmod(value_num, 1.0) != 0) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, "an integer"_s, value); + if (value_num < min || value_num > max) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, globalObject, name, min, max, value); uint32_t result = JSC::toInt32(value_num); return result; } @@ -333,7 +341,7 @@ public: } auto thisObject = JSC::jsDynamicCast(thisValue); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(lexicalGlobalObject, throwScope, "Buffer"_s, operationName); RELEASE_AND_RETURN(throwScope, (operation(&lexicalGlobalObject, &callFrame, thisObject))); @@ -350,7 +358,7 @@ JSC::EncodedJSValue JSBuffer__bufferFromPointerAndLengthAndDeinit(JSC::JSGlobalO auto* globalObject = defaultGlobalObject(lexicalGlobalObject); auto* subclassStructure = globalObject->JSBufferSubclassStructure(); - if (LIKELY(length > 0)) { + if (length > 0) [[likely]] { auto buffer = ArrayBuffer::createFromBytes({ reinterpret_cast(ptr), length }, createSharedTask([ctx, bytesDeallocator](void* p) { if (bytesDeallocator) bytesDeallocator(p, ctx); @@ -369,7 +377,7 @@ using namespace JSC; static JSC::EncodedJSValue writeToBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSArrayBufferView* castedThis, JSString* str, uint32_t offset, uint32_t length, BufferEncodingType encoding) { - if (UNLIKELY(str->length() == 0)) + if (str->length() == 0) [[unlikely]] return JSC::JSValue::encode(JSC::jsNumber(0)); const auto& view = str->view(lexicalGlobalObject); @@ -416,7 +424,7 @@ JSC::JSUint8Array* createBuffer(JSC::JSGlobalObject* lexicalGlobalObject, const { auto* buffer = createUninitializedBuffer(lexicalGlobalObject, length); - if (LIKELY(ptr && length > 0 && buffer)) + if (ptr && length > 0 && buffer) [[likely]] memcpy(buffer->typedVector(), ptr, length); return buffer; @@ -454,7 +462,7 @@ static JSC::JSUint8Array* JSBuffer__bufferFromLengthAsArray(JSC::JSGlobalObject* { auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject->vm()); - if (UNLIKELY(length < 0)) { + if (length < 0) [[unlikely]] { throwNodeRangeError(lexicalGlobalObject, throwScope, "Invalid array length"_s); return nullptr; } @@ -560,7 +568,7 @@ JSC::EncodedJSValue constructFromEncoding(JSGlobalObject* lexicalGlobalObject, W } JSC::JSValue decoded = JSC::JSValue::decode(result); - if (UNLIKELY(!result)) { + if (!result) [[unlikely]] { throwTypeError(lexicalGlobalObject, scope, "An error occurred while decoding the string"_s); return {}; } @@ -621,7 +629,7 @@ static JSC::EncodedJSValue jsBufferConstructorFunction_allocBody(JSC::JSGlobalOb return JSValue::encode(createEmptyBuffer(lexicalGlobalObject)); } // fill argument - if (UNLIKELY(callFrame->argumentCount() > 1)) { + if (callFrame->argumentCount() > 1) [[unlikely]] { auto* uint8Array = createUninitializedBuffer(lexicalGlobalObject, length); RETURN_IF_EXCEPTION(scope, {}); @@ -650,17 +658,17 @@ static JSC::EncodedJSValue jsBufferConstructorFunction_allocBody(JSC::JSGlobalOb ZigString str = Zig::toZigString(view); - if (UNLIKELY(!Bun__Buffer_fill(&str, startPtr, end - start, encoding))) { + if (!Bun__Buffer_fill(&str, startPtr, end - start, encoding)) [[unlikely]] { return Bun::ERR::INVALID_ARG_VALUE(scope, lexicalGlobalObject, "value"_s, value); } } else if (auto* view = JSC::jsDynamicCast(value)) { - if (UNLIKELY(view->isDetached())) { + if (view->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, scope, "Uint8Array is detached"_s); return {}; } size_t length = view->byteLength(); - if (UNLIKELY(length == 0)) { + if (length == 0) [[unlikely]] { return Bun::ERR::INVALID_ARG_VALUE(scope, lexicalGlobalObject, "value"_s, value); } @@ -755,7 +763,7 @@ static JSC::EncodedJSValue jsBufferConstructorFunction_byteLengthBody(JSC::JSGlo } } - if (LIKELY(arg0.value().isString())) + if (arg0.value().isString()) [[likely]] return jsBufferByteLengthFromStringAndEncoding(lexicalGlobalObject, asString(arg0.value()), encoding); if (auto* arrayBufferView = jsDynamicCast(arg0.value())) { @@ -776,20 +784,20 @@ static JSC::EncodedJSValue jsBufferConstructorFunction_compareBody(JSC::JSGlobal auto castedThisValue = callFrame->argument(0); JSC::JSArrayBufferView* castedThis = JSC::jsDynamicCast(castedThisValue); - if (UNLIKELY(!castedThis)) { + if (!castedThis) [[unlikely]] { return Bun::ERR::INVALID_ARG_TYPE(throwScope, lexicalGlobalObject, "buf1"_s, "Buffer or Uint8Array"_s, castedThisValue); } - if (UNLIKELY(castedThis->isDetached())) { + if (castedThis->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, throwScope, "Uint8Array (first argument) is detached"_s); return {}; } auto buffer = callFrame->argument(1); JSC::JSArrayBufferView* view = JSC::jsDynamicCast(buffer); - if (UNLIKELY(!view)) { + if (!view) [[unlikely]] { return Bun::ERR::INVALID_ARG_TYPE(throwScope, lexicalGlobalObject, "buf2"_s, "Buffer or Uint8Array"_s, buffer); } - if (UNLIKELY(view->isDetached())) { + if (view->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, throwScope, "Uint8Array (second argument) is detached"_s); return {}; } @@ -844,7 +852,7 @@ static JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JSGlobalO // This is a small optimization MarkedArgumentBuffer args; args.ensureCapacity(arrayLength); - if (UNLIKELY(args.hasOverflowed())) { + if (args.hasOverflowed()) [[unlikely]] { throwOutOfMemoryError(lexicalGlobalObject, throwScope); return {}; } @@ -857,7 +865,7 @@ static JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JSGlobalO if (!typedArray) { return Bun::ERR::INVALID_ARG_TYPE(throwScope, lexicalGlobalObject, makeString("list["_s, i, "]"_s), "Buffer or Uint8Array"_s, element); } - if (UNLIKELY(typedArray->isDetached())) { + if (typedArray->isDetached()) [[unlikely]] { return throwVMTypeError(lexicalGlobalObject, throwScope, "ArrayBufferView is detached"_s); } @@ -871,7 +879,7 @@ static JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JSGlobalO size_t availableLength = byteLength; if (!totalLengthValue.isUndefined()) { - if (UNLIKELY(!totalLengthValue.isNumber())) { + if (!totalLengthValue.isNumber()) [[unlikely]] { throwTypeError(lexicalGlobalObject, throwScope, "totalLength must be a valid number"_s); return {}; } @@ -1030,11 +1038,11 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSGlobalOb auto arg0 = callFrame->argument(0); JSC::JSUint8Array* view = JSC::jsDynamicCast(arg0); - if (UNLIKELY(!view)) { + if (!view) [[unlikely]] { return Bun::ERR::INVALID_ARG_TYPE(throwScope, lexicalGlobalObject, "target"_s, "Buffer or Uint8Array"_s, arg0); } - if (UNLIKELY(view->isDetached())) { + if (view->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, throwScope, "Uint8Array is detached"_s); return {}; } @@ -1060,7 +1068,7 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSGlobalOb RETURN_IF_EXCEPTION(throwScope, {}); } RETURN_IF_EXCEPTION(throwScope, {}); - FALLTHROUGH; + [[fallthrough]]; case 4: sourceStartValue = callFrame->uncheckedArgument(3); if (sourceStartValue != jsUndefined()) { @@ -1068,7 +1076,7 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSGlobalOb RETURN_IF_EXCEPTION(throwScope, {}); } RETURN_IF_EXCEPTION(throwScope, {}); - FALLTHROUGH; + [[fallthrough]]; case 3: targetEndValue = callFrame->uncheckedArgument(2); if (targetEndValue != jsUndefined()) { @@ -1076,7 +1084,7 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSGlobalOb RETURN_IF_EXCEPTION(throwScope, {}); } RETURN_IF_EXCEPTION(throwScope, {}); - FALLTHROUGH; + [[fallthrough]]; case 2: targetStartValue = callFrame->uncheckedArgument(1); if (targetStartValue != jsUndefined()) { @@ -1208,11 +1216,11 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_equalsBody(JSC::JSGlobalObj auto buffer = callFrame->uncheckedArgument(0); JSC::JSArrayBufferView* view = JSC::jsDynamicCast(buffer); - if (UNLIKELY(!view)) { + if (!view) [[unlikely]] { return Bun::ERR::INVALID_ARG_TYPE(throwScope, lexicalGlobalObject, "otherBuffer"_s, "Buffer or Uint8Array"_s, buffer); } - if (UNLIKELY(view->isDetached())) { + if (view->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, throwScope, "Uint8Array is detached"_s); return {}; } @@ -1253,13 +1261,13 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlobalObjec switch (callFrame->argumentCount()) { case 4: encodingValue = callFrame->uncheckedArgument(3); - FALLTHROUGH; + [[fallthrough]]; case 3: endValue = callFrame->uncheckedArgument(2); - FALLTHROUGH; + [[fallthrough]]; case 2: offsetValue = callFrame->uncheckedArgument(1); - FALLTHROUGH; + [[fallthrough]]; default: break; } @@ -1301,7 +1309,7 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlobalObjec if (str.len == 0) { memset(startPtr, 0, end - offset); - } else if (UNLIKELY(!Bun__Buffer_fill(&str, startPtr, end - offset, encoding))) { + } else if (!Bun__Buffer_fill(&str, startPtr, end - offset, encoding)) [[unlikely]] { return Bun::ERR::INVALID_ARG_VALUE(scope, lexicalGlobalObject, "value"_s, value); } } else if (auto* view = JSC::jsDynamicCast(value)) { @@ -1309,13 +1317,13 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlobalObjec auto* head = startPtr; size_t remain = end - offset; - if (UNLIKELY(view->isDetached())) { + if (view->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, scope, "Uint8Array is detached"_s); return {}; } size_t length = view->byteLength(); - if (UNLIKELY(length == 0)) { + if (length == 0) [[unlikely]] { scope.throwException(lexicalGlobalObject, createError(lexicalGlobalObject, Bun::ErrorCode::ERR_INVALID_ARG_VALUE, "Buffer cannot be empty"_s)); return {}; } @@ -1592,7 +1600,7 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_inspectBody(JSC::JSGlobalOb auto filter = showHidden.toBoolean(globalObject) ? DontEnumPropertiesMode::Include : DontEnumPropertiesMode::Exclude; - if (UNLIKELY(castedThis->hasNonReifiedStaticProperties())) { + if (castedThis->hasNonReifiedStaticProperties()) [[unlikely]] { castedThis->reifyAllStaticProperties(globalObject); RETURN_IF_EXCEPTION(scope, {}); } @@ -1644,7 +1652,7 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_swap16Body(JSC::JSGlobalObj return {}; } - if (UNLIKELY(castedThis->isDetached())) { + if (castedThis->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, scope, "Buffer is detached"_s); return {}; } @@ -1674,7 +1682,7 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_swap32Body(JSC::JSGlobalObj return {}; } - if (UNLIKELY(castedThis->isDetached())) { + if (castedThis->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, scope, "Buffer is detached"_s); return {}; } @@ -1709,7 +1717,7 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_swap64Body(JSC::JSGlobalObj return {}; } - if (UNLIKELY(castedThis->isDetached())) { + if (castedThis->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, scope, "Buffer is detached"_s); return {}; } @@ -1736,7 +1744,7 @@ JSC::EncodedJSValue jsBufferToStringFromBytes(JSGlobalObject* lexicalGlobalObjec { auto& vm = lexicalGlobalObject->vm(); - if (UNLIKELY(bytes.size() == 0)) { + if (bytes.size() == 0) [[unlikely]] { RELEASE_AND_RETURN(scope, JSValue::encode(jsEmptyString(vm))); } @@ -1748,7 +1756,7 @@ JSC::EncodedJSValue jsBufferToStringFromBytes(JSGlobalObject* lexicalGlobalObjec case WebCore::BufferEncodingType::buffer: { auto* buffer = createUninitializedBuffer(lexicalGlobalObject, bytes.size()); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(!buffer)) { + if (!buffer) [[unlikely]] { throwOutOfMemoryError(lexicalGlobalObject, scope); return JSValue::encode({}); } @@ -1758,7 +1766,7 @@ JSC::EncodedJSValue jsBufferToStringFromBytes(JSGlobalObject* lexicalGlobalObjec case BufferEncodingType::latin1: { std::span data; auto str = String::tryCreateUninitialized(bytes.size(), data); - if (UNLIKELY(str.isNull())) { + if (str.isNull()) [[unlikely]] { throwOutOfMemoryError(lexicalGlobalObject, scope); return JSValue::encode({}); } @@ -1774,7 +1782,7 @@ JSC::EncodedJSValue jsBufferToStringFromBytes(JSGlobalObject* lexicalGlobalObjec return JSValue::encode(jsEmptyString(vm)); } auto str = String::tryCreateUninitialized(u16length, data); - if (UNLIKELY(str.isNull())) { + if (str.isNull()) [[unlikely]] { throwOutOfMemoryError(lexicalGlobalObject, scope); return JSValue::encode({}); } @@ -1784,7 +1792,7 @@ JSC::EncodedJSValue jsBufferToStringFromBytes(JSGlobalObject* lexicalGlobalObjec case BufferEncodingType::ascii: { std::span data; auto str = String::tryCreateUninitialized(bytes.size(), data); - if (UNLIKELY(str.isNull())) { + if (str.isNull()) [[unlikely]] { throwOutOfMemoryError(lexicalGlobalObject, scope); return JSValue::encode({}); } @@ -1800,7 +1808,7 @@ JSC::EncodedJSValue jsBufferToStringFromBytes(JSGlobalObject* lexicalGlobalObjec RETURN_IF_EXCEPTION(scope, JSValue::encode({})); JSValue stringValue = JSValue::decode(res); - if (UNLIKELY(!stringValue.isString())) { + if (!stringValue.isString()) [[unlikely]] { scope.throwException(lexicalGlobalObject, stringValue); return JSValue::encode({}); } @@ -1820,7 +1828,7 @@ JSC::EncodedJSValue jsBufferToString(JSC::JSGlobalObject* lexicalGlobalObject, T auto byteLength = castedThis->byteLength(); - if (UNLIKELY(!byteLength)) { + if (!byteLength) [[unlikely]] { RELEASE_AND_RETURN(scope, JSValue::encode(jsEmptyString(vm))); } @@ -1928,24 +1936,24 @@ static JSC::EncodedJSValue jsBufferPrototypeFunction_SliceWithEncoding(JSC::JSGl const JSValue startValue = callFrame->argument(0); const JSValue endValue = callFrame->argument(1); - if (UNLIKELY(!castedThis)) { + if (!castedThis) [[unlikely]] { throwTypeError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); return {}; } const size_t length = castedThis->byteLength(); - if (UNLIKELY(length == 0)) { + if (length == 0) [[unlikely]] { return JSC::JSValue::encode(JSC::jsEmptyString(vm)); } size_t start = 0; size_t end = length; - if (UNLIKELY(!parseArrayIndex(scope, lexicalGlobalObject, startValue, start, "start must be a positive integer"_s))) { + if (!parseArrayIndex(scope, lexicalGlobalObject, startValue, start, "start must be a positive integer"_s)) [[unlikely]] { return {}; } - if (UNLIKELY(!parseArrayIndex(scope, lexicalGlobalObject, endValue, end, "end must be a positive integer"_s))) { + if (!parseArrayIndex(scope, lexicalGlobalObject, endValue, end, "end must be a positive integer"_s)) [[unlikely]] { return {}; } @@ -2038,12 +2046,12 @@ static JSC::EncodedJSValue jsBufferPrototypeFunctionWriteWithEncoding(JSC::JSGlo JSValue offsetValue = callFrame->argument(1); JSValue lengthValue = callFrame->argument(2); - if (UNLIKELY(!castedThis)) { + if (!castedThis) [[unlikely]] { throwTypeError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); return {}; } - if (UNLIKELY(castedThis->isDetached())) { + if (castedThis->isDetached()) [[unlikely]] { throwTypeError(lexicalGlobalObject, scope, "ArrayBufferView is detached"_s); return {}; } @@ -2132,7 +2140,7 @@ extern "C" JSC::EncodedJSValue JSBuffer__fromMmap(Zig::GlobalObject* globalObjec auto* view = JSC::JSUint8Array::create(globalObject, structure, WTFMove(buffer), 0, length); - if (UNLIKELY(!view)) { + if (!view) [[unlikely]] { throwOutOfMemoryError(globalObject, scope); return {}; } @@ -2438,27 +2446,34 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigInt64LE, (JSGlobalObj auto scope = DECLARE_THROW_SCOPE(vm); auto* castedThis = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!castedThis)) return throwVMError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); + if (!castedThis) [[unlikely]] + return throwVMError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); auto byteLength = castedThis->byteLength(); auto valueVal = callFrame->argument(0); auto offsetVal = callFrame->argument(1); - if (UNLIKELY(!valueVal.isBigInt())) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "value"_s, "bigint"_s, valueVal); + if (!valueVal.isBigInt()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "value"_s, "bigint"_s, valueVal); auto* bigint = valueVal.asHeapBigInt(); - if (UNLIKELY(bigint->sign() > 1)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= -(2n ** 63n) and < 2n ** 63n"_s, valueVal); + if (bigint->length() > 1) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= -(2n ** 63n) and < 2n ** 63n"_s, valueVal); auto limb = valueVal.toBigUInt64(lexicalGlobalObject); if (!bigint->sign() && limb > 0x7fffffffffffffff) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= -(2n ** 63n) and < 2n ** 63n"_s, valueVal); if (bigint->sign() && limb - 0x8000000000000000 > 0x7fffffffffffffff) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= -(2n ** 63n) and < 2n ** 63n"_s, valueVal); int64_t value = static_cast(limb); if (offsetVal.isUndefined()) offsetVal = jsNumber(0); - if (UNLIKELY(!offsetVal.isNumber())) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "offset"_s, "number"_s, offsetVal); + if (!offsetVal.isNumber()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "offset"_s, "number"_s, offsetVal); auto offsetD = offsetVal.asNumber(); - if (UNLIKELY(std::fmod(offsetD, 1.0) != 0)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, "an integer"_s, offsetVal); + if (std::fmod(offsetD, 1.0) != 0) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, "an integer"_s, offsetVal); size_t offset = offsetD; - if (UNLIKELY(offset < 0)) return Bun::ERR::BUFFER_OUT_OF_BOUNDS(scope, lexicalGlobalObject, "offset"_s); - if (UNLIKELY(offset > byteLength - 8)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, 0, byteLength - 8, offsetVal); + if (offset < 0) [[unlikely]] + return Bun::ERR::BUFFER_OUT_OF_BOUNDS(scope, lexicalGlobalObject, "offset"_s); + if (offset > byteLength - 8) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, 0, byteLength - 8, offsetVal); write_int64_le(static_cast(castedThis->vector()) + offset, value); return JSValue::encode(jsNumber(offset + 8)); @@ -2470,27 +2485,34 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigInt64BE, (JSGlobalObj auto scope = DECLARE_THROW_SCOPE(vm); auto* castedThis = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!castedThis)) return throwVMError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); + if (!castedThis) [[unlikely]] + return throwVMError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); auto byteLength = castedThis->byteLength(); auto valueVal = callFrame->argument(0); auto offsetVal = callFrame->argument(1); - if (UNLIKELY(!valueVal.isBigInt())) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "value"_s, "bigint"_s, valueVal); + if (!valueVal.isBigInt()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "value"_s, "bigint"_s, valueVal); auto* bigint = valueVal.asHeapBigInt(); - if (UNLIKELY(bigint->sign() > 1)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= -(2n ** 63n) and < 2n ** 63n"_s, valueVal); + if (bigint->length() > 1) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= -(2n ** 63n) and < 2n ** 63n"_s, valueVal); auto limb = valueVal.toBigUInt64(lexicalGlobalObject); if (!bigint->sign() && limb > 0x7fffffffffffffff) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= -(2n ** 63n) and < 2n ** 63n"_s, valueVal); if (bigint->sign() && limb - 0x8000000000000000 > 0x7fffffffffffffff) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= -(2n ** 63n) and < 2n ** 63n"_s, valueVal); int64_t value = static_cast(limb); if (offsetVal.isUndefined()) offsetVal = jsNumber(0); - if (UNLIKELY(!offsetVal.isNumber())) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "offset"_s, "number"_s, offsetVal); + if (!offsetVal.isNumber()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "offset"_s, "number"_s, offsetVal); auto offsetD = offsetVal.asNumber(); - if (UNLIKELY(std::fmod(offsetD, 1.0) != 0)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, "an integer"_s, offsetVal); + if (std::fmod(offsetD, 1.0) != 0) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, "an integer"_s, offsetVal); size_t offset = offsetD; - if (UNLIKELY(offset < 0)) return Bun::ERR::BUFFER_OUT_OF_BOUNDS(scope, lexicalGlobalObject, "offset"_s); - if (UNLIKELY(offset > byteLength - 8)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, 0, byteLength - 8, offsetVal); + if (offset < 0) [[unlikely]] + return Bun::ERR::BUFFER_OUT_OF_BOUNDS(scope, lexicalGlobalObject, "offset"_s); + if (offset > byteLength - 8) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, 0, byteLength - 8, offsetVal); write_int64_be(static_cast(castedThis->vector()) + offset, value); return JSValue::encode(jsNumber(offset + 8)); @@ -2502,25 +2524,33 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigUInt64LE, (JSGlobalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* castedThis = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!castedThis)) return throwVMError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); + if (!castedThis) [[unlikely]] + return throwVMError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); auto byteLength = castedThis->byteLength(); auto valueVal = callFrame->argument(0); auto offsetVal = callFrame->argument(1); - if (UNLIKELY(!valueVal.isBigInt())) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "value"_s, "bigint"_s, valueVal); + if (!valueVal.isBigInt()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "value"_s, "bigint"_s, valueVal); auto* bigint = valueVal.asHeapBigInt(); - if (UNLIKELY(bigint->sign())) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= 0n and < 2n ** 64n"_s, valueVal); - if (UNLIKELY(bigint->length() > 1)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= 0n and < 2n ** 64n"_s, valueVal); + if (bigint->sign()) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= 0n and < 2n ** 64n"_s, valueVal); + if (bigint->length() > 1) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= 0n and < 2n ** 64n"_s, valueVal); uint64_t value = valueVal.toBigUInt64(lexicalGlobalObject); if (offsetVal.isUndefined()) offsetVal = jsNumber(0); - if (UNLIKELY(!offsetVal.isNumber())) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "offset"_s, "number"_s, offsetVal); + if (!offsetVal.isNumber()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "offset"_s, "number"_s, offsetVal); auto offsetD = offsetVal.asNumber(); - if (UNLIKELY(std::fmod(offsetD, 1.0) != 0)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, "an integer"_s, offsetVal); + if (std::fmod(offsetD, 1.0) != 0) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, "an integer"_s, offsetVal); size_t offset = offsetD; - if (UNLIKELY(offset < 0)) return Bun::ERR::BUFFER_OUT_OF_BOUNDS(scope, lexicalGlobalObject, "offset"_s); - if (UNLIKELY(offset > byteLength - 8)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, 0, byteLength - 8, offsetVal); + if (offset < 0) [[unlikely]] + return Bun::ERR::BUFFER_OUT_OF_BOUNDS(scope, lexicalGlobalObject, "offset"_s); + if (offset > byteLength - 8) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, 0, byteLength - 8, offsetVal); write_int64_le(static_cast(castedThis->vector()) + offset, value); return JSValue::encode(jsNumber(offset + 8)); @@ -2532,25 +2562,33 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferPrototypeFunction_writeBigUInt64BE, (JSGlobalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* castedThis = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!castedThis)) return throwVMError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); + if (!castedThis) [[unlikely]] + return throwVMError(lexicalGlobalObject, scope, "Expected ArrayBufferView"_s); auto byteLength = castedThis->byteLength(); auto valueVal = callFrame->argument(0); auto offsetVal = callFrame->argument(1); - if (UNLIKELY(!valueVal.isBigInt())) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "value"_s, "bigint"_s, valueVal); + if (!valueVal.isBigInt()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "value"_s, "bigint"_s, valueVal); auto* bigint = valueVal.asHeapBigInt(); - if (UNLIKELY(bigint->sign())) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= 0n and < 2n ** 64n"_s, valueVal); - if (UNLIKELY(bigint->length() > 1)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= 0n and < 2n ** 64n"_s, valueVal); + if (bigint->sign()) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= 0n and < 2n ** 64n"_s, valueVal); + if (bigint->length() > 1) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "value"_s, ">= 0n and < 2n ** 64n"_s, valueVal); uint64_t value = valueVal.toBigUInt64(lexicalGlobalObject); if (offsetVal.isUndefined()) offsetVal = jsNumber(0); - if (UNLIKELY(!offsetVal.isNumber())) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "offset"_s, "number"_s, offsetVal); + if (!offsetVal.isNumber()) [[unlikely]] + return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, "offset"_s, "number"_s, offsetVal); auto offsetD = offsetVal.asNumber(); - if (UNLIKELY(std::fmod(offsetD, 1.0) != 0)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, "an integer"_s, offsetVal); + if (std::fmod(offsetD, 1.0) != 0) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, "an integer"_s, offsetVal); size_t offset = offsetD; - if (UNLIKELY(offset < 0)) return Bun::ERR::BUFFER_OUT_OF_BOUNDS(scope, lexicalGlobalObject, "offset"_s); - if (UNLIKELY(offset > byteLength - 8)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, 0, byteLength - 8, offsetVal); + if (offset < 0) [[unlikely]] + return Bun::ERR::BUFFER_OUT_OF_BOUNDS(scope, lexicalGlobalObject, "offset"_s); + if (offset > byteLength - 8) [[unlikely]] + return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, "offset"_s, 0, byteLength - 8, offsetVal); write_int64_be(static_cast(castedThis->vector()) + offset, value); return JSValue::encode(jsNumber(offset + 8)); @@ -2800,7 +2838,7 @@ EncodedJSValue constructBufferFromArrayBuffer(JSC::ThrowScope& throwScope, JSGlo if (isResizableOrGrowableShared) { auto* subclassStructure = globalObject->JSResizableOrGrowableSharedBufferSubclassStructure(); auto* uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, subclassStructure, WTFMove(buffer), offset, std::nullopt); - if (UNLIKELY(!uint8Array)) { + if (!uint8Array) [[unlikely]] { throwOutOfMemoryError(globalObject, throwScope); return {}; } @@ -2808,7 +2846,7 @@ EncodedJSValue constructBufferFromArrayBuffer(JSC::ThrowScope& throwScope, JSGlo } auto* subclassStructure = globalObject->JSBufferSubclassStructure(); auto* uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, subclassStructure, WTFMove(buffer), offset, length); - if (UNLIKELY(!uint8Array)) { + if (!uint8Array) [[unlikely]] { throwOutOfMemoryError(globalObject, throwScope); return {}; } @@ -2869,12 +2907,12 @@ static JSC::EncodedJSValue createJSBufferFromJS(JSC::JSGlobalObject* lexicalGlob JSC::JSArrayBufferView* view = jsCast(distinguishingArg.asCell()); void* data = view->vector(); size_t byteLength = view->length(); - if (UNLIKELY(!data)) { + if (!data) [[unlikely]] { throwException(globalObject, throwScope, createRangeError(globalObject, "Buffer is detached"_s)); return {}; } auto* uint8Array = createUninitializedBuffer(lexicalGlobalObject, byteLength); - if (UNLIKELY(!uint8Array)) { + if (!uint8Array) [[unlikely]] { ASSERT(throwScope.exception()); return {}; } @@ -2891,7 +2929,7 @@ static JSC::EncodedJSValue createJSBufferFromJS(JSC::JSGlobalObject* lexicalGlob JSC::JSArrayBufferView* view = jsCast(distinguishingArg.asCell()); void* data = view->vector(); size_t byteLength = view->byteLength(); - if (UNLIKELY(!data)) { + if (!data) [[unlikely]] { throwException(globalObject, throwScope, createRangeError(globalObject, "Buffer is detached"_s)); return {}; } diff --git a/src/bun.js/bindings/JSBufferEncodingType.cpp b/src/bun.js/bindings/JSBufferEncodingType.cpp index 17052ae85b..312e30d806 100644 --- a/src/bun.js/bindings/JSBufferEncodingType.cpp +++ b/src/bun.js/bindings/JSBufferEncodingType.cpp @@ -54,7 +54,7 @@ template<> JSString* convertEnumerationToJS(JSGlobalObject& lexicalGlobalObject, template static std::optional parseEnumerationAllowBufferInternal(JSGlobalObject& lexicalGlobalObject, JSValue arg) { - if (UNLIKELY(!arg.isString())) { + if (!arg.isString()) [[unlikely]] { return std::nullopt; } diff --git a/src/bun.js/bindings/JSBufferList.cpp b/src/bun.js/bindings/JSBufferList.cpp index 4f10dd85bc..c181f7aeb7 100644 --- a/src/bun.js/bindings/JSBufferList.cpp +++ b/src/bun.js/bindings/JSBufferList.cpp @@ -41,10 +41,10 @@ JSC::JSValue JSBufferList::concat(JSC::VM& vm, JSC::JSGlobalObject* lexicalGloba auto iter = m_deque.begin(); if (len == 1) { auto array = JSC::jsDynamicCast(iter->get()); - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { return throwTypeError(lexicalGlobalObject, throwScope, "concat can only be called when all buffers are Uint8Array"_s); } - if (UNLIKELY(array->byteLength() > n)) { + if (array->byteLength() > n) [[unlikely]] { throwNodeRangeError(lexicalGlobalObject, throwScope, "specified size too small to fit all buffers"_s); return {}; } @@ -52,7 +52,7 @@ JSC::JSValue JSBufferList::concat(JSC::VM& vm, JSC::JSGlobalObject* lexicalGloba } // Buffer.allocUnsafe(n >>> 0) JSC::JSUint8Array* uint8Array = createUninitializedBuffer(lexicalGlobalObject, n); - if (UNLIKELY(!uint8Array)) { + if (!uint8Array) [[unlikely]] { ASSERT(throwScope.exception()); return {}; } @@ -60,15 +60,15 @@ JSC::JSValue JSBufferList::concat(JSC::VM& vm, JSC::JSGlobalObject* lexicalGloba size_t i = 0; for (const auto end = m_deque.end(); iter != end; ++iter) { auto array = JSC::jsDynamicCast(iter->get()); - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { return throwTypeError(lexicalGlobalObject, throwScope, "concat can only be called when all buffers are Uint8Array"_s); } const size_t length = array->byteLength(); - if (UNLIKELY(i + length > n)) { + if (i + length > n) [[unlikely]] { throwNodeRangeError(lexicalGlobalObject, throwScope, "specified size too small to fit all buffers"_s); return {}; } - if (UNLIKELY(!uint8Array->setFromTypedArray(lexicalGlobalObject, i, array, 0, length, JSC::CopyType::Unobservable))) { + if (!uint8Array->setFromTypedArray(lexicalGlobalObject, i, array, 0, length, JSC::CopyType::Unobservable)) [[unlikely]] { return throwOutOfMemoryError(lexicalGlobalObject, throwScope); } i += length; @@ -117,7 +117,7 @@ JSC::JSValue JSBufferList::_getString(JSC::VM& vm, JSC::JSGlobalObject* lexicalG } JSC::JSString* str = JSC::jsDynamicCast(m_deque.first().get()); - if (UNLIKELY(!str)) { + if (!str) [[unlikely]] { return throwTypeError(lexicalGlobalObject, throwScope, "_getString can only be called when all buffers are string"_s); } const size_t len = str->length(); @@ -137,7 +137,7 @@ JSC::JSValue JSBufferList::_getString(JSC::VM& vm, JSC::JSGlobalObject* lexicalG while (m_deque.size() > 0) { auto& element = m_deque.first(); JSC::JSString* str = JSC::jsDynamicCast(element.get()); - if (UNLIKELY(!str)) { + if (!str) [[unlikely]] { return throwTypeError(lexicalGlobalObject, throwScope, "_getString can only be called when all buffers are string"_s); } const size_t len = str->length(); @@ -169,7 +169,7 @@ JSC::JSValue JSBufferList::_getBuffer(JSC::VM& vm, JSC::JSGlobalObject* lexicalG } JSC::JSUint8Array* array = JSC::jsDynamicCast(m_deque.first().get()); - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { return throwTypeError(lexicalGlobalObject, throwScope, "_getBuffer can only be called when all buffers are Uint8Array"_s); } const size_t len = array->byteLength(); @@ -190,7 +190,7 @@ JSC::JSValue JSBufferList::_getBuffer(JSC::VM& vm, JSC::JSGlobalObject* lexicalG // Buffer.allocUnsafe(n >>> 0) JSC::JSUint8Array* uint8Array = createUninitializedBuffer(lexicalGlobalObject, n); - if (UNLIKELY(!uint8Array)) { + if (!uint8Array) [[unlikely]] { ASSERT(throwScope.exception()); return {}; } @@ -199,12 +199,12 @@ JSC::JSValue JSBufferList::_getBuffer(JSC::VM& vm, JSC::JSGlobalObject* lexicalG while (m_deque.size() > 0) { auto& element = m_deque.first(); JSC::JSUint8Array* array = JSC::jsDynamicCast(element.get()); - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { return throwTypeError(lexicalGlobalObject, throwScope, "_getBuffer can only be called when all buffers are Uint8Array"_s); } const size_t len = array->byteLength(); if (n < len) { - if (UNLIKELY(!uint8Array->setFromTypedArray(lexicalGlobalObject, offset, array, 0, n, JSC::CopyType::Unobservable))) { + if (!uint8Array->setFromTypedArray(lexicalGlobalObject, offset, array, 0, n, JSC::CopyType::Unobservable)) [[unlikely]] { return throwOutOfMemoryError(lexicalGlobalObject, throwScope); } auto buffer = array->possiblySharedBuffer(); @@ -214,7 +214,7 @@ JSC::JSValue JSBufferList::_getBuffer(JSC::VM& vm, JSC::JSGlobalObject* lexicalG offset += n; break; } - if (UNLIKELY(!uint8Array->setFromTypedArray(lexicalGlobalObject, offset, array, 0, len, JSC::CopyType::Unobservable))) { + if (!uint8Array->setFromTypedArray(lexicalGlobalObject, offset, array, 0, len, JSC::CopyType::Unobservable)) [[unlikely]] { return throwOutOfMemoryError(lexicalGlobalObject, throwScope); } this->removeFirst(); @@ -313,7 +313,7 @@ static inline JSC::EncodedJSValue jsBufferListPrototypeFunction_concatBody(JSC:: } int32_t n = callFrame->argument(0).toInt32(lexicalGlobalObject); - if (UNLIKELY(n < 0)) { + if (n < 0) [[unlikely]] { throwException(lexicalGlobalObject, throwScope, createError(lexicalGlobalObject, "n should be larger than or equal to 0"_s)); return {}; } @@ -342,7 +342,7 @@ static inline JSC::EncodedJSValue jsBufferListPrototypeFunction_consumeBody(JSC: } int32_t n = callFrame->argument(0).toInt32(lexicalGlobalObject); - if (UNLIKELY(n < 0)) { + if (n < 0) [[unlikely]] { throwException(lexicalGlobalObject, throwScope, createError(lexicalGlobalObject, "n should be larger than or equal to 0"_s)); return {}; } diff --git a/src/bun.js/bindings/JSBufferList.h b/src/bun.js/bindings/JSBufferList.h index 713b706152..b9a0d63377 100644 --- a/src/bun.js/bindings/JSBufferList.h +++ b/src/bun.js/bindings/JSBufferList.h @@ -72,7 +72,7 @@ public: } JSC::JSValue shift() { - if (UNLIKELY(length() == 0)) + if (length() == 0) [[unlikely]] return JSC::jsUndefined(); auto v = m_deque.first().get(); @@ -90,7 +90,7 @@ public: } JSC::JSValue first() { - if (UNLIKELY(length() == 0)) + if (length() == 0) [[unlikely]] return JSC::jsUndefined(); return JSC::JSValue(m_deque.first().get()); } diff --git a/src/bun.js/bindings/JSBundlerPlugin.cpp b/src/bun.js/bindings/JSBundlerPlugin.cpp index f4b77c4a95..33fccb7181 100644 --- a/src/bun.js/bindings/JSBundlerPlugin.cpp +++ b/src/bun.js/bindings/JSBundlerPlugin.cpp @@ -360,7 +360,7 @@ JSC_DEFINE_HOST_FUNCTION(jsBundlerPluginFunction_onBeforeParse, (JSC::JSGlobalOb // The dlopen *void handle is attached to the node_addon as a NapiExternal Bun::NapiExternal* napi_external = jsDynamicCast(node_addon.getObject()->get(globalObject, WebCore::builtinNames(vm).napiDlopenHandlePrivateName())); - if (UNLIKELY(!napi_external)) { + if (!napi_external) [[unlikely]] { Bun::throwError(globalObject, scope, ErrorCode::ERR_INVALID_ARG_TYPE, "Expected node_addon (2nd argument) to have a napiDlopenHandle property"_s); return {}; } @@ -387,7 +387,7 @@ JSC_DEFINE_HOST_FUNCTION(jsBundlerPluginFunction_onBeforeParse, (JSC::JSGlobalOb NapiExternal* externalPtr = nullptr; if (!external.isUndefinedOrNull()) { externalPtr = jsDynamicCast(external); - if (UNLIKELY(!externalPtr)) { + if (!externalPtr) [[unlikely]] { Bun::throwError(globalObject, scope, ErrorCode::ERR_INVALID_ARG_TYPE, "Expected external (3rd argument) to be a NAPI external"_s); return {}; } @@ -504,12 +504,12 @@ extern "C" void JSBundlerPlugin__matchOnLoad(Bun::JSBundlerPlugin* plugin, const WTF::String pathStr = path ? path->toWTFString(BunString::ZeroCopy) : WTF::String(); JSFunction* function = plugin->onLoadFunction.get(plugin); - if (UNLIKELY(!function)) + if (!function) [[unlikely]] return; JSC::CallData callData = JSC::getCallData(function); - if (UNLIKELY(callData.type == JSC::CallData::Type::None)) + if (callData.type == JSC::CallData::Type::None) [[unlikely]] return; auto scope = DECLARE_CATCH_SCOPE(plugin->vm()); @@ -547,12 +547,12 @@ extern "C" void JSBundlerPlugin__matchOnResolve(Bun::JSBundlerPlugin* plugin, co auto& vm = JSC::getVM(globalObject); JSFunction* function = plugin->onResolveFunction.get(plugin); - if (UNLIKELY(!function)) + if (!function) [[unlikely]] return; JSC::CallData callData = JSC::getCallData(function); - if (UNLIKELY(callData.type == JSC::CallData::Type::None)) + if (callData.type == JSC::CallData::Type::None) [[unlikely]] return; auto scope = DECLARE_CATCH_SCOPE(vm); @@ -565,7 +565,7 @@ extern "C" void JSBundlerPlugin__matchOnResolve(Bun::JSBundlerPlugin* plugin, co call(globalObject, function, callData, plugin, arguments); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { auto exception = JSValue(scope.exception()); scope.clearException(); if (!plugin->plugin.tombstoned) { @@ -603,7 +603,7 @@ extern "C" JSC::EncodedJSValue JSBundlerPlugin__loadAndResolvePluginsForServe(Bu auto* runSetupFn = plugin->setupFunction.get(plugin); JSC::CallData callData = JSC::getCallData(loadAndResolvePluginsForServeBuiltinFn); - if (UNLIKELY(callData.type == JSC::CallData::Type::None)) + if (callData.type == JSC::CallData::Type::None) [[unlikely]] return JSValue::encode(jsUndefined()); MarkedArgumentBuffer arguments; @@ -626,11 +626,11 @@ extern "C" JSC::EncodedJSValue JSBundlerPlugin__runSetupFunction( auto scope = DECLARE_CATCH_SCOPE(vm); auto* setupFunction = jsCast(plugin->setupFunction.get(plugin)); - if (UNLIKELY(!setupFunction)) + if (!setupFunction) [[unlikely]] return JSValue::encode(jsUndefined()); JSC::CallData callData = JSC::getCallData(setupFunction); - if (UNLIKELY(callData.type == JSC::CallData::Type::None)) + if (callData.type == JSC::CallData::Type::None) [[unlikely]] return JSValue::encode(jsUndefined()); MarkedArgumentBuffer arguments; diff --git a/src/bun.js/bindings/JSCommonJSExtensions.cpp b/src/bun.js/bindings/JSCommonJSExtensions.cpp index 024418d8f5..34b0056ac4 100644 --- a/src/bun.js/bindings/JSCommonJSExtensions.cpp +++ b/src/bun.js/bindings/JSCommonJSExtensions.cpp @@ -255,6 +255,8 @@ JSC::EncodedJSValue builtinLoader(JSC::JSGlobalObject* globalObject, JSC::CallFr BunString empty = BunStringEmpty; JSC::VM& vm = globalObject->vm(); ErrorableResolvedSource res; + res.success = false; + memset(&res.result, 0, sizeof res.result); JSValue result = fetchCommonJSModuleNonBuiltin( global->bunVM(), @@ -279,7 +281,7 @@ JSC::EncodedJSValue builtinLoader(JSC::JSGlobalObject* globalObject, JSC::CallFr ASSERT(callData.type == JSC::CallData::Type::JS); NakedPtr returnedException = nullptr; JSC::profiledCall(global, JSC::ProfilingReason::API, requireESM, callData, mod, args, returnedException); - if (UNLIKELY(returnedException)) { + if (returnedException) [[unlikely]] { throwException(globalObject, scope, returnedException->value()); return JSC::JSValue::encode({}); } diff --git a/src/bun.js/bindings/JSCommonJSModule.cpp b/src/bun.js/bindings/JSCommonJSModule.cpp index aea46b7498..e376461d9d 100644 --- a/src/bun.js/bindings/JSCommonJSModule.cpp +++ b/src/bun.js/bindings/JSCommonJSModule.cpp @@ -115,7 +115,7 @@ static bool evaluateCommonJSModuleOnce(JSC::VM& vm, Zig::GlobalObject* globalObj SourceCode code = std::move(moduleObject->sourceCode); // If an exception occurred somewhere else, we might have cleared the source code. - if (UNLIKELY(code.isNull())) { + if (code.isNull()) [[unlikely]] { throwException(globalObject, scope, createError(globalObject, "Failed to evaluate module"_s)); return false; } @@ -142,7 +142,7 @@ static bool evaluateCommonJSModuleOnce(JSC::VM& vm, Zig::GlobalObject* globalObj moduleObject->hasEvaluated = true; }; - if (UNLIKELY(Bun__VM__specifierIsEvalEntryPoint(globalObject->bunVM(), JSValue::encode(filename)))) { + if (Bun__VM__specifierIsEvalEntryPoint(globalObject->bunVM(), JSValue::encode(filename))) [[unlikely]] { initializeModuleObject(); scope.assertNoExceptionExceptTermination(); @@ -168,13 +168,13 @@ static bool evaluateCommonJSModuleOnce(JSC::VM& vm, Zig::GlobalObject* globalObj ASSERT(fnValue); JSObject* fn = fnValue.getObject(); - if (UNLIKELY(!fn)) { + if (!fn) [[unlikely]] { scope.throwException(globalObject, createTypeError(globalObject, "Expected CommonJS module to have a function wrapper. If you weren't messing around with Bun's internals, this is a bug in Bun"_s)); RELEASE_AND_RETURN(scope, false); } JSC::CallData callData = JSC::getCallData(fn); - if (UNLIKELY(callData.type == CallData::Type::None)) { + if (callData.type == CallData::Type::None) [[unlikely]] { scope.throwException(globalObject, createTypeError(globalObject, "Expected CommonJS module to have a function wrapper. If you weren't messing around with Bun's internals, this is a bug in Bun"_s)); RELEASE_AND_RETURN(scope, false); } @@ -247,13 +247,13 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionEvaluateCommonJSModule, (JSGlobalObject * lex ASSERT(callframe->argumentCount() == 2); JSCommonJSModule* moduleObject = jsDynamicCast(callframe->uncheckedArgument(0)); JSCommonJSModule* referrer = jsDynamicCast(callframe->uncheckedArgument(1)); - if (UNLIKELY(!moduleObject)) { + if (!moduleObject) [[unlikely]] { RELEASE_AND_RETURN(throwScope, JSValue::encode(jsUndefined())); } JSValue returnValue = jsNull(); - if (LIKELY(referrer)) { - if (UNLIKELY(referrer->m_childrenValue)) { + if (referrer) [[likely]] { + if (referrer->m_childrenValue) [[unlikely]] { // It's too hard to append from native code: // referrer.children.indexOf(moduleObject) === -1 && referrer.children.push(moduleObject) returnValue = referrer->m_childrenValue.get(); @@ -298,12 +298,12 @@ JSC_DEFINE_HOST_FUNCTION(requireResolvePathsFunction, (JSGlobalObject * globalOb // can see through the `this`. JSValue thisValue = callframe->thisValue(); auto* requireResolveBound = jsDynamicCast(thisValue); - if (UNLIKELY(!requireResolveBound)) { + if (!requireResolveBound) [[unlikely]] { return JSValue::encode(constructEmptyArray(globalObject, nullptr, 0)); } JSValue boundThis = requireResolveBound->boundThis(); JSString* filename = jsDynamicCast(boundThis); - if (UNLIKELY(!filename)) { + if (!filename) [[unlikely]] { return JSValue::encode(constructEmptyArray(globalObject, nullptr, 0)); } RETURN_IF_EXCEPTION(scope, {}); @@ -421,7 +421,7 @@ void RequireFunctionPrototype::finishCreation(JSC::VM& vm) JSC_DEFINE_CUSTOM_GETTER(getterFilename, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) { JSCommonJSModule* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } return JSValue::encode(thisObject->m_filename.get()); @@ -429,7 +429,7 @@ JSC_DEFINE_CUSTOM_GETTER(getterFilename, (JSC::JSGlobalObject * globalObject, JS JSC_DEFINE_CUSTOM_GETTER(getterId, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) { JSCommonJSModule* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } return JSValue::encode(thisObject->m_id.get()); @@ -438,7 +438,7 @@ JSC_DEFINE_CUSTOM_GETTER(getterId, (JSC::JSGlobalObject * globalObject, JSC::Enc JSC_DEFINE_CUSTOM_GETTER(getterPath, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) { JSCommonJSModule* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } return JSValue::encode(thisObject->m_dirname.get()); @@ -447,7 +447,7 @@ JSC_DEFINE_CUSTOM_GETTER(getterPath, (JSC::JSGlobalObject * globalObject, JSC::E JSC_DEFINE_CUSTOM_GETTER(getterParent, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) { JSCommonJSModule* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } @@ -493,7 +493,7 @@ JSC_DEFINE_CUSTOM_GETTER(getterPaths, (JSC::JSGlobalObject * globalObject, JSC:: auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); JSCommonJSModule* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } @@ -527,7 +527,7 @@ JSC_DEFINE_CUSTOM_SETTER(setterChildren, JSC_DEFINE_CUSTOM_GETTER(getterChildren, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) { JSCommonJSModule* mod = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!mod)) { + if (!mod) [[unlikely]] { return JSValue::encode(jsUndefined()); } @@ -543,10 +543,12 @@ JSC_DEFINE_CUSTOM_GETTER(getterChildren, (JSC::JSGlobalObject * globalObject, JS JSCommonJSModule* child = jsCast(childBarrier.get()); // Check the last module since duplicate imports, if any, will // probably be adjacent. Then just do a linear scan. - if (UNLIKELY(last == child)) continue; + if (last == child) [[unlikely]] + continue; int i = 0; while (i < n) { - if (UNLIKELY(children.at(i).asCell() == child)) goto next; + if (children.at(i).asCell() == child) [[unlikely]] + goto next; i += 1; } children.append(child); @@ -571,7 +573,7 @@ JSC_DEFINE_CUSTOM_GETTER(getterChildren, (JSC::JSGlobalObject * globalObject, JS JSC_DEFINE_CUSTOM_GETTER(getterLoaded, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) { JSCommonJSModule* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } @@ -648,7 +650,7 @@ JSC_DEFINE_CUSTOM_SETTER(setterLoaded, JSC_DEFINE_CUSTOM_GETTER(getterUnderscoreCompile, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) { JSCommonJSModule* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } if (thisObject->m_overriddenCompile) { @@ -688,7 +690,7 @@ JSC_DEFINE_HOST_FUNCTION(functionJSCommonJSModule_compile, (JSGlobalObject * glo String wrappedString; auto* zigGlobalObject = jsCast(globalObject); - if (UNLIKELY(zigGlobalObject->hasOverriddenModuleWrapper)) { + if (zigGlobalObject->hasOverriddenModuleWrapper) [[unlikely]] { wrappedString = makeString( zigGlobalObject->m_moduleWrapperStart, sourceString, @@ -1020,7 +1022,7 @@ void populateESMExports( } for (auto property : properties) { - if (UNLIKELY(property.isEmpty() || property.isNull() || property == esModuleMarker || property.isPrivateName() || property.isSymbol())) + if (property.isEmpty() || property.isNull() || property == esModuleMarker || property.isPrivateName() || property.isSymbol()) [[unlikely]] continue; // ignore constructor @@ -1077,7 +1079,7 @@ void populateESMExports( } for (auto property : properties) { - if (UNLIKELY(property.isEmpty() || property.isNull() || property == vm.propertyNames->defaultKeyword || property.isPrivateName() || property.isSymbol())) + if (property.isEmpty() || property.isNull() || property == vm.propertyNames->defaultKeyword || property.isPrivateName() || property.isSymbol()) [[unlikely]] continue; // ignore constructor @@ -1219,8 +1221,9 @@ ALWAYS_INLINE EncodedJSValue finishRequireWithError(Zig::GlobalObject* globalObj throwScope.throwException(globalObject, exception); RELEASE_AND_RETURN(throwScope, {}); } -#define REQUIRE_CJS_RETURN_IF_EXCEPTION \ - if (UNLIKELY(throwScope.exception())) return finishRequireWithError(globalObject, throwScope, specifierValue) +#define REQUIRE_CJS_RETURN_IF_EXCEPTION \ + if (throwScope.exception()) [[unlikely]] \ + return finishRequireWithError(globalObject, throwScope, specifierValue) // JSCommonJSModule.$require(resolvedId, newModule, userArgumentCount, userOptions) JSC_DEFINE_HOST_FUNCTION(jsFunctionRequireCommonJS, (JSGlobalObject * lexicalGlobalObject, CallFrame* callframe)) @@ -1253,7 +1256,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionRequireCommonJS, (JSGlobalObject * lexicalGlo // $argumentCount() always returns a Int32 JSValue int32_t userArgumentCount = callframe->argument(2).asInt32(); // If they called require(id), skip the check for the type attribute - if (UNLIKELY(userArgumentCount >= 2)) { + if (userArgumentCount >= 2) [[unlikely]] { JSValue options = callframe->uncheckedArgument(3); if (options.isObject()) { JSObject* obj = options.getObject(); @@ -1276,7 +1279,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionRequireCommonJS, (JSGlobalObject * lexicalGlo specifierValue, specifier, &referrerStr, - LIKELY(typeAttribute.isEmpty()) + typeAttribute.isEmpty() ? nullptr : &typeAttributeStr); REQUIRE_CJS_RETURN_IF_EXCEPTION; @@ -1298,6 +1301,8 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionRequireNativeModule, (JSGlobalObject * lexica WTF::String specifier = specifierValue.toWTFString(globalObject); RETURN_IF_EXCEPTION(throwScope, {}); ErrorableResolvedSource res; + res.success = false; + memset(&res.result, 0, sizeof res.result); BunString specifierStr = Bun::toString(specifier); if (auto result = fetchBuiltinModuleWithoutResolution(globalObject, &specifierStr, &res)) { if (res.success) @@ -1324,7 +1329,7 @@ void JSCommonJSModule::evaluate( { auto& vm = JSC::getVM(globalObject); - if (UNLIKELY(globalObject->hasOverriddenModuleWrapper)) { + if (globalObject->hasOverriddenModuleWrapper) [[unlikely]] { auto string = source.source_code.toWTFString(BunString::ZeroCopy); auto trimStart = string.find('\n'); if (trimStart != WTF::notFound) { @@ -1431,7 +1436,7 @@ std::optional createCommonJSModule( requireMapKey = JSC::jsString(vm, WTF::String("."_s)); } - if (UNLIKELY(globalObject->hasOverriddenModuleWrapper)) { + if (globalObject->hasOverriddenModuleWrapper) [[unlikely]] { auto concat = makeString( globalObject->m_moduleWrapperStart, source.source_code.toWTFString(BunString::ZeroCopy), diff --git a/src/bun.js/bindings/JSDOMExceptionHandling.cpp b/src/bun.js/bindings/JSDOMExceptionHandling.cpp index b8038c19f8..f2c83e14e7 100644 --- a/src/bun.js/bindings/JSDOMExceptionHandling.cpp +++ b/src/bun.js/bindings/JSDOMExceptionHandling.cpp @@ -146,7 +146,7 @@ void reportCurrentException(JSGlobalObject* lexicalGlobalObject) JSValue createDOMException(JSGlobalObject* lexicalGlobalObject, ExceptionCode ec, const String& message) { auto& vm = JSC::getVM(lexicalGlobalObject); - if (UNLIKELY(vm.hasPendingTerminationException())) + if (vm.hasPendingTerminationException()) [[unlikely]] return jsUndefined(); switch (ec) { diff --git a/src/bun.js/bindings/JSDOMExceptionHandling.h b/src/bun.js/bindings/JSDOMExceptionHandling.h index e208b48800..600673927e 100644 --- a/src/bun.js/bindings/JSDOMExceptionHandling.h +++ b/src/bun.js/bindings/JSDOMExceptionHandling.h @@ -85,7 +85,7 @@ ALWAYS_INLINE void propagateException(JSC::JSGlobalObject& lexicalGlobalObject, inline void propagateException(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& throwScope, ExceptionOr&& value) { - if (UNLIKELY(value.hasException())) + if (value.hasException()) [[unlikely]] propagateException(lexicalGlobalObject, throwScope, value.releaseException()); } @@ -100,7 +100,7 @@ template void invokeFunctorPropagatingExceptionIfNecessary(JSC if constexpr (IsExceptionOr) { auto result = functor(); - if (UNLIKELY(result.hasException())) + if (result.hasException()) [[unlikely]] propagateException(lexicalGlobalObject, throwScope, result.releaseException()); } else functor(); @@ -112,7 +112,7 @@ template void invokeFunctorPropagatingExceptionIfNecessary(JSC if constexpr (IsExceptionOr) { auto result = functor(); - if (UNLIKELY(result.hasException())) + if (result.hasException()) [[unlikely]] propagateException(lexicalGlobalObject, throwScope, result.releaseException()); } else functor(); diff --git a/src/bun.js/bindings/JSDOMFile.cpp b/src/bun.js/bindings/JSDOMFile.cpp index dbb2acfbd7..a69d1b66d0 100644 --- a/src/bun.js/bindings/JSDOMFile.cpp +++ b/src/bun.js/bindings/JSDOMFile.cpp @@ -85,7 +85,7 @@ public: void* ptr = JSDOMFile__construct(lexicalGlobalObject, callFrame); - if (UNLIKELY(!ptr)) { + if (!ptr) [[unlikely]] { return JSValue::encode(JSC::jsUndefined()); } diff --git a/src/bun.js/bindings/JSDOMWrapperCache.h b/src/bun.js/bindings/JSDOMWrapperCache.h index 13991a0065..d692416a04 100644 --- a/src/bun.js/bindings/JSDOMWrapperCache.h +++ b/src/bun.js/bindings/JSDOMWrapperCache.h @@ -216,7 +216,7 @@ template inline void setSubclassStructureIfNeeded(JSC::JSGlob auto scope = DECLARE_THROW_SCOPE(vm); // If the new target isn't actually callable - if (UNLIKELY(!newTarget->isCallable())) + if (!newTarget->isCallable()) [[unlikely]] newTarget = constructor; auto* functionGlobalObject = JSC::getFunctionRealm(lexicalGlobalObject, newTarget); diff --git a/src/bun.js/bindings/JSEnvironmentVariableMap.cpp b/src/bun.js/bindings/JSEnvironmentVariableMap.cpp index 647d3b5c86..6f08fa2a2a 100644 --- a/src/bun.js/bindings/JSEnvironmentVariableMap.cpp +++ b/src/bun.js/bindings/JSEnvironmentVariableMap.cpp @@ -31,13 +31,13 @@ JSC_DEFINE_CUSTOM_GETTER(jsGetterEnvironmentVariable, (JSGlobalObject * globalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); ZigString name = toZigString(propertyName.publicName()); ZigString value = { nullptr, 0 }; - if (UNLIKELY(name.len == 0)) + if (name.len == 0) [[unlikely]] return JSValue::encode(jsUndefined()); if (!Bun__getEnvValue(globalObject, &name, &value)) { @@ -57,7 +57,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsSetterEnvironmentVariable, (JSGlobalObject * globalOb return false; auto string = JSValue::decode(value).toString(globalObject); - if (UNLIKELY(!string)) + if (!string) [[unlikely]] return false; object->putDirect(vm, propertyName, string, 0); @@ -70,7 +70,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsTimeZoneEnvironmentVariableGetter, (JSGlobalObject * auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); auto* clientData = WebCore::clientData(vm); @@ -152,12 +152,12 @@ JSC_DEFINE_CUSTOM_GETTER(jsNodeTLSRejectUnauthorizedGetter, (JSGlobalObject * gl auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); const auto& privateName = NODE_TLS_REJECT_UNAUTHORIZED_PRIVATE_PROPERTY(vm); JSValue result = thisObject->getDirect(vm, privateName); - if (UNLIKELY(result)) { + if (result) [[unlikely]] { return JSValue::encode(result); } @@ -206,12 +206,12 @@ JSC_DEFINE_CUSTOM_GETTER(jsBunConfigVerboseFetchGetter, (JSGlobalObject * global auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return JSValue::encode(jsUndefined()); const auto& privateName = BUN_CONFIG_VERBOSE_FETCH_PRIVATE_PROPERTY(vm); JSValue result = thisObject->getDirect(vm, privateName); - if (UNLIKELY(result)) { + if (result) [[unlikely]] { return JSValue::encode(result); } @@ -332,7 +332,7 @@ JSValue createEnvironmentVariablesMap(Zig::GlobalObject* globalObject) // CustomGetterSetter doesn't support indexed properties yet. // This causes strange issues when the environment variable name is an integer. - if (UNLIKELY(chars[0] >= '0' && chars[0] <= '9')) { + if (chars[0] >= '0' && chars[0] <= '9') [[unlikely]] { if (auto index = parseIndex(identifier)) { ZigString valueString = { nullptr, 0 }; ZigString nameStr = toZigString(name); diff --git a/src/bun.js/bindings/JSFFIFunction.cpp b/src/bun.js/bindings/JSFFIFunction.cpp index a8e73534b1..0e5c296607 100644 --- a/src/bun.js/bindings/JSFFIFunction.cpp +++ b/src/bun.js/bindings/JSFFIFunction.cpp @@ -204,7 +204,7 @@ FFI_Callback_call(FFICallbackFunctionWrapper& wrapper, size_t argCount, JSC::Enc arguments.appendWithCrashOnOverflow(JSC::JSValue::decode(args[i])); WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); @@ -231,7 +231,7 @@ FFI_Callback_threadsafe_call(FFICallbackFunctionWrapper& wrapper, size_t argCoun arguments.appendWithCrashOnOverflow(JSC::JSValue::decode(argsVec[i])); WTF::NakedPtr exception; JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return; @@ -250,7 +250,7 @@ FFI_Callback_call_0(FFICallbackFunctionWrapper& wrapper, size_t argCount, JSC::E WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); @@ -271,7 +271,7 @@ FFI_Callback_call_1(FFICallbackFunctionWrapper& wrapper, size_t argCount, JSC::E WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); @@ -293,7 +293,7 @@ FFI_Callback_call_2(FFICallbackFunctionWrapper& wrapper, size_t argCount, JSC::E WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); @@ -315,7 +315,7 @@ extern "C" JSC::EncodedJSValue FFI_Callback_call_3(FFICallbackFunctionWrapper& w WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); @@ -338,7 +338,7 @@ extern "C" JSC::EncodedJSValue FFI_Callback_call_4(FFICallbackFunctionWrapper& w WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); @@ -362,7 +362,7 @@ extern "C" JSC::EncodedJSValue FFI_Callback_call_5(FFICallbackFunctionWrapper& w WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); @@ -388,7 +388,7 @@ FFI_Callback_call_6(FFICallbackFunctionWrapper& wrapper, size_t argCount, JSC::E WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); @@ -415,7 +415,7 @@ FFI_Callback_call_7(FFICallbackFunctionWrapper& wrapper, size_t argCount, JSC::E WTF::NakedPtr exception; auto result = JSC::profiledCall(globalObject, JSC::ProfilingReason::API, function, JSC::getCallData(function), JSC::jsUndefined(), arguments, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); scope.throwException(globalObject, exception); return JSC::JSValue::encode(JSC::jsNull()); diff --git a/src/bun.js/bindings/JSMockFunction.cpp b/src/bun.js/bindings/JSMockFunction.cpp index 39faa9857d..372346a2cc 100644 --- a/src/bun.js/bindings/JSMockFunction.cpp +++ b/src/bun.js/bindings/JSMockFunction.cpp @@ -38,7 +38,7 @@ BUN_DECLARE_HOST_FUNCTION(JSMock__jsSpyOn); BUN_DECLARE_HOST_FUNCTION(JSMock__jsMockFn); #define CHECK_IS_MOCK_FUNCTION(thisValue) \ - if (UNLIKELY(!thisObject)) { \ + if (!thisObject) [[unlikely]] { \ scope.throwException(globalObject, createInvalidThisError(globalObject, thisValue, "Mock"_s)); \ return {}; \ } @@ -59,9 +59,9 @@ namespace Bun { template inline To tryJSDynamicCast(JSValue from) { - if (UNLIKELY(!from)) + if (!from) [[unlikely]] return nullptr; - if (UNLIKELY(!from.isCell())) + if (!from.isCell()) [[unlikely]] return nullptr; return jsDynamicCast(from.asCell()); } @@ -80,7 +80,7 @@ inline To tryJSDynamicCast(JSValue from) template inline To tryJSDynamicCast(JSC::WriteBarrier& from) { - if (UNLIKELY(!from)) + if (!from) [[unlikely]] return nullptr; return jsDynamicCast(from.get()); @@ -812,7 +812,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionCall, (JSGlobalObject * lexicalGlobalObje auto& vm = JSC::getVM(globalObject); JSMockFunction* fn = jsDynamicCast(callframe->jsCallee()); auto scope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(!fn)) { + if (!fn) [[unlikely]] { throwTypeError(globalObject, scope, "Expected callee to be mock function"_s); return {}; } @@ -900,7 +900,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionCall, (JSGlobalObject * lexicalGlobalObje case JSMockImplementation::Kind::Call: { JSValue result = impl->underlyingValue.get(); JSC::CallData callData = JSC::getCallData(result); - if (UNLIKELY(callData.type == JSC::CallData::Type::None)) { + if (callData.type == JSC::CallData::Type::None) [[unlikely]] { throwTypeError(globalObject, scope, "Expected mock implementation to be callable"_s); return {}; } @@ -921,7 +921,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionCall, (JSGlobalObject * lexicalGlobalObje } } - if (UNLIKELY(!returnValue)) { + if (!returnValue) [[unlikely]] { returnValue = jsUndefined(); } @@ -1238,7 +1238,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionGetter_mockGetLastCall, (JSC::JSGlobalObj auto& vm = JSC::getVM(globalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); JSValue thisObject = callframe->thisValue(); - if (UNLIKELY(!thisObject.isObject())) { + if (!thisObject.isObject()) [[unlikely]] { return JSValue::encode(jsUndefined()); } JSValue callsValue = thisObject.get(globalObject, Identifier::fromString(vm, "calls"_s)); @@ -1336,7 +1336,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionWithImplementation, (JSC::JSGlobalObject JSValue tempImplValue = callframe->argument(0); JSValue callback = callframe->argument(1); JSC::CallData callData = JSC::getCallData(callback); - if (UNLIKELY(callData.type == JSC::CallData::Type::None)) { + if (callData.type == JSC::CallData::Type::None) [[unlikely]] { throwTypeError(globalObject, scope, "Expected mock implementation to be callable"_s); return {}; } @@ -1440,7 +1440,7 @@ BUN_DEFINE_HOST_FUNCTION(JSMock__jsSpyOn, (JSC::JSGlobalObject * lexicalGlobalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* globalObject = jsDynamicCast(lexicalGlobalObject); - if (UNLIKELY(!globalObject)) { + if (!globalObject) [[unlikely]] { throwVMError(globalObject, scope, "Cannot run spyOn from a different global context"_s); return {}; } @@ -1472,7 +1472,7 @@ BUN_DEFINE_HOST_FUNCTION(JSMock__jsSpyOn, (JSC::JSGlobalObject * lexicalGlobalOb if (!hasValue || slot.isValue()) { JSValue value = jsUndefined(); if (hasValue) { - if (UNLIKELY(slot.isTaintedByOpaqueObject())) { + if (slot.isTaintedByOpaqueObject()) [[unlikely]] { // if it's a Proxy or JSModuleNamespaceObject value = object->get(globalObject, propertyKey); } else { @@ -1564,7 +1564,7 @@ BUN_DEFINE_HOST_FUNCTION(JSMock__jsMockFn, (JSC::JSGlobalObject * lexicalGlobalO globalObject, globalObject->mockModule.mockFunctionStructure.getInitializedOnMainThread(globalObject)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwOutOfMemoryError(globalObject, scope); return {}; } diff --git a/src/bun.js/bindings/JSPropertyIterator.cpp b/src/bun.js/bindings/JSPropertyIterator.cpp index 969b95866d..b7891e8383 100644 --- a/src/bun.js/bindings/JSPropertyIterator.cpp +++ b/src/bun.js/bindings/JSPropertyIterator.cpp @@ -47,13 +47,13 @@ extern "C" JSPropertyIterator* Bun__JSPropertyIterator__create(JSC::JSGlobalObje auto scope = DECLARE_THROW_SCOPE(vm); JSC::PropertyNameArray array(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Exclude); - if (UNLIKELY(object->hasNonReifiedStaticProperties())) { + if (object->hasNonReifiedStaticProperties()) [[unlikely]] { object->reifyAllStaticProperties(globalObject); RETURN_IF_EXCEPTION(scope, {}); } #if OS(WINDOWS) - if (UNLIKELY(object->type() == JSC::ProxyObjectType)) { + if (object->type() == JSC::ProxyObjectType) [[unlikely]] { // Check if we're actually iterating through the JSEnvironmentVariableMap's proxy. auto* zigGlobal = defaultGlobalObject(globalObject); if (zigGlobal->m_processEnvObject.isInitialized()) { @@ -131,7 +131,7 @@ static EncodedJSValue getOwnProxyObject(JSPropertyIterator* iter, JSObject* obje extern "C" EncodedJSValue Bun__JSPropertyIterator__getNameAndValue(JSPropertyIterator* iter, JSC::JSGlobalObject* globalObject, JSC::JSObject* object, BunString* propertyName, size_t i) { const auto& prop = iter->properties->propertyNameVector()[i]; - if (UNLIKELY(iter->isSpecialProxy)) { + if (iter->isSpecialProxy) [[unlikely]] { return getOwnProxyObject(iter, object, prop, propertyName); } @@ -155,7 +155,7 @@ extern "C" EncodedJSValue Bun__JSPropertyIterator__getNameAndValue(JSPropertyIte extern "C" EncodedJSValue Bun__JSPropertyIterator__getNameAndValueNonObservable(JSPropertyIterator* iter, JSC::JSGlobalObject* globalObject, JSC::JSObject* object, BunString* propertyName, size_t i) { const auto& prop = iter->properties->propertyNameVector()[i]; - if (UNLIKELY(iter->isSpecialProxy)) { + if (iter->isSpecialProxy) [[unlikely]] { return getOwnProxyObject(iter, object, prop, propertyName); } auto& vm = iter->vm; diff --git a/src/bun.js/bindings/JSStringDecoder.cpp b/src/bun.js/bindings/JSStringDecoder.cpp index 7899c4bcfb..f87158ad8f 100644 --- a/src/bun.js/bindings/JSStringDecoder.cpp +++ b/src/bun.js/bindings/JSStringDecoder.cpp @@ -84,8 +84,9 @@ ALWAYS_INLINE bool isContinuation(uint8_t byte) static inline JSStringDecoder* jsStringDecoderCast(JSGlobalObject* globalObject, JSValue stringDecoderValue, WTF::ASCIILiteral functionName) { ASSERT(stringDecoderValue); - if (auto cast = jsDynamicCast(stringDecoderValue); LIKELY(cast)) + if (auto cast = jsDynamicCast(stringDecoderValue); cast) [[likely]] { return cast; + } auto& vm = JSC::getVM(globalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); @@ -93,9 +94,10 @@ static inline JSStringDecoder* jsStringDecoderCast(JSGlobalObject* globalObject, if (JSC::JSObject* thisObject = stringDecoderValue.getObject()) { auto clientData = WebCore::clientData(vm); JSValue existingDecoderValue = thisObject->getIfPropertyExists(globalObject, clientData->builtinNames().decodePrivateName()); - if (LIKELY(existingDecoderValue)) { - if (auto cast = jsDynamicCast(existingDecoderValue); LIKELY(cast)) + if (existingDecoderValue) [[likely]] { + if (auto cast = jsDynamicCast(existingDecoderValue); cast) [[likely]] { return cast; + } } } @@ -411,7 +413,7 @@ static inline JSC::EncodedJSValue jsStringDecoderPrototypeFunction_writeBody(JSC auto buffer = callFrame->uncheckedArgument(0); JSC::JSArrayBufferView* view = JSC::jsDynamicCast(buffer); - if (UNLIKELY(!view || view->isDetached())) { + if (!view || view->isDetached()) [[unlikely]] { // What node does: // StringDecoder.prototype.write = function write(buf) { // if (typeof buf === 'string') @@ -434,7 +436,7 @@ static inline JSC::EncodedJSValue jsStringDecoderPrototypeFunction_endBody(JSC:: auto buffer = callFrame->uncheckedArgument(0); JSC::JSArrayBufferView* view = JSC::jsDynamicCast(buffer); - if (UNLIKELY(!view || view->isDetached())) { + if (!view || view->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Uint8Array"_s); return {}; } @@ -451,7 +453,7 @@ static inline JSC::EncodedJSValue jsStringDecoderPrototypeFunction_textBody(JSC: auto buffer = callFrame->uncheckedArgument(0); JSC::JSArrayBufferView* view = JSC::jsDynamicCast(buffer); - if (UNLIKELY(!view || view->isDetached())) { + if (!view || view->isDetached()) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Uint8Array"_s); return {}; } diff --git a/src/bun.js/bindings/JSValue.zig b/src/bun.js/bindings/JSValue.zig index ac6bb53818..78c2536c5c 100644 --- a/src/bun.js/bindings/JSValue.zig +++ b/src/bun.js/bindings/JSValue.zig @@ -98,33 +98,34 @@ pub const JSValue = enum(i64) { ModuleEnvironment = 55, StrictEvalActivation = 56, WithScope = 57, - ModuleNamespaceObject = 58, - ShadowRealm = 59, - RegExpObject = 60, - JSDate = 61, - ProxyObject = 62, - Generator = 63, - AsyncGenerator = 64, - JSArrayIterator = 65, - Iterator = 66, - IteratorHelper = 67, - MapIterator = 68, - SetIterator = 69, - StringIterator = 70, - WrapForValidIterator = 71, - RegExpStringIterator = 72, - AsyncFromSyncIterator = 73, - JSPromise = 74, - Map = 75, - Set = 76, - WeakMap = 77, - WeakSet = 78, - WebAssemblyModule = 79, - WebAssemblyInstance = 80, - WebAssemblyGCObject = 81, - StringObject = 82, - DerivedStringObject = 83, - InternalFieldTuple = 84, + DisposableStack = 58, + ModuleNamespaceObject = 59, + ShadowRealm = 60, + RegExpObject = 61, + JSDate = 62, + ProxyObject = 63, + Generator = 64, + AsyncGenerator = 65, + JSArrayIterator = 66, + Iterator = 67, + IteratorHelper = 68, + MapIterator = 69, + SetIterator = 70, + StringIterator = 71, + WrapForValidIterator = 72, + RegExpStringIterator = 73, + AsyncFromSyncIterator = 74, + JSPromise = 75, + Map = 76, + Set = 77, + WeakMap = 78, + WeakSet = 79, + WebAssemblyModule = 80, + WebAssemblyInstance = 81, + WebAssemblyGCObject = 82, + StringObject = 83, + DerivedStringObject = 84, + InternalFieldTuple = 85, MaxJS = 0b11111111, Event = 0b11101111, diff --git a/src/bun.js/bindings/JSX509Certificate.cpp b/src/bun.js/bindings/JSX509Certificate.cpp index 87fd4dbdeb..8720e599f0 100644 --- a/src/bun.js/bindings/JSX509Certificate.cpp +++ b/src/bun.js/bindings/JSX509Certificate.cpp @@ -109,14 +109,14 @@ static JSValue createX509Certificate(JSC::VM& vm, JSGlobalObject* globalObject, RETURN_IF_EXCEPTION(scope, {}); data = std::span(reinterpret_cast(view.span().data()), view.span().size()); } else if (auto* typedArray = jsDynamicCast(arg)) { - if (UNLIKELY(typedArray->isDetached())) { + if (typedArray->isDetached()) [[unlikely]] { Bun::throwError(globalObject, scope, ErrorCode::ERR_INVALID_ARG_TYPE, "TypedArray is detached"_s); return {}; } data = typedArray->span(); } else if (auto* buffer = jsDynamicCast(arg)) { auto* impl = buffer->impl(); - if (UNLIKELY(!impl)) { + if (!impl) [[unlikely]] { Bun::throwError(globalObject, scope, ErrorCode::ERR_INVALID_ARG_TYPE, "Buffer is detached"_s); return {}; } @@ -157,7 +157,7 @@ JSC_DEFINE_HOST_FUNCTION(x509CertificateConstructorConstruct, (JSGlobalObject * auto* zigGlobalObject = defaultGlobalObject(globalObject); Structure* structure = zigGlobalObject->m_JSX509CertificateClassStructure.get(zigGlobalObject); JSValue newTarget = callFrame->newTarget(); - if (UNLIKELY(zigGlobalObject->m_JSX509CertificateClassStructure.constructor(zigGlobalObject) != newTarget)) { + if (zigGlobalObject->m_JSX509CertificateClassStructure.constructor(zigGlobalObject) != newTarget) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); if (!newTarget) { throwTypeError(globalObject, scope, "Class constructor Script cannot be invoked without 'new'"_s); diff --git a/src/bun.js/bindings/JSX509CertificatePrototype.cpp b/src/bun.js/bindings/JSX509CertificatePrototype.cpp index 10e60553fe..198960046e 100644 --- a/src/bun.js/bindings/JSX509CertificatePrototype.cpp +++ b/src/bun.js/bindings/JSX509CertificatePrototype.cpp @@ -99,7 +99,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncToString, (JSGlobalObject * g auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "toString"_s); return {}; } @@ -248,7 +248,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncCheckEmail, (JSGlobalObject * auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "checkEmail"_s); return {}; } @@ -281,7 +281,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncCheckHost, (JSGlobalObject * auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "checkHost"_s); return {}; } @@ -314,7 +314,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncCheckIP, (JSGlobalObject * gl auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "checkIP"_s); return {}; } @@ -347,7 +347,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncCheckIssued, (JSGlobalObject auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwVMError(globalObject, scope, createError(globalObject, ErrorCode::ERR_INVALID_THIS, "checkIssued called on incompatible receiver"_s)); JSX509Certificate* issuer = jsDynamicCast(callFrame->argument(0)); @@ -367,7 +367,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncCheckPrivateKey, (JSGlobalObj auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwVMError(globalObject, scope, createError(globalObject, ErrorCode::ERR_INVALID_THIS, "checkPrivateKey called on incompatible receiver"_s)); JSValue pkeyValue = callFrame->argument(0); @@ -391,7 +391,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncToJSON, (JSGlobalObject * glo auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwVMError(globalObject, scope, createError(globalObject, ErrorCode::ERR_INVALID_THIS, "toJSON called on incompatible receiver"_s)); // There's no standardized JSON encoding for X509 certs so we @@ -405,7 +405,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncToLegacyObject, (JSGlobalObje auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "toLegacyObject"_s); return {}; } @@ -433,7 +433,7 @@ JSC_DEFINE_HOST_FUNCTION(jsX509CertificateProtoFuncVerify, (JSGlobalObject * glo auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "verify"_s); return {}; } @@ -459,7 +459,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_ca, (JSGlobalObject * globalObj auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "ca"_s); return {}; } @@ -473,7 +473,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_fingerprint, (JSGlobalObject * auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "fingerprint"_s); return {}; } @@ -487,7 +487,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_fingerprint256, (JSGlobalObject auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "fingerprint256"_s); return {}; } @@ -501,7 +501,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_fingerprint512, (JSGlobalObject auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "fingerprint512"_s); return {}; } @@ -515,7 +515,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_subject, (JSGlobalObject * glob auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "subject"_s); return {}; } @@ -529,7 +529,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_subjectAltName, (JSGlobalObject auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "subjectAltName"_s); return {}; } @@ -543,7 +543,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_infoAccess, (JSGlobalObject * g auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "infoAccess"_s); return {}; } @@ -562,7 +562,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_keyUsage, (JSGlobalObject * glo auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "keyUsage"_s); return {}; } @@ -576,7 +576,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_issuer, (JSGlobalObject * globa auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "issuer"_s); return {}; } @@ -590,7 +590,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_issuerCertificate, (JSGlobalObj auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "issuerCertificate"_s); return {}; } @@ -617,7 +617,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_publicKey, (JSGlobalObject * gl auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "publicKey"_s); return {}; } @@ -631,7 +631,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_raw, (JSGlobalObject * globalOb auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "raw"_s); return {}; } @@ -645,7 +645,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_serialNumber, (JSGlobalObject * auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "serialNumber"_s); return {}; } @@ -659,7 +659,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_validFrom, (JSGlobalObject * gl auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "validFrom"_s); return {}; } @@ -673,7 +673,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_validTo, (JSGlobalObject * glob auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "validTo"_s); return {}; } @@ -687,7 +687,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_validToDate, (JSGlobalObject * auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "validToDate"_s); return {}; } @@ -710,7 +710,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsX509CertificateGetter_validFromDate, (JSGlobalObject auto scope = DECLARE_THROW_SCOPE(vm); JSX509Certificate* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "X509Certificate"_s, "validFromDate"_s); return {}; } diff --git a/src/bun.js/bindings/ModuleLoader.cpp b/src/bun.js/bindings/ModuleLoader.cpp index 4cdb70fcc2..a8aae7b75b 100644 --- a/src/bun.js/bindings/ModuleLoader.cpp +++ b/src/bun.js/bindings/ModuleLoader.cpp @@ -111,7 +111,7 @@ static JSC::SyntheticSourceProvider::SyntheticSourceGenerator generateInternalMo bool hasDefault = false; for (auto& entry : properties) { - if (UNLIKELY(entry == vm.propertyNames->defaultKeyword)) { + if (entry == vm.propertyNames->defaultKeyword) [[unlikely]] { hasDefault = true; } exportNames.append(entry); @@ -219,7 +219,7 @@ OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC:: } JSC::JSObject* object = objectValue.getObject(); - if (UNLIKELY(!object)) { + if (!object) [[unlikely]] { scope.throwException(globalObject, JSC::createError(globalObject, "Expected module mock to return an object"_s)); result.value.error = scope.exception(); @@ -253,7 +253,7 @@ OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC:: } } - if (UNLIKELY(loader == BunLoaderTypeNone)) { + if (loader == BunLoaderTypeNone) [[unlikely]] { throwException(globalObject, scope, createError(globalObject, "Expected loader to be one of \"js\", \"jsx\", \"object\", \"ts\", \"tsx\", \"toml\", or \"json\""_s)); result.value.error = scope.exception(); return result; @@ -275,7 +275,7 @@ OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC:: } } - if (UNLIKELY(result.value.sourceText.value.isEmpty())) { + if (result.value.sourceText.value.isEmpty()) [[unlikely]] { throwException(globalObject, scope, createError(globalObject, "Expected \"contents\" to be a string or an ArrayBufferView"_s)); result.value.error = scope.exception(); return result; @@ -532,7 +532,8 @@ JSValue resolveAndFetchBuiltinModule( auto& vm = JSC::getVM(globalObject); auto scope = DECLARE_THROW_SCOPE(vm); ErrorableResolvedSource res; - memset(&res, 0, sizeof(ErrorableResolvedSource)); + res.success = false; + memset(&res.result, 0, sizeof res.result); if (Bun__resolveAndFetchBuiltinModule(bunVM, specifier, &res)) { ASSERT(res.success); @@ -607,7 +608,8 @@ JSValue fetchCommonJSModule( auto& vm = JSC::getVM(globalObject); auto scope = DECLARE_THROW_SCOPE(vm); ErrorableResolvedSource resValue; - memset(&resValue, 0, sizeof(ErrorableResolvedSource)); + resValue.success = false; + memset(&resValue.result, 0, sizeof resValue.result); ErrorableResolvedSource* res = &resValue; ResolvedSourceCodeHolder sourceCodeHolder(res); @@ -1074,8 +1076,9 @@ using namespace Bun; BUN_DEFINE_HOST_FUNCTION(jsFunctionOnLoadObjectResultResolve, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { auto& vm = JSC::getVM(globalObject); - ErrorableResolvedSource res = {}; + ErrorableResolvedSource res; res.success = false; + memset(&res.result, 0, sizeof res.result); JSC::JSValue objectResult = callFrame->argument(0); PendingVirtualModuleResult* pendingModule = JSC::jsCast(callFrame->argument(1)); JSC::JSValue specifierString = pendingModule->internalField(0).get(); diff --git a/src/bun.js/bindings/NodeDirent.cpp b/src/bun.js/bindings/NodeDirent.cpp index 043d09e617..de4385bac7 100644 --- a/src/bun.js/bindings/NodeDirent.cpp +++ b/src/bun.js/bindings/NodeDirent.cpp @@ -168,7 +168,7 @@ JSC_DEFINE_HOST_FUNCTION(constructDirent, (JSC::JSGlobalObject * globalObject, J Structure* structure = zigGlobalObject->m_JSDirentClassStructure.get(zigGlobalObject); auto* originalStructure = structure; JSValue newTarget = callFrame->newTarget(); - if (UNLIKELY(zigGlobalObject->m_JSDirentClassStructure.constructor(zigGlobalObject) != newTarget)) { + if (zigGlobalObject->m_JSDirentClassStructure.constructor(zigGlobalObject) != newTarget) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); if (!newTarget) { throwTypeError(globalObject, scope, "Class constructor Dirent cannot be invoked without 'new'"_s); @@ -201,14 +201,14 @@ JSC_DEFINE_HOST_FUNCTION(constructDirent, (JSC::JSGlobalObject * globalObject, J static inline int32_t getType(JSC::VM& vm, JSValue value, Zig::GlobalObject* globalObject) { JSObject* object = value.getObject(); - if (UNLIKELY(!object)) { + if (!object) [[unlikely]] { return std::numeric_limits::max(); } auto* structure = getStructure(globalObject); JSValue type; if (structure->id() != object->structure()->id()) { type = object->get(globalObject, Bun::builtinNames(vm).dataPrivateName()); - if (UNLIKELY(!type)) { + if (!type) [[unlikely]] { return std::numeric_limits::max(); } } else { diff --git a/src/bun.js/bindings/NodeHTTP.cpp b/src/bun.js/bindings/NodeHTTP.cpp index 540b179842..3565d214cc 100644 --- a/src/bun.js/bindings/NodeHTTP.cpp +++ b/src/bun.js/bindings/NodeHTTP.cpp @@ -273,7 +273,7 @@ public: JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeHTTPServerSocketClose, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(JSC::jsUndefined()); } if (thisObject->isClosed()) { @@ -616,7 +616,7 @@ static void assignHeadersFromUWebSocketsForCall(uWS::HttpRequest* request, JSVal } // Get the method. - if (UNLIKELY(methodString.isUndefinedOrNull())) { + if (methodString.isUndefinedOrNull()) [[unlikely]] { std::string_view methodView = request->getMethod(); WTF::String methodString = String::fromUTF8ReplacingInvalidSequences({ reinterpret_cast(methodView.data()), methodView.length() }); args.append(jsString(vm, WTFMove(methodString))); @@ -686,7 +686,7 @@ static void assignHeadersFromUWebSocketsForCall(uWS::HttpRequest* request, JSVal { ObjectInitializationScope initializationScope(vm); - if (LIKELY(array = JSArray::tryCreateUninitializedRestricted(initializationScope, nullptr, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), arrayValues.size()))) { + if ((array = JSArray::tryCreateUninitializedRestricted(initializationScope, nullptr, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), arrayValues.size()))) [[likely]] { EncodedJSValue* data = arrayValues.data(); for (size_t i = 0, size = arrayValues.size(); i < size; ++i) { array->initializeIndex(initializationScope, i, JSValue::decode(data[i])); @@ -819,7 +819,7 @@ static EncodedJSValue assignHeadersFromUWebSockets(uWS::HttpRequest* request, JS StringView nameView = StringView(std::span { reinterpret_cast(pair.first.data()), pair.first.length() }); std::span data; auto value = String::tryCreateUninitialized(pair.second.length(), data); - if (UNLIKELY(value.isNull())) { + if (value.isNull()) [[unlikely]] { throwOutOfMemoryError(globalObject, scope); return JSValue::encode({}); } @@ -1079,7 +1079,7 @@ static void NodeHTTPServer__writeHead( return; } - if (UNLIKELY(headersObject->hasNonReifiedStaticProperties())) { + if (headersObject->hasNonReifiedStaticProperties()) [[unlikely]] { headersObject->reifyAllStaticProperties(globalObject); RETURN_IF_EXCEPTION(scope, void()); } @@ -1403,7 +1403,7 @@ JSC_DEFINE_HOST_FUNCTION(jsHTTPSetHeader, (JSGlobalObject * globalObject, CallFr unsigned length = array->length(); if (length > 0) { JSValue item = array->getIndex(globalObject, 0); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return JSValue::encode(jsUndefined()); auto value = item.toWTFString(globalObject); @@ -1413,7 +1413,7 @@ JSC_DEFINE_HOST_FUNCTION(jsHTTPSetHeader, (JSGlobalObject * globalObject, CallFr } for (unsigned i = 1; i < length; ++i) { JSValue value = array->getIndex(globalObject, i); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return JSValue::encode(jsUndefined()); auto string = value.toWTFString(globalObject); RETURN_IF_EXCEPTION(scope, {}); diff --git a/src/bun.js/bindings/NodeTimerObject.cpp b/src/bun.js/bindings/NodeTimerObject.cpp index 0840f62528..d3523c983d 100644 --- a/src/bun.js/bindings/NodeTimerObject.cpp +++ b/src/bun.js/bindings/NodeTimerObject.cpp @@ -59,7 +59,7 @@ static bool call(JSGlobalObject* globalObject, JSValue timerObject, JSValue call bool hadException = false; - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { auto* exception = scope.exception(); scope.clearException(); Bun__reportUnhandledError(globalObject, JSValue::encode(exception)); @@ -77,7 +77,7 @@ static bool call(JSGlobalObject* globalObject, JSValue timerObject, JSValue call extern "C" bool Bun__JSTimeout__call(JSGlobalObject* globalObject, EncodedJSValue timerObject, EncodedJSValue callbackValue, EncodedJSValue argumentsValue) { auto& vm = globalObject->vm(); - if (UNLIKELY(vm.hasPendingTerminationException())) { + if (vm.hasPendingTerminationException()) [[unlikely]] { return true; } diff --git a/src/bun.js/bindings/NodeVM.cpp b/src/bun.js/bindings/NodeVM.cpp index 8146a46774..1002de4582 100644 --- a/src/bun.js/bindings/NodeVM.cpp +++ b/src/bun.js/bindings/NodeVM.cpp @@ -748,7 +748,7 @@ constructScript(JSGlobalObject* globalObject, CallFrame* callFrame, JSValue newT auto* zigGlobalObject = defaultGlobalObject(globalObject); Structure* structure = zigGlobalObject->NodeVMScriptStructure(); - if (UNLIKELY(zigGlobalObject->NodeVMScript() != newTarget)) { + if (zigGlobalObject->NodeVMScript() != newTarget) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); if (!newTarget) { throwTypeError(globalObject, scope, "Class constructor Script cannot be invoked without 'new'"_s); @@ -868,7 +868,7 @@ static JSC::EncodedJSValue runInContext(NodeVMGlobalObject* globalObject, NodeVM NakedPtr exception; JSValue result = JSC::evaluate(globalObject, script->source(), globalObject, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { if (handleException(globalObject, vm, exception, throwScope)) { return {}; } @@ -896,7 +896,7 @@ JSC_DEFINE_HOST_FUNCTION(scriptCreateCachedData, (JSGlobalObject * globalObject, JSValue thisValue = callFrame->thisValue(); auto* script = jsDynamicCast(thisValue); - if (UNLIKELY(!script)) { + if (!script) [[unlikely]] { return ERR::INVALID_ARG_VALUE(scope, globalObject, "this"_s, thisValue, "must be a Script"_s); } @@ -911,7 +911,7 @@ JSC_DEFINE_HOST_FUNCTION(scriptRunInContext, (JSGlobalObject * globalObject, Cal JSValue thisValue = callFrame->thisValue(); auto* script = jsDynamicCast(thisValue); - if (UNLIKELY(!script)) { + if (!script) [[unlikely]] { return ERR::INVALID_ARG_VALUE(scope, globalObject, "this"_s, thisValue, "must be a Script"_s); } @@ -947,7 +947,7 @@ JSC_DEFINE_HOST_FUNCTION(scriptRunInThisContext, (JSGlobalObject * globalObject, auto* script = jsDynamicCast(thisValue); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(!script)) { + if (!script) [[unlikely]] { return ERR::INVALID_ARG_VALUE(throwScope, globalObject, "this"_s, thisValue, "must be a Script"_s); } @@ -969,7 +969,7 @@ JSC_DEFINE_HOST_FUNCTION(scriptRunInThisContext, (JSGlobalObject * globalObject, NakedPtr exception; JSValue result = JSC::evaluate(globalObject, script->source(), globalObject, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { if (handleException(globalObject, vm, exception, throwScope)) { return {}; } @@ -987,7 +987,7 @@ JSC_DEFINE_CUSTOM_GETTER(scriptGetSourceMapURL, (JSGlobalObject * globalObject, auto scope = DECLARE_THROW_SCOPE(vm); JSValue thisValue = JSValue::decode(thisValueEncoded); auto* script = jsDynamicCast(thisValue); - if (UNLIKELY(!script)) { + if (!script) [[unlikely]] { return ERR::INVALID_ARG_VALUE(scope, globalObject, "this"_s, thisValue, "must be a Script"_s); } @@ -1001,7 +1001,7 @@ JSC_DEFINE_CUSTOM_GETTER(scriptGetCachedData, (JSGlobalObject * globalObject, JS auto scope = DECLARE_THROW_SCOPE(vm); JSValue thisValue = JSValue::decode(thisValueEncoded); auto* script = jsDynamicCast(thisValue); - if (UNLIKELY(!script)) { + if (!script) [[unlikely]] { return ERR::INVALID_ARG_VALUE(scope, globalObject, "this"_s, thisValue, "must be a Script"_s); } @@ -1018,7 +1018,7 @@ JSC_DEFINE_CUSTOM_GETTER(scriptGetCachedDataProduced, (JSGlobalObject * globalOb auto scope = DECLARE_THROW_SCOPE(vm); JSValue thisValue = JSValue::decode(thisValueEncoded); auto* script = jsDynamicCast(thisValue); - if (UNLIKELY(!script)) { + if (!script) [[unlikely]] { return ERR::INVALID_ARG_VALUE(scope, globalObject, "this"_s, thisValue, "must be a Script"_s); } @@ -1031,7 +1031,7 @@ JSC_DEFINE_CUSTOM_GETTER(scriptGetCachedDataRejected, (JSGlobalObject * globalOb auto scope = DECLARE_THROW_SCOPE(vm); JSValue thisValue = JSValue::decode(thisValueEncoded); auto* script = jsDynamicCast(thisValue); - if (UNLIKELY(!script)) { + if (!script) [[unlikely]] { return ERR::INVALID_ARG_VALUE(scope, globalObject, "this"_s, thisValue, "must be a Script"_s); } @@ -1094,7 +1094,7 @@ JSC_DEFINE_HOST_FUNCTION(vmModuleRunInNewContext, (JSGlobalObject * globalObject NakedPtr exception; JSValue result = JSC::evaluate(context, sourceCode, context, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { if (handleException(globalObject, vm, exception, scope)) { return {}; } @@ -1135,7 +1135,7 @@ JSC_DEFINE_HOST_FUNCTION(vmModuleRunInThisContext, (JSGlobalObject * globalObjec WTF::NakedPtr exception; JSValue result = JSC::evaluate(globalObject, source, globalObject, exception); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { if (handleException(globalObject, vm, exception, throwScope)) { return {}; } @@ -1258,7 +1258,7 @@ JSC_DEFINE_HOST_FUNCTION(scriptRunInNewContext, (JSGlobalObject * globalObject, contextObjectValue = JSC::constructEmptyObject(globalObject); } - if (UNLIKELY(!contextObjectValue || !contextObjectValue.isObject())) { + if (!contextObjectValue || !contextObjectValue.isObject()) [[unlikely]] { throwTypeError(globalObject, scope, "Context must be an object"_s); return {}; } @@ -1590,7 +1590,7 @@ bool NodeVMGlobalObject::deleteProperty(JSCell* cell, JSGlobalObject* globalObje { auto* thisObject = jsCast(cell); - if (UNLIKELY(!thisObject->m_sandbox)) { + if (!thisObject->m_sandbox) [[unlikely]] { return Base::deleteProperty(cell, globalObject, propertyName, slot); } @@ -1737,7 +1737,7 @@ static String stringifyAnonymousFunction(JSGlobalObject* globalObject, const Arg program = tryMakeString("(function () {"_s, body, "})"_s); *outOffset = "(function () {"_s.length(); - if (UNLIKELY(!program)) { + if (!program) [[unlikely]] { throwOutOfMemoryError(globalObject, scope); return {}; } @@ -1762,7 +1762,7 @@ static String stringifyAnonymousFunction(JSGlobalObject* globalObject, const Arg program = tryMakeString("(function ("_s, paramString.toString(), ") {"_s, body, "})"_s); *outOffset = "(function ("_s.length() + paramString.length() + ") {"_s.length(); - if (UNLIKELY(!program)) { + if (!program) [[unlikely]] { throwOutOfMemoryError(globalObject, scope); return {}; } @@ -1797,7 +1797,7 @@ static JSC::EncodedJSValue createCachedData(JSGlobalObject* globalObject, JSC::S RefPtr bytecode = getBytecode(globalObject, executable, source); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(!bytecode)) { + if (!bytecode) [[unlikely]] { return throwVMError(globalObject, scope, "createCachedData failed"_s); } diff --git a/src/bun.js/bindings/ObjectBindings.cpp b/src/bun.js/bindings/ObjectBindings.cpp index 7795997031..7ccd219cf3 100644 --- a/src/bun.js/bindings/ObjectBindings.cpp +++ b/src/bun.js/bindings/ObjectBindings.cpp @@ -24,7 +24,7 @@ static bool getNonIndexPropertySlotPrototypePollutionMitigation(JSC::VM& vm, JSO JSObject* objectPrototype = nullptr; while (true) { Structure* structure = object->structureID().decode(); - if (LIKELY(!TypeInfo::overridesGetOwnPropertySlot(object->inlineTypeFlags()))) { + if (!TypeInfo::overridesGetOwnPropertySlot(object->inlineTypeFlags())) [[likely]] { if (object->getOwnNonIndexPropertySlot(vm, structure, propertyName, slot)) return true; } else { @@ -32,13 +32,13 @@ static bool getNonIndexPropertySlotPrototypePollutionMitigation(JSC::VM& vm, JSO RETURN_IF_EXCEPTION(scope, false); if (hasSlot) return true; - if (UNLIKELY(slot.isVMInquiry() && slot.isTaintedByOpaqueObject())) + if (slot.isVMInquiry() && slot.isTaintedByOpaqueObject()) [[unlikely]] return false; if (object->type() == ProxyObjectType && slot.internalMethodType() == PropertySlot::InternalMethodType::HasProperty) return false; } JSValue prototype; - if (LIKELY(!structure->typeInfo().overridesGetPrototype() || slot.internalMethodType() == PropertySlot::InternalMethodType::VMInquiry)) + if (!structure->typeInfo().overridesGetPrototype() || slot.internalMethodType() == PropertySlot::InternalMethodType::VMInquiry) [[likely]] prototype = object->getPrototypeDirect(); else { prototype = object->getPrototype(vm, globalObject); diff --git a/src/bun.js/bindings/ProcessBindingTTYWrap.cpp b/src/bun.js/bindings/ProcessBindingTTYWrap.cpp index c41551b76e..9e5866e78b 100644 --- a/src/bun.js/bindings/ProcessBindingTTYWrap.cpp +++ b/src/bun.js/bindings/ProcessBindingTTYWrap.cpp @@ -238,7 +238,7 @@ JSC_DEFINE_HOST_FUNCTION(TTYWrap_functionSetMode, } TTYWrapObject* ttyWrap = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!ttyWrap)) { + if (!ttyWrap) [[unlikely]] { JSC::throwTypeError(globalObject, throwScope, "TTY.setRawMode expects a TTYWrapObject as this"_s); return {}; } @@ -275,7 +275,7 @@ JSC_DEFINE_HOST_FUNCTION(TTYWrap_functionGetWindowSize, } TTYWrapObject* ttyWrap = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!ttyWrap)) { + if (!ttyWrap) [[unlikely]] { JSC::throwTypeError(globalObject, throwScope, "TTY.getWindowSize expects a TTYWrapObject as this"_s); return {}; } diff --git a/src/bun.js/bindings/ProcessBindingUV.cpp b/src/bun.js/bindings/ProcessBindingUV.cpp index 2738b9b0fe..1d6c6ac9cd 100644 --- a/src/bun.js/bindings/ProcessBindingUV.cpp +++ b/src/bun.js/bindings/ProcessBindingUV.cpp @@ -362,7 +362,7 @@ JSC_DEFINE_HOST_FUNCTION(jsErrname, (JSGlobalObject * globalObject, JSC::CallFra // Node.js crashes here: // However, we should ensure this function never throws // That's why we do not call toPrimitive here or throw on invalid input. - if (UNLIKELY(!arg0.isInt32AsAnyInt())) { + if (!arg0.isInt32AsAnyInt()) [[unlikely]] { return JSValue::encode(jsString(vm, String("Unknown system error"_s))); } diff --git a/src/bun.js/bindings/SQLClient.cpp b/src/bun.js/bindings/SQLClient.cpp index cf6b5692f8..8b76c2c81b 100644 --- a/src/bun.js/bindings/SQLClient.cpp +++ b/src/bun.js/bindings/SQLClient.cpp @@ -134,7 +134,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel Zig::GlobalObject* zigGlobal = jsCast(globalObject); auto* subclassStructure = zigGlobal->JSBufferSubclassStructure(); auto* uint8Array = JSC::JSUint8Array::createUninitialized(globalObject, subclassStructure, cell.value.raw.length); - if (UNLIKELY(uint8Array == nullptr)) { + if (uint8Array == nullptr) [[unlikely]] { return {}; } @@ -173,7 +173,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel Zig::GlobalObject* zigGlobal = jsCast(globalObject); auto* subclassStructure = zigGlobal->JSBufferSubclassStructure(); auto* uint8Array = JSC::JSUint8Array::createUninitialized(globalObject, subclassStructure, cell.value.bytea[1]); - if (UNLIKELY(uint8Array == nullptr)) { + if (uint8Array == nullptr) [[unlikely]] { return {}; } @@ -195,7 +195,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel uint32_t length = cell.value.array.length; for (uint32_t i = 0; i < length; i++) { JSValue result = toJS(vm, globalObject, cell.value.array.cells[i]); - if (UNLIKELY(result.isEmpty())) { + if (result.isEmpty()) [[unlikely]] { return {}; } @@ -210,7 +210,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel switch (type) { case JSC::JSType::Int32ArrayType: { JSC::JSInt32Array* array = JSC::JSInt32Array::createUninitialized(globalObject, globalObject->typedArrayStructureWithTypedArrayType(), length); - if (UNLIKELY(array == nullptr)) { + if (array == nullptr) [[unlikely]] { return {}; } @@ -222,7 +222,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel } case JSC::JSType::Uint32ArrayType: { JSC::JSUint32Array* array = JSC::JSUint32Array::createUninitialized(globalObject, globalObject->typedArrayStructureWithTypedArrayType(), length); - if (UNLIKELY(array == nullptr)) { + if (array == nullptr) [[unlikely]] { return {}; } @@ -233,7 +233,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel } case JSC::JSType::Int16ArrayType: { JSC::JSInt16Array* array = JSC::JSInt16Array::createUninitialized(globalObject, globalObject->typedArrayStructureWithTypedArrayType(), length); - if (UNLIKELY(array == nullptr)) { + if (array == nullptr) [[unlikely]] { return {}; } @@ -245,7 +245,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel } case JSC::JSType::Uint16ArrayType: { JSC::JSUint16Array* array = JSC::JSUint16Array::createUninitialized(globalObject, globalObject->typedArrayStructureWithTypedArrayType(), length); - if (UNLIKELY(array == nullptr)) { + if (array == nullptr) [[unlikely]] { return {}; } @@ -256,7 +256,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel } case JSC::JSType::Float16ArrayType: { JSC::JSFloat16Array* array = JSC::JSFloat16Array::createUninitialized(globalObject, globalObject->typedArrayStructureWithTypedArrayType(), length); - if (UNLIKELY(array == nullptr)) { + if (array == nullptr) [[unlikely]] { return {}; } @@ -267,7 +267,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel } case JSC::JSType::Float32ArrayType: { JSC::JSFloat32Array* array = JSC::JSFloat32Array::createUninitialized(globalObject, globalObject->typedArrayStructureWithTypedArrayType(), length); - if (UNLIKELY(array == nullptr)) { + if (array == nullptr) [[unlikely]] { return {}; } @@ -278,7 +278,7 @@ static JSC::JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, DataCel } case JSC::JSType::Float64ArrayType: { JSC::JSFloat64Array* array = JSC::JSFloat64Array::createUninitialized(globalObject, globalObject->typedArrayStructureWithTypedArrayType(), length); - if (UNLIKELY(array == nullptr)) { + if (array == nullptr) [[unlikely]] { return {}; } diff --git a/src/bun.js/bindings/Uint8Array.cpp b/src/bun.js/bindings/Uint8Array.cpp index 11d53e87fb..9acc6cca9d 100644 --- a/src/bun.js/bindings/Uint8Array.cpp +++ b/src/bun.js/bindings/Uint8Array.cpp @@ -10,7 +10,7 @@ extern "C" JSC::EncodedJSValue JSUint8Array__fromDefaultAllocator(JSC::JSGlobalO { JSC::JSUint8Array* uint8Array; - if (LIKELY(length > 0)) { + if (length > 0) [[likely]] { auto buffer = ArrayBuffer::createFromBytes({ ptr, length }, createSharedTask([](void* p) { mi_free(p); })); @@ -28,7 +28,7 @@ extern "C" JSC::EncodedJSValue JSArrayBuffer__fromDefaultAllocator(JSC::JSGlobal JSC::JSArrayBuffer* arrayBuffer; - if (LIKELY(length > 0)) { + if (length > 0) [[likely]] { RefPtr buffer = ArrayBuffer::createFromBytes({ ptr, length }, createSharedTask([](void* p) { mi_free(p); })); diff --git a/src/bun.js/bindings/Weak.cpp b/src/bun.js/bindings/Weak.cpp index 5d40ffbb4b..cc0cb6f638 100644 --- a/src/bun.js/bindings/Weak.cpp +++ b/src/bun.js/bindings/Weak.cpp @@ -31,7 +31,7 @@ class WeakRefOwner : public JSC::WeakHandleOwner { public: void finalize(JSC::Handle handle, void* context) final { - if (LIKELY(context)) { + if (context) [[likely]] { switch (T) { case WeakRefType::FetchResponse: Bun__FetchResponse_finalize(context); diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index b7a577dade..fe13ebfb0e 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -292,7 +292,6 @@ extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(c JSC::Options::useShadowRealm() = true; JSC::Options::useV8DateParser() = true; JSC::Options::evalMode() = evalMode; - JSC::Options::useIteratorHelpers() = true; JSC::Options::heapGrowthSteepnessFactor() = 1.0; JSC::Options::heapGrowthMaxIncrease() = 2.0; JSC::dangerouslyOverrideJSCBytecodeCacheVersion(getWebKitBytecodeCacheVersion()); @@ -301,16 +300,16 @@ extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(c JSC::Options::showPrivateScriptsInStackTraces() = true; #endif - if (LIKELY(envc > 0)) { + if (envc > 0) [[likely]] { while (envc--) { const char* env = (const char*)envp[envc]; // need to check for \0 so we might as well make this single pass // strlen would check the end of the string - if (LIKELY(!(env[0] == 'B' && env[1] == 'U' && env[2] == 'N' && env[3] == '_' && env[4] == 'J' && env[5] == 'S' && env[6] == 'C' && env[7] == '_'))) { + if (!(env[0] == 'B' && env[1] == 'U' && env[2] == 'N' && env[3] == '_' && env[4] == 'J' && env[5] == 'S' && env[6] == 'C' && env[7] == '_')) [[likely]] { continue; } - if (UNLIKELY(!JSC::Options::setOption(env + 8))) { + if (!JSC::Options::setOption(env + 8)) [[unlikely]] { onCrash(env, strlen(env)); } } @@ -674,7 +673,7 @@ static String computeErrorInfoWithoutPrepareStackTrace( } } - if (UNLIKELY(!globalObject)) { + if (!globalObject) [[unlikely]] { globalObject = defaultGlobalObject(); } @@ -909,7 +908,7 @@ extern "C" JSC::JSGlobalObject* Zig__GlobalObject__create(void* console_client, { auto heapSize = miniMode ? JSC::HeapType::Small : JSC::HeapType::Large; RefPtr vmPtr = JSC::VM::tryCreate(heapSize); - if (UNLIKELY(!vmPtr)) { + if (!vmPtr) [[unlikely]] { BUN_PANIC("Failed to allocate JavaScriptCore Virtual Machine. Did your computer run out of memory? Or maybe you compiled Bun with a mismatching libc++ version or compiler?"); } vmPtr->refSuppressingSaferCPPChecking(); @@ -945,9 +944,9 @@ extern "C" JSC::JSGlobalObject* Zig__GlobalObject__create(void* console_client, WebCore::JSVMClientData::create(&vm, Bun__getVM()); const auto createGlobalObject = [&]() -> Zig::GlobalObject* { - if (UNLIKELY(executionContextId == std::numeric_limits::max() || executionContextId > 1)) { + if (executionContextId == std::numeric_limits::max() || executionContextId > 1) [[unlikely]] { auto* structure = Zig::GlobalObject::createStructure(vm); - if (UNLIKELY(!structure)) { + if (!structure) [[unlikely]] { return nullptr; } return Zig::GlobalObject::create( @@ -956,7 +955,7 @@ extern "C" JSC::JSGlobalObject* Zig__GlobalObject__create(void* console_client, static_cast(executionContextId)); } else if (evalMode) { auto* structure = Zig::EvalGlobalObject::createStructure(vm); - if (UNLIKELY(!structure)) { + if (!structure) [[unlikely]] { return nullptr; } return Zig::EvalGlobalObject::create( @@ -966,7 +965,7 @@ extern "C" JSC::JSGlobalObject* Zig__GlobalObject__create(void* console_client, } else { auto* structure = Zig::GlobalObject::createStructure(vm); - if (UNLIKELY(!structure)) { + if (!structure) [[unlikely]] { return nullptr; } return Zig::GlobalObject::create( @@ -976,7 +975,7 @@ extern "C" JSC::JSGlobalObject* Zig__GlobalObject__create(void* console_client, }; auto* globalObject = createGlobalObject(); - if (UNLIKELY(!globalObject)) { + if (!globalObject) [[unlikely]] { BUN_PANIC("Failed to allocate JavaScript global object. Did your computer run out of memory?"); } @@ -1063,8 +1062,9 @@ JSC_DEFINE_HOST_FUNCTION(functionFulfillModuleSync, auto specifier = Bun::toString(moduleKey); ErrorableResolvedSource res; res.success = false; - res.result.err.code = 0; - res.result.err.ptr = nullptr; + // zero-initialize entire result union. zeroed BunString has BunStringTag::Dead, and zeroed + // EncodedJSValues are empty, which our code should be handling + memset(&res.result, 0, sizeof res.result); JSValue result = Bun::fetchESMSourceCodeSync( globalObject, @@ -1528,8 +1528,8 @@ JSC_DEFINE_HOST_FUNCTION(functionNativeMicrotaskTrampoline, double cellPtr = callFrame->uncheckedArgument(0).asNumber(); double callbackPtr = callFrame->uncheckedArgument(1).asNumber(); - void* cell = reinterpret_cast(__bit_cast(cellPtr)); - auto* callback = reinterpret_cast(__bit_cast(callbackPtr)); + void* cell = reinterpret_cast(std::bit_cast(cellPtr)); + auto* callback = reinterpret_cast(std::bit_cast(callbackPtr)); callback(cell); return JSValue::encode(jsUndefined()); } @@ -1610,7 +1610,7 @@ JSC_DEFINE_HOST_FUNCTION(functionBTOA, std::span ptr; unsigned length = encodedString.length(); auto dest = WTF::String::tryCreateUninitialized(length, ptr); - if (UNLIKELY(dest.isNull())) { + if (dest.isNull()) [[unlikely]] { throwOutOfMemoryError(globalObject, throwScope); return {}; } @@ -1691,7 +1691,7 @@ extern "C" JSC::EncodedJSValue ArrayBuffer__fromSharedMemfd(int64_t fd, JSC::JSG Structure* structure = globalObject->arrayBufferStructure(JSC::ArrayBufferSharingMode::Default); - if (UNLIKELY(!structure)) { + if (!structure) [[unlikely]] { return JSC::JSValue::encode(JSC::JSValue {}); } @@ -1709,7 +1709,7 @@ extern "C" JSC::EncodedJSValue Bun__createArrayBufferForCopy(JSC::JSGlobalObject auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); auto arrayBuffer = JSC::ArrayBuffer::tryCreateUninitialized(len, 1); - if (UNLIKELY(!arrayBuffer)) { + if (!arrayBuffer) [[unlikely]] { JSC::throwOutOfMemoryError(globalObject, scope); return {}; } @@ -1726,7 +1726,7 @@ extern "C" JSC::EncodedJSValue Bun__allocUint8ArrayForCopy(JSC::JSGlobalObject* JSC::JSUint8Array* array = JSC::JSUint8Array::createUninitialized(globalObject, globalObject->m_typedArrayUint8.get(globalObject), len); - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { JSC::throwOutOfMemoryError(globalObject, scope); return {}; } @@ -1745,7 +1745,7 @@ extern "C" JSC::EncodedJSValue Bun__allocArrayBufferForCopy(JSC::JSGlobalObject* auto* subclassStructure = globalObject->JSBufferSubclassStructure(); auto buf = JSC::JSUint8Array::createUninitialized(lexicalGlobalObject, subclassStructure, len); - if (UNLIKELY(!buf)) { + if (!buf) [[unlikely]] { return {}; } @@ -1762,7 +1762,7 @@ extern "C" JSC::EncodedJSValue Bun__createUint8ArrayForCopy(JSC::JSGlobalObject* auto* subclassStructure = isBuffer ? reinterpret_cast(globalObject)->JSBufferSubclassStructure() : globalObject->typedArrayStructureWithTypedArrayType(); JSC::JSUint8Array* array = JSC::JSUint8Array::createUninitialized(globalObject, subclassStructure, len); - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { JSC::throwOutOfMemoryError(globalObject, scope); return {}; } @@ -1781,7 +1781,7 @@ JSC_DEFINE_HOST_FUNCTION(functionCreateUninitializedArrayBuffer, auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); auto arrayBuffer = JSC::ArrayBuffer::tryCreateUninitialized(len, 1); - if (UNLIKELY(!arrayBuffer)) { + if (!arrayBuffer) [[unlikely]] { JSC::throwOutOfMemoryError(globalObject, scope); return {}; } @@ -1796,7 +1796,7 @@ static inline JSC::EncodedJSValue jsFunctionAddEventListenerBody(JSC::JSGlobalOb UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->globalEventScope; - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -1825,7 +1825,7 @@ static inline JSC::EncodedJSValue jsFunctionRemoveEventListenerBody(JSC::JSGloba UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->globalEventScope; - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -1854,7 +1854,7 @@ static inline JSC::EncodedJSValue jsFunctionDispatchEventBody(JSC::JSGlobalObjec UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->globalEventScope; - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto event = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "event"_s, "EventTarget"_s, "dispatchEvent"_s, "Event"_s); }); @@ -1939,7 +1939,7 @@ JSC_DEFINE_HOST_FUNCTION(getInternalWritableStream, (JSGlobalObject*, CallFrame* ASSERT(callFrame->argumentCount() == 1); auto* writableStream = jsDynamicCast(callFrame->uncheckedArgument(0)); - if (UNLIKELY(!writableStream)) + if (!writableStream) [[unlikely]] return JSValue::encode(jsUndefined()); return JSValue::encode(writableStream->wrapped().internalWritableStream()); } @@ -1962,7 +1962,7 @@ JSC_DEFINE_HOST_FUNCTION(addAbortAlgorithmToSignal, (JSGlobalObject * globalObje auto& vm = JSC::getVM(globalObject); auto* abortSignal = jsDynamicCast(callFrame->uncheckedArgument(0)); - if (UNLIKELY(!abortSignal)) + if (!abortSignal) [[unlikely]] return JSValue::encode(JSValue(JSC::JSValue::JSFalse)); Ref abortAlgorithm = JSAbortAlgorithm::create(vm, callFrame->uncheckedArgument(1).getObject()); @@ -1977,7 +1977,7 @@ JSC_DEFINE_HOST_FUNCTION(removeAbortAlgorithmFromSignal, (JSGlobalObject*, CallF ASSERT(callFrame->argumentCount() == 2); auto* abortSignal = jsDynamicCast(callFrame->uncheckedArgument(0)); - if (UNLIKELY(!abortSignal)) + if (!abortSignal) [[unlikely]] return JSValue::encode(JSValue(JSC::JSValue::JSFalse)); AbortSignal::removeAbortAlgorithmFromSignal(abortSignal->wrapped(), callFrame->uncheckedArgument(1).asUInt32()); @@ -2013,7 +2013,7 @@ static inline std::optional invokeReadableStreamFunction(JSC::JSGl extern "C" bool ReadableStream__tee(JSC::EncodedJSValue possibleReadableStream, Zig::GlobalObject* globalObject, JSC::EncodedJSValue* possibleReadableStream1, JSC::EncodedJSValue* possibleReadableStream2) { auto* readableStream = jsDynamicCast(JSC::JSValue::decode(possibleReadableStream)); - if (UNLIKELY(!readableStream)) + if (!readableStream) [[unlikely]] return false; auto& lexicalGlobalObject = *globalObject; @@ -2039,7 +2039,7 @@ extern "C" bool ReadableStream__tee(JSC::EncodedJSValue possibleReadableStream, extern "C" void ReadableStream__cancel(JSC::EncodedJSValue possibleReadableStream, Zig::GlobalObject* globalObject) { auto* readableStream = jsDynamicCast(JSC::JSValue::decode(possibleReadableStream)); - if (UNLIKELY(!readableStream)) + if (!readableStream) [[unlikely]] return; if (!ReadableStream::isLocked(globalObject, readableStream)) { @@ -2057,7 +2057,7 @@ extern "C" void ReadableStream__detach(JSC::EncodedJSValue possibleReadableStrea return; auto* readableStream = static_cast(value.asCell()); - if (UNLIKELY(!readableStream)) + if (!readableStream) [[unlikely]] return; readableStream->setNativePtr(globalObject->vm(), jsNumber(-1)); readableStream->setNativeType(0); @@ -2103,7 +2103,7 @@ extern "C" int32_t ReadableStreamTag__tagged(Zig::GlobalObject* globalObject, JS } } - if (UNLIKELY(throwScope.exception())) { + if (throwScope.exception()) [[unlikely]] { *ptr = nullptr; return -1; } @@ -2121,7 +2121,7 @@ extern "C" int32_t ReadableStreamTag__tagged(Zig::GlobalObject* globalObject, JS JSC::JSValue result = profiledCall(globalObject, JSC::ProfilingReason::API, createIterator, JSC::getCallData(createIterator), JSC::jsUndefined(), arguments); - if (UNLIKELY(throwScope.exception())) { + if (throwScope.exception()) [[unlikely]] { return -1; } @@ -2213,17 +2213,17 @@ static inline JSC::EncodedJSValue ZigGlobalObject__readableStreamToArrayBufferBo JSC::JSObject* object = result.getObject(); - if (UNLIKELY(!result || result.isUndefinedOrNull())) + if (!result || result.isUndefinedOrNull()) [[unlikely]] return JSValue::encode(result); - if (UNLIKELY(!object)) { + if (!object) [[unlikely]] { auto throwScope = DECLARE_THROW_SCOPE(vm); throwTypeError(globalObject, throwScope, "Expected object"_s); return {}; } JSC::JSPromise* promise = JSC::jsDynamicCast(object); - if (UNLIKELY(!promise)) { + if (!promise) [[unlikely]] { auto throwScope = DECLARE_THROW_SCOPE(vm); throwTypeError(globalObject, throwScope, "Expected promise"_s); return {}; @@ -2259,17 +2259,17 @@ extern "C" JSC::EncodedJSValue ZigGlobalObject__readableStreamToBytes(Zig::Globa JSC::JSObject* object = result.getObject(); - if (UNLIKELY(!result || result.isUndefinedOrNull())) + if (!result || result.isUndefinedOrNull()) [[unlikely]] return JSValue::encode(result); - if (UNLIKELY(!object)) { + if (!object) [[unlikely]] { auto throwScope = DECLARE_THROW_SCOPE(vm); throwTypeError(globalObject, throwScope, "Expected object"_s); return {}; } JSC::JSPromise* promise = JSC::jsDynamicCast(object); - if (UNLIKELY(!promise)) { + if (!promise) [[unlikely]] { auto throwScope = DECLARE_THROW_SCOPE(vm); throwTypeError(globalObject, throwScope, "Expected promise"_s); return {}; @@ -2371,7 +2371,7 @@ JSC_DEFINE_HOST_FUNCTION(functionReadableStreamToArrayBuffer, (JSGlobalObject * { auto& vm = JSC::getVM(globalObject); - if (UNLIKELY(callFrame->argumentCount() < 1)) { + if (callFrame->argumentCount() < 1) [[unlikely]] { auto throwScope = DECLARE_THROW_SCOPE(vm); throwTypeError(globalObject, throwScope, "Expected at least one argument"_s); return {}; @@ -2386,7 +2386,7 @@ JSC_DEFINE_HOST_FUNCTION(functionReadableStreamToBytes, (JSGlobalObject * global { auto& vm = JSC::getVM(globalObject); - if (UNLIKELY(callFrame->argumentCount() < 1)) { + if (callFrame->argumentCount() < 1) [[unlikely]] { auto throwScope = DECLARE_THROW_SCOPE(vm); throwTypeError(globalObject, throwScope, "Expected at least one argument"_s); return {}; @@ -2402,14 +2402,14 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotask, (JSGlobalObject * globalObj auto scope = DECLARE_CATCH_SCOPE(vm); auto job = callframe->argument(0); - if (UNLIKELY(!job || job.isUndefinedOrNull())) { + if (!job || job.isUndefinedOrNull()) [[unlikely]] { return JSValue::encode(jsUndefined()); } auto callData = JSC::getCallData(job); MarkedArgumentBuffer arguments; - if (UNLIKELY(callData.type == CallData::Type::None)) { + if (callData.type == CallData::Type::None) [[unlikely]] { return JSValue::encode(jsUndefined()); } @@ -2465,7 +2465,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionPerformMicrotaskVariadic, (JSGlobalObject * g auto callData = JSC::getCallData(job); MarkedArgumentBuffer arguments; - if (UNLIKELY(callData.type == CallData::Type::None)) { + if (callData.type == CallData::Type::None) [[unlikely]] { return JSValue::encode(jsUndefined()); } @@ -3969,7 +3969,7 @@ extern "C" void JSC__JSGlobalObject__queueMicrotaskCallback(Zig::GlobalObject* g JSFunction* function = globalObject->nativeMicrotaskTrampoline(); // Do not use JSCell* here because the GC will try to visit it. - globalObject->queueMicrotask(function, JSValue(__bit_cast(reinterpret_cast(ptr))), JSValue(__bit_cast(reinterpret_cast(callback))), jsUndefined(), jsUndefined()); + globalObject->queueMicrotask(function, JSValue(std::bit_cast(reinterpret_cast(ptr))), JSValue(std::bit_cast(reinterpret_cast(callback))), jsUndefined(), jsUndefined()); } JSC::Identifier GlobalObject::moduleLoaderResolve(JSGlobalObject* jsGlobalObject, @@ -4091,12 +4091,12 @@ JSC::JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject* j Zig__GlobalObject__resolve(&resolved, globalObject, &moduleNameZ, &sourceOriginZ, &queryString); // If resolution failed, make sure it becomes a pending exception - if (UNLIKELY(!resolved.success && !scope.exception())) { + if (!resolved.success && !scope.exception()) [[unlikely]] { throwException(scope, resolved.result.err, globalObject); } // And convert that pending exception into a rejected promise. - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { auto* promise = JSC::JSInternalPromise::create(vm, globalObject->internalPromiseStructure()); moduleNameZ.deref(); sourceOriginZ.deref(); @@ -4161,7 +4161,7 @@ JSC::JSInternalPromise* GlobalObject::moduleLoaderFetch(JSGlobalObject* globalOb auto moduleKeyJS = key.toString(globalObject); RETURN_IF_EXCEPTION(scope, {}); auto moduleKey = moduleKeyJS->value(globalObject); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return rejectedInternalPromise(globalObject, scope.exception()->value()); if (moduleKey->endsWith(".node"_s)) { @@ -4192,8 +4192,9 @@ JSC::JSInternalPromise* GlobalObject::moduleLoaderFetch(JSGlobalObject* globalOb auto typeAttribute = Bun::toString(typeAttributeString); ErrorableResolvedSource res; res.success = false; - res.result.err.code = 0; - res.result.err.ptr = nullptr; + // zero-initialize entire result union. zeroed BunString has BunStringTag::Dead, and zeroed + // EncodedJSValues are empty, which our code should be handling + memset(&res.result, 0, sizeof res.result); JSValue result = Bun::fetchESMSourceCodeAsync( reinterpret_cast(globalObject), @@ -4227,7 +4228,7 @@ JSC::JSValue GlobalObject::moduleLoaderEvaluate(JSGlobalObject* lexicalGlobalObj JSValue sentValue, JSValue resumeMode) { - if (UNLIKELY(scriptFetcher && scriptFetcher.isObject())) { + if (scriptFetcher && scriptFetcher.isObject()) [[unlikely]] { return scriptFetcher; } @@ -4247,7 +4248,7 @@ JSC::JSValue EvalGlobalObject::moduleLoaderEvaluate(JSGlobalObject* lexicalGloba { Zig::GlobalObject* globalObject = jsCast(lexicalGlobalObject); - if (UNLIKELY(scriptFetcher && scriptFetcher.isObject())) { + if (scriptFetcher && scriptFetcher.isObject()) [[unlikely]] { if (Bun__VM__specifierIsEvalEntryPoint(globalObject->bunVM(), JSValue::encode(key))) { Bun__VM__setEntryPointEvalResultESM(globalObject->bunVM(), JSValue::encode(scriptFetcher)); } diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 5b2ff40aef..29a74e28ba 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -614,7 +614,7 @@ template bool Bun__deepEquals(JSC::JSGlobalObject* globalObject, JSValue v1, JSValue v2, MarkedArgumentBuffer& gcBuffer, Vector, 16>& stack, ThrowScope* scope, bool addToStack) { VM& vm = globalObject->vm(); - if (UNLIKELY(!vm.isSafeToRecurse())) { + if (!vm.isSafeToRecurse()) [[unlikely]] { throwStackOverflowError(globalObject, *scope); return false; } @@ -772,7 +772,7 @@ bool Bun__deepEquals(JSC::JSGlobalObject* globalObject, JSValue v1, JSValue v2, JSValue prop1 = o1->get(globalObject, propertyName1); RETURN_IF_EXCEPTION(*scope, false); - if (UNLIKELY(!prop1)) { + if (!prop1) [[unlikely]] { return false; } @@ -940,7 +940,7 @@ bool Bun__deepEquals(JSC::JSGlobalObject* globalObject, JSValue v1, JSValue v2, JSValue prop1 = o1->get(globalObject, propertyName1); RETURN_IF_EXCEPTION(*scope, false); - if (UNLIKELY(!prop1)) { + if (!prop1) [[unlikely]] { return false; } @@ -1085,24 +1085,24 @@ std::optional specialObjectsDequal(JSC::JSGlobalObject* globalObject, Mark return false; } - if (UNLIKELY(left->isShared() != right->isShared())) { + if (left->isShared() != right->isShared()) [[unlikely]] { return false; } if (byteLength == 0) return true; - if (UNLIKELY(right->isDetached() || left->isDetached())) { + if (right->isDetached() || left->isDetached()) [[unlikely]] { return false; } const void* vector = left->data(); const void* rightVector = right->data(); - if (UNLIKELY(!vector || !rightVector)) { + if (!vector || !rightVector) [[unlikely]] { return false; } - if (UNLIKELY(vector == rightVector)) + if (vector == rightVector) [[unlikely]] return true; return (memcmp(vector, rightVector, byteLength) == 0); @@ -1125,7 +1125,7 @@ std::optional specialObjectsDequal(JSC::JSGlobalObject* globalObject, Mark if (JSC::RegExpObject* left = jsDynamicCast(c1)) { JSC::RegExpObject* right = jsDynamicCast(c2); - if (UNLIKELY(!right)) { + if (!right) [[unlikely]] { return false; } @@ -1143,7 +1143,7 @@ std::optional specialObjectsDequal(JSC::JSGlobalObject* globalObject, Mark if (JSC::ErrorInstance* left = jsDynamicCast(c1)) { JSC::ErrorInstance* right = jsDynamicCast(c2); - if (UNLIKELY(!right)) { + if (!right) [[unlikely]] { return false; } @@ -1209,7 +1209,7 @@ std::optional specialObjectsDequal(JSC::JSGlobalObject* globalObject, Mark JSValue prop1 = left->get(globalObject, propertyName1); RETURN_IF_EXCEPTION(*scope, false); - if (UNLIKELY(!prop1)) { + if (!prop1) [[unlikely]] { return false; } @@ -1283,17 +1283,17 @@ std::optional specialObjectsDequal(JSC::JSGlobalObject* globalObject, Mark if (byteLength == 0) return true; - if (UNLIKELY(right->isDetached() || left->isDetached())) { + if (right->isDetached() || left->isDetached()) [[unlikely]] { return false; } const void* vector = left->vector(); const void* rightVector = right->vector(); - if (UNLIKELY(!vector || !rightVector)) { + if (!vector || !rightVector) [[unlikely]] { return false; } - if (UNLIKELY(vector == rightVector)) + if (vector == rightVector) [[unlikely]] return true; // For Float32Array and Float64Array, when not in strict mode, we need to @@ -2910,7 +2910,7 @@ bool JSC__JSValue__asArrayBuffer_(JSC::EncodedJSValue JSValue0, JSC::JSGlobalObj { ASSERT_NO_PENDING_EXCEPTION(arg1); JSC::JSValue value = JSC::JSValue::decode(JSValue0); - if (UNLIKELY(!value) || !value.isCell()) { + if (!value || !value.isCell()) [[unlikely]] { return false; } @@ -3125,7 +3125,7 @@ void JSC__JSValue__toZigString(JSC::EncodedJSValue JSValue0, ZigString* arg1, JS auto* strValue = value.toStringOrNull(arg2); - if (UNLIKELY(!strValue)) { + if (!strValue) [[unlikely]] { arg1->len = 0; arg1->ptr = nullptr; return; @@ -3936,7 +3936,7 @@ JSC::EncodedJSValue JSC__JSValue__getIfPropertyExistsImpl(JSC::EncodedJSValue JS auto& vm = JSC::getVM(globalObject); JSC::JSObject* object = value.getObject(); - if (UNLIKELY(!object)) { + if (!object) [[unlikely]] { return JSValue::encode(JSValue::decode(JSC::JSValue::ValueDeleted)); } @@ -4304,12 +4304,12 @@ static void populateStackFramePosition(const JSC::StackFrame* stackFrame, BunStr return; auto* provider = code->source().provider(); - if (UNLIKELY(!provider)) + if (!provider) [[unlikely]] return; // Make sure the range is valid: // https://github.com/oven-sh/bun/issues/6951 WTF::StringView sourceString = provider->source(); - if (UNLIKELY(sourceString.isNull())) + if (sourceString.isNull()) [[unlikely]] return; if (!stackFrame->hasBytecodeIndex()) { @@ -4627,12 +4627,12 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, bool getFromSourceURL = false; if (stackTrace != nullptr && stackTrace->size() > 0) { populateStackTrace(vm, *stackTrace, &except->stack, global, flags); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } } else if (err->stackTrace() != nullptr && err->stackTrace()->size() > 0) { populateStackTrace(vm, *err->stackTrace(), &except->stack, global, flags); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } } else { @@ -4653,7 +4653,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, except->message = Bun::toStringRef(err->sanitizedMessageString(global)); } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4670,7 +4670,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4680,7 +4680,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4690,7 +4690,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4700,7 +4700,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4710,7 +4710,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } } @@ -4727,7 +4727,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, if (JSC::JSValue stackValue = obj->getIfPropertyExists(global, vm.propertyNames->stack)) { if (stackValue.isString()) { WTF::String stack = stackValue.toWTFString(global); - if (UNLIKELY(catchScope.exception())) { + if (catchScope.exception()) [[unlikely]] { catchScope.clearExceptionExceptTermination(); } if (!stack.isEmpty()) { @@ -4772,7 +4772,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, } } - if (UNLIKELY(catchScope.exception())) { + if (catchScope.exception()) [[unlikely]] { catchScope.clearExceptionExceptTermination(); } } @@ -4822,7 +4822,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global, void exceptionFromString(ZigException* except, JSC::JSValue value, JSC::JSGlobalObject* global) { auto& vm = JSC::getVM(global); - if (UNLIKELY(vm.hasPendingTerminationException())) { + if (vm.hasPendingTerminationException()) [[unlikely]] { return; } @@ -4855,7 +4855,7 @@ void exceptionFromString(ZigException* except, JSC::JSValue value, JSC::JSGlobal } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4866,7 +4866,7 @@ void exceptionFromString(ZigException* except, JSC::JSValue value, JSC::JSGlobal } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4878,7 +4878,7 @@ void exceptionFromString(ZigException* except, JSC::JSValue value, JSC::JSGlobal } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4896,7 +4896,7 @@ void exceptionFromString(ZigException* except, JSC::JSValue value, JSC::JSGlobal } } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); } @@ -4921,7 +4921,7 @@ void exceptionFromString(ZigException* except, JSC::JSValue value, JSC::JSGlobal } auto str = value.toWTFString(global); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); return; } @@ -5501,7 +5501,7 @@ static void JSC__JSValue__forEachPropertyImpl(JSC::EncodedJSValue JSValue0, JSC: auto& vm = JSC::getVM(globalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(!vm.isSafeToRecurse())) { + if (!vm.isSafeToRecurse()) [[unlikely]] { throwStackOverflowError(globalObject, throwScope); return; } @@ -5585,7 +5585,7 @@ restart: iter(globalObject, arg2, &key, JSC::JSValue::encode(propertyValue), prop->isSymbol(), isPrivate); // Propagate exceptions from callbacks. - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { return false; } return true; @@ -5609,7 +5609,7 @@ restart: } } // Ignore exceptions from Proxy "getPrototype" trap. - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearException(); } } @@ -5632,7 +5632,7 @@ restart: RETURN_IF_EXCEPTION(scope, void()); for (auto& property : properties) { - if (UNLIKELY(property.isEmpty() || property.isNull())) + if (property.isEmpty() || property.isNull()) [[unlikely]] continue; // ignore constructor @@ -5777,7 +5777,7 @@ void JSC__JSValue__forEachPropertyOrdered(JSC::EncodedJSValue JSValue0, JSC::JSG auto clientData = WebCore::clientData(vm); for (auto property : vector) { - if (UNLIKELY(property.isEmpty() || property.isNull())) + if (property.isEmpty() || property.isNull()) [[unlikely]] continue; // ignore constructor @@ -5814,7 +5814,7 @@ void JSC__JSValue__forEachPropertyOrdered(JSC::EncodedJSValue JSValue0, JSC::JSG propertyValue = slot.getValue(globalObject, property); } - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { scope.clearException(); propertyValue = jsUndefined(); } @@ -5842,11 +5842,11 @@ bool JSC__JSValue__isInstanceOf(JSC::EncodedJSValue JSValue0, JSC::JSGlobalObjec JSValue jsValue = JSValue::decode(JSValue0); JSValue jsValue1 = JSValue::decode(JSValue1); - if (UNLIKELY(!jsValue1.isObject())) { + if (!jsValue1.isObject()) [[unlikely]] { return false; } JSObject* jsConstructor = JSC::asObject(jsValue1); - if (UNLIKELY(!jsConstructor->structure()->typeInfo().implementsHasInstance())) + if (!jsConstructor->structure()->typeInfo().implementsHasInstance()) [[unlikely]] return false; bool result = jsConstructor->hasInstance(globalObject, jsValue); @@ -6400,13 +6400,13 @@ CPP_DECL void Bun__CallFrame__getCallerSrcLoc(JSC::CallFrame* callFrame, JSC::JS extern "C" EncodedJSValue Bun__JSObject__getCodePropertyVMInquiry(JSC::JSGlobalObject* global, JSC::JSObject* object) { - if (UNLIKELY(!object)) { + if (!object) [[unlikely]] { return {}; } auto& vm = global->vm(); auto scope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(object->type() == JSC::ProxyObjectType)) { + if (object->type() == JSC::ProxyObjectType) [[unlikely]] { return {}; } @@ -6429,7 +6429,7 @@ extern "C" EncodedJSValue Bun__JSObject__getCodePropertyVMInquiry(JSC::JSGlobalO extern "C" void Bun__JSValue__unprotect(JSC::EncodedJSValue encodedValue) { JSC::JSValue value = JSC::JSValue::decode(encodedValue); - if (LIKELY(value && value.isCell())) { + if (value && value.isCell()) [[likely]] { JSCell* cell = value.asCell(); // Necessary if we're inside a finalizer due to an assertion. @@ -6442,7 +6442,7 @@ extern "C" void Bun__JSValue__unprotect(JSC::EncodedJSValue encodedValue) extern "C" void Bun__JSValue__protect(JSC::EncodedJSValue encodedValue) { JSC::JSValue value = JSC::JSValue::decode(encodedValue); - if (LIKELY(value && value.isCell())) { + if (value && value.isCell()) [[likely]] { JSCell* cell = value.asCell(); gcProtect(cell); } diff --git a/src/bun.js/bindings/c-bindings.cpp b/src/bun.js/bindings/c-bindings.cpp index 8675973c05..cc6d4e250b 100644 --- a/src/bun.js/bindings/c-bindings.cpp +++ b/src/bun.js/bindings/c-bindings.cpp @@ -479,7 +479,7 @@ extern "C" void bun_initialize_process() err = dup2(devNullFd_, target_fd); } while (err < 0 && errno == EINTR); - if (UNLIKELY(err != 0)) { + if (err != 0) [[unlikely]] { abort(); } }; @@ -487,7 +487,7 @@ extern "C" void bun_initialize_process() for (int fd = 0; fd < 3; fd++) { int result = isatty(fd); if (result == 0) { - if (UNLIKELY(errno == EBADF)) { + if (errno == EBADF) [[unlikely]] { // the fd is invalid, let's make sure it's always valid setDevNullFd(fd); } @@ -499,7 +499,7 @@ extern "C" void bun_initialize_process() err = tcgetattr(fd, &termios_to_restore_later[fd]); } while (err == -1 && errno == EINTR); - if (LIKELY(err == 0)) { + if (err == 0) [[likely]] { anyTTYs = true; } } diff --git a/src/bun.js/bindings/debug-helpers.h b/src/bun.js/bindings/debug-helpers.h index c40316c4d1..36295158e1 100644 --- a/src/bun.js/bindings/debug-helpers.h +++ b/src/bun.js/bindings/debug-helpers.h @@ -5,7 +5,7 @@ namespace JSC { Inspector::InspectorDebuggerAgent* debuggerAgent(JSC::JSGlobalObject* globalObject) { - if (LIKELY(!globalObject->hasDebugger())) { + if (!globalObject->hasDebugger()) [[likely]] { return nullptr; } diff --git a/src/bun.js/bindings/decodeURIComponentSIMD.cpp b/src/bun.js/bindings/decodeURIComponentSIMD.cpp index 6e40681e5b..5f8c768ead 100644 --- a/src/bun.js/bindings/decodeURIComponentSIMD.cpp +++ b/src/bun.js/bindings/decodeURIComponentSIMD.cpp @@ -285,7 +285,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionDecodeURIComponentSIMD, (JSC::JSGlobalObject size_t expected_length = simdutf::latin1_length_from_utf16(span.size()); std::span ptr; WTF::String convertedString = WTF::String::tryCreateUninitialized(expected_length, ptr); - if (UNLIKELY(convertedString.isNull())) { + if (convertedString.isNull()) [[unlikely]] { throwVMError(globalObject, scope, createOutOfMemoryError(globalObject)); return {}; } diff --git a/src/bun.js/bindings/helpers.h b/src/bun.js/bindings/helpers.h index 0d1ee0ed6e..1c70272776 100644 --- a/src/bun.js/bindings/helpers.h +++ b/src/bun.js/bindings/helpers.h @@ -77,14 +77,14 @@ static const WTF::String toString(ZigString str) if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); } - if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { + if (isTaggedUTF8Ptr(str.ptr)) [[unlikely]] { ASSERT_WITH_MESSAGE(!isTaggedExternalPtr(str.ptr), "UTF8 and external ptr are mutually exclusive. The external will never be freed."); return WTF::String::fromUTF8ReplacingInvalidSequences(std::span { untag(str.ptr), str.len }); } - if (UNLIKELY(isTaggedExternalPtr(str.ptr))) { + if (isTaggedExternalPtr(str.ptr)) [[unlikely]] { // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. - if (UNLIKELY(str.len > Bun__stringSyntheticAllocationLimit)) { + if (str.len > Bun__stringSyntheticAllocationLimit) [[unlikely]] { free_global_string(nullptr, reinterpret_cast(const_cast(untag(str.ptr))), static_cast(str.len)); return {}; } @@ -96,7 +96,7 @@ static const WTF::String toString(ZigString str) } // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. - if (UNLIKELY(str.len > Bun__stringSyntheticAllocationLimit)) { + if (str.len > Bun__stringSyntheticAllocationLimit) [[unlikely]] { return {}; } @@ -121,12 +121,12 @@ static const WTF::String toString(ZigString str, StringPointer ptr) if (str.len == 0 || str.ptr == nullptr || ptr.len == 0) { return WTF::String(); } - if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { + if (isTaggedUTF8Ptr(str.ptr)) [[unlikely]] { return WTF::String::fromUTF8ReplacingInvalidSequences(std::span { &untag(str.ptr)[ptr.off], ptr.len }); } // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. - if (UNLIKELY(str.len > Bun__stringSyntheticAllocationLimit)) { + if (str.len > Bun__stringSyntheticAllocationLimit) [[unlikely]] { return {}; } @@ -141,12 +141,12 @@ static const WTF::String toStringCopy(ZigString str, StringPointer ptr) if (str.len == 0 || str.ptr == nullptr || ptr.len == 0) { return WTF::String(); } - if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { + if (isTaggedUTF8Ptr(str.ptr)) [[unlikely]] { return WTF::String::fromUTF8ReplacingInvalidSequences(std::span { &untag(str.ptr)[ptr.off], ptr.len }); } // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. - if (UNLIKELY(str.len > Bun__stringSyntheticAllocationLimit)) { + if (str.len > Bun__stringSyntheticAllocationLimit) [[unlikely]] { return {}; } @@ -161,21 +161,22 @@ static const WTF::String toStringCopy(ZigString str) if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); } - if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { + if (isTaggedUTF8Ptr(str.ptr)) [[unlikely]] { return WTF::String::fromUTF8ReplacingInvalidSequences(std::span { untag(str.ptr), str.len }); } if (isTaggedUTF16Ptr(str.ptr)) { std::span out; auto impl = WTF::StringImpl::tryCreateUninitialized(str.len, out); - if (UNLIKELY(!impl)) + if (!impl) [[unlikely]] { return WTF::String(); + } memcpy(out.data(), untag(str.ptr), str.len * sizeof(UChar)); return WTF::String(WTFMove(impl)); } else { std::span out; auto impl = WTF::StringImpl::tryCreateUninitialized(str.len, out); - if (UNLIKELY(!impl)) + if (!impl) [[unlikely]] return WTF::String(); memcpy(out.data(), untag(str.ptr), str.len * sizeof(LChar)); return WTF::String(WTFMove(impl)); @@ -301,7 +302,7 @@ static const WTF::String toStringStatic(ZigString str) if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); } - if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { + if (isTaggedUTF8Ptr(str.ptr)) [[unlikely]] { abort(); } @@ -318,7 +319,7 @@ static const WTF::String toStringStatic(ZigString str) static JSC::JSValue getErrorInstance(const ZigString* str, JSC::JSGlobalObject* globalObject) { WTF::String message = toString(*str); - if (UNLIKELY(message.isNull() && str->len > 0)) { + if (message.isNull() && str->len > 0) [[unlikely]] { // pending exception while creating an error. return JSC::JSValue(); } diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp index da229db8c9..8fd003ceab 100644 --- a/src/bun.js/bindings/napi.cpp +++ b/src/bun.js/bindings/napi.cpp @@ -116,7 +116,7 @@ using namespace Zig; // Return an error code if arg is null. Only use for input validation. #define NAPI_CHECK_ARG(_env, arg) \ do { \ - if (UNLIKELY((arg) == nullptr)) { \ + if ((arg) == nullptr) [[unlikely]] { \ return napi_set_last_error(_env, napi_invalid_arg); \ } \ } while (0) @@ -587,7 +587,7 @@ extern "C" napi_status napi_delete_property(napi_env env, napi_value object, auto deleteResult = target->deleteProperty(globalObject, keyProp.toPropertyKey(globalObject)); NAPI_RETURN_IF_EXCEPTION(env); - if (LIKELY(result)) { + if (result) [[likely]] { *result = deleteResult; } // we checked for an exception above @@ -665,7 +665,7 @@ extern "C" napi_status napi_create_arraybuffer(napi_env env, auto* jsArrayBuffer = JSC::JSArrayBuffer::create(vm, globalObject->arrayBufferStructure(), WTFMove(arrayBuffer)); NAPI_RETURN_IF_EXCEPTION(env); - if (LIKELY(data && jsArrayBuffer->impl())) { + if (data && jsArrayBuffer->impl()) [[likely]] { *data = jsArrayBuffer->impl()->data(); } *result = toNapi(jsArrayBuffer, globalObject); @@ -700,11 +700,11 @@ extern "C" napi_status napi_is_typedarray(napi_env env, napi_value value, bool* // it doesn't copy the string // but it's only safe to use if we are not setting a property // because we can't guarantee the lifetime of it -#define PROPERTY_NAME_FROM_UTF8(identifierName) \ - size_t utf8Len = strlen(utf8Name); \ - WTF::String nameString = LIKELY(WTF::charactersAreAllASCII(std::span { reinterpret_cast(utf8Name), utf8Len })) \ - ? WTF::String(WTF::StringImpl::createWithoutCopying({ utf8Name, utf8Len })) \ - : WTF::String::fromUTF8(utf8Name); \ +#define PROPERTY_NAME_FROM_UTF8(identifierName) \ + size_t utf8Len = strlen(utf8Name); \ + WTF::String nameString = WTF::charactersAreAllASCII(std::span { reinterpret_cast(utf8Name), utf8Len }) \ + ? WTF::String(WTF::StringImpl::createWithoutCopying({ utf8Name, utf8Len })) \ + : WTF::String::fromUTF8(utf8Name); \ JSC::PropertyName identifierName = JSC::Identifier::fromString(vm, nameString); extern "C" napi_status napi_has_named_property(napi_env env, napi_value object, @@ -1264,7 +1264,7 @@ extern "C" napi_status napi_reference_unref(napi_env env, napi_ref ref, NapiRef* napiRef = toJS(ref); napiRef->unref(); - if (LIKELY(result)) { + if (result) [[likely]] { *result = napiRef->refCount; } NAPI_RETURN_SUCCESS(env); @@ -1294,7 +1294,7 @@ extern "C" napi_status napi_reference_ref(napi_env env, napi_ref ref, NAPI_CHECK_ARG(env, ref); NapiRef* napiRef = toJS(ref); napiRef->ref(); - if (LIKELY(result)) { + if (result) [[likely]] { *result = napiRef->refCount; } NAPI_RETURN_SUCCESS(env); @@ -1380,7 +1380,7 @@ extern "C" napi_status napi_get_and_clear_last_exception(napi_env env, NAPI_PREAMBLE_NO_THROW_SCOPE(env); NAPI_CHECK_ENV_NOT_IN_GC(env); - if (UNLIKELY(!result)) { + if (!result) [[unlikely]] { return napi_set_last_error(env, napi_invalid_arg); } @@ -1710,7 +1710,7 @@ JSC_HOST_CALL_ATTRIBUTES JSC::EncodedJSValue NapiClass_ConstructorFunction(JSC:: napi = jsDynamicCast(constructorTarget); } - if (UNLIKELY(!napi)) { + if (!napi) [[unlikely]] { JSC::throwVMError(globalObject, scope, JSC::createTypeError(globalObject, "NapiClass constructor called on an object that is not a NapiClass"_s)); return JSValue::encode(JSC::jsUndefined()); } @@ -2180,12 +2180,12 @@ napi_status napi_get_value_string_any_encoding(napi_env env, napi_value napiValu return napi_set_last_error(env, napi_ok); } - if (UNLIKELY(bufsize == 0)) { + if (bufsize == 0) [[unlikely]] { if (writtenPtr) *writtenPtr = 0; return napi_set_last_error(env, napi_ok); } - if (UNLIKELY(bufsize == NAPI_AUTO_LENGTH)) { + if (bufsize == NAPI_AUTO_LENGTH) [[unlikely]] { if (writtenPtr) *writtenPtr = 0; buf[0] = '\0'; return napi_set_last_error(env, napi_ok); @@ -2295,7 +2295,7 @@ extern "C" napi_status napi_delete_element(napi_env env, napi_value objectValue, JSObject* jsObject = jsValue.getObject(); NAPI_RETURN_EARLY_IF_FALSE(env, jsObject, napi_object_expected); - if (LIKELY(result)) { + if (result) [[likely]] { *result = jsObject->methodTable()->deletePropertyByIndex(jsObject, toJS(env), index); } NAPI_RETURN_SUCCESS_UNLESS_EXCEPTION(env); @@ -2724,7 +2724,7 @@ extern "C" napi_status napi_instanceof(napi_env env, napi_value object, napi_val return napi_set_last_error(env, napi_pending_exception); } - if (UNLIKELY(!constructorObject->structure()->typeInfo().implementsHasInstance())) { + if (!constructorObject->structure()->typeInfo().implementsHasInstance()) [[unlikely]] { *result = false; } else { *result = constructorObject->hasInstance(globalObject, objectValue); @@ -2810,7 +2810,7 @@ extern "C" napi_status napi_check_object_type_tag(napi_env env, napi_value value if (found_tag && found_tag->matches(*type_tag)) { match = true; } - if (LIKELY(result)) { + if (result) [[likely]] { *result = match; } NAPI_RETURN_SUCCESS(env); @@ -2915,7 +2915,7 @@ extern "C" JS_EXPORT napi_status napi_remove_env_cleanup_hook(napi_env env, { NAPI_PREAMBLE(env); - if (LIKELY(function != nullptr) && !env->globalObject()->vm().hasTerminationRequest()) { + if (function != nullptr && !env->globalObject()->vm().hasTerminationRequest()) [[likely]] { env->removeCleanupHook(function, data); } diff --git a/src/bun.js/bindings/napi.h b/src/bun.js/bindings/napi.h index 3853337402..f4e44cf135 100644 --- a/src/bun.js/bindings/napi.h +++ b/src/bun.js/bindings/napi.h @@ -53,7 +53,7 @@ struct napi_async_cleanup_hook_handle__ { #define NAPI_RELEASE_ASSERT(assertion, ...) \ do { \ - if (UNLIKELY(!(assertion))) { \ + if (!(assertion)) [[unlikely]] { \ WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__, #assertion, __VA_ARGS__); \ WTFReportBacktrace(); \ NAPI_ABORT("Aborted"); \ diff --git a/src/bun.js/bindings/node/NodeTimers.cpp b/src/bun.js/bindings/node/NodeTimers.cpp index 7df2fecd11..955907fb91 100644 --- a/src/bun.js/bindings/node/NodeTimers.cpp +++ b/src/bun.js/bindings/node/NodeTimers.cpp @@ -34,7 +34,7 @@ JSC_DEFINE_HOST_FUNCTION(functionSetTimeout, ArgList argumentsList = ArgList(callFrame, 2); auto* args = JSC::JSImmutableButterfly::tryCreateFromArgList(vm, argumentsList); - if (UNLIKELY(!args)) { + if (!args) [[unlikely]] { JSC::throwOutOfMemoryError(globalObject, scope); return {}; } @@ -43,7 +43,7 @@ JSC_DEFINE_HOST_FUNCTION(functionSetTimeout, } } - if (UNLIKELY(!job.isObject() || !job.getObject()->isCallable())) { + if (!job.isObject() || !job.getObject()->isCallable()) [[unlikely]] { Bun::throwError(globalObject, scope, ErrorCode::ERR_INVALID_ARG_TYPE, "setTimeout expects a function"_s); return {}; } @@ -90,7 +90,7 @@ JSC_DEFINE_HOST_FUNCTION(functionSetInterval, ArgList argumentsList = ArgList(callFrame, 2); auto* args = JSC::JSImmutableButterfly::tryCreateFromArgList(vm, argumentsList); - if (UNLIKELY(!args)) { + if (!args) [[unlikely]] { JSC::throwOutOfMemoryError(globalObject, scope); return {}; } @@ -99,7 +99,7 @@ JSC_DEFINE_HOST_FUNCTION(functionSetInterval, } } - if (UNLIKELY(!job.isObject() || !job.getObject()->isCallable())) { + if (!job.isObject() || !job.getObject()->isCallable()) [[unlikely]] { Bun::throwError(globalObject, scope, ErrorCode::ERR_INVALID_ARG_TYPE, "setInterval expects a function"_s); return {}; } @@ -152,7 +152,7 @@ JSC_DEFINE_HOST_FUNCTION(functionSetImmediate, ArgList argumentsList = ArgList(callFrame, 1); auto* args = JSC::JSImmutableButterfly::tryCreateFromArgList(vm, argumentsList); - if (UNLIKELY(!args)) { + if (!args) [[unlikely]] { JSC::throwOutOfMemoryError(globalObject, scope); return {}; } diff --git a/src/bun.js/bindings/node/crypto/CryptoGenDhKeyPair.cpp b/src/bun.js/bindings/node/crypto/CryptoGenDhKeyPair.cpp index ac09bc022f..b73602daf1 100644 --- a/src/bun.js/bindings/node/crypto/CryptoGenDhKeyPair.cpp +++ b/src/bun.js/bindings/node/crypto/CryptoGenDhKeyPair.cpp @@ -155,7 +155,7 @@ std::optional DhKeyPairJobCtx::fromJS(JSGlobalObject* globalObj if (JSArrayBufferView* view = jsDynamicCast(primeValue)) { prime = ncrypto::BignumPointer(reinterpret_cast(view->vector()), view->byteLength()); - if (UNLIKELY(!prime)) { + if (!prime) [[unlikely]] { ERR::OUT_OF_RANGE(scope, globalObject, "prime is too big"_s); return std::nullopt; } @@ -164,7 +164,7 @@ std::optional DhKeyPairJobCtx::fromJS(JSGlobalObject* globalObj } else if (JSArrayBuffer* buffer = jsDynamicCast(primeValue)) { auto impl = buffer->impl(); prime = ncrypto::BignumPointer(reinterpret_cast(impl->data()), impl->byteLength()); - if (UNLIKELY(!prime)) { + if (!prime) [[unlikely]] { ERR::OUT_OF_RANGE(scope, globalObject, "prime is too big"_s); return std::nullopt; } diff --git a/src/bun.js/bindings/node/crypto/CryptoPrimes.cpp b/src/bun.js/bindings/node/crypto/CryptoPrimes.cpp index 3051640da7..7422f6eea7 100644 --- a/src/bun.js/bindings/node/crypto/CryptoPrimes.cpp +++ b/src/bun.js/bindings/node/crypto/CryptoPrimes.cpp @@ -377,12 +377,12 @@ JSC_DEFINE_HOST_FUNCTION(jsGeneratePrime, (JSC::JSGlobalObject * lexicalGlobalOb } if (add) { - if (UNLIKELY(ncrypto::BignumPointer::GetBitCount(add.get()) > size)) { + if (ncrypto::BignumPointer::GetBitCount(add.get()) > size) [[unlikely]] { throwError(lexicalGlobalObject, scope, ErrorCode::ERR_OUT_OF_RANGE, "invalid options.add"_s); return JSValue::encode({}); } - if (UNLIKELY(rem && add <= rem)) { + if (rem && add <= rem) [[unlikely]] { throwError(lexicalGlobalObject, scope, ErrorCode::ERR_OUT_OF_RANGE, "invalid options.rem"_s); return JSValue::encode({}); } @@ -478,12 +478,12 @@ JSC_DEFINE_HOST_FUNCTION(jsGeneratePrimeSync, (JSC::JSGlobalObject * lexicalGlob } if (add) { - if (UNLIKELY(ncrypto::BignumPointer::GetBitCount(add.get()) > size)) { + if (ncrypto::BignumPointer::GetBitCount(add.get()) > size) [[unlikely]] { throwError(lexicalGlobalObject, scope, ErrorCode::ERR_OUT_OF_RANGE, "invalid options.add"_s); return JSValue::encode({}); } - if (UNLIKELY(rem && add <= rem)) { + if (rem && add <= rem) [[unlikely]] { throwError(lexicalGlobalObject, scope, ErrorCode::ERR_OUT_OF_RANGE, "invalid options.rem"_s); return JSValue::encode({}); } diff --git a/src/bun.js/bindings/node/crypto/CryptoSignJob.cpp b/src/bun.js/bindings/node/crypto/CryptoSignJob.cpp index 336294c3c4..7b9c02691e 100644 --- a/src/bun.js/bindings/node/crypto/CryptoSignJob.cpp +++ b/src/bun.js/bindings/node/crypto/CryptoSignJob.cpp @@ -89,7 +89,7 @@ void SignJobCtx::runTask(JSGlobalObject* globalObject) { ClearErrorOnReturn clearError; auto context = EVPMDCtxPointer::New(); - if (UNLIKELY(!context)) { + if (!context) [[unlikely]] { m_opensslError = ERR_get_error(); return; } diff --git a/src/bun.js/bindings/node/crypto/CryptoUtil.cpp b/src/bun.js/bindings/node/crypto/CryptoUtil.cpp index 66530b1867..3afe1b3fdc 100644 --- a/src/bun.js/bindings/node/crypto/CryptoUtil.cpp +++ b/src/bun.js/bindings/node/crypto/CryptoUtil.cpp @@ -69,7 +69,7 @@ EncodedJSValue encode(JSGlobalObject* lexicalGlobalObject, ThrowScope& scope, st VM& vm = lexicalGlobalObject->vm(); auto* globalObject = defaultGlobalObject(lexicalGlobalObject); - if (UNLIKELY(!bytes.size() and encoding != BufferEncodingType::buffer)) { + if (!bytes.size() and encoding != BufferEncodingType::buffer) [[unlikely]] { return JSValue::encode(jsEmptyString(vm)); } @@ -110,7 +110,7 @@ JSValue unsignedBigIntToBuffer(JSGlobalObject* lexicalGlobalObject, ThrowScope& JSString* paddedHex = hex.length() % 2 ? jsString(vm, tryMakeString('0', hex)) : jsString(vm, hex); - if (UNLIKELY(!paddedHex)) { + if (!paddedHex) [[unlikely]] { throwOutOfMemoryError(lexicalGlobalObject, scope); return {}; } diff --git a/src/bun.js/bindings/node/crypto/DiffieHellmanFunctions.h b/src/bun.js/bindings/node/crypto/DiffieHellmanFunctions.h index de2fee67e0..4e7f78850b 100644 --- a/src/bun.js/bindings/node/crypto/DiffieHellmanFunctions.h +++ b/src/bun.js/bindings/node/crypto/DiffieHellmanFunctions.h @@ -23,7 +23,7 @@ JSC::EncodedJSValue jsDiffieHellmanProtoFuncGenerateKeysTemplate(JSC::JSGlobalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, DiffieHellmanType::info()->className, "generateKeys"_s); return {}; } @@ -48,7 +48,7 @@ JSC::EncodedJSValue jsDiffieHellmanProtoFuncComputeSecretTemplate(JSC::JSGlobalO auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, DiffieHellmanType::info()->className, "computeSecret"_s); return {}; } @@ -126,7 +126,7 @@ JSC::EncodedJSValue jsDiffieHellmanProtoFuncGetPrimeTemplate(JSC::JSGlobalObject auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, DiffieHellmanType::info()->className, "getPrime"_s); return {}; } @@ -152,7 +152,7 @@ JSC::EncodedJSValue jsDiffieHellmanProtoFuncGetGeneratorTemplate(JSC::JSGlobalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, DiffieHellmanType::info()->className, "getGenerator"_s); return {}; } @@ -178,7 +178,7 @@ JSC::EncodedJSValue jsDiffieHellmanProtoFuncGetPublicKeyTemplate(JSC::JSGlobalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, DiffieHellmanType::info()->className, "getPublicKey"_s); return {}; } @@ -204,7 +204,7 @@ JSC::EncodedJSValue jsDiffieHellmanProtoFuncGetPrivateKeyTemplate(JSC::JSGlobalO auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, DiffieHellmanType::info()->className, "getPrivateKey"_s); return {}; } @@ -229,7 +229,7 @@ JSC::EncodedJSValue jsDiffieHellmanProtoFuncSetPublicKeyTemplate(JSC::JSGlobalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, DiffieHellmanType::info()->className, "setPublicKey"_s); return {}; } @@ -266,7 +266,7 @@ JSC::EncodedJSValue jsDiffieHellmanProtoFuncSetPrivateKeyTemplate(JSC::JSGlobalO auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = JSC::jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwThisTypeError(*globalObject, scope, DiffieHellmanType::info()->className, "setPrivateKey"_s); return {}; } diff --git a/src/bun.js/bindings/node/crypto/JSCipherConstructor.cpp b/src/bun.js/bindings/node/crypto/JSCipherConstructor.cpp index ed43f741ad..d9a60647b1 100644 --- a/src/bun.js/bindings/node/crypto/JSCipherConstructor.cpp +++ b/src/bun.js/bindings/node/crypto/JSCipherConstructor.cpp @@ -151,13 +151,13 @@ JSC_DEFINE_HOST_FUNCTION(constructCipher, (JSC::JSGlobalObject * globalObject, J WTF::String cipherString = cipherValue.toWTFString(globalObject); RETURN_IF_EXCEPTION(scope, JSValue::encode({})); - if (UNLIKELY(keyData.size() > INT_MAX)) { + if (keyData.size() > INT_MAX) [[unlikely]] { return ERR::OUT_OF_RANGE(scope, globalObject, "key is too big"_s, 0, INT_MAX, jsNumber(keyData.size())); } int32_t ivLen = 0; if (ivView) { - if (UNLIKELY(ivView->byteLength() > INT_MAX)) { + if (ivView->byteLength() > INT_MAX) [[unlikely]] { return ERR::OUT_OF_RANGE(scope, globalObject, "iv is too big"_s, 0, INT_MAX, jsNumber(ivView->byteLength())); } ivLen = ivView->byteLength(); diff --git a/src/bun.js/bindings/node/crypto/JSDiffieHellman.cpp b/src/bun.js/bindings/node/crypto/JSDiffieHellman.cpp index 15e991e119..2779093b34 100644 --- a/src/bun.js/bindings/node/crypto/JSDiffieHellman.cpp +++ b/src/bun.js/bindings/node/crypto/JSDiffieHellman.cpp @@ -60,7 +60,7 @@ JSC_DEFINE_HOST_FUNCTION(jsDiffieHellmanGetter_verifyError, (JSC::JSGlobalObject JSValue thisValue = callFrame->thisValue(); JSDiffieHellman* thisObject = JSC::jsDynamicCast(thisValue); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwVMTypeError(globalObject, scope); return {}; } diff --git a/src/bun.js/bindings/node/crypto/JSDiffieHellmanGroupConstructor.cpp b/src/bun.js/bindings/node/crypto/JSDiffieHellmanGroupConstructor.cpp index dc4b1f4c6f..d6bd665276 100644 --- a/src/bun.js/bindings/node/crypto/JSDiffieHellmanGroupConstructor.cpp +++ b/src/bun.js/bindings/node/crypto/JSDiffieHellmanGroupConstructor.cpp @@ -47,7 +47,7 @@ JSC_DEFINE_HOST_FUNCTION(constructDiffieHellmanGroup, (JSC::JSGlobalObject * glo JSC::Structure* structure = zigGlobalObject->m_JSDiffieHellmanGroupClassStructure.get(zigGlobalObject); JSC::JSValue newTarget = callFrame->newTarget(); - if (UNLIKELY(zigGlobalObject->m_JSDiffieHellmanGroupClassStructure.constructor(zigGlobalObject) != newTarget)) { + if (zigGlobalObject->m_JSDiffieHellmanGroupClassStructure.constructor(zigGlobalObject) != newTarget) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); if (!newTarget) { throwError(globalObject, scope, ErrorCode::ERR_INVALID_THIS, "Class constructor DiffieHellmanGroup cannot be invoked without 'new'"_s); diff --git a/src/bun.js/bindings/node/crypto/JSHash.cpp b/src/bun.js/bindings/node/crypto/JSHash.cpp index cbc4ccc623..98fc4f4542 100644 --- a/src/bun.js/bindings/node/crypto/JSHash.cpp +++ b/src/bun.js/bindings/node/crypto/JSHash.cpp @@ -301,7 +301,7 @@ JSC_DEFINE_HOST_FUNCTION(constructHash, (JSC::JSGlobalObject * globalObject, JSC // Handle new target JSC::JSValue newTarget = callFrame->newTarget(); - if (UNLIKELY(zigGlobalObject->m_JSHashClassStructure.constructor(zigGlobalObject) != newTarget)) { + if (zigGlobalObject->m_JSHashClassStructure.constructor(zigGlobalObject) != newTarget) [[unlikely]] { if (!newTarget) { throwTypeError(globalObject, scope, "Class constructor Hash cannot be invoked without 'new'"_s); return {}; diff --git a/src/bun.js/bindings/node/crypto/JSHmac.cpp b/src/bun.js/bindings/node/crypto/JSHmac.cpp index 8d6a6b5773..fff0284917 100644 --- a/src/bun.js/bindings/node/crypto/JSHmac.cpp +++ b/src/bun.js/bindings/node/crypto/JSHmac.cpp @@ -241,7 +241,7 @@ JSC_DEFINE_HOST_FUNCTION(constructHmac, (JSC::JSGlobalObject * globalObject, JSC // Handle new target JSC::JSValue newTarget = callFrame->newTarget(); - if (UNLIKELY(zigGlobalObject->m_JSHmacClassStructure.constructor(zigGlobalObject) != newTarget)) { + if (zigGlobalObject->m_JSHmacClassStructure.constructor(zigGlobalObject) != newTarget) [[unlikely]] { if (!newTarget) { throwTypeError(globalObject, scope, "Class constructor Hmac cannot be invoked without 'new'"_s); return {}; diff --git a/src/bun.js/bindings/node/crypto/JSKeyObjectConstructor.cpp b/src/bun.js/bindings/node/crypto/JSKeyObjectConstructor.cpp index 04bfbcb1fa..47370b03ed 100644 --- a/src/bun.js/bindings/node/crypto/JSKeyObjectConstructor.cpp +++ b/src/bun.js/bindings/node/crypto/JSKeyObjectConstructor.cpp @@ -93,7 +93,7 @@ JSC_DEFINE_HOST_FUNCTION(jsKeyObjectConstructor_from, (JSGlobalObject * lexicalG WebCore::CryptoKey& wrappedKey = cryptoKey->wrapped(); auto keyObjectResult = KeyObject::create(wrappedKey); - if (UNLIKELY(keyObjectResult.hasException())) { + if (keyObjectResult.hasException()) [[unlikely]] { WebCore::propagateException(*lexicalGlobalObject, scope, keyObjectResult.releaseException()); return JSValue::encode({}); } diff --git a/src/bun.js/bindings/node/crypto/JSSign.cpp b/src/bun.js/bindings/node/crypto/JSSign.cpp index 7835db85bc..9bbdab4eae 100644 --- a/src/bun.js/bindings/node/crypto/JSSign.cpp +++ b/src/bun.js/bindings/node/crypto/JSSign.cpp @@ -151,7 +151,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSignProtoFuncInit, (JSC::JSGlobalObject * globalObjec // Get the JSSign object from thisValue and verify it's valid JSSign* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "Sign"_s, "init"_s); return {}; } @@ -231,7 +231,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSignProtoFuncUpdate, (JSC::JSGlobalObject * globalObj // Get the JSSign object from thisValue and verify it's valid JSSign* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "Sign"_s, "update"_s); return JSValue::encode({}); } @@ -394,7 +394,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSignProtoFuncSign, (JSC::JSGlobalObject * lexicalGlob // Get the JSSign object from thisValue and verify it's valid JSSign* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*lexicalGlobalObject, scope, "Sign"_s, "sign"_s); return {}; } @@ -484,7 +484,7 @@ JSC_DEFINE_HOST_FUNCTION(constructSign, (JSC::JSGlobalObject * globalObject, JSC JSC::Structure* structure = zigGlobalObject->m_JSSignClassStructure.get(zigGlobalObject); JSC::JSValue newTarget = callFrame->newTarget(); - if (UNLIKELY(zigGlobalObject->m_JSSignClassStructure.constructor(zigGlobalObject) != newTarget)) { + if (zigGlobalObject->m_JSSignClassStructure.constructor(zigGlobalObject) != newTarget) [[unlikely]] { if (!newTarget) { throwTypeError(globalObject, scope, "Class constructor Sign cannot be invoked without 'new'"_s); return {}; diff --git a/src/bun.js/bindings/node/crypto/JSVerify.cpp b/src/bun.js/bindings/node/crypto/JSVerify.cpp index e4c310fd63..e59cfc3895 100644 --- a/src/bun.js/bindings/node/crypto/JSVerify.cpp +++ b/src/bun.js/bindings/node/crypto/JSVerify.cpp @@ -157,7 +157,7 @@ JSC_DEFINE_HOST_FUNCTION(jsVerifyProtoFuncInit, (JSGlobalObject * globalObject, // Get the JSVerify object from thisValue and verify it's valid JSVerify* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "Verify"_s, "init"_s); return {}; } @@ -211,7 +211,7 @@ JSC_DEFINE_HOST_FUNCTION(jsVerifyProtoFuncUpdate, (JSGlobalObject * globalObject // Get the JSVerify object from thisValue and verify it's valid JSVerify* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "Verify"_s, "update"_s); return JSValue::encode({}); } @@ -314,7 +314,7 @@ JSC_DEFINE_HOST_FUNCTION(jsVerifyProtoFuncVerify, (JSGlobalObject * globalObject // Get the JSVerify object from thisValue and verify it's valid JSVerify* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { Bun::throwThisTypeError(*globalObject, scope, "Verify"_s, "verify"_s); return JSValue::encode({}); } diff --git a/src/bun.js/bindings/node/crypto/KeyObject.cpp b/src/bun.js/bindings/node/crypto/KeyObject.cpp index a8e31fa349..a1b048156c 100644 --- a/src/bun.js/bindings/node/crypto/KeyObject.cpp +++ b/src/bun.js/bindings/node/crypto/KeyObject.cpp @@ -1218,7 +1218,7 @@ KeyObject::PrepareAsymmetricKeyResult KeyObject::prepareAsymmetricKey(JSC::JSGlo RETURN_IF_EXCEPTION(scope, {}); auto keyObject = create(key); - if (UNLIKELY(keyObject.hasException())) { + if (keyObject.hasException()) [[unlikely]] { WebCore::propagateException(*globalObject, scope, keyObject.releaseException()); return {}; } @@ -1286,7 +1286,7 @@ KeyObject::PrepareAsymmetricKeyResult KeyObject::prepareAsymmetricKey(JSC::JSGlo RETURN_IF_EXCEPTION(scope, {}); auto keyObject = create(key); - if (UNLIKELY(keyObject.hasException())) { + if (keyObject.hasException()) [[unlikely]] { WebCore::propagateException(*globalObject, scope, keyObject.releaseException()); } KeyObject handle = keyObject.releaseReturnValue(); @@ -1424,7 +1424,7 @@ KeyObject KeyObject::prepareSecretKey(JSGlobalObject* globalObject, ThrowScope& return {}; } auto keyObject = create(key); - if (UNLIKELY(keyObject.hasException())) { + if (keyObject.hasException()) [[unlikely]] { WebCore::propagateException(globalObject, scope, keyObject.releaseException()); return {}; } diff --git a/src/bun.js/bindings/root.h b/src/bun.js/bindings/root.h index ba06c1e7d2..182264805b 100644 --- a/src/bun.js/bindings/root.h +++ b/src/bun.js/bindings/root.h @@ -74,6 +74,9 @@ #include #ifdef __cplusplus +#if OS(LINUX) +#include +#endif #include #include #include diff --git a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp index 9f2835a1a0..4218eca000 100644 --- a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp +++ b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp @@ -170,7 +170,7 @@ static inline JSC::JSValue jsBigIntFromSQLite(JSC::JSGlobalObject* globalObject, } #define CHECK_THIS \ - if (UNLIKELY(!castedThis)) { \ + if (!castedThis) [[unlikely]] { \ throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQLStatement"_s)); \ return {}; \ } @@ -178,7 +178,7 @@ static inline JSC::JSValue jsBigIntFromSQLite(JSC::JSGlobalObject* globalObject, #define DO_REBIND(param) \ if (param.isObject()) { \ JSC::JSValue reb = castedThis->rebind(lexicalGlobalObject, param, true, castedThis->version_db->db); \ - if (UNLIKELY(!reb.isNumber())) { \ + if (!reb.isNumber()) [[unlikely]] { \ return JSValue::encode(reb); /* this means an error */ \ } \ } else { \ @@ -187,13 +187,13 @@ static inline JSC::JSValue jsBigIntFromSQLite(JSC::JSGlobalObject* globalObject, } #define CHECK_PREPARED \ - if (UNLIKELY(castedThis->stmt == nullptr || castedThis->version_db == nullptr)) { \ + if (castedThis->stmt == nullptr || castedThis->version_db == nullptr) [[unlikely]] { \ throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Statement has finalized"_s)); \ return {}; \ } #define CHECK_PREPARED_JIT \ - if (UNLIKELY(castedThis->stmt == nullptr || castedThis->version_db == nullptr)) { \ + if (castedThis->stmt == nullptr || castedThis->version_db == nullptr) [[unlikely]] { \ throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Statement has finalized"_s)); \ return {}; \ } @@ -508,7 +508,7 @@ static JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, sqlite3_stmt case SQLITE3_TEXT: { size_t len = sqlite3_column_bytes(stmt, i); const unsigned char* text = len > 0 ? sqlite3_column_text(stmt, i) : nullptr; - if (UNLIKELY(text == nullptr || len == 0)) { + if (text == nullptr || len == 0) [[unlikely]] { return jsEmptyString(vm); } @@ -517,7 +517,7 @@ static JSValue toJS(JSC::VM& vm, JSC::JSGlobalObject* globalObject, sqlite3_stmt case SQLITE_BLOB: { size_t len = sqlite3_column_bytes(stmt, i); const void* blob = len > 0 ? sqlite3_column_blob(stmt, i) : nullptr; - if (LIKELY(len > 0 && blob != nullptr)) { + if (len > 0 && blob != nullptr) [[likely]] { JSC::JSUint8Array* array = JSC::JSUint8Array::createUninitialized(globalObject, globalObject->m_typedArrayUint8.get(globalObject), len); memcpy(array->vector(), blob, len); return array; @@ -656,7 +656,7 @@ static void initializeColumnNames(JSC::JSGlobalObject* lexicalGlobalObject, JSSQ } } - if (LIKELY(!anyHoles)) { + if (!anyHoles) [[likely]] { PropertyOffset offset; JSObject* prototype = castedThis->userPrototype ? castedThis->userPrototype.get() : globalObject.objectPrototype(); Structure* structure = globalObject.structureCache().emptyObjectStructureForPrototype(&globalObject, prototype, columnNames->size()); @@ -751,11 +751,11 @@ static inline bool rebindValue(JSC::JSGlobalObject* lexicalGlobalObject, sqlite3 throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, WTF::String::fromUTF8(sqlite3_errmsg(db)))); }; -#define CHECK_BIND(param) \ - int result = param; \ - if (UNLIKELY(result != SQLITE_OK)) { \ - throwSQLiteError(); \ - return false; \ +#define CHECK_BIND(param) \ + int result = param; \ + if (result != SQLITE_OK) [[unlikely]] { \ + throwSQLiteError(); \ + return false; \ } // only clone if necessary @@ -779,13 +779,13 @@ static inline bool rebindValue(JSC::JSGlobalObject* lexicalGlobalObject, sqlite3 CHECK_BIND(sqlite3_bind_double(stmt, i, value.asDouble())) } else if (value.isString()) { auto* str = value.toStringOrNull(lexicalGlobalObject); - if (UNLIKELY(!str)) { + if (!str) [[unlikely]] { throwException(lexicalGlobalObject, scope, createTypeError(lexicalGlobalObject, "Expected string"_s)); return false; } const auto roped = str->view(lexicalGlobalObject); - if (UNLIKELY(roped->isNull())) { + if (roped->isNull()) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Out of memory :("_s)); return false; } @@ -799,14 +799,14 @@ static inline bool rebindValue(JSC::JSGlobalObject* lexicalGlobalObject, sqlite3 CHECK_BIND(sqlite3_bind_text(stmt, i, utf8.data(), utf8.length(), SQLITE_TRANSIENT)); } - } else if (UNLIKELY(value.isHeapBigInt())) { + } else if (value.isHeapBigInt()) [[unlikely]] { if (!isSafeInteger) { CHECK_BIND(sqlite3_bind_int64(stmt, i, JSBigInt::toBigInt64(value))); } else { JSBigInt* bigInt = value.asHeapBigInt(); const auto min = JSBigInt::compare(bigInt, std::numeric_limits::min()); const auto max = JSBigInt::compare(bigInt, std::numeric_limits::max()); - if (LIKELY((min == JSBigInt::ComparisonResult::GreaterThan || min == JSBigInt::ComparisonResult::Equal) && (max == JSBigInt::ComparisonResult::LessThan || max == JSBigInt::ComparisonResult::Equal))) { + if ((min == JSBigInt::ComparisonResult::GreaterThan || min == JSBigInt::ComparisonResult::Equal) && (max == JSBigInt::ComparisonResult::LessThan || max == JSBigInt::ComparisonResult::Equal)) [[likely]] { CHECK_BIND(sqlite3_bind_int64(stmt, i, JSBigInt::toBigInt64(value))); } else { throwRangeError(lexicalGlobalObject, scope, makeString("BigInt value '"_s, bigInt->toString(lexicalGlobalObject, 10), "' is out of range"_s)); @@ -843,7 +843,7 @@ static JSC::JSValue rebindObject(JSC::JSGlobalObject* globalObject, SQLiteBindin // // { ?2: "foo", ?1: "bar" } // - if (UNLIKELY(bindings.hasOutOfOrderNames)) { + if (bindings.hasOutOfOrderNames) [[unlikely]] { const auto& getValue = [&](const char* name, size_t i) -> JSValue { JSValue value = {}; @@ -870,7 +870,7 @@ static JSC::JSValue rebindObject(JSC::JSGlobalObject* globalObject, SQLiteBindin return {}; } - if (LIKELY(!slot.isTaintedByOpaqueObject())) { + if (!slot.isTaintedByOpaqueObject()) [[likely]] { return slot.getValue(globalObject, identifier); } @@ -902,7 +902,7 @@ static JSC::JSValue rebindObject(JSC::JSGlobalObject* globalObject, SQLiteBindin // // { 0: "foo", 1: "bar", "2": "baz" } // - else if (UNLIKELY(bindings.isOnlyIndexed)) { + else if (bindings.isOnlyIndexed) [[unlikely]] { for (size_t i = 0; i < size; i++) { JSValue value = target->getDirectIndex(globalObject, i); if (!value && !scope.exception()) { @@ -964,7 +964,7 @@ static JSC::JSValue rebindObject(JSC::JSGlobalObject* globalObject, SQLiteBindin RETURN_IF_EXCEPTION(scope, {}); JSValue value; - if (LIKELY(!slot.isTaintedByOpaqueObject())) + if (!slot.isTaintedByOpaqueObject()) [[likely]] value = slot.getValue(globalObject, property); else { value = target->get(globalObject, property); @@ -1033,7 +1033,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementSetCustomSQLite, (JSC::JSGlobalObject * l JSValue thisValue = callFrame->thisValue(); JSSQLStatementConstructor* thisObject = jsDynamicCast(thisValue.getObject()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQL"_s)); return {}; } @@ -1044,7 +1044,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementSetCustomSQLite, (JSC::JSGlobalObject * l } JSC::JSValue sqliteStrValue = callFrame->argument(0); - if (UNLIKELY(!sqliteStrValue.isString())) { + if (!sqliteStrValue.isString()) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQLite path"_s)); return {}; } @@ -1090,7 +1090,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementDeserialize, (JSC::JSGlobalObject * lexic RETURN_IF_EXCEPTION(scope, {}); } - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQL"_s)); return {}; } @@ -1100,18 +1100,18 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementDeserialize, (JSC::JSGlobalObject * lexic return {}; } - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected Uint8Array or Buffer"_s)); return {}; } - if (UNLIKELY(array->isDetached())) { + if (array->isDetached()) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "TypedArray is detached"_s)); return {}; } #if LAZY_LOAD_SQLITE - if (UNLIKELY(lazyLoadSQLite() < 0)) { + if (lazyLoadSQLite() < 0) [[unlikely]] { WTF::String msg = WTF::String::fromUTF8(dlerror()); throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, msg)); return {}; @@ -1121,12 +1121,12 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementDeserialize, (JSC::JSGlobalObject * lexic size_t byteLength = array->byteLength(); void* ptr = array->vector(); - if (UNLIKELY(ptr == nullptr || byteLength == 0)) { + if (ptr == nullptr || byteLength == 0) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "ArrayBuffer must not be empty"_s)); return {}; } void* data = sqlite3_malloc64(byteLength); - if (UNLIKELY(data == nullptr)) { + if (data == nullptr) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Failed to allocate memory"_s)); return {}; } @@ -1174,19 +1174,19 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementSerialize, (JSC::JSGlobalObject * lexical JSValue thisValue = callFrame->thisValue(); JSSQLStatementConstructor* thisObject = jsDynamicCast(thisValue.getObject()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQL"_s)); return {}; } int32_t dbIndex = callFrame->argument(0).toInt32(lexicalGlobalObject); - if (UNLIKELY(dbIndex < 0 || dbIndex >= databases().size())) { + if (dbIndex < 0 || dbIndex >= databases().size()) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Invalid database handle"_s)); return {}; } sqlite3* db = databases()[dbIndex]->db; - if (UNLIKELY(!db)) { + if (!db) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Can't do this on a closed database"_s)); return {}; } @@ -1200,7 +1200,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementSerialize, (JSC::JSGlobalObject * lexical } sqlite3_int64 length = -1; unsigned char* data = sqlite3_serialize(db, attachedName.utf8().data(), &length, 0); - if (UNLIKELY(data == nullptr && length)) { + if (data == nullptr && length) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Out of memory"_s)); return {}; } @@ -1215,19 +1215,19 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementLoadExtensionFunction, (JSC::JSGlobalObje JSValue thisValue = callFrame->thisValue(); JSSQLStatementConstructor* thisObject = jsDynamicCast(thisValue.getObject()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQL"_s)); return {}; } int32_t dbIndex = callFrame->argument(0).toInt32(lexicalGlobalObject); - if (UNLIKELY(dbIndex < 0 || dbIndex >= databases().size())) { + if (dbIndex < 0 || dbIndex >= databases().size()) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Invalid database handle"_s)); return {}; } JSC::JSValue extension = callFrame->argument(1); - if (UNLIKELY(!extension.isString())) { + if (!extension.isString()) [[unlikely]] { throwException(lexicalGlobalObject, scope, createTypeError(lexicalGlobalObject, "Expected string"_s)); return {}; } @@ -1236,7 +1236,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementLoadExtensionFunction, (JSC::JSGlobalObje RETURN_IF_EXCEPTION(scope, {}); sqlite3* db = databases()[dbIndex]->db; - if (UNLIKELY(!db)) { + if (!db) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Can't do this on a closed database"_s)); return {}; } @@ -1275,7 +1275,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteFunction, (JSC::JSGlobalObject * l JSValue thisValue = callFrame->thisValue(); JSSQLStatementConstructor* thisObject = jsDynamicCast(thisValue.getObject()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQL"_s)); return {}; } @@ -1292,7 +1292,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteFunction, (JSC::JSGlobalObject * l } sqlite3* db = databases()[handle]->db; - if (UNLIKELY(!db)) { + if (!db) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Database has closed"_s)); return {}; } @@ -1301,7 +1301,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteFunction, (JSC::JSGlobalObject * l JSC::JSValue diffValue = callFrame->argument(2); JSC::JSValue sqlValue = callFrame->argument(3); - if (UNLIKELY(!sqlValue.isString())) { + if (!sqlValue.isString()) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQL string"_s)); return {}; } @@ -1309,7 +1309,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteFunction, (JSC::JSGlobalObject * l EnsureStillAliveScope bindingsAliveScope = callFrame->argument(4); auto sqlString = sqlValue.toWTFString(lexicalGlobalObject); - if (UNLIKELY(sqlString.length() == 0)) { + if (sqlString.length() == 0) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "SQL string mustn't be blank"_s)); return {}; } @@ -1347,7 +1347,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteFunction, (JSC::JSGlobalObject * l const int total_changes_before = sqlite3_total_changes(db); while (sqlStringHead && sqlStringHead < end) { - if (UNLIKELY(isSkippedInSQLiteQuery(*sqlStringHead))) { + if (isSkippedInSQLiteQuery(*sqlStringHead)) [[unlikely]] { sqlStringHead++; while (sqlStringHead < end && isSkippedInSQLiteQuery(*sqlStringHead)) @@ -1382,7 +1382,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteFunction, (JSC::JSGlobalObject * l JSC::JSValue reb = rebindStatement(lexicalGlobalObject, bindingsAliveScope.value(), scope, db, sql.stmt, false, bindings, safeIntegers); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(!reb.isNumber())) { + if (!reb.isNumber()) [[unlikely]] { return JSValue::encode(reb); /* this means an error */ } } else { @@ -1400,7 +1400,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteFunction, (JSC::JSGlobalObject * l sqlStringHead = tail; } - if (UNLIKELY(rc != SQLITE_OK && rc != SQLITE_DONE)) { + if (rc != SQLITE_OK && rc != SQLITE_DONE) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, db)); return {}; } @@ -1431,7 +1431,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementIsInTransactionFunction, (JSC::JSGlobalOb JSValue thisValue = callFrame->thisValue(); JSSQLStatementConstructor* thisObject = jsDynamicCast(thisValue.getObject()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQLStatement"_s)); return {}; } @@ -1452,7 +1452,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementIsInTransactionFunction, (JSC::JSGlobalOb sqlite3* db = databases()[handle]->db; - if (UNLIKELY(!db)) { + if (!db) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Database has closed"_s)); return {}; } @@ -1467,7 +1467,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementPrepareStatementFunction, (JSC::JSGlobalO JSValue thisValue = callFrame->thisValue(); JSSQLStatementConstructor* thisObject = jsDynamicCast(thisValue.getObject()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQLStatement"_s)); return {}; } @@ -1585,7 +1585,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementOpenStatementFunction, (JSC::JSGlobalObje } #if LAZY_LOAD_SQLITE - if (UNLIKELY(lazyLoadSQLite() < 0)) { + if (lazyLoadSQLite() < 0) [[unlikely]] { WTF::String msg = WTF::String::fromUTF8(dlerror()); throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, msg)); return {}; @@ -1699,7 +1699,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementFcntlFunction, (JSC::JSGlobalObject * lex JSValue thisValue = callFrame->thisValue(); JSSQLStatementConstructor* thisObject = jsDynamicCast(thisValue.getObject()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQLStatement"_s)); return {}; } @@ -1882,7 +1882,7 @@ static inline JSC::JSArray* constructResultRow(JSC::VM& vm, JSC::JSGlobalObject* Structure* arrayStructure = lexicalGlobalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous); JSC::JSArray* result; - if (LIKELY(result = JSC::JSArray::tryCreateUninitializedRestricted(initializationScope, arrayStructure, columnCount))) { + if ((result = JSC::JSArray::tryCreateUninitializedRestricted(initializationScope, arrayStructure, columnCount))) [[likely]] { for (size_t i = 0; i < columnCount; i++) { result->initializeIndex(initializationScope, i, arguments.at(i)); } @@ -1924,7 +1924,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementSetPrototypeFunction, (JSGlobalObject * l JSValue prototype = classObject->getIfPropertyExists(lexicalGlobalObject, vm.propertyNames->prototype); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(!prototype && !scope.exception())) { + if (!prototype && !scope.exception()) [[unlikely]] { throwTypeError(lexicalGlobalObject, scope, "Expected constructor to have a prototype"_s); return {}; } @@ -1969,7 +1969,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionIterate, (JSC::JS int busy = sqlite3_stmt_busy(stmt); if (!busy) { int statusCode = sqlite3_reset(stmt); - if (UNLIKELY(statusCode != SQLITE_OK)) { + if (statusCode != SQLITE_OK) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db)); return {}; } @@ -2018,7 +2018,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionAll, (JSC::JSGlob CHECK_PREPARED int statusCode = sqlite3_reset(stmt); - if (UNLIKELY(statusCode != SQLITE_OK)) { + if (statusCode != SQLITE_OK) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db)); return {}; } @@ -2071,7 +2071,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionAll, (JSC::JSGlob result = JSC::constructEmptyArray(lexicalGlobalObject, nullptr, 0); } - if (UNLIKELY(status != SQLITE_DONE && status != SQLITE_OK)) { + if (status != SQLITE_DONE && status != SQLITE_OK) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db)); sqlite3_reset(stmt); return {}; @@ -2098,7 +2098,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionGet, (JSC::JSGlob CHECK_PREPARED int statusCode = sqlite3_reset(stmt); - if (UNLIKELY(statusCode != SQLITE_OK)) { + if (statusCode != SQLITE_OK) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db)); return {}; } @@ -2150,7 +2150,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRows, (JSC::JSGlo CHECK_PREPARED int statusCode = sqlite3_reset(stmt); - if (UNLIKELY(statusCode != SQLITE_OK)) { + if (statusCode != SQLITE_OK) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db)); sqlite3_reset(stmt); return {}; @@ -2190,7 +2190,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRows, (JSC::JSGlo do { JSC::JSArray* row = constructResultRow(vm, lexicalGlobalObject, castedThis, columnCount); - if (UNLIKELY(!row || scope.exception())) { + if (!row || scope.exception()) [[unlikely]] { sqlite3_reset(stmt); RELEASE_AND_RETURN(scope, {}); } @@ -2206,7 +2206,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRows, (JSC::JSGlo result = JSC::constructEmptyArray(lexicalGlobalObject, nullptr, 0); } - if (UNLIKELY(status != SQLITE_DONE && status != SQLITE_OK)) { + if (status != SQLITE_DONE && status != SQLITE_OK) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db)); sqlite3_reset(stmt); return {}; @@ -2229,7 +2229,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRun, (JSC::JSGlob CHECK_PREPARED int statusCode = sqlite3_reset(stmt); - if (UNLIKELY(statusCode != SQLITE_OK)) { + if (statusCode != SQLITE_OK) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db)); return {}; } @@ -2241,7 +2241,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRun, (JSC::JSGlob DO_REBIND(arg0); } - if (UNLIKELY(!castedThis->version_db->db)) { + if (!castedThis->version_db->db) [[unlikely]] { throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Database has closed"_s)); return {}; } @@ -2261,7 +2261,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRun, (JSC::JSGlob status = sqlite3_step(stmt); } - if (UNLIKELY(status != SQLITE_DONE && status != SQLITE_OK)) { + if (status != SQLITE_DONE && status != SQLITE_OK) [[unlikely]] { throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db)); sqlite3_reset(stmt); return {}; diff --git a/src/bun.js/bindings/webcore/BroadcastChannel.cpp b/src/bun.js/bindings/webcore/BroadcastChannel.cpp index 37fffd0400..bf4dab991e 100644 --- a/src/bun.js/bindings/webcore/BroadcastChannel.cpp +++ b/src/bun.js/bindings/webcore/BroadcastChannel.cpp @@ -268,7 +268,7 @@ void BroadcastChannel::dispatchMessage(Ref&& message) auto scope = DECLARE_CATCH_SCOPE(vm); Vector> dummyPorts; auto event = MessageEvent::create(*globalObject, WTFMove(message), {}, {}, nullptr, WTFMove(dummyPorts)); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { // Currently, we assume that the only way we can get here is if we have a termination. RELEASE_ASSERT(vm.hasPendingTerminationException()); return; diff --git a/src/bun.js/bindings/webcore/BufferSource.h b/src/bun.js/bindings/webcore/BufferSource.h index e764fc3169..5e8f688a3d 100644 --- a/src/bun.js/bindings/webcore/BufferSource.h +++ b/src/bun.js/bindings/webcore/BufferSource.h @@ -97,7 +97,7 @@ std::optional BufferSource::decode(Decoder& decoder) return BufferSource(); auto dataSize = CheckedSize { *size }; - if (UNLIKELY(dataSize.hasOverflowed())) + if (dataSize.hasOverflowed()) [[unlikely]] return std::nullopt; const uint8_t* data = decoder.decodeFixedLengthReference(dataSize, alignof(uint8_t)); diff --git a/src/bun.js/bindings/webcore/EventContext.cpp b/src/bun.js/bindings/webcore/EventContext.cpp index c80863a7d4..5b3b6c9240 100644 --- a/src/bun.js/bindings/webcore/EventContext.cpp +++ b/src/bun.js/bindings/webcore/EventContext.cpp @@ -45,7 +45,7 @@ void EventContext::handleLocalEvents(Event& event, EventInvokePhase phase) const event.setTarget(m_target.get()); event.setCurrentTarget(m_currentTarget.get(), m_currentTargetIsInShadowTree); - if (!m_node || UNLIKELY(m_type == Type::Window)) { + if (!m_node || m_type == Type::Window) [[unlikely]] { m_currentTarget->fireEventListeners(event, phase); return; } diff --git a/src/bun.js/bindings/webcore/EventEmitter.cpp b/src/bun.js/bindings/webcore/EventEmitter.cpp index b68f5d2c47..a34db09b4f 100644 --- a/src/bun.js/bindings/webcore/EventEmitter.cpp +++ b/src/bun.js/bindings/webcore/EventEmitter.cpp @@ -145,7 +145,7 @@ int EventEmitter::listenerCount(const Identifier& eventType) int result = 0; if (auto* listenersVector = data->eventListenerMap.find(eventType)) { for (auto& registeredListener : *listenersVector) { - if (UNLIKELY(registeredListener->wasRemoved())) + if (registeredListener->wasRemoved()) [[unlikely]] continue; if (registeredListener->callback().jsFunction()) { @@ -164,7 +164,7 @@ Vector EventEmitter::getListeners(const Identifier& eventType) Vector listeners; if (auto* listenersVector = data->eventListenerMap.find(eventType)) { for (auto& registeredListener : *listenersVector) { - if (UNLIKELY(registeredListener->wasRemoved())) + if (registeredListener->wasRemoved()) [[unlikely]] continue; if (JSC::JSObject* jsFunction = registeredListener->callback().jsFunction()) { @@ -184,7 +184,7 @@ bool EventEmitter::fireEventListeners(const Identifier& eventType, const MarkedA return false; auto* listenersVector = data->eventListenerMap.find(eventType); - if (UNLIKELY(!listenersVector)) { + if (!listenersVector) [[unlikely]] { if (eventType == scriptExecutionContext()->vm().propertyNames->error && arguments.size() > 0) { Ref protectedThis(*this); auto* thisObject = protectedThis->m_thisObject.get(); @@ -223,7 +223,7 @@ bool EventEmitter::innerInvokeEventListeners(const Identifier& eventType, Simple for (auto& registeredListener : listeners) { // The below code used to be in here, but it's WRONG. Even if a listener is removed, // if we're in the middle of firing listeners, we still need to call it. - // if (UNLIKELY(registeredListener->wasRemoved())) + // if (registeredListener->wasRemoved()) [[unlikely]] // continue; auto& callback = registeredListener->callback(); @@ -239,12 +239,12 @@ bool EventEmitter::innerInvokeEventListeners(const Identifier& eventType, Simple if (registeredListener->isOnce()) removeListener(eventType, callback); - if (UNLIKELY(!jsFunction)) + if (!jsFunction) [[unlikely]] continue; JSC::JSGlobalObject* lexicalGlobalObject = jsFunction->globalObject(); auto callData = JSC::getCallData(jsFunction); - if (UNLIKELY(callData.type == JSC::CallData::Type::None)) + if (callData.type == JSC::CallData::Type::None) [[unlikely]] continue; fired = true; @@ -252,7 +252,7 @@ bool EventEmitter::innerInvokeEventListeners(const Identifier& eventType, Simple call(lexicalGlobalObject, jsFunction, callData, thisValue, arguments, exceptionPtr); auto* exception = exceptionPtr.get(); - if (UNLIKELY(exception)) { + if (exception) [[unlikely]] { auto errorIdentifier = vm.propertyNames->error; auto hasErrorListener = this->hasActiveEventListeners(errorIdentifier); if (!hasErrorListener || eventType == errorIdentifier) { diff --git a/src/bun.js/bindings/webcore/EventListenerMap.cpp b/src/bun.js/bindings/webcore/EventListenerMap.cpp index 540f498e00..4c8539aac4 100644 --- a/src/bun.js/bindings/webcore/EventListenerMap.cpp +++ b/src/bun.js/bindings/webcore/EventListenerMap.cpp @@ -131,7 +131,7 @@ bool EventListenerMap::add(const AtomString& eventType, Ref&& lis static bool removeListenerFromVector(EventListenerVector& listeners, EventListener& listener, bool useCapture) { size_t indexOfRemovedListener = findListener(listeners, listener, useCapture); - if (UNLIKELY(indexOfRemovedListener == notFound)) + if (indexOfRemovedListener == notFound) [[unlikely]] return false; listeners[indexOfRemovedListener]->markAsRemoved(); diff --git a/src/bun.js/bindings/webcore/EventPath.cpp b/src/bun.js/bindings/webcore/EventPath.cpp index 5be68a187f..b78dd25bef 100644 --- a/src/bun.js/bindings/webcore/EventPath.cpp +++ b/src/bun.js/bindings/webcore/EventPath.cpp @@ -122,7 +122,7 @@ EventPath::EventPath(Node& originalTarget, Event& event) // // break; // // ContainerNode* parent = node->parentNode(); -// // if (UNLIKELY(!parent)) { +// // if (!parent) [[unlikely]] { // // // https://dom.spec.whatwg.org/#interface-document // // if (is(*node) && event.type() != eventNames().loadEvent) { // // ASSERT(target); @@ -134,7 +134,7 @@ EventPath::EventPath(Node& originalTarget, Event& event) // // return; // // } -// // if (auto* shadowRootOfParent = parent->shadowRoot(); UNLIKELY(shadowRootOfParent)) { +// // if (auto* shadowRootOfParent = parent->shadowRoot(); shadowRootOfParent) [[unlikely]]) { // // if (auto* assignedSlot = shadowRootOfParent->findAssignedSlot(*node)) { // // if (shadowRootOfParent->mode() != ShadowRootMode::Open) // // closedShadowDepth++; @@ -176,18 +176,18 @@ EventPath::EventPath(Node& originalTarget, Event& event) // // Node& currentTarget = *context.node(); // // TreeScope& currentTreeScope = currentTarget.treeScope(); -// // if (UNLIKELY(previousTreeScope && ¤tTreeScope != previousTreeScope)) +// // if (previousTreeScope && ¤tTreeScope != previousTreeScope) [[unlikely]] // // retargeter.moveToNewTreeScope(previousTreeScope, currentTreeScope); // // Node* currentRelatedNode = retargeter.currentNode(currentTarget); -// // if (UNLIKELY(!originIsRelatedTarget && context.target() == currentRelatedNode)) { +// // if (!originIsRelatedTarget && context.target() == currentRelatedNode) [[unlikely]] { // // m_path.shrink(contextIndex); // // break; // // } // // context.setRelatedTarget(currentRelatedNode); -// // if (UNLIKELY(originIsRelatedTarget && context.node() == &rootNodeInOriginTreeScope)) { +// // if (originIsRelatedTarget && context.node() == &rootNodeInOriginTreeScope) [[unlikely]] { // // m_path.shrink(contextIndex + 1); // // break; // // } @@ -209,7 +209,7 @@ EventPath::EventPath(Node& originalTarget, Event& event) // for (auto& context : m_path) { // Node& currentTarget = *context.node(); // TreeScope& currentTreeScope = currentTarget.treeScope(); -// if (UNLIKELY(previousTreeScope && ¤tTreeScope != previousTreeScope)) +// if (previousTreeScope && ¤tTreeScope != previousTreeScope) [[unlikely]] // retargeter.moveToNewTreeScope(previousTreeScope, currentTreeScope); // if (context.isTouchEventContext()) { @@ -307,7 +307,7 @@ EventPath::EventPath(EventTarget& target) // { // auto& targetTreeScope = target.treeScope(); // TreeScope* currentTreeScope = &m_relatedNode.treeScope(); -// if (LIKELY(currentTreeScope == &targetTreeScope && target.isConnected() && m_relatedNode.isConnected())) +// if (currentTreeScope == &targetTreeScope && target.isConnected() && m_relatedNode.isConnected()) [[likely]] // return; // if (¤tTreeScope->documentScope() != &targetTreeScope.documentScope()) { diff --git a/src/bun.js/bindings/webcore/EventTarget.cpp b/src/bun.js/bindings/webcore/EventTarget.cpp index ce31060daf..593c9d90ee 100644 --- a/src/bun.js/bindings/webcore/EventTarget.cpp +++ b/src/bun.js/bindings/webcore/EventTarget.cpp @@ -116,7 +116,7 @@ bool EventTarget::addEventListener(const AtomString& eventType, RefonDidChangeListener)) { + if (this->onDidChangeListener) [[unlikely]] { this->onDidChangeListener(*this, eventType, OnDidChangeListenerKind::Add); } return true; @@ -154,7 +154,7 @@ bool EventTarget::removeEventListener(const AtomString& eventType, EventListener if (eventNames().isWheelEventType(eventType)) invalidateEventListenerRegions(); - if (UNLIKELY(this->onDidChangeListener)) { + if (this->onDidChangeListener) [[unlikely]] { this->onDidChangeListener(*this, eventType, OnDidChangeListenerKind::Remove); } eventListenersDidChange(); @@ -321,7 +321,7 @@ void EventTarget::innerInvokeEventListeners(Event& event, EventListenerVector li // InspectorInstrumentation::willDispatchEvent(downcast(context), event); for (auto& registeredListener : listeners) { - if (UNLIKELY(registeredListener->wasRemoved())) + if (registeredListener->wasRemoved()) [[unlikely]] continue; if (phase == EventInvokePhase::Capturing && !registeredListener->useCapture()) @@ -393,7 +393,7 @@ void EventTarget::removeAllEventListeners() // if (data->eventListenerMap.contains(eventNames().wheelEvent) || data->eventListenerMap.contains(eventNames().mousewheelEvent)) // invalidateEventListenerRegions(); - if (UNLIKELY(this->onDidChangeListener)) { + if (this->onDidChangeListener) [[unlikely]] { for (auto& eventType : data->eventListenerMap.eventTypes()) { this->onDidChangeListener(*this, eventType, OnDidChangeListenerKind::Clear); } diff --git a/src/bun.js/bindings/webcore/HTTPParsers.cpp b/src/bun.js/bindings/webcore/HTTPParsers.cpp index d65cf81915..27424e2271 100644 --- a/src/bun.js/bindings/webcore/HTTPParsers.cpp +++ b/src/bun.js/bindings/webcore/HTTPParsers.cpp @@ -131,7 +131,7 @@ bool isValidHTTPHeaderValue(const StringView& value) const LChar* begin = value.span8().data(); const LChar* end = begin + value.length(); for (const LChar* p = begin; p != end; ++p) { - if (UNLIKELY(*p <= 13)) { + if (*p <= 13) [[unlikely]] { LChar c = *p; if (c == 0x00 || c == 0x0A || c == 0x0D) return false; diff --git a/src/bun.js/bindings/webcore/IdentifierEventListenerMap.cpp b/src/bun.js/bindings/webcore/IdentifierEventListenerMap.cpp index 246efa61c0..cbdfe6aa46 100644 --- a/src/bun.js/bindings/webcore/IdentifierEventListenerMap.cpp +++ b/src/bun.js/bindings/webcore/IdentifierEventListenerMap.cpp @@ -92,7 +92,7 @@ bool IdentifierEventListenerMap::prepend(const JSC::Identifier& eventType, RefmarkAsRemoved(); diff --git a/src/bun.js/bindings/webcore/InternalWritableStream.cpp b/src/bun.js/bindings/webcore/InternalWritableStream.cpp index b368692f88..e630db19cb 100644 --- a/src/bun.js/bindings/webcore/InternalWritableStream.cpp +++ b/src/bun.js/bindings/webcore/InternalWritableStream.cpp @@ -61,7 +61,7 @@ ExceptionOr> InternalWritableStream::createFromUnder ASSERT(!arguments.hasOverflowed()); auto result = invokeWritableStreamFunction(globalObject, privateName, arguments); - if (UNLIKELY(result.hasException())) + if (result.hasException()) [[unlikely]] return result.releaseException(); ASSERT(result.returnValue().isObject()); @@ -111,7 +111,7 @@ void InternalWritableStream::lock() ASSERT(!arguments.hasOverflowed()); auto result = invokeWritableStreamFunction(*globalObject, privateName, arguments); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] scope.clearException(); } diff --git a/src/bun.js/bindings/webcore/JSAbortController.cpp b/src/bun.js/bindings/webcore/JSAbortController.cpp index 81a279ff6e..14f2e4f378 100644 --- a/src/bun.js/bindings/webcore/JSAbortController.cpp +++ b/src/bun.js/bindings/webcore/JSAbortController.cpp @@ -103,7 +103,7 @@ template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSAbortControllerDOMConstruct auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "AbortController"_s); auto object = AbortController::create(*context); if constexpr (IsExceptionOr) @@ -189,7 +189,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsAbortControllerConstructor, (JSGlobalObject * lexical auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSAbortController::getConstructor(vm, prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSAbortSignal.cpp b/src/bun.js/bindings/webcore/JSAbortSignal.cpp index 7131141869..453f337675 100644 --- a/src/bun.js/bindings/webcore/JSAbortSignal.cpp +++ b/src/bun.js/bindings/webcore/JSAbortSignal.cpp @@ -203,7 +203,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsAbortSignalConstructor, (JSGlobalObject * lexicalGlob auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSAbortSignal::getConstructor(vm, prototype->globalObject())); } @@ -268,7 +268,7 @@ static inline JSC::EncodedJSValue jsAbortSignalConstructorFunction_abortBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return JSValue::encode(jsUndefined()); EnsureStillAliveScope argument0 = callFrame->argument(0); auto reason = convert(*lexicalGlobalObject, argument0.value()); @@ -287,10 +287,10 @@ static inline JSC::EncodedJSValue jsAbortSignalConstructorFunction_timeoutBody(J auto throwScope = DECLARE_THROW_SCOPE(vm); UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return JSValue::encode(jsUndefined()); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto milliseconds = convert>(*lexicalGlobalObject, argument0.value()); @@ -310,7 +310,7 @@ static inline JSC::EncodedJSValue jsAbortSignalConstructorFunction_anyBody(JSC:: UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return JSValue::encode(jsUndefined()); EnsureStillAliveScope argument0 = callFrame->argument(0); diff --git a/src/bun.js/bindings/webcore/JSAbortSignalCustom.cpp b/src/bun.js/bindings/webcore/JSAbortSignalCustom.cpp index ddb54dab50..e77fae8f93 100644 --- a/src/bun.js/bindings/webcore/JSAbortSignalCustom.cpp +++ b/src/bun.js/bindings/webcore/JSAbortSignalCustom.cpp @@ -34,7 +34,7 @@ bool JSAbortSignalOwner::isReachableFromOpaqueRoots(JSC::Handle ha { auto& abortSignal = JSC::jsCast(handle.slot()->asCell())->wrapped(); if (abortSignal.isFiringEventListeners()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "EventTarget firing event listeners"_s; return true; } @@ -43,20 +43,20 @@ bool JSAbortSignalOwner::isReachableFromOpaqueRoots(JSC::Handle ha return false; if (abortSignal.isFollowingSignal()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Is Following Signal"_s; return true; } if (abortSignal.hasAbortEventListener()) { if (abortSignal.hasActiveTimeoutTimer()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Has Timeout And Abort Event Listener"_s; return true; } if (abortSignal.isDependent()) { if (!abortSignal.sourceSignals().isEmptyIgnoringNullReferences()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Has Source Signals And Abort Event Listener"_s; return true; } @@ -64,7 +64,7 @@ bool JSAbortSignalOwner::isReachableFromOpaqueRoots(JSC::Handle ha // https://github.com/oven-sh/bun/issues/4517 if (abortSignal.hasPendingActivity()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Has Pending Activity"_s; return true; } diff --git a/src/bun.js/bindings/webcore/JSAddEventListenerOptions.cpp b/src/bun.js/bindings/webcore/JSAddEventListenerOptions.cpp index bda4e35f99..d3eea92f51 100644 --- a/src/bun.js/bindings/webcore/JSAddEventListenerOptions.cpp +++ b/src/bun.js/bindings/webcore/JSAddEventListenerOptions.cpp @@ -35,7 +35,7 @@ template<> AddEventListenerOptions convertDictionary(JS auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcore/JSBroadcastChannel.cpp b/src/bun.js/bindings/webcore/JSBroadcastChannel.cpp index c187d6ab5a..728bc13e30 100644 --- a/src/bun.js/bindings/webcore/JSBroadcastChannel.cpp +++ b/src/bun.js/bindings/webcore/JSBroadcastChannel.cpp @@ -110,10 +110,10 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSBroadcastChannelDOMCon auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "BroadcastChannel"_s); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); @@ -271,7 +271,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsBroadcastChannelConstructor, (JSGlobalObject * lexica auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSBroadcastChannel::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -350,7 +350,7 @@ static inline JSC::EncodedJSValue jsBroadcastChannelPrototypeFunction_postMessag UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto message = convert(*lexicalGlobalObject, argument0.value()); @@ -434,7 +434,7 @@ bool JSBroadcastChannelOwner::isReachableFromOpaqueRoots(JSC::Handle(handle.slot()->asCell()); auto& wrapped = jsBroadcastChannel->wrapped(); if (!wrapped.isContextStopped() && wrapped.hasPendingActivity()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "ActiveDOMObject with pending activity"_s; return true; } diff --git a/src/bun.js/bindings/webcore/JSByteLengthQueuingStrategy.cpp b/src/bun.js/bindings/webcore/JSByteLengthQueuingStrategy.cpp index 1703532701..9169e46d27 100644 --- a/src/bun.js/bindings/webcore/JSByteLengthQueuingStrategy.cpp +++ b/src/bun.js/bindings/webcore/JSByteLengthQueuingStrategy.cpp @@ -162,7 +162,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsByteLengthQueuingStrategyConstructor, (JSGlobalObject auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSByteLengthQueuingStrategy::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSCallbackData.cpp b/src/bun.js/bindings/webcore/JSCallbackData.cpp index 4b607fcb9c..32567a04c0 100644 --- a/src/bun.js/bindings/webcore/JSCallbackData.cpp +++ b/src/bun.js/bindings/webcore/JSCallbackData.cpp @@ -65,7 +65,7 @@ JSValue JSCallbackData::invokeCallback(VM& vm, JSObject* callback, JSValue thisV ASSERT(!functionName.isNull()); function = callback->get(lexicalGlobalObject, functionName); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { returnedException = scope.exception(); scope.clearException(); return JSValue(); @@ -109,7 +109,7 @@ template void JSCallbackDataWeak::visitJSFunction(JSC::SlotVisitor&); bool JSCallbackDataWeak::WeakOwner::isReachableFromOpaqueRoots(JSC::Handle, void* context, AbstractSlotVisitor& visitor, ASCIILiteral* reason) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Context is opaque root"_s; // FIXME: what is the context. return visitor.containsOpaqueRoot(context); } diff --git a/src/bun.js/bindings/webcore/JSCloseEvent.cpp b/src/bun.js/bindings/webcore/JSCloseEvent.cpp index 18883e2e34..0abd88897b 100644 --- a/src/bun.js/bindings/webcore/JSCloseEvent.cpp +++ b/src/bun.js/bindings/webcore/JSCloseEvent.cpp @@ -54,7 +54,7 @@ template<> CloseEvent::Init convertDictionary(JSGlobalObject& auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } @@ -181,7 +181,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSCloseEventDOMConstruct auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -271,7 +271,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCloseEventConstructor, (JSGlobalObject * lexicalGloba auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSCloseEvent::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSCookie.cpp b/src/bun.js/bindings/webcore/JSCookie.cpp index 78ce7a22e1..b1d25e9c50 100644 --- a/src/bun.js/bindings/webcore/JSCookie.cpp +++ b/src/bun.js/bindings/webcore/JSCookie.cpp @@ -35,7 +35,7 @@ static Cookie* toCookieWrapped(JSGlobalObject* lexicalGlobalObject, JSC::ThrowSc { auto& vm = getVM(lexicalGlobalObject); auto* impl = JSCookie::toWrapped(vm, value); - if (UNLIKELY(!impl)) + if (!impl) [[unlikely]] throwVMTypeError(lexicalGlobalObject, throwScope); return impl; } @@ -48,7 +48,7 @@ static int64_t getExpiresValue(JSGlobalObject* lexicalGlobalObject, JSC::ThrowSc if (auto* dateInstance = jsDynamicCast(expiresValue)) { double date = dateInstance->internalNumber(); - if (UNLIKELY(std::isnan(date) || std::isinf(date))) { + if (std::isnan(date) || std::isinf(date)) [[unlikely]] { throwScope.throwException(lexicalGlobalObject, createRangeError(lexicalGlobalObject, "expires must be a valid Date (or Number)"_s)); return Cookie::emptyExpiresAtValue; } @@ -57,7 +57,7 @@ static int64_t getExpiresValue(JSGlobalObject* lexicalGlobalObject, JSC::ThrowSc if (expiresValue.isNumber()) { double expires = expiresValue.asNumber(); - if (UNLIKELY(std::isnan(expires) || !std::isfinite(expires))) { + if (std::isnan(expires) || !std::isfinite(expires)) [[unlikely]] { throwScope.throwException(lexicalGlobalObject, createRangeError(lexicalGlobalObject, "expires must be a valid Number (or Date)"_s)); return Cookie::emptyExpiresAtValue; } @@ -287,7 +287,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSCookieDOMConstructor:: auto* castedThis = jsCast(callFrame->jsCallee()); // Check if this was called with 'new' - if (UNLIKELY(!callFrame->thisValue().isObject())) + if (!callFrame->thisValue().isObject()) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotAConstructorError(lexicalGlobalObject, callFrame->jsCallee())); // Static method: parse(cookieString) @@ -296,7 +296,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSCookieDOMConstructor:: auto cookieString = convert(*lexicalGlobalObject, callFrame->argument(0)); RETURN_IF_EXCEPTION(throwScope, {}); - if (UNLIKELY(!WebCore::isValidHTTPHeaderValue(cookieString))) { + if (!WebCore::isValidHTTPHeaderValue(cookieString)) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, throwScope, "cookie string is not a valid HTTP header value"_s); RELEASE_AND_RETURN(throwScope, {}); } @@ -468,7 +468,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookieConstructor, (JSGlobalObject * lexicalGlobalObj auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSCookie::getConstructor(vm, prototype->globalObject())); } @@ -533,7 +533,7 @@ JSC_DEFINE_HOST_FUNCTION(jsCookieStaticFunctionParse, (JSGlobalObject * lexicalG return JSValue::encode(toJSNewlyCreated(lexicalGlobalObject, defaultGlobalObject(lexicalGlobalObject), WTFMove(cookie))); } - if (UNLIKELY(!WebCore::isValidHTTPHeaderValue(cookieString))) { + if (!WebCore::isValidHTTPHeaderValue(cookieString)) [[unlikely]] { throwVMTypeError(lexicalGlobalObject, throwScope, "cookie string is not a valid HTTP header value"_s); RELEASE_AND_RETURN(throwScope, {}); } @@ -619,7 +619,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_name, (JSGlobalObject * lexical auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "name"_s); auto& impl = thisObject->wrapped(); return JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.name())); @@ -630,7 +630,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_value, (JSGlobalObject * lexica auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "value"_s); auto& impl = thisObject->wrapped(); return JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.value())); @@ -641,7 +641,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_value, (JSGlobalObject * lexica auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "value"_s); auto& impl = thisObject->wrapped(); auto value = convert(*lexicalGlobalObject, JSValue::decode(encodedValue)); @@ -655,7 +655,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_domain, (JSGlobalObject * lexic auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "domain"_s); auto& impl = thisObject->wrapped(); return JSValue::encode(toJS>(*lexicalGlobalObject, throwScope, impl.domain())); @@ -666,7 +666,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_domain, (JSGlobalObject * lexic auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "domain"_s); auto& impl = thisObject->wrapped(); auto value = convert(*lexicalGlobalObject, JSValue::decode(encodedValue)); @@ -680,7 +680,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_path, (JSGlobalObject * lexical auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "path"_s); auto& impl = thisObject->wrapped(); return JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.path())); @@ -691,7 +691,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_path, (JSGlobalObject * lexical auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "path"_s); auto& impl = thisObject->wrapped(); auto value = convert(*lexicalGlobalObject, JSValue::decode(encodedValue)); @@ -705,7 +705,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_expires, (JSGlobalObject * lexi auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "expires"_s); auto& impl = thisObject->wrapped(); if (impl.hasExpiry()) { @@ -728,7 +728,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_expires, (JSGlobalObject * lexi auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "expires"_s); auto& impl = thisObject->wrapped(); auto value = getExpiresValue(lexicalGlobalObject, throwScope, JSValue::decode(encodedValue)); @@ -743,7 +743,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_secure, (JSGlobalObject * lexic auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "secure"_s); auto& impl = thisObject->wrapped(); return JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.secure())); @@ -754,7 +754,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_secure, (JSGlobalObject * lexic auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "secure"_s); auto& impl = thisObject->wrapped(); auto value = convert(*lexicalGlobalObject, JSValue::decode(encodedValue)); @@ -768,7 +768,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_sameSite, (JSGlobalObject * lex auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "sameSite"_s); auto& impl = thisObject->wrapped(); @@ -780,7 +780,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_sameSite, (JSGlobalObject * lex auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "sameSite"_s); auto& impl = thisObject->wrapped(); @@ -809,7 +809,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_httpOnly, (JSGlobalObject * lex auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "httpOnly"_s); auto& impl = thisObject->wrapped(); return JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.httpOnly())); @@ -820,7 +820,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_httpOnly, (JSGlobalObject * lex auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "httpOnly"_s); auto& impl = thisObject->wrapped(); auto value = convert(*lexicalGlobalObject, JSValue::decode(encodedValue)); @@ -835,7 +835,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_maxAge, (JSGlobalObject * lexic auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "maxAge"_s); auto& impl = thisObject->wrapped(); double maxAge = impl.maxAge(); @@ -849,7 +849,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_maxAge, (JSGlobalObject * lexic auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "maxAge"_s); auto& impl = thisObject->wrapped(); if (JSValue::decode(encodedValue).isUndefinedOrNull()) { @@ -869,7 +869,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookiePrototypeGetter_partitioned, (JSGlobalObject * auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "partitioned"_s); auto& impl = thisObject->wrapped(); return JSValue::encode(toJS(*lexicalGlobalObject, throwScope, impl.partitioned())); @@ -880,7 +880,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsCookiePrototypeSetter_partitioned, (JSGlobalObject * auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(*lexicalGlobalObject, throwScope, "Cookie"_s, "partitioned"_s); auto& impl = thisObject->wrapped(); auto value = convert(*lexicalGlobalObject, JSValue::decode(encodedValue)); diff --git a/src/bun.js/bindings/webcore/JSCookieMap.cpp b/src/bun.js/bindings/webcore/JSCookieMap.cpp index 4abc49ff01..e225f9f8c8 100644 --- a/src/bun.js/bindings/webcore/JSCookieMap.cpp +++ b/src/bun.js/bindings/webcore/JSCookieMap.cpp @@ -42,7 +42,7 @@ CookieMap* toWrapped(JSGlobalObject& lexicalGlobalObject, ExceptionThrower&& exc auto& vm = getVM(&lexicalGlobalObject); auto scope = DECLARE_THROW_SCOPE(vm); auto* impl = JSCookieMap::toWrapped(vm, value); - if (UNLIKELY(!impl)) + if (!impl) [[unlikely]] exceptionThrower(lexicalGlobalObject, scope); return impl; } @@ -267,7 +267,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookieMapConstructor, (JSGlobalObject * lexicalGlobal auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSCookieMap::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -277,7 +277,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCookieMapPrototypeGetter_size, (JSGlobalObject * lexi auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(jsNumber(thisObject->wrapped().size())); } diff --git a/src/bun.js/bindings/webcore/JSCountQueuingStrategy.cpp b/src/bun.js/bindings/webcore/JSCountQueuingStrategy.cpp index 6fcd6817c9..2fe6d262e1 100644 --- a/src/bun.js/bindings/webcore/JSCountQueuingStrategy.cpp +++ b/src/bun.js/bindings/webcore/JSCountQueuingStrategy.cpp @@ -162,7 +162,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCountQueuingStrategyConstructor, (JSGlobalObject * le auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSCountQueuingStrategy::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSCustomEvent.cpp b/src/bun.js/bindings/webcore/JSCustomEvent.cpp index d96394d3a3..c764817533 100644 --- a/src/bun.js/bindings/webcore/JSCustomEvent.cpp +++ b/src/bun.js/bindings/webcore/JSCustomEvent.cpp @@ -58,7 +58,7 @@ template<> CustomEvent::Init convertDictionary(JSGlobalObject auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { Bun::throwError(&lexicalGlobalObject, throwScope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "The \"options\" argument must be of type object."_s); return {}; @@ -164,7 +164,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSCustomEventDOMConstruc auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -253,7 +253,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCustomEventConstructor, (JSGlobalObject * lexicalGlob auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSCustomEvent::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -276,7 +276,7 @@ static inline JSC::EncodedJSValue jsCustomEventPrototypeFunction_initCustomEvent UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSDOMAttribute.h b/src/bun.js/bindings/webcore/JSDOMAttribute.h index 1811351557..6e03505b9f 100644 --- a/src/bun.js/bindings/webcore/JSDOMAttribute.h +++ b/src/bun.js/bindings/webcore/JSDOMAttribute.h @@ -44,7 +44,7 @@ public: auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); auto* thisObject = castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { if constexpr (shouldThrow == CastedThisErrorBehavior::Throw) return JSC::throwVMDOMAttributeSetterTypeError(&lexicalGlobalObject, throwScope, JSClass::info(), attributeName); else @@ -61,7 +61,7 @@ public: auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); auto* thisObject = castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { if constexpr (shouldThrow == CastedThisErrorBehavior::Throw) return JSC::throwVMDOMAttributeSetterTypeError(&lexicalGlobalObject, throwScope, JSClass::info(), attributeName); else @@ -88,7 +88,7 @@ public: RELEASE_AND_RETURN(throwScope, (JSC::JSValue::encode(getter(lexicalGlobalObject, *thisObject)))); } else { auto* thisObject = castThisValue(lexicalGlobalObject, JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { if constexpr (shouldThrow == CastedThisErrorBehavior::Throw) return JSC::throwVMDOMAttributeGetterTypeError(&lexicalGlobalObject, throwScope, JSClass::info(), attributeName); else if constexpr (shouldThrow == CastedThisErrorBehavior::RejectPromise) diff --git a/src/bun.js/bindings/webcore/JSDOMBuiltinConstructor.h b/src/bun.js/bindings/webcore/JSDOMBuiltinConstructor.h index 4e6200fb1e..69492a8ad9 100644 --- a/src/bun.js/bindings/webcore/JSDOMBuiltinConstructor.h +++ b/src/bun.js/bindings/webcore/JSDOMBuiltinConstructor.h @@ -80,7 +80,7 @@ template inline JSC::Structure* JSDOMBuiltinConstructor(vm, *globalObject()); auto scope = DECLARE_THROW_SCOPE(vm); @@ -101,7 +101,7 @@ template inline JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES J return {}; } auto* structure = castedThis->getDOMStructureForJSObject(lexicalGlobalObject, asObject(callFrame->thisValue())); - if (UNLIKELY(!structure)) + if (!structure) [[unlikely]] return {}; auto* jsObject = JSClass::create(structure, castedThis->globalObject()); @@ -114,7 +114,7 @@ template inline JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES J ASSERT(callFrame); auto* castedThis = JSC::jsCast(callFrame->jsCallee()); auto* structure = castedThis->getDOMStructureForJSObject(lexicalGlobalObject, asObject(callFrame->newTarget())); - if (UNLIKELY(!structure)) + if (!structure) [[unlikely]] return {}; auto* jsObject = JSClass::create(structure, castedThis->globalObject()); diff --git a/src/bun.js/bindings/webcore/JSDOMConvertBase.h b/src/bun.js/bindings/webcore/JSDOMConvertBase.h index a60e301d11..cd4b872c28 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertBase.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertBase.h @@ -175,7 +175,7 @@ template inline JSC::JSValue toJS(JSC::JSGlobalObject& l return JSC::jsUndefined(); } else if constexpr (std::is_same_v, FunctorReturnType>) { auto result = valueOrFunctor(); - if (UNLIKELY(result.hasException())) { + if (result.hasException()) [[unlikely]] { propagateException(lexicalGlobalObject, throwScope, result.releaseException()); return {}; } @@ -184,7 +184,7 @@ template inline JSC::JSValue toJS(JSC::JSGlobalObject& l return toJS(lexicalGlobalObject, throwScope, valueOrFunctor()); } else { if constexpr (IsExceptionOr) { - if (UNLIKELY(valueOrFunctor.hasException())) { + if (valueOrFunctor.hasException()) [[unlikely]] { propagateException(lexicalGlobalObject, throwScope, valueOrFunctor.releaseException()); return {}; } @@ -205,7 +205,7 @@ template inline JSC::JSValue toJS(JSC::JSGlobalObject& l return JSC::jsUndefined(); } else if constexpr (std::is_same_v, FunctorReturnType>) { auto result = valueOrFunctor(); - if (UNLIKELY(result.hasException())) { + if (result.hasException()) [[unlikely]] { propagateException(lexicalGlobalObject, throwScope, result.releaseException()); return {}; } @@ -214,7 +214,7 @@ template inline JSC::JSValue toJS(JSC::JSGlobalObject& l return toJS(lexicalGlobalObject, globalObject, throwScope, valueOrFunctor()); } else { if constexpr (IsExceptionOr) { - if (UNLIKELY(valueOrFunctor.hasException())) { + if (valueOrFunctor.hasException()) [[unlikely]] { propagateException(lexicalGlobalObject, throwScope, valueOrFunctor.releaseException()); return {}; } @@ -235,7 +235,7 @@ template inline JSC::JSValue toJSNewlyCreated(JSC::JSGlo return JSC::jsUndefined(); } else if constexpr (std::is_same_v, FunctorReturnType>) { auto result = valueOrFunctor(); - if (UNLIKELY(result.hasException())) { + if (result.hasException()) [[unlikely]] { propagateException(lexicalGlobalObject, throwScope, result.releaseException()); return {}; } @@ -245,7 +245,7 @@ template inline JSC::JSValue toJSNewlyCreated(JSC::JSGlo } else { if constexpr (IsExceptionOr) { - if (UNLIKELY(valueOrFunctor.hasException())) { + if (valueOrFunctor.hasException()) [[unlikely]] { propagateException(lexicalGlobalObject, throwScope, valueOrFunctor.releaseException()); return {}; } diff --git a/src/bun.js/bindings/webcore/JSDOMConvertBufferSource.h b/src/bun.js/bindings/webcore/JSDOMConvertBufferSource.h index 2a192eea13..6d36609719 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertBufferSource.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertBufferSource.h @@ -147,7 +147,7 @@ struct BufferSourceConverter { object = WrapperType::toWrappedAllowShared(vm, value); else object = WrapperType::toWrapped(vm, value); - if (UNLIKELY(!object)) + if (!object) [[unlikely]] exceptionThrower(lexicalGlobalObject, scope); return object; } diff --git a/src/bun.js/bindings/webcore/JSDOMConvertEnumeration.h b/src/bun.js/bindings/webcore/JSDOMConvertEnumeration.h index 14aa522c46..71df8e0298 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertEnumeration.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertEnumeration.h @@ -50,7 +50,7 @@ template struct Converter> : DefaultConverter(lexicalGlobalObject, value); RETURN_IF_EXCEPTION(throwScope, {}); - if (UNLIKELY(!result)) { + if (!result) [[unlikely]] { exceptionThrower(lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcore/JSDOMConvertEventListener.h b/src/bun.js/bindings/webcore/JSDOMConvertEventListener.h index 09d0cbb6e1..4f32b41820 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertEventListener.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertEventListener.h @@ -38,7 +38,7 @@ template struct Converter> : DefaultConverter struct Converter> : DefaultConverter::toWrapped(lexicalGlobalObject, value); - if (UNLIKELY(!object)) + if (!object) [[unlikely]] exceptionThrower(lexicalGlobalObject, scope); return object; } diff --git a/src/bun.js/bindings/webcore/JSDOMConvertNumbers.h b/src/bun.js/bindings/webcore/JSDOMConvertNumbers.h index 0daac2583a..ed279b251e 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertNumbers.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertNumbers.h @@ -279,7 +279,7 @@ template<> struct Converter : DefaultConverter { static inline float convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, double number) { - if (UNLIKELY(!std::isfinite(number))) + if (!std::isfinite(number)) [[unlikely]] throwNonFiniteTypeError(lexicalGlobalObject, scope); return static_cast(number); } @@ -290,9 +290,9 @@ template<> struct Converter : DefaultConverter { auto scope = DECLARE_THROW_SCOPE(vm); double number = value.toNumber(&lexicalGlobalObject); RETURN_IF_EXCEPTION(scope, 0.0); - if (UNLIKELY(number < std::numeric_limits::lowest() || number > std::numeric_limits::max())) + if (number < std::numeric_limits::lowest() || number > std::numeric_limits::max()) [[unlikely]] throwTypeError(&lexicalGlobalObject, scope, "The provided value is outside the range of a float"_s); - if (UNLIKELY(!std::isfinite(number))) + if (!std::isfinite(number)) [[unlikely]] throwNonFiniteTypeError(lexicalGlobalObject, scope); return static_cast(number); } @@ -323,9 +323,9 @@ template<> struct Converter : DefaultConverter::lowest())) + if (number < std::numeric_limits::lowest()) [[unlikely]] return -std::numeric_limits::infinity(); - if (UNLIKELY(number > std::numeric_limits::max())) + if (number > std::numeric_limits::max()) [[unlikely]] return std::numeric_limits::infinity(); return static_cast(number); } @@ -346,7 +346,7 @@ template<> struct JSConverter { template<> struct Converter : DefaultConverter { static inline double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, double number) { - if (UNLIKELY(!std::isfinite(number))) + if (!std::isfinite(number)) [[unlikely]] throwNonFiniteTypeError(lexicalGlobalObject, scope); return number; } @@ -357,7 +357,7 @@ template<> struct Converter : DefaultConverter { auto scope = DECLARE_THROW_SCOPE(vm); double number = value.toNumber(&lexicalGlobalObject); RETURN_IF_EXCEPTION(scope, 0.0); - if (UNLIKELY(!std::isfinite(number))) + if (!std::isfinite(number)) [[unlikely]] throwNonFiniteTypeError(lexicalGlobalObject, scope); return number; } diff --git a/src/bun.js/bindings/webcore/JSDOMConvertRecord.h b/src/bun.js/bindings/webcore/JSDOMConvertRecord.h index 3e02800eaf..e6caa4e989 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertRecord.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertRecord.h @@ -186,7 +186,7 @@ private: // 2. Let value be ? Get(O, key). JSC::JSValue subValue; - if (LIKELY(!slot.isTaintedByOpaqueObject())) + if (!slot.isTaintedByOpaqueObject()) [[likely]] subValue = slot.getValue(&lexicalGlobalObject, key); else subValue = object->get(&lexicalGlobalObject, key); diff --git a/src/bun.js/bindings/webcore/JSDOMConvertSequences.h b/src/bun.js/bindings/webcore/JSDOMConvertSequences.h index 28ed89119d..0f57bf691e 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertSequences.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertSequences.h @@ -53,7 +53,7 @@ struct GenericSequenceConverter { auto scope = DECLARE_THROW_SCOPE(vm); auto convertedValue = Converter::convert(*lexicalGlobalObject, nextValue); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return; result.append(WTFMove(convertedValue)); }); @@ -68,7 +68,7 @@ struct GenericSequenceConverter { auto scope = DECLARE_THROW_SCOPE(vm); auto convertedValue = Converter::convert(*lexicalGlobalObject, nextValue, std::forward(exceptionThrower)); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return; result.append(WTFMove(convertedValue)); }); @@ -86,7 +86,7 @@ struct GenericSequenceConverter { auto scope = DECLARE_THROW_SCOPE(vm); auto convertedValue = Converter::convert(lexicalGlobalObject, nextValue); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return; result.append(WTFMove(convertedValue)); }); @@ -480,7 +480,7 @@ template struct JSConverter> { RETURN_IF_EXCEPTION(scope, {}); list.append(jsValue); } - if (UNLIKELY(list.hasOverflowed())) { + if (list.hasOverflowed()) [[unlikely]] { throwOutOfMemoryError(&lexicalGlobalObject, scope); return {}; } @@ -518,7 +518,7 @@ template struct JSConverter> { RETURN_IF_EXCEPTION(scope, {}); list.append(jsValue); } - if (UNLIKELY(list.hasOverflowed())) { + if (list.hasOverflowed()) [[unlikely]] { throwOutOfMemoryError(&lexicalGlobalObject, scope); return {}; } diff --git a/src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp b/src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp index a9f1035700..c2d77e7e0c 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp +++ b/src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp @@ -33,7 +33,7 @@ using namespace JSC; String identifierToString(JSGlobalObject& lexicalGlobalObject, const Identifier& identifier) { - if (UNLIKELY(identifier.isSymbol())) { + if (identifier.isSymbol()) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm()); throwTypeError(&lexicalGlobalObject, scope, SymbolCoercionError); return {}; @@ -44,7 +44,7 @@ String identifierToString(JSGlobalObject& lexicalGlobalObject, const Identifier& static inline bool throwIfInvalidByteString(JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, const String& string) { - if (UNLIKELY(!string.containsOnlyLatin1())) { + if (!string.containsOnlyLatin1()) [[unlikely]] { throwTypeError(&lexicalGlobalObject, scope); return true; } @@ -58,7 +58,7 @@ String identifierToByteString(JSGlobalObject& lexicalGlobalObject, const Identif auto string = identifierToString(lexicalGlobalObject, identifier); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string))) + if (throwIfInvalidByteString(lexicalGlobalObject, scope, string)) [[unlikely]] return {}; return string; } @@ -71,7 +71,7 @@ String valueToByteString(JSGlobalObject& lexicalGlobalObject, JSValue value) auto string = value.toWTFString(&lexicalGlobalObject); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string))) + if (throwIfInvalidByteString(lexicalGlobalObject, scope, string)) [[unlikely]] return {}; return string; } @@ -84,7 +84,7 @@ AtomString valueToByteAtomString(JSC::JSGlobalObject& lexicalGlobalObject, JSC:: AtomString string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject).data; RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string.string()))) + if (throwIfInvalidByteString(lexicalGlobalObject, scope, string.string())) [[unlikely]] return nullAtom(); return string; diff --git a/src/bun.js/bindings/webcore/JSDOMException.cpp b/src/bun.js/bindings/webcore/JSDOMException.cpp index 9a85bb4c8c..e33f56fbfb 100644 --- a/src/bun.js/bindings/webcore/JSDOMException.cpp +++ b/src/bun.js/bindings/webcore/JSDOMException.cpp @@ -271,7 +271,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMExceptionConstructor, (JSGlobalObject * lexicalGlo auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSDOMException::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSDOMFormData.cpp b/src/bun.js/bindings/webcore/JSDOMFormData.cpp index 94c7a45cde..168f7b2328 100644 --- a/src/bun.js/bindings/webcore/JSDOMFormData.cpp +++ b/src/bun.js/bindings/webcore/JSDOMFormData.cpp @@ -113,7 +113,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMFormDataPrototype_getLength, (JSGlobalObject * lex auto& vm = JSC::getVM(lexicalGlobalObject); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); size_t length = thisObject->wrapped().count(); @@ -161,7 +161,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMFormDataDOMConstruc auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "FormData"_s); auto object = DOMFormData::create(context); if constexpr (IsExceptionOr) @@ -267,7 +267,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMFormDataConstructor, (JSGlobalObject * lexicalGlob auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSDOMFormData::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -350,7 +350,7 @@ static inline JSC::EncodedJSValue jsDOMFormDataPrototypeFunction_deleteBody(JSC: UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); @@ -370,7 +370,7 @@ static inline JSC::EncodedJSValue jsDOMFormDataPrototypeFunction_getBody(JSC::JS UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* nameStr = argument0.value().toString(lexicalGlobalObject); @@ -392,7 +392,7 @@ static inline JSC::EncodedJSValue jsDOMFormDataPrototypeFunction_getAllBody(JSC: UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* nameStr = argument0.value().toString(lexicalGlobalObject); @@ -425,7 +425,7 @@ static inline JSC::EncodedJSValue jsDOMFormDataPrototypeFunction_hasBody(JSC::JS UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSDOMIterator.h b/src/bun.js/bindings/webcore/JSDOMIterator.h index f9d145acec..a870e64d83 100644 --- a/src/bun.js/bindings/webcore/JSDOMIterator.h +++ b/src/bun.js/bindings/webcore/JSDOMIterator.h @@ -225,12 +225,12 @@ template JSC::JSValue iteratorForEach(JSC::JSGlobalObject& JSC::MarkedArgumentBuffer arguments; appendForEachArguments(lexicalGlobalObject, *thisObject.globalObject(), arguments, value); arguments.append(&thisObject); - if (UNLIKELY(arguments.hasOverflowed())) { + if (arguments.hasOverflowed()) [[unlikely]] { throwOutOfMemoryError(&lexicalGlobalObject, scope); return {}; } JSC::profiledCall(&lexicalGlobalObject, ProfilingReason::API, callback, callData, thisValue, arguments); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] break; } return JSC::jsUndefined(); diff --git a/src/bun.js/bindings/webcore/JSDOMOperation.cpp b/src/bun.js/bindings/webcore/JSDOMOperation.cpp index a102ff1d68..73e31a4eec 100644 --- a/src/bun.js/bindings/webcore/JSDOMOperation.cpp +++ b/src/bun.js/bindings/webcore/JSDOMOperation.cpp @@ -11,7 +11,7 @@ namespace WebCore { JSC::JSObject* createNotEnoughArgumentsErrorBun(JSC::JSGlobalObject* globalObject) { JSC::JSObject* error = JSC::createNotEnoughArgumentsError(globalObject); - if (LIKELY(error)) { + if (error) [[likely]] { auto& vm = JSC::getVM(globalObject); const auto& names = WebCore::builtinNames(vm); error->putDirect(vm, names.codePublicName(), JSC::jsString(vm, WTF::String("ERR_MISSING_ARGS"_s)), 0); @@ -23,7 +23,7 @@ JSC::JSObject* createNotEnoughArgumentsErrorBun(JSC::JSGlobalObject* globalObjec void throwNodeRangeError(JSGlobalObject* lexicalGlobalObject, ThrowScope& scope, const String& message) { auto* error = createRangeError(lexicalGlobalObject, message); - if (LIKELY(error)) { + if (error) [[likely]] { auto& vm = getVM(lexicalGlobalObject); auto& builtinNames = Bun::builtinNames(vm); error->putDirect(vm, builtinNames.codePublicName(), jsString(vm, String("ERR_OUT_OF_RANGE"_s))); @@ -34,7 +34,7 @@ void throwNodeRangeError(JSGlobalObject* lexicalGlobalObject, ThrowScope& scope, void throwNodeRangeError(JSGlobalObject* lexicalGlobalObject, ThrowScope& scope, ASCIILiteral message) { auto* error = createRangeError(lexicalGlobalObject, message); - if (LIKELY(error)) { + if (error) [[likely]] { auto& vm = getVM(lexicalGlobalObject); auto& builtinNames = Bun::builtinNames(vm); error->putDirect(vm, builtinNames.codePublicName(), jsString(vm, String("ERR_OUT_OF_RANGE"_s))); diff --git a/src/bun.js/bindings/webcore/JSDOMOperation.h b/src/bun.js/bindings/webcore/JSDOMOperation.h index 4a3fa99191..b15c8c78d6 100644 --- a/src/bun.js/bindings/webcore/JSDOMOperation.h +++ b/src/bun.js/bindings/webcore/JSDOMOperation.h @@ -52,7 +52,7 @@ public: auto* thisObject = cast(lexicalGlobalObject, callFrame); if constexpr (shouldThrow != CastedThisErrorBehavior::Assert) { - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwThisTypeError(lexicalGlobalObject, throwScope, JSClass::info()->className, operationName); } else ASSERT(thisObject); diff --git a/src/bun.js/bindings/webcore/JSDOMOperationReturningPromise.h b/src/bun.js/bindings/webcore/JSDOMOperationReturningPromise.h index d71ce3208c..99aa7437e8 100644 --- a/src/bun.js/bindings/webcore/JSDOMOperationReturningPromise.h +++ b/src/bun.js/bindings/webcore/JSDOMOperationReturningPromise.h @@ -41,7 +41,7 @@ public: return JSC::JSValue::encode(callPromiseFunction(lexicalGlobalObject, callFrame, [&operationName](JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, Ref&& promise) { auto* thisObject = IDLOperation::cast(lexicalGlobalObject, callFrame); if constexpr (shouldThrow != CastedThisErrorBehavior::Assert) { - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return rejectPromiseWithThisTypeError(promise.get(), JSClass::info()->className, operationName); } else ASSERT(thisObject); @@ -60,8 +60,9 @@ public: { auto* thisObject = IDLOperation::cast(lexicalGlobalObject, callFrame); if constexpr (shouldThrow != CastedThisErrorBehavior::Assert) { - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] { return rejectPromiseWithThisTypeError(lexicalGlobalObject, JSClass::info()->className, operationName); + } } else ASSERT(thisObject); diff --git a/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp b/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp index a1399773c3..63ce534b43 100644 --- a/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp +++ b/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp @@ -165,13 +165,13 @@ void DeferredPromise::reject(Exception exception, RejectAsHandled rejectAsHandle } auto error = createDOMException(lexicalGlobalObject, WTFMove(exception)); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { handleUncaughtException(scope, lexicalGlobalObject); return; } reject(lexicalGlobalObject, error, rejectAsHandled); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] handleUncaughtException(scope, lexicalGlobalObject); } @@ -200,13 +200,13 @@ void DeferredPromise::reject(ExceptionCode ec, const String& message, RejectAsHa } auto error = createDOMException(&lexicalGlobalObject, ec, message); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { handleUncaughtException(scope, lexicalGlobalObject); return; } reject(lexicalGlobalObject, error, rejectAsHandled); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] handleUncaughtException(scope, lexicalGlobalObject); } @@ -225,7 +225,7 @@ void DeferredPromise::reject(const JSC::PrivateName& privateName, RejectAsHandle void rejectPromiseWithExceptionIfAny(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, JSPromise& promise, JSC::CatchScope& catchScope) { UNUSED_PARAM(lexicalGlobalObject); - if (LIKELY(!catchScope.exception())) + if (!catchScope.exception()) [[likely]] return; JSValue error = catchScope.exception()->value(); diff --git a/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.h b/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.h index a0256aa3ad..f7fbd4c02c 100644 --- a/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.h +++ b/src/bun.js/bindings/webcore/JSDOMPromiseDeferred.h @@ -154,7 +154,7 @@ public: JSC::JSLockHolder locker(vm); auto scope = DECLARE_CATCH_SCOPE(vm); resolve(*lexicalGlobalObject, callback(*globalObject())); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] handleUncaughtException(scope, *lexicalGlobalObject); } @@ -171,7 +171,7 @@ public: JSC::JSLockHolder locker(vm); auto scope = DECLARE_CATCH_SCOPE(vm); reject(*lexicalGlobalObject, callback(*globalObject()), rejectAsHandled); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] handleUncaughtException(scope, *lexicalGlobalObject); } diff --git a/src/bun.js/bindings/webcore/JSDOMURL.cpp b/src/bun.js/bindings/webcore/JSDOMURL.cpp index 444393f497..ef5b82ab2d 100755 --- a/src/bun.js/bindings/webcore/JSDOMURL.cpp +++ b/src/bun.js/bindings/webcore/JSDOMURL.cpp @@ -154,7 +154,7 @@ template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMURLDOMConstructor::const auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto url = convert(*lexicalGlobalObject, argument0.value()); @@ -273,7 +273,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURLConstructor, (JSGlobalObject * lexicalGlobalObj auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSDOMURL::getConstructor(vm, prototype->globalObject())); } @@ -635,7 +635,7 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_parseBody(JSC::JSG auto throwScope = DECLARE_THROW_SCOPE(vm); UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto url = convert(*lexicalGlobalObject, argument0.value()); @@ -657,7 +657,7 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_canParseBody(JSC:: auto throwScope = DECLARE_THROW_SCOPE(vm); UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto url = convert(*lexicalGlobalObject, argument0.value()); @@ -695,7 +695,7 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURL1Bo UNUSED_PARAM(lexicalGlobalObject); UNUSED_PARAM(callFrame); // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); - // if (UNLIKELY(!context)) + // if (!context) [[unlikely]] return JSValue::encode(jsUndefined()); // EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); // auto blob = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "blob", "URL", "createObjectURL", "Blob"); }); @@ -709,10 +709,10 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_revokeObjectURLBod // auto throwScope = DECLARE_THROW_SCOPE(vm); UNUSED_PARAM(lexicalGlobalObject); UNUSED_PARAM(callFrame); - // if (UNLIKELY(callFrame->argumentCount() < 1)) + // if (callFrame->argumentCount() < 1) [[unlikely]] // return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); - // if (UNLIKELY(!context)) + // if (!context) [[unlikely]] return JSValue::encode(jsUndefined()); // EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); // auto url = convert(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSErrorEvent.cpp b/src/bun.js/bindings/webcore/JSErrorEvent.cpp index 45039d780f..ae464e73fa 100644 --- a/src/bun.js/bindings/webcore/JSErrorEvent.cpp +++ b/src/bun.js/bindings/webcore/JSErrorEvent.cpp @@ -57,7 +57,7 @@ template<> ErrorEvent::Init convertDictionary(JSGlobalObject& auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } @@ -210,7 +210,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSErrorEventDOMConstruct auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -302,7 +302,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsErrorEventConstructor, (JSGlobalObject * lexicalGloba auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSErrorEvent::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSEvent.cpp b/src/bun.js/bindings/webcore/JSEvent.cpp index bd6b1cd8b6..1a59d7200f 100644 --- a/src/bun.js/bindings/webcore/JSEvent.cpp +++ b/src/bun.js/bindings/webcore/JSEvent.cpp @@ -154,7 +154,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSEventDOMConstructor::c auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -287,7 +287,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsEventConstructor, (JSGlobalObject * lexicalGlobalObje auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSEvent::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -445,7 +445,7 @@ static inline JSValue jsEvent_timeStampGetter(JSGlobalObject& lexicalGlobalObjec auto& vm = JSC::getVM(&lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* context = (thisObject).globalObject()->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return jsUndefined(); auto& impl = thisObject.wrapped(); RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.timeStampForBindings(*context)))); @@ -567,7 +567,7 @@ static inline JSC::EncodedJSValue jsEventPrototypeFunction_initEventBody(JSC::JS UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSEventEmitter.cpp b/src/bun.js/bindings/webcore/JSEventEmitter.cpp index c150748537..ecb5e0dfa5 100644 --- a/src/bun.js/bindings/webcore/JSEventEmitter.cpp +++ b/src/bun.js/bindings/webcore/JSEventEmitter.cpp @@ -104,7 +104,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSEventEmitterDOMConstru auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "EventEmitter"_s); auto object = EventEmitter::create(*context); if constexpr (IsExceptionOr) @@ -132,7 +132,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSEventEmitterDOMConstru auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) { + if (!context) [[unlikely]] { return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "EventEmitter"_s); } const auto object = EventEmitter::create(*context); @@ -250,7 +250,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsEventEmitterConstructor, (JSGlobalObject * lexicalGlo auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSEventEmitter::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -261,7 +261,7 @@ inline JSC::EncodedJSValue JSEventEmitter::addListener(JSC::JSGlobalObject* lexi auto throwScope = DECLARE_THROW_SCOPE(vm); JSC::JSValue actualThis = callFrame->thisValue(); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto eventType = argument0.value().toPropertyKey(lexicalGlobalObject); @@ -374,7 +374,7 @@ inline JSC::EncodedJSValue JSEventEmitter::removeListener(JSC::JSGlobalObject* l auto throwScope = DECLARE_THROW_SCOPE(vm); JSC::JSValue actualThis = callFrame->thisValue(); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto eventType = argument0.value().toPropertyKey(lexicalGlobalObject); @@ -430,7 +430,7 @@ static inline JSC::EncodedJSValue jsEventEmitterPrototypeFunction_emitBody(JSC:: auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = castedThis->wrapped(); size_t argumentCount = callFrame->argumentCount(); - if (UNLIKELY(argumentCount < 1)) + if (argumentCount < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto eventType = callFrame->uncheckedArgument(0).toPropertyKey(lexicalGlobalObject); RETURN_IF_EXCEPTION(throwScope, {}); @@ -469,7 +469,7 @@ static inline JSC::EncodedJSValue jsEventEmitterPrototypeFunction_listenerCountB auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto eventType = callFrame->uncheckedArgument(0).toPropertyKey(lexicalGlobalObject); RETURN_IF_EXCEPTION(throwScope, {}); @@ -486,7 +486,7 @@ static inline JSC::EncodedJSValue jsEventEmitterPrototypeFunction_listenersBody( auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto eventType = callFrame->uncheckedArgument(0).toPropertyKey(lexicalGlobalObject); RETURN_IF_EXCEPTION(throwScope, {}); @@ -547,7 +547,7 @@ bool JSEventEmitterOwner::isReachableFromOpaqueRoots(JSC::Handle h { auto* jsEventEmitter = jsCast(handle.slot()->asCell()); if (jsEventEmitter->wrapped().isFiringEventListeners()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "EventEmitter firing event listeners"_s; return true; } @@ -568,10 +568,10 @@ JSC_DEFINE_HOST_FUNCTION(Events_functionGetEventListeners, { auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto argument0 = jsEventEmitterCast(vm, lexicalGlobalObject, callFrame->uncheckedArgument(0)); - if (UNLIKELY(!argument0)) { + if (!argument0) [[unlikely]] { throwException(lexicalGlobalObject, throwScope, createError(lexicalGlobalObject, "Expected EventEmitter"_s)); return {}; } @@ -590,10 +590,10 @@ JSC_DEFINE_HOST_FUNCTION(Events_functionListenerCount, { auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto argument0 = jsEventEmitterCast(vm, lexicalGlobalObject, callFrame->uncheckedArgument(0)); - if (UNLIKELY(!argument0)) { + if (!argument0) [[unlikely]] { throwException(lexicalGlobalObject, throwScope, createError(lexicalGlobalObject, "Expected EventEmitter"_s)); return {}; } @@ -609,10 +609,10 @@ JSC_DEFINE_HOST_FUNCTION(Events_functionOnce, auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(callFrame->argumentCount() < 3)) + if (callFrame->argumentCount() < 3) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto argument0 = jsEventEmitterCastFast(vm, lexicalGlobalObject, callFrame->uncheckedArgument(0)); - if (UNLIKELY(!argument0)) { + if (!argument0) [[unlikely]] { throwException(lexicalGlobalObject, throwScope, createError(lexicalGlobalObject, "Expected EventEmitter"_s)); return {}; } @@ -633,10 +633,10 @@ JSC_DEFINE_HOST_FUNCTION(Events_functionOn, auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(callFrame->argumentCount() < 3)) + if (callFrame->argumentCount() < 3) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto argument0 = jsEventEmitterCastFast(vm, lexicalGlobalObject, callFrame->uncheckedArgument(0)); - if (UNLIKELY(!argument0)) { + if (!argument0) [[unlikely]] { throwException(lexicalGlobalObject, throwScope, createError(lexicalGlobalObject, "Expected EventEmitter"_s)); return {}; } diff --git a/src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp b/src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp index 1f4e847808..ce367f441b 100644 --- a/src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp +++ b/src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp @@ -43,12 +43,12 @@ std::unique_ptr jsEventEmitterCast(VM& vm, JSC::JSGlobalO JSEventEmitter* jsEventEmitterCastFast(VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSValue thisValue) { - if (UNLIKELY(!thisValue.isCell())) { + if (!thisValue.isCell()) [[unlikely]] { return nullptr; } JSCell* thisCell = thisValue.asCell(); - if (UNLIKELY(!thisCell->isObject())) { + if (!thisCell->isObject()) [[unlikely]] { return nullptr; } diff --git a/src/bun.js/bindings/webcore/JSEventEmitterCustom.h b/src/bun.js/bindings/webcore/JSEventEmitterCustom.h index 8835363b60..91c9f8732f 100644 --- a/src/bun.js/bindings/webcore/JSEventEmitterCustom.h +++ b/src/bun.js/bindings/webcore/JSEventEmitterCustom.h @@ -42,8 +42,9 @@ public: auto thisValue = callFrame.thisValue().toThis(&lexicalGlobalObject, JSC::ECMAMode::strict()); auto* thisObject = jsEventEmitterCastFast(vm, &lexicalGlobalObject, thisValue); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] { return throwThisTypeError(lexicalGlobalObject, throwScope, "EventEmitter", operationName); + } RELEASE_AND_RETURN(throwScope, (operation(&lexicalGlobalObject, &callFrame, thisObject))); } diff --git a/src/bun.js/bindings/webcore/JSEventInit.cpp b/src/bun.js/bindings/webcore/JSEventInit.cpp index ea979f1d35..c0fdf5fadb 100644 --- a/src/bun.js/bindings/webcore/JSEventInit.cpp +++ b/src/bun.js/bindings/webcore/JSEventInit.cpp @@ -33,7 +33,7 @@ template<> EventInit convertDictionary(JSGlobalObject& lexicalGlobalO auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcore/JSEventListener.cpp b/src/bun.js/bindings/webcore/JSEventListener.cpp index 82ad9f609e..3d6b166956 100644 --- a/src/bun.js/bindings/webcore/JSEventListener.cpp +++ b/src/bun.js/bindings/webcore/JSEventListener.cpp @@ -203,7 +203,7 @@ void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext return; handleEventFunction = jsFunction->get(lexicalGlobalObject, Identifier::fromString(vm, "handleEvent"_s)); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { auto* exception = scope.exception(); scope.clearException(); event.target()->uncaughtExceptionInEventHandler(); @@ -255,7 +255,7 @@ void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext // See event_target.js function addCatch in node if (retval.isObject()) { auto then = retval.get(lexicalGlobalObject, vm.propertyNames->then); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { auto* exception = scope.exception(); scope.clearException(); event.target()->uncaughtExceptionInEventHandler(); @@ -267,7 +267,7 @@ void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext arglist.append(JSValue(JSC::jsUndefined())); arglist.append(JSValue(JSC::JSFunction::create(vm, lexicalGlobalObject, 1, String(), jsFunctionEmitUncaughtExceptionNextTick, ImplementationVisibility::Public, NoIntrinsic))); // err => process.nextTick(() => throw err) JSC::call(lexicalGlobalObject, then, retval, arglist, "Promise.then is not callable"_s); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { auto* exception = scope.exception(); scope.clearException(); event.target()->uncaughtExceptionInEventHandler(); @@ -288,7 +288,7 @@ void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext // // This is a OnBeforeUnloadEventHandler, and therefore the return value must be coerced into a String. // if (is(event)) { // String resultStr = convert>(*lexicalGlobalObject, retval); - // if (UNLIKELY(scope.exception())) { + // if (scope.exception()) [[unlikely]] { // if (handleExceptionIfNeeded(scope.exception())) // return; // } diff --git a/src/bun.js/bindings/webcore/JSEventListenerOptions.cpp b/src/bun.js/bindings/webcore/JSEventListenerOptions.cpp index b4034dbd81..e7116675d2 100644 --- a/src/bun.js/bindings/webcore/JSEventListenerOptions.cpp +++ b/src/bun.js/bindings/webcore/JSEventListenerOptions.cpp @@ -33,7 +33,7 @@ template<> EventListenerOptions convertDictionary(JSGlobal auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcore/JSEventModifierInit.cpp b/src/bun.js/bindings/webcore/JSEventModifierInit.cpp index d5ec4ea696..2e9cca6c65 100644 --- a/src/bun.js/bindings/webcore/JSEventModifierInit.cpp +++ b/src/bun.js/bindings/webcore/JSEventModifierInit.cpp @@ -37,7 +37,7 @@ template<> EventModifierInit convertDictionary(JSGlobalObject auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcore/JSEventTarget.cpp b/src/bun.js/bindings/webcore/JSEventTarget.cpp index c3bcde5d50..953bc19363 100644 --- a/src/bun.js/bindings/webcore/JSEventTarget.cpp +++ b/src/bun.js/bindings/webcore/JSEventTarget.cpp @@ -108,7 +108,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSEventTargetDOMConstruc auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "EventTarget"_s); auto object = EventTarget::create(*context); if constexpr (IsExceptionOr) @@ -201,7 +201,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsEventTargetConstructor, (JSGlobalObject * lexicalGlob auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSEventTarget::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -213,7 +213,7 @@ static inline JSC::EncodedJSValue jsEventTargetPrototypeFunction_addEventListene UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -259,7 +259,7 @@ static inline JSC::EncodedJSValue jsEventTargetPrototypeFunction_removeEventList UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -288,7 +288,7 @@ static inline JSC::EncodedJSValue jsEventTargetPrototypeFunction_dispatchEventBo UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto event = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "event"_s, "EventTarget"_s, "dispatchEvent"_s, "Event"_s); }); @@ -346,7 +346,7 @@ bool JSEventTargetOwner::isReachableFromOpaqueRoots(JSC::Handle ha { auto* jsEventTarget = jsCast(handle.slot()->asCell()); if (jsEventTarget->wrapped().isFiringEventListeners()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "EventTarget firing event listeners"_s; return true; } diff --git a/src/bun.js/bindings/webcore/JSEventTargetCustom.h b/src/bun.js/bindings/webcore/JSEventTargetCustom.h index 019bca3dbd..4de018f6f8 100644 --- a/src/bun.js/bindings/webcore/JSEventTargetCustom.h +++ b/src/bun.js/bindings/webcore/JSEventTargetCustom.h @@ -65,8 +65,9 @@ public: auto thisValue = callFrame.thisValue().toThis(&lexicalGlobalObject, JSC::ECMAMode::strict()); auto thisObject = jsEventTargetCast(vm, thisValue.isUndefinedOrNull() ? JSC::JSValue(&lexicalGlobalObject) : thisValue); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] { return throwThisTypeError(lexicalGlobalObject, throwScope, "EventTarget", operationName); + } RELEASE_AND_RETURN(throwScope, (operation(&lexicalGlobalObject, &callFrame, thisObject.get()))); } diff --git a/src/bun.js/bindings/webcore/JSEventTargetNode.cpp b/src/bun.js/bindings/webcore/JSEventTargetNode.cpp index fc6b5b8065..de4588d552 100644 --- a/src/bun.js/bindings/webcore/JSEventTargetNode.cpp +++ b/src/bun.js/bindings/webcore/JSEventTargetNode.cpp @@ -30,7 +30,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeEventsGetEventListeners, (JSGlobalObject auto eventType = callFrame->argument(1).toWTFString(globalObject); RETURN_IF_EXCEPTION(throwScope, {}); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return Bun::throwError(globalObject, throwScope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, "ERR_INVALID_ARG_TYPE: first argument must be of type EventEmitter"_s); } diff --git a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp index f9127c7524..36d65fb6db 100644 --- a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp +++ b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp @@ -187,7 +187,7 @@ template<> void JSFetchHeadersDOMConstructor::initializeProperties(VM& vm, JSDOM JSC_DEFINE_CUSTOM_GETTER(jsFetchHeadersGetterCount, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) { JSFetchHeaders* castedThis = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!castedThis)) { + if (!castedThis) [[unlikely]] { return JSValue::encode(jsUndefined()); } @@ -201,11 +201,11 @@ JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_getAll, (JSGlobalObject auto& vm = JSC::getVM(lexicalGlobalObject); auto scope = DECLARE_THROW_SCOPE(vm); JSFetchHeaders* castedThis = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!castedThis)) { + if (!castedThis) [[unlikely]] { return JSValue::encode(jsUndefined()); } - if (UNLIKELY(!callFrame->argumentCount())) { + if (!callFrame->argumentCount()) [[unlikely]] { throwTypeError(lexicalGlobalObject, scope, "Missing argument"_s); return {}; } @@ -275,7 +275,7 @@ JSC::EncodedJSValue fetchHeadersGetSetCookie(JSC::JSGlobalObject* lexicalGlobalO JSC::JSArray* array = constructEmptyArray(lexicalGlobalObject, nullptr, count); RETURN_IF_EXCEPTION(scope, {}); - if (UNLIKELY(!array)) { + if (!array) [[unlikely]] { throwOutOfMemoryError(lexicalGlobalObject, scope); return {}; } @@ -292,7 +292,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_getSetCookie, (JSGlobal { auto& vm = JSC::getVM(lexicalGlobalObject); JSFetchHeaders* castedThis = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!castedThis)) { + if (!castedThis) [[unlikely]] { return JSValue::encode(jsUndefined()); } auto& impl = castedThis->wrapped(); @@ -381,7 +381,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsFetchHeadersConstructor, (JSGlobalObject * lexicalGlo auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSFetchHeaders::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -393,7 +393,7 @@ static inline JSC::EncodedJSValue jsFetchHeadersPrototypeFunction_appendBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); @@ -429,7 +429,7 @@ static inline JSC::EncodedJSValue jsFetchHeadersPrototypeFunction_deleteBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* nameString = argument0.value().toString(lexicalGlobalObject); @@ -451,7 +451,7 @@ static inline JSC::EncodedJSValue jsFetchHeadersPrototypeFunction_getBody(JSC::J UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* nameString = argument0.value().toString(lexicalGlobalObject); @@ -473,7 +473,7 @@ static inline JSC::EncodedJSValue jsFetchHeadersPrototypeFunction_hasBody(JSC::J UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* nameString = argument0.value().toString(lexicalGlobalObject); @@ -495,7 +495,7 @@ static inline JSC::EncodedJSValue jsFetchHeadersPrototypeFunction_setBody(JSC::J UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSMIMEParams.cpp b/src/bun.js/bindings/webcore/JSMIMEParams.cpp index 3fca56a6e7..562589a711 100644 --- a/src/bun.js/bindings/webcore/JSMIMEParams.cpp +++ b/src/bun.js/bindings/webcore/JSMIMEParams.cpp @@ -392,7 +392,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMEParamsProtoFuncGet, (JSGlobalObject * globalObjec // 1. Get this value auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEParams")); RETURN_IF_EXCEPTION(scope, {}); } @@ -420,7 +420,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMEParamsProtoFuncHas, (JSGlobalObject * globalObjec auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEParams")); RETURN_IF_EXCEPTION(scope, {}); } @@ -442,7 +442,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMEParamsProtoFuncSet, (JSGlobalObject * globalObjec auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEParams")); RETURN_IF_EXCEPTION(scope, {}); } @@ -484,7 +484,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMEParamsProtoFuncDelete, (JSGlobalObject * globalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEParams")); RETURN_IF_EXCEPTION(scope, {}); } @@ -506,7 +506,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMEParamsProtoFuncToString, (JSGlobalObject * global auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEParams")); RETURN_IF_EXCEPTION(scope, {}); } @@ -557,7 +557,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMEParamsProtoFuncEntries, (JSGlobalObject * globalO { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEParams")); RETURN_IF_EXCEPTION(scope, {}); } @@ -568,7 +568,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMEParamsProtoFuncKeys, (JSGlobalObject * globalObje { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEParams")); RETURN_IF_EXCEPTION(scope, {}); } @@ -579,7 +579,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMEParamsProtoFuncValues, (JSGlobalObject * globalOb { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEParams")); RETURN_IF_EXCEPTION(scope, {}); } @@ -654,7 +654,7 @@ JSC_DEFINE_HOST_FUNCTION(constructMIMEParams, (JSGlobalObject * globalObject, Ca JSC::Structure* structure = zigGlobalObject->m_JSMIMEParamsClassStructure.get(zigGlobalObject); JSC::JSValue newTarget = callFrame->newTarget(); - if (UNLIKELY(zigGlobalObject->m_JSMIMEParamsClassStructure.constructor(zigGlobalObject) != newTarget)) { + if (zigGlobalObject->m_JSMIMEParamsClassStructure.constructor(zigGlobalObject) != newTarget) [[unlikely]] { if (!newTarget) { throwTypeError(globalObject, scope, "Class constructor MIMEParams cannot be invoked without 'new'"_s); return {}; diff --git a/src/bun.js/bindings/webcore/JSMIMEType.cpp b/src/bun.js/bindings/webcore/JSMIMEType.cpp index 7fec9c5ac0..7e01208479 100644 --- a/src/bun.js/bindings/webcore/JSMIMEType.cpp +++ b/src/bun.js/bindings/webcore/JSMIMEType.cpp @@ -345,7 +345,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsMIMETypeProtoGetterType, (JSGlobalObject * globalObje auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEType")); return {}; } @@ -359,7 +359,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsMIMETypeProtoSetterType, (JSGlobalObject * globalObje auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEType")); return {}; } @@ -385,7 +385,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsMIMETypeProtoGetterSubtype, (JSGlobalObject * globalO auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEType")); return {}; } @@ -399,7 +399,7 @@ JSC_DEFINE_CUSTOM_SETTER(jsMIMETypeProtoSetterSubtype, (JSGlobalObject * globalO auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEType")); return {}; } @@ -425,7 +425,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsMIMETypeProtoGetterEssence, (JSGlobalObject * globalO auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEType")); return {}; } @@ -440,7 +440,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsMIMETypeProtoGetterParams, (JSGlobalObject * globalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSC::JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEType")); return {}; } @@ -454,7 +454,7 @@ JSC_DEFINE_HOST_FUNCTION(jsMIMETypeProtoFuncToString, (JSGlobalObject * globalOb auto scope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { scope.throwException(globalObject, Bun::createInvalidThisError(globalObject, thisObject, "MIMEType")); return {}; } @@ -543,7 +543,7 @@ JSC_DEFINE_HOST_FUNCTION(constructMIMEType, (JSGlobalObject * globalObject, Call JSC::Structure* structure = zigGlobalObject->m_JSMIMETypeClassStructure.get(zigGlobalObject); JSC::JSValue newTarget = callFrame->newTarget(); - if (UNLIKELY(zigGlobalObject->m_JSMIMETypeClassStructure.constructor(zigGlobalObject) != newTarget)) { + if (zigGlobalObject->m_JSMIMETypeClassStructure.constructor(zigGlobalObject) != newTarget) [[unlikely]] { if (!newTarget) { throwTypeError(globalObject, scope, "Class constructor MIMEType cannot be invoked without 'new'"_s); return {}; diff --git a/src/bun.js/bindings/webcore/JSMessageChannel.cpp b/src/bun.js/bindings/webcore/JSMessageChannel.cpp index 92f5a3bd95..0d46552605 100644 --- a/src/bun.js/bindings/webcore/JSMessageChannel.cpp +++ b/src/bun.js/bindings/webcore/JSMessageChannel.cpp @@ -96,7 +96,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSMessageChannelDOMConst auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "MessageChannel"_s); auto object = MessageChannel::create(*context); if constexpr (IsExceptionOr) @@ -182,7 +182,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsMessageChannelConstructor, (JSGlobalObject * lexicalG auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSMessageChannel::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSMessageEvent.cpp b/src/bun.js/bindings/webcore/JSMessageEvent.cpp index 015b153de8..b7db3c24a4 100644 --- a/src/bun.js/bindings/webcore/JSMessageEvent.cpp +++ b/src/bun.js/bindings/webcore/JSMessageEvent.cpp @@ -67,7 +67,7 @@ template<> MessageEvent::Init convertDictionary(JSGlobalObje auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } @@ -236,7 +236,7 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSMessageEventDOMConstru auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); @@ -331,7 +331,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsMessageEventConstructor, (JSGlobalObject * lexicalGlo auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSMessageEvent::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -404,7 +404,7 @@ static inline JSC::EncodedJSValue jsMessageEventPrototypeFunction_initMessageEve UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert>(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSMessagePort.cpp b/src/bun.js/bindings/webcore/JSMessagePort.cpp index 0fba410d36..94aad037df 100644 --- a/src/bun.js/bindings/webcore/JSMessagePort.cpp +++ b/src/bun.js/bindings/webcore/JSMessagePort.cpp @@ -178,7 +178,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsMessagePortConstructor, (JSGlobalObject * lexicalGlob auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSMessagePort::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -428,12 +428,12 @@ bool JSMessagePortOwner::isReachableFromOpaqueRoots(JSC::Handle ha auto* jsMessagePort = jsCast(handle.slot()->asCell()); auto& wrapped = jsMessagePort->wrapped(); if (wrapped.hasPendingActivity()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "ActiveDOMObject with pending activity"_s; return true; } MessagePort* owner = &jsMessagePort->wrapped(); - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Reachable from MessagePort"_s; return visitor.containsOpaqueRoot(owner); diff --git a/src/bun.js/bindings/webcore/JSPerformance.cpp b/src/bun.js/bindings/webcore/JSPerformance.cpp index 862cbc4d1c..55e677a097 100644 --- a/src/bun.js/bindings/webcore/JSPerformance.cpp +++ b/src/bun.js/bindings/webcore/JSPerformance.cpp @@ -310,7 +310,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceConstructor, (JSGlobalObject * lexicalGlob auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformance::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -446,7 +446,7 @@ static inline JSC::EncodedJSValue jsPerformancePrototypeFunction_getEntriesByTyp UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert(*lexicalGlobalObject, argument0.value()); @@ -466,7 +466,7 @@ static inline JSC::EncodedJSValue jsPerformancePrototypeFunction_getEntriesByNam UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); @@ -504,7 +504,7 @@ static inline JSC::EncodedJSValue jsPerformancePrototypeFunction_setResourceTimi UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto maxSize = convert(*lexicalGlobalObject, argument0.value()); @@ -524,7 +524,7 @@ static inline JSC::EncodedJSValue jsPerformancePrototypeFunction_markBody(JSC::J UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto markName = convert(*lexicalGlobalObject, argument0.value()); @@ -565,7 +565,7 @@ static inline JSC::EncodedJSValue jsPerformancePrototypeFunction_measureBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto measureName = convert(*lexicalGlobalObject, argument0.value()); @@ -627,7 +627,7 @@ bool JSPerformanceOwner::isReachableFromOpaqueRoots(JSC::Handle ha ScriptExecutionContext* owner = WTF::getPtr(jsPerformance->wrapped().scriptExecutionContext()); if (!owner) return false; - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Reachable from ScriptExecutionContext"_s; return visitor.containsOpaqueRoot(&jsPerformance->wrapped()); } diff --git a/src/bun.js/bindings/webcore/JSPerformanceEntry.cpp b/src/bun.js/bindings/webcore/JSPerformanceEntry.cpp index 91096d92c7..1ff05b9c48 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceEntry.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceEntry.cpp @@ -169,7 +169,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceEntryConstructor, (JSGlobalObject * lexica auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformanceEntry::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSPerformanceMark.cpp b/src/bun.js/bindings/webcore/JSPerformanceMark.cpp index 3fe0c5162c..a7fa5e5768 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceMark.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceMark.cpp @@ -94,10 +94,10 @@ template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSPerformanceMarkDOMConstruct auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "PerformanceMark"_s); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto markName = convert(*lexicalGlobalObject, argument0.value()); @@ -181,7 +181,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceMarkConstructor, (JSGlobalObject * lexical auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformanceMark::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSPerformanceMarkOptions.cpp b/src/bun.js/bindings/webcore/JSPerformanceMarkOptions.cpp index 77a6362b1f..34319cf833 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceMarkOptions.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceMarkOptions.cpp @@ -34,7 +34,7 @@ template<> PerformanceMarkOptions convertDictionary(JSGl auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcore/JSPerformanceMeasure.cpp b/src/bun.js/bindings/webcore/JSPerformanceMeasure.cpp index 9f0649e5c5..c0dbd10789 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceMeasure.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceMeasure.cpp @@ -147,7 +147,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceMeasureConstructor, (JSGlobalObject * lexi auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformanceMeasure::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSPerformanceMeasureOptions.cpp b/src/bun.js/bindings/webcore/JSPerformanceMeasureOptions.cpp index 498415c571..41adb2ddb9 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceMeasureOptions.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceMeasureOptions.cpp @@ -37,7 +37,7 @@ template<> PerformanceMeasureOptions convertDictionary PerformanceObserver::Init convertDictionary EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSPerformanceObserverDOMConst auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "PerformanceObserver"_s); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto callback = convert>( @@ -260,7 +260,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceObserverConstructor, (JSGlobalObject * lex auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformanceObserver::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -270,7 +270,7 @@ static inline JSValue jsPerformanceObserverConstructor_supportedEntryTypesGetter auto& vm = JSC::getVM(&lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* context = jsCast(&lexicalGlobalObject)->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return jsUndefined(); RELEASE_AND_RETURN(throwScope, (toJS>(lexicalGlobalObject, *jsCast(&lexicalGlobalObject), throwScope, PerformanceObserver::supportedEntryTypes(*context)))); } diff --git a/src/bun.js/bindings/webcore/JSPerformanceObserverCustom.cpp b/src/bun.js/bindings/webcore/JSPerformanceObserverCustom.cpp index 1b037cac78..7393d427d7 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceObserverCustom.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceObserverCustom.cpp @@ -41,7 +41,7 @@ DEFINE_VISIT_ADDITIONAL_CHILDREN(JSPerformanceObserver); bool JSPerformanceObserverOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, JSC::AbstractSlotVisitor&, ASCIILiteral* reason) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Registered PerformanceObserver callback"_s; return JSC::jsCast(handle.slot()->asCell())->wrapped().isRegistered(); diff --git a/src/bun.js/bindings/webcore/JSPerformanceObserverEntryList.cpp b/src/bun.js/bindings/webcore/JSPerformanceObserverEntryList.cpp index d8a63e055f..7c5a4972b4 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceObserverEntryList.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceObserverEntryList.cpp @@ -167,7 +167,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceObserverEntryListConstructor, (JSGlobalObj auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformanceObserverEntryList::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -194,7 +194,7 @@ static inline JSC::EncodedJSValue jsPerformanceObserverEntryListPrototypeFunctio UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto type = convert(*lexicalGlobalObject, argument0.value()); @@ -214,7 +214,7 @@ static inline JSC::EncodedJSValue jsPerformanceObserverEntryListPrototypeFunctio UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSPerformanceResourceTiming.cpp b/src/bun.js/bindings/webcore/JSPerformanceResourceTiming.cpp index 71f3027255..dbef65a877 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceResourceTiming.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceResourceTiming.cpp @@ -199,7 +199,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceResourceTimingConstructor, (JSGlobalObject auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformanceResourceTiming::getConstructor(vm, prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSPerformanceServerTiming.cpp b/src/bun.js/bindings/webcore/JSPerformanceServerTiming.cpp index 70e5675976..492a393198 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceServerTiming.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceServerTiming.cpp @@ -167,7 +167,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceServerTimingConstructor, (JSGlobalObject * auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformanceServerTiming::getConstructor(vm, prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSPerformanceTiming.cpp b/src/bun.js/bindings/webcore/JSPerformanceTiming.cpp index 412dfdd4b7..1f21ac34f4 100644 --- a/src/bun.js/bindings/webcore/JSPerformanceTiming.cpp +++ b/src/bun.js/bindings/webcore/JSPerformanceTiming.cpp @@ -202,7 +202,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsPerformanceTimingConstructor, (JSGlobalObject * lexic auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSPerformanceTiming::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSReadableByteStreamController.cpp b/src/bun.js/bindings/webcore/JSReadableByteStreamController.cpp index 83896c86b0..45b7b9ec96 100644 --- a/src/bun.js/bindings/webcore/JSReadableByteStreamController.cpp +++ b/src/bun.js/bindings/webcore/JSReadableByteStreamController.cpp @@ -165,7 +165,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsReadableByteStreamControllerConstructor, (JSGlobalObj auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSReadableByteStreamController::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSReadableStream.cpp b/src/bun.js/bindings/webcore/JSReadableStream.cpp index a524a66895..2079d2f5c6 100644 --- a/src/bun.js/bindings/webcore/JSReadableStream.cpp +++ b/src/bun.js/bindings/webcore/JSReadableStream.cpp @@ -229,7 +229,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamConstructor, (JSGlobalObject * lexicalG auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSReadableStream::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSReadableStreamBYOBReader.cpp b/src/bun.js/bindings/webcore/JSReadableStreamBYOBReader.cpp index 320597bf95..4719a158ee 100644 --- a/src/bun.js/bindings/webcore/JSReadableStreamBYOBReader.cpp +++ b/src/bun.js/bindings/webcore/JSReadableStreamBYOBReader.cpp @@ -164,7 +164,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamBYOBReaderConstructor, (JSGlobalObject auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSReadableStreamBYOBReader::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSReadableStreamBYOBRequest.cpp b/src/bun.js/bindings/webcore/JSReadableStreamBYOBRequest.cpp index 6e6687724f..9fdedf8eb4 100644 --- a/src/bun.js/bindings/webcore/JSReadableStreamBYOBRequest.cpp +++ b/src/bun.js/bindings/webcore/JSReadableStreamBYOBRequest.cpp @@ -163,7 +163,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamBYOBRequestConstructor, (JSGlobalObject auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSReadableStreamBYOBRequest::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSReadableStreamDefaultController.cpp b/src/bun.js/bindings/webcore/JSReadableStreamDefaultController.cpp index 4863283b49..d36e435b39 100644 --- a/src/bun.js/bindings/webcore/JSReadableStreamDefaultController.cpp +++ b/src/bun.js/bindings/webcore/JSReadableStreamDefaultController.cpp @@ -167,7 +167,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamDefaultControllerConstructor, (JSGlobal auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSReadableStreamDefaultController::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.cpp b/src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.cpp index 676fd4fc6a..64f2927a8c 100644 --- a/src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.cpp +++ b/src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.cpp @@ -167,7 +167,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsReadableStreamDefaultReaderConstructor, (JSGlobalObje auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSReadableStreamDefaultReader::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSReadableStreamSink.cpp b/src/bun.js/bindings/webcore/JSReadableStreamSink.cpp index 55e24a462c..0a34f52ff5 100644 --- a/src/bun.js/bindings/webcore/JSReadableStreamSink.cpp +++ b/src/bun.js/bindings/webcore/JSReadableStreamSink.cpp @@ -143,7 +143,7 @@ static inline JSC::EncodedJSValue jsReadableStreamSinkPrototypeFunction_enqueueB UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto chunk = convert>(*lexicalGlobalObject, argument0.value()); @@ -178,7 +178,7 @@ static inline JSC::EncodedJSValue jsReadableStreamSinkPrototypeFunction_errorBod UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto message = convert(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSReadableStreamSource.cpp b/src/bun.js/bindings/webcore/JSReadableStreamSource.cpp index 0dfba15343..b2e5751b09 100644 --- a/src/bun.js/bindings/webcore/JSReadableStreamSource.cpp +++ b/src/bun.js/bindings/webcore/JSReadableStreamSource.cpp @@ -192,7 +192,7 @@ static inline JSC::EncodedJSValue jsReadableStreamSourcePrototypeFunction_cancel UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto reason = convert(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSStructuredSerializeOptions.cpp b/src/bun.js/bindings/webcore/JSStructuredSerializeOptions.cpp index cc6bb17125..60ac148800 100644 --- a/src/bun.js/bindings/webcore/JSStructuredSerializeOptions.cpp +++ b/src/bun.js/bindings/webcore/JSStructuredSerializeOptions.cpp @@ -35,7 +35,7 @@ template<> StructuredSerializeOptions convertDictionary(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSTextDecoderStream::getConstructor(vm, prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSTextEncoder.cpp b/src/bun.js/bindings/webcore/JSTextEncoder.cpp index ae86bc0447..aab8702b6c 100644 --- a/src/bun.js/bindings/webcore/JSTextEncoder.cpp +++ b/src/bun.js/bindings/webcore/JSTextEncoder.cpp @@ -85,7 +85,7 @@ template<> TextEncoder::EncodeIntoResult convertDictionaryisErrorInstance())) { +// if (JSC::JSValue::decode(res).isObject() && JSC::JSValue::decode(res).getObject()->isErrorInstance()) [[unlikely]] { // throwScope.throwException(lexicalGlobalObject, JSC::JSValue::decode(res)); // return { encodedJSValue() }; // } @@ -354,7 +354,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsTextEncoderConstructor, (JSGlobalObject * lexicalGlob auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSTextEncoder::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -408,7 +408,7 @@ static inline JSC::EncodedJSValue jsTextEncoderPrototypeFunction_encodeBody(JSC: RETURN_IF_EXCEPTION(throwScope, {}); - if (UNLIKELY(JSC::JSValue::decode(res).isObject() && JSC::JSValue::decode(res).getObject()->isErrorInstance())) { + if (JSC::JSValue::decode(res).isObject() && JSC::JSValue::decode(res).getObject()->isErrorInstance()) [[unlikely]] { throwScope.throwException(lexicalGlobalObject, JSC::JSValue::decode(res)); return {}; } @@ -425,7 +425,7 @@ static inline JSC::EncodedJSValue jsTextEncoderPrototypeFunction_encodeIntoBody( { auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* str = argument0.value().toString(lexicalGlobalObject); diff --git a/src/bun.js/bindings/webcore/JSTextEncoderStream.cpp b/src/bun.js/bindings/webcore/JSTextEncoderStream.cpp index caed2ea076..cad039c79c 100644 --- a/src/bun.js/bindings/webcore/JSTextEncoderStream.cpp +++ b/src/bun.js/bindings/webcore/JSTextEncoderStream.cpp @@ -155,7 +155,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsTextEncoderStreamConstructor, (JSGlobalObject * lexic auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSTextEncoderStream::getConstructor(vm, prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSTransformStream.cpp b/src/bun.js/bindings/webcore/JSTransformStream.cpp index 6ce71289c3..72b8aa9ff3 100644 --- a/src/bun.js/bindings/webcore/JSTransformStream.cpp +++ b/src/bun.js/bindings/webcore/JSTransformStream.cpp @@ -159,7 +159,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsTransformStreamConstructor, (JSGlobalObject * lexical auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSTransformStream::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSTransformStreamDefaultController.cpp b/src/bun.js/bindings/webcore/JSTransformStreamDefaultController.cpp index 8be090d13d..b1e864f4a2 100644 --- a/src/bun.js/bindings/webcore/JSTransformStreamDefaultController.cpp +++ b/src/bun.js/bindings/webcore/JSTransformStreamDefaultController.cpp @@ -164,7 +164,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsTransformStreamDefaultControllerConstructor, (JSGloba auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSTransformStreamDefaultController::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSURLSearchParams.cpp b/src/bun.js/bindings/webcore/JSURLSearchParams.cpp index 1828b958e4..5db61d5d94 100644 --- a/src/bun.js/bindings/webcore/JSURLSearchParams.cpp +++ b/src/bun.js/bindings/webcore/JSURLSearchParams.cpp @@ -160,7 +160,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsURLSearchParamsPrototype_getLength, (JSGlobalObject * auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* thisObject = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!thisObject)) + if (!thisObject) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(jsNumber(thisObject->wrapped().size())); } @@ -239,7 +239,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsURLSearchParamsConstructor, (JSGlobalObject * lexical auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSURLSearchParams::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -251,7 +251,7 @@ static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_appendBody( UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); @@ -274,7 +274,7 @@ static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_deleteBody( UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); @@ -302,7 +302,7 @@ static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_getBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* nameString = argument0.value().toString(lexicalGlobalObject); @@ -324,7 +324,7 @@ static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_getAllBody( UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* nameString = argument0.value().toString(lexicalGlobalObject); @@ -346,7 +346,7 @@ static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_hasBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto* nameString = argument0.value().toString(lexicalGlobalObject); @@ -376,7 +376,7 @@ static inline JSC::EncodedJSValue jsURLSearchParamsPrototypeFunction_setBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto name = convert(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/JSWebSocket.cpp b/src/bun.js/bindings/webcore/JSWebSocket.cpp index ba26a0389d..8fc8c4985f 100644 --- a/src/bun.js/bindings/webcore/JSWebSocket.cpp +++ b/src/bun.js/bindings/webcore/JSWebSocket.cpp @@ -150,7 +150,7 @@ static inline JSC::EncodedJSValue constructJSWebSocket1(JSGlobalObject* lexicalG auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "WebSocket"_s); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto url = convert(*lexicalGlobalObject, argument0.value()); @@ -177,7 +177,7 @@ static inline JSC::EncodedJSValue constructJSWebSocket2(JSGlobalObject* lexicalG auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "WebSocket"_s); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto url = convert(*lexicalGlobalObject, argument0.value()); @@ -203,7 +203,7 @@ static inline JSC::EncodedJSValue constructJSWebSocket3(JSGlobalObject* lexicalG auto throwScope = DECLARE_THROW_SCOPE(vm); auto* globalObject = jsCast(lexicalGlobalObject); auto* context = globalObject->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "WebSocket"_s); auto url = convert(*lexicalGlobalObject, urlValue); RETURN_IF_EXCEPTION(throwScope, {}); @@ -377,7 +377,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsWebSocketConstructor, (JSGlobalObject * lexicalGlobal auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSWebSocket::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -916,12 +916,12 @@ bool JSWebSocketOwner::isReachableFromOpaqueRoots(JSC::Handle hand auto* jsWebSocket = jsCast(handle.slot()->asCell()); auto& wrapped = jsWebSocket->wrapped(); if (wrapped.hasPendingActivity()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "ActiveDOMObject with pending activity"_s; return true; } if (jsWebSocket->wrapped().isFiringEventListeners()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "EventTarget firing event listeners"_s; return true; } diff --git a/src/bun.js/bindings/webcore/JSWorker.cpp b/src/bun.js/bindings/webcore/JSWorker.cpp index d72a58a81c..3a82d266e4 100644 --- a/src/bun.js/bindings/webcore/JSWorker.cpp +++ b/src/bun.js/bindings/webcore/JSWorker.cpp @@ -122,10 +122,10 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSWorkerDOMConstructor:: auto* castedThis = jsCast(callFrame->jsCallee()); auto* globalObject = defaultGlobalObject(lexicalGlobalObject); ASSERT(castedThis); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto* context = castedThis->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "Worker"_s); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); String scriptUrl; @@ -371,7 +371,7 @@ template<> void JSWorkerDOMConstructor::initializeProperties(VM& vm, JSDOMGlobal JSC_DEFINE_CUSTOM_GETTER(jsWorker_threadIdGetter, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName)) { auto* castedThis = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!castedThis)) + if (!castedThis) [[unlikely]] return JSValue::encode(jsUndefined()); auto& worker = castedThis->wrapped(); @@ -437,7 +437,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsWorkerConstructor, (JSGlobalObject * lexicalGlobalObj auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSWorker::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -659,7 +659,7 @@ bool JSWorkerOwner::isReachableFromOpaqueRoots(JSC::Handle handle, auto* jsWorker = jsCast(handle.slot()->asCell()); auto& wrapped = jsWorker->wrapped(); if (!wrapped.isContextStopped() && wrapped.hasPendingActivity()) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "ActiveDOMObject with pending activity"_s; return true; } diff --git a/src/bun.js/bindings/webcore/JSWorkerOptions.cpp b/src/bun.js/bindings/webcore/JSWorkerOptions.cpp index 96c654a934..06c7989629 100644 --- a/src/bun.js/bindings/webcore/JSWorkerOptions.cpp +++ b/src/bun.js/bindings/webcore/JSWorkerOptions.cpp @@ -36,7 +36,7 @@ template<> WorkerOptions convertDictionary(JSGlobalObject& lexica auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcore/JSWritableStream.cpp b/src/bun.js/bindings/webcore/JSWritableStream.cpp index 2753681e57..2a3d29a291 100644 --- a/src/bun.js/bindings/webcore/JSWritableStream.cpp +++ b/src/bun.js/bindings/webcore/JSWritableStream.cpp @@ -199,7 +199,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamConstructor, (JSGlobalObject * lexicalG auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSWritableStream::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSWritableStreamDefaultController.cpp b/src/bun.js/bindings/webcore/JSWritableStreamDefaultController.cpp index efc60f53b1..3f7ca87a3a 100644 --- a/src/bun.js/bindings/webcore/JSWritableStreamDefaultController.cpp +++ b/src/bun.js/bindings/webcore/JSWritableStreamDefaultController.cpp @@ -160,7 +160,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamDefaultControllerConstructor, (JSGlobal auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSWritableStreamDefaultController::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.cpp b/src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.cpp index 77464b656a..37fc0672c1 100644 --- a/src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.cpp +++ b/src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.cpp @@ -167,7 +167,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsWritableStreamDefaultWriterConstructor, (JSGlobalObje auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSWritableStreamDefaultWriter::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } diff --git a/src/bun.js/bindings/webcore/JSWritableStreamSink.cpp b/src/bun.js/bindings/webcore/JSWritableStreamSink.cpp index 49c779a9ce..225e0ff17b 100644 --- a/src/bun.js/bindings/webcore/JSWritableStreamSink.cpp +++ b/src/bun.js/bindings/webcore/JSWritableStreamSink.cpp @@ -145,10 +145,10 @@ static inline JSC::EncodedJSValue jsWritableStreamSinkPrototypeFunction_writeBod UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); - if (UNLIKELY(!context)) + if (!context) [[unlikely]] return JSValue::encode(jsUndefined()); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto value = convert(*lexicalGlobalObject, argument0.value()); @@ -183,7 +183,7 @@ static inline JSC::EncodedJSValue jsWritableStreamSinkPrototypeFunction_errorBod UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 1)) + if (callFrame->argumentCount() < 1) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto message = convert(*lexicalGlobalObject, argument0.value()); diff --git a/src/bun.js/bindings/webcore/MessageEvent.cpp b/src/bun.js/bindings/webcore/MessageEvent.cpp index 8fab43f3f2..8fdc58adb4 100644 --- a/src/bun.js/bindings/webcore/MessageEvent.cpp +++ b/src/bun.js/bindings/webcore/MessageEvent.cpp @@ -100,7 +100,7 @@ auto MessageEvent::create(JSC::JSGlobalObject& globalObject, Refdeserialize(globalObject, &globalObject, ports, SerializationErrorMode::NonThrowing, &didFail); - if (UNLIKELY(catchScope.exception())) + if (catchScope.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 6c3b67c5f5..defe579516 100644 --- a/src/bun.js/bindings/webcore/MessagePort.cpp +++ b/src/bun.js/bindings/webcore/MessagePort.cpp @@ -273,7 +273,7 @@ void MessagePort::dispatchMessages() return; auto ports = MessagePort::entanglePorts(*context, WTFMove(message.transferredPorts)); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { // Currently, we assume that the only way we can get here is if we have a termination. RELEASE_ASSERT(vm->hasPendingTerminationException()); return; diff --git a/src/bun.js/bindings/webcore/ReadableStream.cpp b/src/bun.js/bindings/webcore/ReadableStream.cpp index 51395243b3..6f267a0b35 100644 --- a/src/bun.js/bindings/webcore/ReadableStream.cpp +++ b/src/bun.js/bindings/webcore/ReadableStream.cpp @@ -163,7 +163,7 @@ void ReadableStream::cancel(const Exception& exception) JSC::JSLockHolder lock(vm); auto scope = DECLARE_CATCH_SCOPE(vm); auto value = createDOMException(&lexicalGlobalObject, exception.code(), exception.message()); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { ASSERT(vm.hasPendingTerminationException()); return; } @@ -184,7 +184,7 @@ void ReadableStream::cancel(WebCore::JSDOMGlobalObject& globalObject, JSReadable JSC::JSLockHolder lock(vm); auto scope = DECLARE_CATCH_SCOPE(vm); auto value = createDOMException(&globalObject, exception.code(), exception.message()); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { ASSERT(vm.hasPendingTerminationException()); return; } diff --git a/src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp b/src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp index ca3e35b2ba..11e6675ef9 100644 --- a/src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp +++ b/src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp @@ -77,7 +77,7 @@ void ReadableStreamDefaultController::error(const Exception& exception) auto scope = DECLARE_CATCH_SCOPE(vm); auto value = createDOMException(&lexicalGlobalObject, exception.code(), exception.message()); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { ASSERT(vm.hasPendingTerminationException()); return; } @@ -100,7 +100,7 @@ void ReadableStreamDefaultController::error(JSC::JSValue error) auto scope = DECLARE_THROW_SCOPE(vm); auto value = JSC::Exception::create(vm, error); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { ASSERT(vm.hasPendingTerminationException()); return; } diff --git a/src/bun.js/bindings/webcore/SerializedScriptValue.cpp b/src/bun.js/bindings/webcore/SerializedScriptValue.cpp index 36f0905ccc..a4a2971dac 100644 --- a/src/bun.js/bindings/webcore/SerializedScriptValue.cpp +++ b/src/bun.js/bindings/webcore/SerializedScriptValue.cpp @@ -1317,7 +1317,7 @@ private: else return false; - if (UNLIKELY(jsCast(obj)->isOutOfBounds())) { + if (jsCast(obj)->isOutOfBounds()) [[unlikely]] { code = SerializationReturnCode::DataCloneError; return true; } @@ -2572,7 +2572,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) lengthStack.append(length); } arrayStartVisitMember: - FALLTHROUGH; + [[fallthrough]]; case ArrayStartVisitMember: { JSObject* array = inputObjectStack.last(); uint32_t index = indexStack.last(); @@ -2582,7 +2582,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) propertyStack.append(PropertyNameArray(vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude)); array->getOwnNonIndexPropertyNames(m_lexicalGlobalObject, propertyStack.last(), DontEnumPropertiesMode::Exclude); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; if (propertyStack.last().size()) { write(NonIndexPropertiesTag); @@ -2596,7 +2596,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) break; } inValue = array->getDirectIndex(m_lexicalGlobalObject, index); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; if (!inValue) { indexStack.last()++; @@ -2636,11 +2636,11 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) indexStack.append(0); propertyStack.append(PropertyNameArray(vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude)); inObject->methodTable()->getOwnPropertyNames(inObject, m_lexicalGlobalObject, propertyStack.last(), DontEnumPropertiesMode::Exclude); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; } objectStartVisitMember: - FALLTHROUGH; + [[fallthrough]]; case ObjectStartVisitMember: { JSObject* object = inputObjectStack.last(); uint32_t index = indexStack.last(); @@ -2653,7 +2653,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) break; } inValue = getProperty(object, properties[index]); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; if (!inValue) { @@ -2663,7 +2663,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) } write(properties[index]); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; auto terminalCode = SerializationReturnCode::SuccessfullyCompleted; @@ -2673,10 +2673,10 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) } if (terminalCode != SerializationReturnCode::SuccessfullyCompleted) return terminalCode; - FALLTHROUGH; + [[fallthrough]]; } case ObjectEndVisitMember: { - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; indexStack.last()++; @@ -2690,7 +2690,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) if (!startMap(inMap)) break; JSMapIterator* iterator = JSMapIterator::create(m_lexicalGlobalObject, m_lexicalGlobalObject->mapIteratorStructure(), inMap, IterationKind::Entries); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; m_gcBuffer.appendWithCrashOnOverflow(inMap); m_gcBuffer.appendWithCrashOnOverflow(iterator); @@ -2708,7 +2708,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) ASSERT(jsDynamicCast(object)); propertyStack.append(PropertyNameArray(vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude)); object->methodTable()->getOwnPropertyNames(object, m_lexicalGlobalObject, propertyStack.last(), DontEnumPropertiesMode::Exclude); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; write(NonMapPropertiesTag); indexStack.append(0); @@ -2738,7 +2738,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) if (!startSet(inSet)) break; JSSetIterator* iterator = JSSetIterator::create(m_lexicalGlobalObject, m_lexicalGlobalObject->setIteratorStructure(), inSet, IterationKind::Keys); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; m_gcBuffer.appendWithCrashOnOverflow(inSet); m_gcBuffer.appendWithCrashOnOverflow(iterator); @@ -2756,7 +2756,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) ASSERT(jsDynamicCast(object)); propertyStack.append(PropertyNameArray(vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude)); object->methodTable()->getOwnPropertyNames(object, m_lexicalGlobalObject, propertyStack.last(), DontEnumPropertiesMode::Exclude); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] return SerializationReturnCode::ExistingExceptionError; write(NonSetPropertiesTag); indexStack.append(0); @@ -4618,7 +4618,7 @@ private: return jsBigInt32(0); #else JSBigInt* bigInt = JSBigInt::tryCreateZero(m_lexicalGlobalObject->vm()); - if (UNLIKELY(!bigInt)) { + if (!bigInt) [[unlikely]] { fail(); return JSValue(); } @@ -5021,7 +5021,7 @@ private: Structure* structure = m_globalObject->arrayBufferStructure(arrayBuffer->sharingMode()); // A crazy RuntimeFlags mismatch could mean that we are not equipped to handle shared // array buffers while the sender is. In that case, we would see a null structure here. - if (UNLIKELY(!structure)) { + if (!structure) [[unlikely]] { fail(); return JSValue(); } @@ -5038,7 +5038,7 @@ private: Structure* structure = m_globalObject->arrayBufferStructure(arrayBuffer->sharingMode()); // A crazy RuntimeFlags mismatch could mean that we are not equipped to handle shared // array buffers while the sender is. In that case, we would see a null structure here. - if (UNLIKELY(!structure)) { + if (!structure) [[unlikely]] { fail(); return JSValue(); } @@ -5243,13 +5243,13 @@ DeserializationResult CloneDeserializer::deserialize() goto error; } JSArray* outArray = constructEmptyArray(m_globalObject, static_cast(nullptr), length); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] goto error; m_gcBuffer.appendWithCrashOnOverflow(outArray); outputObjectStack.append(outArray); } arrayStartVisitMember: - FALLTHROUGH; + [[fallthrough]]; case ArrayStartVisitMember: { uint32_t index; if (!read(index)) { @@ -5267,7 +5267,7 @@ DeserializationResult CloneDeserializer::deserialize() if (JSValue terminal = readTerminal()) { putProperty(outputObjectStack.last(), index, terminal); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { fail(); goto error; } @@ -5282,7 +5282,7 @@ DeserializationResult CloneDeserializer::deserialize() case ArrayEndVisitMember: { JSObject* outArray = outputObjectStack.last(); putProperty(outArray, indexStack.last(), outValue); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { fail(); goto error; } @@ -5298,7 +5298,7 @@ DeserializationResult CloneDeserializer::deserialize() outputObjectStack.append(outObject); } objectStartVisitMember: - FALLTHROUGH; + [[fallthrough]]; case ObjectStartVisitMember: { CachedStringRef cachedString; bool wasTerminator = false; @@ -5314,7 +5314,7 @@ DeserializationResult CloneDeserializer::deserialize() if (JSValue terminal = readTerminal()) { putProperty(outputObjectStack.last(), cachedString->identifier(vm), terminal); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { fail(); goto error; } @@ -5354,7 +5354,7 @@ DeserializationResult CloneDeserializer::deserialize() } case MapDataEndVisitValue: { mapStack.last()->set(m_lexicalGlobalObject, mapKeyStack.last(), outValue); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { fail(); goto error; } @@ -5383,7 +5383,7 @@ DeserializationResult CloneDeserializer::deserialize() case SetDataEndVisitKey: { JSSet* set = setStack.last(); set->add(m_lexicalGlobalObject, outValue); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { fail(); goto error; } @@ -5849,12 +5849,12 @@ ExceptionOr> SerializedScriptValue::create(JSGlobalOb // in maybeThrowExceptionIfSerializationFailed (since that may also throw other // different errors), and then re-check if we have an exception after the call. // If so, we'll throw it again. - if (UNLIKELY(scope.exception()) || throwExceptions == SerializationErrorMode::Throwing) + if (scope.exception() || throwExceptions == SerializationErrorMode::Throwing) [[unlikely]] maybeThrowExceptionIfSerializationFailed(lexicalGlobalObject, code); // If we rethrew an exception just now, or we failed with a status code other than success, // we should exit right now. - if (UNLIKELY(scope.exception()) || code != SerializationReturnCode::SuccessfullyCompleted) + if (scope.exception() || code != SerializationReturnCode::SuccessfullyCompleted) [[unlikely]] return exceptionForSerializationFailure(code); auto arrayBufferContentsArray = transferArrayBuffers(vm, arrayBuffers); @@ -5938,7 +5938,7 @@ RefPtr SerializedScriptValue::create(JSContextRef originC JSValue value = toJS(lexicalGlobalObject, apiValue); auto serializedValue = SerializedScriptValue::create(*lexicalGlobalObject, value); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { if (exception) *exception = toRef(lexicalGlobalObject, scope.exception()->value()); scope.clearException(); @@ -6068,7 +6068,7 @@ JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject, *didFail = result.second != SerializationReturnCode::SuccessfullyCompleted; // Deserialize may throw an exception. Similar to serialize (~L6240, SerializedScriptValue::create), // we'll catch and rethrow. - if (UNLIKELY(scope.exception()) || throwExceptions == SerializationErrorMode::Throwing) + if (scope.exception() || throwExceptions == SerializationErrorMode::Throwing) [[unlikely]] maybeThrowExceptionIfSerializationFailed(lexicalGlobalObject, result.second); // Rethrow is a bit simpler here since we don't deal with return codes. @@ -6133,7 +6133,7 @@ JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, J auto scope = DECLARE_CATCH_SCOPE(vm); JSValue value = deserialize(*lexicalGlobalObject, lexicalGlobalObject); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { if (exception) *exception = toRef(lexicalGlobalObject, scope.exception()->value()); scope.clearException(); diff --git a/src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp b/src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp index a6c71957da..1217b37ee7 100644 --- a/src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp +++ b/src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp @@ -66,7 +66,7 @@ bool WebCoreTypedArrayController::isAtomicsWaitAllowedOnCurrentThread() bool WebCoreTypedArrayController::JSArrayBufferOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, JSC::AbstractSlotVisitor& visitor, ASCIILiteral* reason) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "ArrayBuffer is opaque root"_s; auto& wrapper = *JSC::jsCast(handle.slot()->asCell()); return visitor.containsOpaqueRoot(wrapper.impl()); diff --git a/src/bun.js/bindings/webcore/WebSocket.cpp b/src/bun.js/bindings/webcore/WebSocket.cpp index 23d5116ebb..c8acf12bf1 100644 --- a/src/bun.js/bindings/webcore/WebSocket.cpp +++ b/src/bun.js/bindings/webcore/WebSocket.cpp @@ -419,7 +419,7 @@ ExceptionOr WebSocket::connect(const String& url, const Vector& pr Vector headerValues; auto headersOrException = FetchHeaders::create(WTFMove(headersInit)); - if (UNLIKELY(headersOrException.hasException())) { + if (headersOrException.hasException()) [[unlikely]] { m_state = CLOSED; updateHasPendingActivity(); return headersOrException.releaseException(); @@ -1041,7 +1041,7 @@ void WebSocket::didReceiveMessage(String&& message) if (m_state != OPEN) return; - // if (UNLIKELY(InspectorInstrumentation::hasFrontends())) { + // if (InspectorInstrumentation::hasFrontends()) [[unlikely]] { // if (auto* inspector = m_channel->channelInspector()) { // auto utf8Message = message.utf8(); // inspector->didReceiveWebSocketFrame(WebSocketChannelInspector::createFrame(utf8Message.dataAsUInt8Ptr(), utf8Message.length(), WebSocketFrame::OpCode::OpCodeText)); @@ -1075,7 +1075,7 @@ void WebSocket::didReceiveBinaryData(const AtomString& eventName, const std::spa if (m_state != OPEN) return; - // if (UNLIKELY(InspectorInstrumentation::hasFrontends())) { + // if (InspectorInstrumentation::hasFrontends()) [[unlikely]] { // if (auto* inspector = m_channel->channelInspector()) // inspector->didReceiveWebSocketFrame(WebSocketChannelInspector::createFrame(binaryData.data(), binaryData.size(), WebSocketFrame::OpCode::OpCodeBinary)); // } @@ -1113,7 +1113,7 @@ void WebSocket::didReceiveBinaryData(const AtomString& eventName, const std::spa auto scope = DECLARE_CATCH_SCOPE(scriptExecutionContext()->vm()); JSUint8Array* buffer = createBuffer(scriptExecutionContext()->jsGlobalObject(), binaryData); - if (UNLIKELY(!buffer || scope.exception())) { + if (!buffer || scope.exception()) [[unlikely]] { scope.clearExceptionExceptTermination(); ErrorEvent::Init errorInit; @@ -1216,7 +1216,7 @@ void WebSocket::didClose(unsigned unhandledBufferedAmount, unsigned short code, // if (!m_channel) // return; - // if (UNLIKELY(InspectorInstrumentation::hasFrontends())) { + // if (InspectorInstrumentation::hasFrontends()) [[unlikely]] { // if (auto* inspector = m_channel->channelInspector()) { // WebSocketFrame closingFrame(WebSocketFrame::OpCodeClose, true, false, false); // inspector->didReceiveWebSocketFrame(closingFrame); diff --git a/src/bun.js/bindings/webcore/Worker.cpp b/src/bun.js/bindings/webcore/Worker.cpp index 5c0b9869fa..3a9ce55aab 100644 --- a/src/bun.js/bindings/webcore/Worker.cpp +++ b/src/bun.js/bindings/webcore/Worker.cpp @@ -594,7 +594,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionPostMessage, auto scope = DECLARE_THROW_SCOPE(vm); Zig::GlobalObject* globalObject = jsDynamicCast(leixcalGlobalObject); - if (UNLIKELY(!globalObject)) + if (!globalObject) [[unlikely]] return JSValue::encode(jsUndefined()); Worker* worker = WebWorker__getParentWorker(globalObject->bunVM()); diff --git a/src/bun.js/bindings/webcrypto/JSAesCbcCfbParams.cpp b/src/bun.js/bindings/webcrypto/JSAesCbcCfbParams.cpp index 621ab9a94f..4864b852b0 100644 --- a/src/bun.js/bindings/webcrypto/JSAesCbcCfbParams.cpp +++ b/src/bun.js/bindings/webcrypto/JSAesCbcCfbParams.cpp @@ -41,7 +41,7 @@ template<> CryptoAlgorithmAesCbcCfbParams convertDictionary CryptoAlgorithmAesCtrParams convertDictionary CryptoAlgorithmAesGcmParams convertDictionary CryptoAlgorithmAesKeyParams convertDictionary CryptoAesKeyAlgorithm convertDictionary(JSGlob auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp b/src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp index 5953adb817..e6b4c607f1 100644 --- a/src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp +++ b/src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp @@ -38,7 +38,7 @@ template<> CryptoAlgorithmParameters convertDictionary CryptoEcKeyAlgorithm convertDictionary(JSGlobal auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcrypto/JSCryptoHmacKeyAlgorithm.cpp b/src/bun.js/bindings/webcrypto/JSCryptoHmacKeyAlgorithm.cpp index 432d1a64cb..074107418a 100644 --- a/src/bun.js/bindings/webcrypto/JSCryptoHmacKeyAlgorithm.cpp +++ b/src/bun.js/bindings/webcrypto/JSCryptoHmacKeyAlgorithm.cpp @@ -42,7 +42,7 @@ template<> CryptoHmacKeyAlgorithm convertDictionary(JSGl auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcrypto/JSCryptoKey.cpp b/src/bun.js/bindings/webcrypto/JSCryptoKey.cpp index f0859052b0..200081ab58 100644 --- a/src/bun.js/bindings/webcrypto/JSCryptoKey.cpp +++ b/src/bun.js/bindings/webcrypto/JSCryptoKey.cpp @@ -93,7 +93,7 @@ template<> std::optional parseEnumeration(JSGl { "secret"_s, CryptoKey::Type::Secret }, }; static constexpr SortedArrayMap enumerationMapping { mappings }; - if (auto* enumerationValue = enumerationMapping.tryGet(stringValue); LIKELY(enumerationValue)) + if (auto* enumerationValue = enumerationMapping.tryGet(stringValue); enumerationValue) [[likely]] return *enumerationValue; return std::nullopt; } @@ -224,7 +224,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCryptoKeyConstructor, (JSGlobalObject * lexicalGlobal auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSCryptoKey::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -324,7 +324,7 @@ void JSCryptoKey::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) bool JSCryptoKeyOwner::isReachableFromOpaqueRoots(JSC::Handle handle, void* context, AbstractSlotVisitor& visitor, ASCIILiteral* reason) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Reachable from CryptoKey"_s; return visitor.containsOpaqueRoot(context); } diff --git a/src/bun.js/bindings/webcrypto/JSCryptoKeyAlgorithm.cpp b/src/bun.js/bindings/webcrypto/JSCryptoKeyAlgorithm.cpp index c9291dd657..7dbcc5a56e 100644 --- a/src/bun.js/bindings/webcrypto/JSCryptoKeyAlgorithm.cpp +++ b/src/bun.js/bindings/webcrypto/JSCryptoKeyAlgorithm.cpp @@ -40,7 +40,7 @@ template<> CryptoKeyAlgorithm convertDictionary(JSGlobalObje auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcrypto/JSCryptoKeyPair.cpp b/src/bun.js/bindings/webcrypto/JSCryptoKeyPair.cpp index f5476207eb..7b148ac182 100644 --- a/src/bun.js/bindings/webcrypto/JSCryptoKeyPair.cpp +++ b/src/bun.js/bindings/webcrypto/JSCryptoKeyPair.cpp @@ -41,7 +41,7 @@ template<> CryptoKeyPair convertDictionary(JSGlobalObject& lexica auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcrypto/JSCryptoKeyUsage.cpp b/src/bun.js/bindings/webcrypto/JSCryptoKeyUsage.cpp index 742f63ea6e..53fc4ff733 100644 --- a/src/bun.js/bindings/webcrypto/JSCryptoKeyUsage.cpp +++ b/src/bun.js/bindings/webcrypto/JSCryptoKeyUsage.cpp @@ -75,7 +75,7 @@ template<> std::optional parseEnumeration(JSGlob { "wrapKey"_s, CryptoKeyUsage::WrapKey }, }; static constexpr SortedArrayMap enumerationMapping { mappings }; - if (auto* enumerationValue = enumerationMapping.tryGet(stringValue); LIKELY(enumerationValue)) + if (auto* enumerationValue = enumerationMapping.tryGet(stringValue); enumerationValue) [[likely]] return *enumerationValue; return std::nullopt; } diff --git a/src/bun.js/bindings/webcrypto/JSCryptoRsaHashedKeyAlgorithm.cpp b/src/bun.js/bindings/webcrypto/JSCryptoRsaHashedKeyAlgorithm.cpp index 52e9e84e2b..518ed8230a 100644 --- a/src/bun.js/bindings/webcrypto/JSCryptoRsaHashedKeyAlgorithm.cpp +++ b/src/bun.js/bindings/webcrypto/JSCryptoRsaHashedKeyAlgorithm.cpp @@ -43,7 +43,7 @@ template<> CryptoRsaHashedKeyAlgorithm convertDictionary CryptoRsaKeyAlgorithm convertDictionary(JSGlob auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcrypto/JSEcKeyParams.cpp b/src/bun.js/bindings/webcrypto/JSEcKeyParams.cpp index b3a60384ea..91ee9a78e3 100644 --- a/src/bun.js/bindings/webcrypto/JSEcKeyParams.cpp +++ b/src/bun.js/bindings/webcrypto/JSEcKeyParams.cpp @@ -38,7 +38,7 @@ template<> CryptoAlgorithmEcKeyParams convertDictionary CryptoAlgorithmEcdhKeyDeriveParams convertDictionary CryptoAlgorithmEcdsaParams convertDictionary CryptoAlgorithmHkdfParams convertDictionary CryptoAlgorithmHmacKeyParams convertDictionary JsonWebKey convertDictionary(JSGlobalObject& lexicalGloba auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcrypto/JSPbkdf2Params.cpp b/src/bun.js/bindings/webcrypto/JSPbkdf2Params.cpp index 81d0db21bc..79d7398577 100644 --- a/src/bun.js/bindings/webcrypto/JSPbkdf2Params.cpp +++ b/src/bun.js/bindings/webcrypto/JSPbkdf2Params.cpp @@ -43,7 +43,7 @@ template<> CryptoAlgorithmPbkdf2Params convertDictionary CryptoAlgorithmRsaHashedImportParams convertDictionary CryptoAlgorithmRsaHashedKeyGenParams convertDictionary CryptoAlgorithmRsaKeyGenParams convertDictionary CryptoAlgorithmRsaOaepParams convertDictionary RsaOtherPrimesInfo convertDictionary(JSGlobalObje auto throwScope = DECLARE_THROW_SCOPE(vm); bool isNullOrUndefined = value.isUndefinedOrNull(); auto* object = isNullOrUndefined ? nullptr : value.getObject(); - if (UNLIKELY(!isNullOrUndefined && !object)) { + if (!isNullOrUndefined && !object) [[unlikely]] { throwTypeError(&lexicalGlobalObject, throwScope); return {}; } diff --git a/src/bun.js/bindings/webcrypto/JSRsaPssParams.cpp b/src/bun.js/bindings/webcrypto/JSRsaPssParams.cpp index 470b9527c5..f14843a38f 100644 --- a/src/bun.js/bindings/webcrypto/JSRsaPssParams.cpp +++ b/src/bun.js/bindings/webcrypto/JSRsaPssParams.cpp @@ -39,7 +39,7 @@ template<> CryptoAlgorithmRsaPssParams convertDictionary std::optional parseEnumeration(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] return throwVMTypeError(lexicalGlobalObject, throwScope); return JSValue::encode(JSSubtleCrypto::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); } @@ -265,7 +265,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_encryptBody(JS UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 3)) + if (callFrame->argumentCount() < 3) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto algorithm = convert>(*lexicalGlobalObject, argument0.value()); @@ -291,7 +291,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_decryptBody(JS UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 3)) + if (callFrame->argumentCount() < 3) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto algorithm = convert>(*lexicalGlobalObject, argument0.value()); @@ -317,7 +317,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_signBody(JSC:: UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 3)) + if (callFrame->argumentCount() < 3) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto algorithm = convert>(*lexicalGlobalObject, argument0.value()); @@ -343,7 +343,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_verifyBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 4)) + if (callFrame->argumentCount() < 4) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto algorithm = convert>(*lexicalGlobalObject, argument0.value()); @@ -372,14 +372,14 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_digestBody(JSC UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto algorithm = convert>(*lexicalGlobalObject, argument0.value()); RETURN_IF_EXCEPTION(throwScope, {}); EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1); auto data = convert>(*lexicalGlobalObject, argument1.value()); - if (UNLIKELY(throwScope.exception())) { + if (throwScope.exception()) [[unlikely]] { throwScope.clearException(); return Bun::ERR::INVALID_ARG_TYPE(throwScope, lexicalGlobalObject, "data"_s, "ArrayBuffer, Buffer, TypedArray, or DataView"_s, argument1.value()); } @@ -398,7 +398,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_generateKeyBod UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 3)) + if (callFrame->argumentCount() < 3) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto algorithm = convert>(*lexicalGlobalObject, argument0.value()); @@ -424,7 +424,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_deriveKeyBody( UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 5)) + if (callFrame->argumentCount() < 5) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto algorithm = convert>(*lexicalGlobalObject, argument0.value()); @@ -456,7 +456,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_deriveBitsBody UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 3)) + if (callFrame->argumentCount() < 3) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto algorithm = convert>(*lexicalGlobalObject, argument0.value()); @@ -482,7 +482,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_importKeyBody( UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 5)) + if (callFrame->argumentCount() < 5) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto format = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeEnumError(lexicalGlobalObject, scope, 0, "format"_s, "SubtleCrypto"_s, "importKey"_s, expectedEnumerationValues()); }); @@ -514,7 +514,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_exportKeyBody( UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 2)) + if (callFrame->argumentCount() < 2) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto format = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeEnumError(lexicalGlobalObject, scope, 0, "format"_s, "SubtleCrypto"_s, "exportKey"_s, expectedEnumerationValues()); }); @@ -539,7 +539,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_wrapKeyBody(JS UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 4)) + if (callFrame->argumentCount() < 4) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto format = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeEnumError(lexicalGlobalObject, scope, 0, "format"_s, "SubtleCrypto"_s, "wrapKey"_s, expectedEnumerationValues()); }); @@ -568,7 +568,7 @@ static inline JSC::EncodedJSValue jsSubtleCryptoPrototypeFunction_unwrapKeyBody( UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); - if (UNLIKELY(callFrame->argumentCount() < 7)) + if (callFrame->argumentCount() < 7) [[unlikely]] return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto format = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeEnumError(lexicalGlobalObject, scope, 0, "format"_s, "SubtleCrypto"_s, "unwrapKey"_s, expectedEnumerationValues()); }); @@ -624,7 +624,7 @@ bool JSSubtleCryptoOwner::isReachableFromOpaqueRoots(JSC::Handle h ScriptExecutionContext* owner = WTF::getPtr(jsSubtleCrypto->wrapped().scriptExecutionContext()); if (!owner) return false; - if (UNLIKELY(reason)) + if (reason) [[unlikely]] *reason = "Reachable from ScriptExecutionContext"_s; return visitor.containsOpaqueRoot(context); } diff --git a/src/bun.js/bindings/webcrypto/SubtleCrypto.cpp b/src/bun.js/bindings/webcrypto/SubtleCrypto.cpp index bc4bb50557..0c8c4cfe3f 100644 --- a/src/bun.js/bindings/webcrypto/SubtleCrypto.cpp +++ b/src/bun.js/bindings/webcrypto/SubtleCrypto.cpp @@ -124,7 +124,7 @@ static ExceptionOr> normalizeCryptoAl RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError }); auto identifier = CryptoAlgorithmRegistry::singleton().identifier(params.name); - if (UNLIKELY(!identifier)) + if (!identifier) [[unlikely]] return Exception { NotSupportedError }; if (*identifier == CryptoAlgorithmIdentifier::Ed25519 && !isSafeCurvesEnabled(state)) @@ -1171,13 +1171,13 @@ void SubtleCrypto::unwrapKey(JSC::JSGlobalObject& state, KeyFormat format, Buffe } auto importAlgorithm = CryptoAlgorithmRegistry::singleton().create(unwrappedKeyAlgorithm->identifier); - if (UNLIKELY(!importAlgorithm)) { + if (!importAlgorithm) [[unlikely]] { promise->reject(Exception { NotSupportedError }); return; } auto unwrapAlgorithm = CryptoAlgorithmRegistry::singleton().create(unwrappingKey.algorithmIdentifier()); - if (UNLIKELY(!unwrapAlgorithm)) { + if (!unwrapAlgorithm) [[unlikely]] { promise->reject(Exception { NotSupportedError }); return; } diff --git a/src/bun.js/modules/BunJSCModule.h b/src/bun.js/modules/BunJSCModule.h index dd8b050951..5270e921bc 100644 --- a/src/bun.js/modules/BunJSCModule.h +++ b/src/bun.js/modules/BunJSCModule.h @@ -246,12 +246,12 @@ JSC_DEFINE_HOST_FUNCTION(functionMemoryUsageStatistics, unsigned size = std::min(left.length(), right.length()); left = left.substring(0, size); right = right.substring(0, size); - int result = WTF::codePointCompare(right, left); - if (result == 0) { + std::strong_ordering result = WTF::codePointCompare(right, left); + if (result == std::strong_ordering::equal) { return originalLeftLength > originalRightLength; } - return result > 0; + return result == std::strong_ordering::greater; } return a.second > b.second; diff --git a/src/bun.js/modules/NodeBufferModule.h b/src/bun.js/modules/NodeBufferModule.h index 8695100999..eba221af55 100644 --- a/src/bun.js/modules/NodeBufferModule.h +++ b/src/bun.js/modules/NodeBufferModule.h @@ -26,7 +26,7 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isUtf8, const char* ptr = nullptr; size_t byteLength = 0; if (bufferView) { - if (UNLIKELY(bufferView->isDetached())) { + if (bufferView->isDetached()) [[unlikely]] { throwTypeError(lexicalGlobalObject, throwScope, "ArrayBufferView is detached"_s); return {}; @@ -46,7 +46,7 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isUtf8, return JSValue::encode(jsBoolean(true)); } - if (UNLIKELY(impl->isDetached())) { + if (impl->isDetached()) [[unlikely]] { return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject, "Cannot validate on a detached buffer"_s); } @@ -81,7 +81,7 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isAscii, size_t byteLength = 0; if (bufferView) { - if (UNLIKELY(bufferView->isDetached())) { + if (bufferView->isDetached()) [[unlikely]] { return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject, "Cannot validate on a detached buffer"_s); } @@ -95,7 +95,7 @@ JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isAscii, ptr = reinterpret_cast(bufferView->vector()); } else if (auto* arrayBuffer = JSC::jsDynamicCast(buffer)) { auto* impl = arrayBuffer->impl(); - if (UNLIKELY(impl->isDetached())) { + if (impl->isDetached()) [[unlikely]] { return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject, "Cannot validate on a detached buffer"_s); } diff --git a/src/bun.js/modules/NodeModuleModule.cpp b/src/bun.js/modules/NodeModuleModule.cpp index f296dbb207..8b9abda5a9 100644 --- a/src/bun.js/modules/NodeModuleModule.cpp +++ b/src/bun.js/modules/NodeModuleModule.cpp @@ -1034,11 +1034,11 @@ void generateNativeModule_NodeModule(JSC::JSGlobalObject* lexicalGlobalObject, const auto& property = Identifier::fromString(vm, entry.m_key); JSValue value = constructor->getIfPropertyExists(globalObject, property); - if (UNLIKELY(catchScope.exception())) { + if (catchScope.exception()) [[unlikely]] { value = {}; catchScope.clearException(); } - if (UNLIKELY(value.isEmpty())) { + if (value.isEmpty()) [[unlikely]] { value = JSC::jsUndefined(); } diff --git a/src/bun.js/modules/NodeUtilTypesModule.cpp b/src/bun.js/modules/NodeUtilTypesModule.cpp index 2e5574ac60..e3217555a4 100644 --- a/src/bun.js/modules/NodeUtilTypesModule.cpp +++ b/src/bun.js/modules/NodeUtilTypesModule.cpp @@ -132,7 +132,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionIsError, JSValue value = slot.getValue(globalObject, vm.propertyNames->toStringTagSymbol); if (value.isString()) { String tag = asString(value)->value(globalObject); - if (UNLIKELY(scope.exception())) + if (scope.exception()) [[unlikely]] scope.clearException(); if (tag == "Error"_s) return JSValue::encode(jsBoolean(true)); diff --git a/src/codegen/bindgen.ts b/src/codegen/bindgen.ts index 10d09e9d6c..271be57437 100644 --- a/src/codegen/bindgen.ts +++ b/src/codegen/bindgen.ts @@ -593,7 +593,7 @@ function emitConvertDictionaryFunction(type: TypeImpl) { cpp.line(`auto throwScope = DECLARE_THROW_SCOPE(vm);`); cpp.line(`bool isNullOrUndefined = value.isUndefinedOrNull();`); cpp.line(`auto* object = isNullOrUndefined ? nullptr : value.getObject();`); - cpp.line(`if (UNLIKELY(!isNullOrUndefined && !object)) {`); + cpp.line(`if (!isNullOrUndefined && !object) [[unlikely]] {`); cpp.line(` throwTypeError(global, throwScope);`); cpp.line(` return false;`); cpp.line(`}`); @@ -761,7 +761,7 @@ function emitConvertEnumFunction(w: CodeWriter, type: TypeImpl) { } w.line(` };`); w.line(` static constexpr SortedArrayMap enumerationMapping { mappings };`); - w.line(` if (auto* enumerationValue = enumerationMapping.tryGet(stringValue); LIKELY(enumerationValue))`); + w.line(` if (auto* enumerationValue = enumerationMapping.tryGet(stringValue); enumerationValue) [[likely]]`); w.line(` return *enumerationValue;`); w.line(` return std::nullopt;`); w.line(`}`); diff --git a/src/codegen/generate-classes.ts b/src/codegen/generate-classes.ts index 81d1d09c08..f0403b5f66 100644 --- a/src/codegen/generate-classes.ts +++ b/src/codegen/generate-classes.ts @@ -647,7 +647,7 @@ JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES ${name}::call(JSC::JSGlobalObject* auto scope = DECLARE_THROW_SCOPE(vm); void* ptr = ${classSymbolName(typeName, "construct")}(globalObject, callFrame); - if (UNLIKELY(!ptr || scope.exception())) { + if (!ptr || scope.exception()) [[unlikely]] { return JSValue::encode(JSC::jsUndefined()); } @@ -674,7 +674,7 @@ JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES ${name}::construct(JSC::JSGlobalObj JSObject* newTarget = asObject(callFrame->newTarget()); auto* constructor = globalObject->${className(typeName)}Constructor(); Structure* structure = globalObject->${className(typeName)}Structure(); - if (UNLIKELY(constructor != newTarget)) { + if (constructor != newTarget) [[unlikely]] { auto* functionGlobalObject = defaultGlobalObject( // ShadowRealm functions belong to a different global object. getFunctionRealm(globalObject, newTarget) @@ -689,7 +689,7 @@ JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES ${name}::construct(JSC::JSGlobalObj void* ptr = ${classSymbolName(typeName, "construct")}(globalObject, callFrame); - if (UNLIKELY(scope.exception())) { + if (scope.exception()) [[unlikely]] { ASSERT_WITH_MESSAGE(!ptr, "Memory leak detected: new ${typeName}() allocated memory without checking for exceptions."); return JSValue::encode(JSC::jsUndefined()); } @@ -1006,8 +1006,9 @@ JSC_DEFINE_CUSTOM_GETTER(js${typeName}Constructor, (JSGlobalObject * lexicalGlob auto* globalObject = reinterpret_cast(lexicalGlobalObject); auto* prototype = jsDynamicCast<${prototypeName(typeName)}*>(JSValue::decode(thisValue)); - if (UNLIKELY(!prototype)) + if (!prototype) [[unlikely]] { return throwVMTypeError(lexicalGlobalObject, throwScope, "Cannot get constructor for ${typeName}"_s); + } return JSValue::encode(globalObject->${className(typeName)}Constructor()); } @@ -1065,7 +1066,7 @@ JSC_DEFINE_CUSTOM_GETTER(${symbolName(typeName, name)}GetterWrap, (JSGlobalObjec auto& vm = JSC::getVM(globalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); ${className(typeName)}* thisObject = jsDynamicCast<${className(typeName)}*>(JSValue::decode(encodedThisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } @@ -1113,7 +1114,7 @@ JSC_DEFINE_CUSTOM_GETTER(${symbolName(typeName, name)}GetterWrap, (JSGlobalObjec Zig::GlobalObject *globalObject = reinterpret_cast(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); ${className(typeName)}* thisObject = jsDynamicCast<${className(typeName)}*>(JSValue::decode(encodedThisValue)); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { return JSValue::encode(jsUndefined()); } JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); @@ -1175,7 +1176,7 @@ JSC_DEFINE_HOST_FUNCTION(${symbolName(typeName, name)}Callback, (JSGlobalObject ${className(typeName)}* thisObject = jsDynamicCast<${className(typeName)}*>(callFrame->thisValue()); - if (UNLIKELY(!thisObject)) { + if (!thisObject) [[unlikely]] { ${ invalidThisBehavior == InvalidThisBehavior.Throw ? ` @@ -1291,8 +1292,9 @@ function generateClassHeader(typeName, obj: ClassDefinition) { { auto* controller = JSC::jsCast<${name}*>(handle.slot()->asCell()); if (${name}::hasPendingActivity(controller->wrapped())) { - if (UNLIKELY(reason)) + if (reason) [[unlikely]] { *reason = "has pending activity"_s; + } return true; } @@ -1560,7 +1562,7 @@ static JSC::JSValue construct${symbolName(obj.name, name)}PropertyCallback(JSC:: output += ` ${name}::~${name}() { - if (LIKELY(m_ctx)) { + if (m_ctx) [[likely]] { ${classSymbolName(typeName, "finalize")}(m_ctx); } } @@ -1653,7 +1655,7 @@ extern JSC_CALLCONV void* JSC_HOST_CALL_ATTRIBUTES ${typeName}__fromJSDirect(JSC Zig::GlobalObject* globalObject = jsDynamicCast(object->globalObject()); - if (UNLIKELY(globalObject == nullptr || cell->structureID() != globalObject->${className(typeName)}Structure()->id())) { + if (globalObject == nullptr || cell->structureID() != globalObject->${className(typeName)}Structure()->id()) [[unlikely]] { return nullptr; } diff --git a/src/codegen/generate-jssink.ts b/src/codegen/generate-jssink.ts index 73eb933afc..6727da7bcf 100644 --- a/src/codegen/generate-jssink.ts +++ b/src/codegen/generate-jssink.ts @@ -380,7 +380,7 @@ JSC_DEFINE_HOST_FUNCTION(functionStartDirectStream, (JSC::JSGlobalObject * lexic JSC_DEFINE_HOST_FUNCTION(${name}__ref, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame *callFrame)) { auto* sink = jsDynamicCast(callFrame->thisValue()); - if (LIKELY(sink)) { + if (sink) [[likely]] { sink->ref(); } return JSC::JSValue::encode(JSC::jsUndefined()); @@ -391,7 +391,7 @@ JSC_DEFINE_HOST_FUNCTION(${name}__ref, (JSC::JSGlobalObject * lexicalGlobalObjec JSC_DEFINE_HOST_FUNCTION(${name}__unref, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame *callFrame)) { auto* sink = jsDynamicCast(callFrame->thisValue()); - if (LIKELY(sink)) { + if (sink) [[likely]] { sink->unref(); } return JSC::JSValue::encode(JSC::jsUndefined()); diff --git a/src/io/io_darwin.cpp b/src/io/io_darwin.cpp index d3636801f9..04d14c6424 100644 --- a/src/io/io_darwin.cpp +++ b/src/io/io_darwin.cpp @@ -18,13 +18,13 @@ extern "C" mach_port_t io_darwin_create_machport(uint64_t wakeup, int32_t fd, mach_port_t self = mach_task_self(); kern_return_t kr = mach_port_allocate(self, MACH_PORT_RIGHT_RECEIVE, &port); - if (UNLIKELY(kr != KERN_SUCCESS)) { + if (kr != KERN_SUCCESS) [[unlikely]] { return 0; } // Insert a send right into the port since we also use this to send kr = mach_port_insert_right(self, port, port, MACH_MSG_TYPE_MAKE_SEND); - if (UNLIKELY(kr != KERN_SUCCESS)) { + if (kr != KERN_SUCCESS) [[unlikely]] { return 0; } @@ -35,7 +35,7 @@ extern "C" mach_port_t io_darwin_create_machport(uint64_t wakeup, int32_t fd, (mach_port_info_t)&limits, MACH_PORT_LIMITS_INFO_COUNT); - if (UNLIKELY(kr != KERN_SUCCESS)) { + if (kr != KERN_SUCCESS) [[unlikely]] { return 0; } diff --git a/src/js/builtins/BunBuiltinNames.h b/src/js/builtins/BunBuiltinNames.h index b61eb33e02..c505c166dc 100644 --- a/src/js/builtins/BunBuiltinNames.h +++ b/src/js/builtins/BunBuiltinNames.h @@ -300,7 +300,7 @@ public: const JSC::Identifier& resolvePublicName() const { return m_vm.propertyNames->resolve;} const JSC::Identifier& inspectCustomPublicName() { - if (UNLIKELY(m_inspectCustomPublicName.isEmpty())) { + if (m_inspectCustomPublicName.isEmpty()) [[unlikely]] { m_inspectCustomPublicName = Identifier::fromUid(m_vm.symbolRegistry().symbolForKey("nodejs.util.inspect.custom"_s)); } return m_inspectCustomPublicName; diff --git a/test/js/node/buffer.test.js b/test/js/node/buffer.test.js index 9236a7bd27..8918d46f31 100644 --- a/test/js/node/buffer.test.js +++ b/test/js/node/buffer.test.js @@ -314,6 +314,22 @@ for (let withOverridenBufferWrite of [false, true]) { Buffer.alloc(1).write("", 1, 0); }); + it("write BigInt beyond 64-bit range", () => { + const b = Buffer.allocUnsafe(64); + for (const signedFunction of ["writeBigInt64BE", "writeBigInt64LE"]) { + expect(() => b[signedFunction](-(2n ** 63n) - 1n)).toThrow(RangeError); + expect(() => b[signedFunction](2n ** 63n)).toThrow(RangeError); + expect(() => b[signedFunction](-(2n ** 65n))).toThrow(RangeError); + expect(() => b[signedFunction](2n ** 65n)).toThrow(RangeError); + } + for (const unsignedFunction of ["writeBigUInt64BE", "writeBigUInt64LE"]) { + expect(() => b[unsignedFunction](-1n)).toThrow(RangeError); + expect(() => b[unsignedFunction](2n ** 64n)).toThrow(RangeError); + expect(() => b[unsignedFunction](-(2n ** 65n))).toThrow(RangeError); + expect(() => b[unsignedFunction](2n ** 65n)).toThrow(RangeError); + } + }); + it("copy() beyond end of buffer", () => { const b = Buffer.allocUnsafe(64); // Try to copy 0 bytes worth of data into an empty buffer