diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 102ae36cd8..74187f9fba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,13 @@ jobs: name: Lint uses: ./.github/workflows/run-lint.yml secrets: inherit + lint-cpp: + if: ${{ !inputs.run-id }} + name: Lint C++ + uses: ./.github/workflows/run-lint-cpp.yml + secrets: inherit + with: + pr-number: ${{ github.event.number }} linux-x64: if: ${{ !inputs.run-id }} name: Build linux-x64 diff --git a/.github/workflows/comment-lint.yml b/.github/workflows/comment-lint.yml new file mode 100644 index 0000000000..dc16b19d32 --- /dev/null +++ b/.github/workflows/comment-lint.yml @@ -0,0 +1,80 @@ +name: Comment Lint + +permissions: + actions: read + pull-requests: write + +on: + workflow_run: + workflows: + - Lint C++ + types: + - completed + +jobs: + comment-lint: + if: ${{ github.repository_owner == 'oven-sh' }} + name: Comment + runs-on: ubuntu-latest + steps: + - name: Download Comment + uses: actions/download-artifact@v4 + with: + name: format.log + github-token: ${{ github.token }} + run-id: ${{ github.event.workflow_run.id }} + - name: PR Number + uses: actions/download-artifact@v4 + with: + name: pr-number.txt + github-token: ${{ github.token }} + run-id: ${{ github.event.workflow_run.id }} + - name: Did Fail + uses: actions/download-artifact@v4 + with: + name: did_fail.txt + github-token: ${{ github.token }} + run-id: ${{ github.event.workflow_run.id }} + - name: Setup Environment + id: env + shell: bash + run: | + # Copy to outputs + echo "pr-number=$(cat pr-number.txt)" >> $GITHUB_OUTPUT + echo "text_output=$(cat format.log)" >> $GITHUB_OUTPUT + echo "did_fail=$(cat did_fail.txt)" >> $GITHUB_OUTPUT + + - name: Find Comment + id: comment + uses: peter-evans/find-comment@v3 + with: + issue-number: ${{ steps.env.outputs.pr-number }} + comment-author: github-actions[bot] + body-includes: + - name: Update Comment + uses: peter-evans/create-or-update-comment@v4 + if: steps.env.outputs.did_fail != '0' + with: + comment-id: ${{ steps.comment.outputs.comment-id }} + issue-number: ${{ steps.env.outputs.pr-number }} + body: | + @${{ github.actor }}, C++ linting failed! + + Logs: + ```cpp + ${{ steps.env.outputs.text_output }} + ``` + + + edit-mode: replace + - name: Update Previous Comment + uses: peter-evans/create-or-update-comment@v4 + if: steps.env.outputs.did_fail == '0' && steps.comment.outputs.comment-id != '' + with: + comment-id: ${{ steps.comment.outputs.comment-id }} + issue-number: ${{ steps.env.outputs.pr-number }} + body: | + @${{ github.actor }}, C++ lint errors fixed! Thank you. + + + edit-mode: replace diff --git a/.github/workflows/comment.yml b/.github/workflows/comment.yml index 261ae622e6..3c798e8fcc 100644 --- a/.github/workflows/comment.yml +++ b/.github/workflows/comment.yml @@ -53,69 +53,3 @@ jobs: issue-number: ${{ steps.env.outputs.pr-number }} body-path: comment.md edit-mode: replace - comment-lint: - if: ${{ github.repository_owner == 'oven-sh' }} - name: Comment - runs-on: ubuntu-latest - steps: - - name: Download Comment - uses: actions/download-artifact@v4 - with: - name: format.log - github-token: ${{ github.token }} - run-id: ${{ github.event.workflow_run.id }} - - name: PR Number - uses: actions/download-artifact@v4 - with: - name: pr-number.txt - github-token: ${{ github.token }} - run-id: ${{ github.event.workflow_run.id }} - - name: PR Number - uses: actions/download-artifact@v4 - with: - name: did_fail.txt - github-token: ${{ github.token }} - run-id: ${{ github.event.workflow_run.id }} - - name: Setup Environment - id: env - shell: bash - run: | - # Copy to outputs - echo "pr-number=$(> $GITHUB_OUTPUT - echo "text_output=$(> $GITHUB_OUTPUT - echo "did_fail=$(> $GITHUB_OUTPUT - - - name: Find Comment - id: comment - uses: peter-evans/find-comment@v3 - with: - issue-number: ${{ steps.env.outputs.pr-number }} - comment-author: github-actions[bot] - body-includes: - - name: Update Comment - uses: peter-evans/create-or-update-comment@v4 - if: steps.env.outputs.did_fail != '0' - with: - comment-id: ${{ steps.comment.outputs.comment-id }} - issue-number: ${{ steps.env.outputs.pr-number }} - body: | - @${{ github.actor }}, C++ linting failed! - - Logs: - ```cpp - ${{ steps.env.outputs.text_output }} - ``` - - - edit-mode: replace - - name: Update Previous Comment - uses: peter-evans/create-or-update-comment@v4 - if: steps.env.outputs.did_fail == '0' && steps.comment.outputs.comment-id != '' - with: - comment-id: ${{ steps.comment.outputs.comment-id }} - issue-number: ${{ steps.env.outputs.pr-number }} - body: | - @${{ github.actor }}, C++ lint errors fixed! Thank you. - - - edit-mode: replace diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3d7dd5c52f..8656fa44af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,6 +65,8 @@ jobs: with: bun-version: "1.0.21" - name: Install Dependencies + run: apt update && apt install -y llvm-16-dev libclang-16-dev clang-16 libssl-dev libxml2-dev build-essential ninja-build cmake + - name: Install npm dependencies run: bun install - name: Sign Release run: | diff --git a/.github/workflows/run-lint-cpp.yml b/.github/workflows/run-lint-cpp.yml new file mode 100644 index 0000000000..02dc7b0255 --- /dev/null +++ b/.github/workflows/run-lint-cpp.yml @@ -0,0 +1,81 @@ +name: Lint C++ + +permissions: + contents: read + actions: write +env: + LLVM_VERSION: 16 + +on: + workflow_call: + inputs: + pr-number: + required: true + type: number + +jobs: + lint-cpp: + name: Lint C++ + runs-on: ${{ github.repository_owner == 'oven-sh' && 'namespace-profile-bun-ci-darwin-aarch64' || 'macos-12' }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + - name: Setup Bun + uses: ./.github/actions/setup-bun + with: + bun-version: latest + - name: Install Dependencies + env: + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_CLEANUP: 1 + run: | + brew install \ + llvm@${{ env.LLVM_VERSION }} \ + ninja \ + coreutils \ + openssl@1.1 \ + libiconv \ + gnu-sed --force --overwrite + echo "$(brew --prefix coreutils)/libexec/gnubin" >> $GITHUB_PATH + echo "$(brew --prefix llvm@$LLVM_VERSION)/bin" >> $GITHUB_PATH + brew link --overwrite llvm@$LLVM_VERSION + - name: Bun install + run: | + bun install + - name: Format + id: format + env: + CPU_TARGET: native + run: | + rm -f did_fail format.log + bun build:tidy &2>1 | tee format.log && echo 0 > did_succeed.txt + # Upload format.log as github artifact for the workflow + echo "text_output=$(cat format.log || echo 0)" >> $GITHUB_OUTPUT + if [ -f did_succeed.txt ]; then + echo "0" > did_fail.txt + else + echo "1" > did_fail.txt + fi + echo "did_fail=$(cat did_fail.txt)" >> $GITHUB_OUTPUT + echo "${{ inputs.pr-number }}" > pr-number.txt + - name: Upload format.log + uses: actions/upload-artifact@v2 + with: + name: format.log + path: format.log + - name: Upload PR + uses: actions/upload-artifact@v2 + with: + name: pr-number.txt + path: pr-number.txt + - name: Upload PR + uses: actions/upload-artifact@v2 + with: + name: did_fail.txt + path: did_fail.txt + - name: Fail the build + if: steps.format.outputs.did_fail == '1' + run: exit 1 diff --git a/.github/workflows/run-lint.yml b/.github/workflows/run-lint.yml index 75316ba1e4..1147631c3c 100644 --- a/.github/workflows/run-lint.yml +++ b/.github/workflows/run-lint.yml @@ -2,6 +2,9 @@ name: Lint permissions: contents: read + actions: write +env: + LLVM_VERSION: 16 on: workflow_call: diff --git a/CMakeLists.txt b/CMakeLists.txt index 687f4457d6..2397d442ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -317,6 +317,10 @@ option(USE_STATIC_LIBATOMIC "Statically link libatomic, requires the presence of option(USE_LTO "Enable Link-Time Optimization" ${DEFAULT_LTO}) +option(BUN_TIDY_ONLY "Only run clang-tidy" OFF) +option(BUN_TIDY_ONLY_EXTRA " Only run clang-tidy, with extra checks for local development" OFF) + + if(NOT ZIG_LIB_DIR) cmake_path(SET ZIG_LIB_DIR NORMALIZE "${CMAKE_CURRENT_SOURCE_DIR}/src/deps/zig/lib") endif() @@ -413,7 +417,7 @@ if(ZIG_COMPILER) find_program(ZIG_COMPILER_ zig ${REQUIRED_IF_NOT_ONLY_CPP_OR_LINK} DOC "Path to the Zig compiler" VALIDATOR validate_zig) set(ZIG_COMPILER "${ZIG_COMPILER_}") message(STATUS "Found Zig Compiler: ${ZIG_COMPILER}") -elseif(NOT BUN_CPP_ONLY AND NOT BUN_LINK_ONLY) +elseif(NOT BUN_CPP_ONLY AND NOT BUN_LINK_ONLY AND NOT BUN_TIDY_ONLY AND NOT BUN_TIDY_ONLY_EXTRA) execute_process( COMMAND "${SHELL}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/download-zig.${SCRIPT_EXTENSION}" @@ -915,7 +919,9 @@ if(WIN32) endif() # -- The Buntime™️ --- -if(NOT BUN_CPP_ONLY) +if(BUN_TIDY_ONLY OR BUN_TIDY_ONLY_EXTRA) + add_library(${bun} OBJECT "${BUN_SOURCES}") +elseif(NOT BUN_CPP_ONLY) add_executable(${bun} "${BUN_SOURCES}" "${BUN_ZIG_OBJ}") else() add_executable(${bun} "${BUN_SOURCES}") @@ -1433,3 +1439,15 @@ endif() if(NO_CODEGEN) message(STATUS "NOTE: NO_CODEGEN is ON, this build expects ./codegen to exist") endif() + +if(BUN_TIDY_ONLY) + find_program(CLANG_TIDY_EXE NAMES "clang-tidy") + set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "-checks=-*,clang-analyzer-*,-clang-analyzer-webkit.UncountedLambdaCapturesChecker" "--fix" "--fix-errors" "--format-style=webkit" "--warnings-as-errors=*") + set_target_properties(${bun} PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") +endif() + +if (BUN_TIDY_ONLY_EXTRA) + find_program(CLANG_TIDY_EXE NAMES "clang-tidy") + set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "-checks=-*,clang-analyzer-*,performance-*,-clang-analyzer-webkit.UncountedLambdaCapturesChecker" "--fix" "--fix-errors" "--format-style=webkit" "--warnings-as-errors=*") + set_target_properties(${bun} PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") +endif() \ No newline at end of file diff --git a/package.json b/package.json index dc022bdd36..11a68a7e1f 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,8 @@ "bump": "bun ./scripts/bump.ts", "build": "if [ ! -e build ]; then bun setup; fi && ninja -C build", "build:valgrind": "cmake . -DZIG_OPTIMIZE=Debug -DUSE_DEBUG_JSC=ON -DCMAKE_BUILD_TYPE=Debug -GNinja -Bbuild-valgrind && ninja -Cbuild-valgrind", + "build:tidy": "cmake . -DZIG_OPTIMIZE=Debug -DUSE_DEBUG_JSC=ON -DBUN_TIDY_ONLY=ON -DCMAKE_BUILD_TYPE=Debug -GNinja -Bbuild-tidy && ninja -Cbuild-tidy", + "build:tidy-extra": "cmake . -DZIG_OPTIMIZE=Debug -DUSE_DEBUG_JSC=ON -DBUN_TIDY_ONLY_EXTRA=ON -DCMAKE_BUILD_TYPE=Debug -GNinja -Bbuild-tidy && ninja -Cbuild-tidy", "build:release": "cmake . -DCMAKE_BUILD_TYPE=Release -GNinja -Bbuild-release && ninja -Cbuild-release", "build:debug-zig-release": "cmake . -DCMAKE_BUILD_TYPE=Release -DZIG_OPTIMIZE=Debug -GNinja -Bbuild-debug-zig-release && ninja -Cbuild-debug-zig-release", "build:safe": "cmake . -DZIG_OPTIMIZE=ReleaseSafe -DUSE_DEBUG_JSC=ON -DCMAKE_BUILD_TYPE=Release -GNinja -Bbuild-safe && ninja -Cbuild-safe", diff --git a/packages/bun-usockets/src/crypto/sni_tree.cpp b/packages/bun-usockets/src/crypto/sni_tree.cpp index fbe0d38d72..d824c8daa7 100644 --- a/packages/bun-usockets/src/crypto/sni_tree.cpp +++ b/packages/bun-usockets/src/crypto/sni_tree.cpp @@ -146,7 +146,7 @@ extern "C" { memcpy(labelString, label.data(), label.length()); it = root->children.emplace(std::string_view((char *) labelString, label.length()), - std::make_unique()).first; + std::make_unique()).first; // NOLINT(clang-analyzer-unix.Malloc) } root = it->second.get(); diff --git a/packages/bun-uws/src/App.h b/packages/bun-uws/src/App.h index 9908a00fe9..68e56c80a2 100644 --- a/packages/bun-uws/src/App.h +++ b/packages/bun-uws/src/App.h @@ -208,12 +208,11 @@ public: /* Delete TopicTree */ if (topicTree) { - delete topicTree; - /* And unregister loop callbacks */ /* We must unregister any loop post handler here */ Loop::get()->removePostHandler(topicTree); Loop::get()->removePreHandler(topicTree); + delete topicTree; } } diff --git a/src/bun.js/bindings/BunInjectedScriptHost.cpp b/src/bun.js/bindings/BunInjectedScriptHost.cpp index f36e4a3e42..d209133300 100644 --- a/src/bun.js/bindings/BunInjectedScriptHost.cpp +++ b/src/bun.js/bindings/BunInjectedScriptHost.cpp @@ -38,7 +38,7 @@ static JSObject* constructInternalProperty(VM& vm, JSGlobalObject* exec, const S return object; } -static JSObject* constructInternalProperty(VM& vm, JSGlobalObject* exec, Identifier name, JSValue value) +static JSObject* constructInternalProperty(VM& vm, JSGlobalObject* exec, const Identifier& name, JSValue value) { auto* object = constructEmptyObject(exec); object->putDirect(vm, Identifier::fromString(vm, "name"_s), JSC::identifierToJSValue(vm, name)); diff --git a/src/bun.js/bindings/BunPlugin.cpp b/src/bun.js/bindings/BunPlugin.cpp index 42adf0d640..d30185f781 100644 --- a/src/bun.js/bindings/BunPlugin.cpp +++ b/src/bun.js/bindings/BunPlugin.cpp @@ -288,13 +288,7 @@ extern "C" JSC::EncodedJSValue setupBunPlugin(JSC::JSGlobalObject* globalObject, if (JSValue targetValue = obj->getIfPropertyExists(globalObject, Identifier::fromString(vm, "target"_s))) { if (auto* targetJSString = targetValue.toStringOrNull(globalObject)) { auto targetString = targetJSString->value(globalObject); - if (targetString == "node"_s) { - target = BunPluginTargetNode; - } else if (targetString == "bun"_s) { - target = BunPluginTargetBun; - } else if (targetString == "browser"_s) { - target = BunPluginTargetBrowser; - } else { + if (!(targetString == "node"_s || targetString == "bun"_s || targetString == "browser"_s)) { JSC::throwTypeError(globalObject, throwScope, "plugin target must be one of 'node', 'bun' or 'browser'"_s); return JSValue::encode(jsUndefined()); } diff --git a/src/bun.js/bindings/BunProcess.cpp b/src/bun.js/bindings/BunProcess.cpp index 678c33b5d9..a0be11e653 100644 --- a/src/bun.js/bindings/BunProcess.cpp +++ b/src/bun.js/bindings/BunProcess.cpp @@ -1603,7 +1603,7 @@ static JSValue constructReportObjectComplete(VM& vm, Zig::GlobalObject* globalOb JSC::JSArray* stackArray = JSC::constructEmptyArray(globalObject, nullptr); - stack.split('\n', [&](WTF::StringView line) { + stack.split('\n', [&](const WTF::StringView& line) { stackArray->push(globalObject, JSC::jsString(vm, line.toString().trim(isASCIIWhitespace))); }); diff --git a/src/bun.js/bindings/CommonJSModuleRecord.cpp b/src/bun.js/bindings/CommonJSModuleRecord.cpp index eee6d08586..ab8bb91e4f 100644 --- a/src/bun.js/bindings/CommonJSModuleRecord.cpp +++ b/src/bun.js/bindings/CommonJSModuleRecord.cpp @@ -872,7 +872,7 @@ void populateESMExports( } void JSCommonJSModule::toSyntheticSource(JSC::JSGlobalObject* globalObject, - JSC::Identifier moduleKey, + const JSC::Identifier& moduleKey, Vector& exportNames, JSC::MarkedArgumentBuffer& exportValues) { @@ -1081,7 +1081,7 @@ std::optional createCommonJSModule( return JSC::SourceCode( JSC::SyntheticSourceProvider::create( [](JSC::JSGlobalObject* lexicalGlobalObject, - JSC::Identifier moduleKey, + const JSC::Identifier& moduleKey, Vector& exportNames, JSC::MarkedArgumentBuffer& exportValues) -> void { auto* globalObject = jsCast(lexicalGlobalObject); diff --git a/src/bun.js/bindings/CommonJSModuleRecord.h b/src/bun.js/bindings/CommonJSModuleRecord.h index ec95645231..8e8459836c 100644 --- a/src/bun.js/bindings/CommonJSModuleRecord.h +++ b/src/bun.js/bindings/CommonJSModuleRecord.h @@ -78,7 +78,7 @@ public: static JSObject* createBoundRequireFunction(VM& vm, JSGlobalObject* lexicalGlobalObject, const WTF::String& pathString); void toSyntheticSource(JSC::JSGlobalObject* globalObject, - JSC::Identifier moduleKey, + const JSC::Identifier& moduleKey, Vector& exportNames, JSC::MarkedArgumentBuffer& exportValues); diff --git a/src/bun.js/bindings/DOMFormData.cpp b/src/bun.js/bindings/DOMFormData.cpp index 6567007a51..026ba0317e 100644 --- a/src/bun.js/bindings/DOMFormData.cpp +++ b/src/bun.js/bindings/DOMFormData.cpp @@ -44,7 +44,7 @@ Ref DOMFormData::create(ScriptExecutionContext* context) return adoptRef(*new DOMFormData(context)); } -Ref DOMFormData::create(ScriptExecutionContext* context, StringView urlEncodedString) +Ref DOMFormData::create(ScriptExecutionContext* context, const StringView& urlEncodedString) { auto newFormData = adoptRef(*new DOMFormData(context)); for (auto& entry : WTF::URLParser::parseURLEncodedForm(urlEncodedString)) { diff --git a/src/bun.js/bindings/DOMFormData.h b/src/bun.js/bindings/DOMFormData.h index 0970d90649..8ca84a29af 100644 --- a/src/bun.js/bindings/DOMFormData.h +++ b/src/bun.js/bindings/DOMFormData.h @@ -52,7 +52,7 @@ public: // static Ref create(ScriptExecutionContext*, const PAL::TextEncoding&); static Ref create(ScriptExecutionContext*); - static Ref create(ScriptExecutionContext*, StringView urlEncodedString); + static Ref create(ScriptExecutionContext*, const StringView& urlEncodedString); const Vector& items() const { return m_items; } // const PAL::TextEncoding& encoding() const { return m_encoding; } diff --git a/src/bun.js/bindings/ImportMetaObject.cpp b/src/bun.js/bindings/ImportMetaObject.cpp index 6f78bc8e04..fa93fc9f67 100644 --- a/src/bun.js/bindings/ImportMetaObject.cpp +++ b/src/bun.js/bindings/ImportMetaObject.cpp @@ -194,7 +194,7 @@ extern "C" JSC::EncodedJSValue functionImportMeta__resolveSync(JSC::JSGlobalObje return JSC::JSValue::encode(JSC::JSValue {}); } - JSC__JSValue from = 0; + JSC__JSValue from = JSC::JSValue::encode(JSC::jsUndefined()); bool isESM = true; if (callFrame->argumentCount() > 1) { diff --git a/src/bun.js/bindings/InternalModuleRegistry.cpp b/src/bun.js/bindings/InternalModuleRegistry.cpp index d14164b337..d83ad266be 100644 --- a/src/bun.js/bindings/InternalModuleRegistry.cpp +++ b/src/bun.js/bindings/InternalModuleRegistry.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include "InternalModuleRegistryConstants.h" namespace Bun { @@ -72,11 +74,11 @@ static void maybeAddCodeCoverage(JSC::VM& vm, const JSC::SourceCode& code) JSValue initializeInternalModuleFromDisk( JSGlobalObject* globalObject, VM& vm, - WTF::String moduleName, + const WTF::String& moduleName, WTF::String fileBase, - WTF::String urlString) + const WTF::String& urlString) { - WTF::String file = makeString(BUN_DYNAMIC_JS_LOAD_PATH, "/"_s, fileBase); + WTF::String file = makeString(BUN_DYNAMIC_JS_LOAD_PATH, "/"_s, WTFMove(fileBase)); if (auto contents = WTF::FileSystemImpl::readEntireFile(file)) { auto string = WTF::String::fromUTF8(contents.value()); INTERNAL_MODULE_REGISTRY_GENERATE_(globalObject, vm, string, moduleName, urlString); diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index d334ac5868..55ad01ddba 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -243,7 +243,7 @@ static inline JSC::EncodedJSValue writeToBuffer(JSC::JSGlobalObject* lexicalGlob if (UNLIKELY(str->length() == 0)) return JSC::JSValue::encode(JSC::jsNumber(0)); - auto view = str->tryGetValue(lexicalGlobalObject); + const auto& view = str->tryGetValue(lexicalGlobalObject); size_t written = 0; switch (encoding) { @@ -371,7 +371,7 @@ static JSC::EncodedJSValue constructFromEncoding(JSGlobalObject* lexicalGlobalOb auto& vm = JSC::getVM(lexicalGlobalObject); auto scope = DECLARE_THROW_SCOPE(vm); - auto view = str->tryGetValue(lexicalGlobalObject); + const auto& view = str->tryGetValue(lexicalGlobalObject); JSC::EncodedJSValue result; if (view.is8Bit()) { @@ -603,7 +603,7 @@ static inline JSC::EncodedJSValue jsBufferByteLengthFromStringAndEncoding(JSC::J case WebCore::BufferEncodingType::base64: case WebCore::BufferEncodingType::base64url: { int64_t length = str->length(); - auto view = str->tryGetValue(lexicalGlobalObject); + const auto& view = str->tryGetValue(lexicalGlobalObject); if (view.is8Bit()) { const auto span = view.span8(); @@ -632,7 +632,7 @@ static inline JSC::EncodedJSValue jsBufferByteLengthFromStringAndEncoding(JSC::J } case WebCore::BufferEncodingType::utf8: { - auto view = str->tryGetValue(lexicalGlobalObject); + const auto& view = str->tryGetValue(lexicalGlobalObject); if (view.is8Bit()) { const auto span = view.span8(); written = Bun__encoding__byteLengthLatin1(span.data(), span.size(), static_cast(encoding)); diff --git a/src/bun.js/bindings/KeyObject.cpp b/src/bun.js/bindings/KeyObject.cpp index c0874c1b32..b96b2de7dd 100644 --- a/src/bun.js/bindings/KeyObject.cpp +++ b/src/bun.js/bindings/KeyObject.cpp @@ -1211,10 +1211,8 @@ JSC::EncodedJSValue KeyObject__createPublicKey(JSC::JSGlobalObject* globalObject throwException(globalObject, scope, createTypeError(globalObject, "Unsupported EC curve"_s)); return JSValue::encode(JSC::jsUndefined()); } - auto alg = CryptoAlgorithmIdentifier::ECDH; - auto result = CryptoKeyEC::platformImportSpki(alg, curve, Vector(std::span { (uint8_t*)data, byteLength }), true, CryptoKeyUsageVerify); + auto result = CryptoKeyEC::platformImportSpki(CryptoAlgorithmIdentifier::ECDH, curve, Vector(std::span { (uint8_t*)data, byteLength }), true, CryptoKeyUsageVerify); if (UNLIKELY(result == nullptr)) { - alg = CryptoAlgorithmIdentifier::ECDSA; result = CryptoKeyEC::platformImportSpki(CryptoAlgorithmIdentifier::ECDSA, curve, Vector(std::span { (uint8_t*)data, byteLength }), true, CryptoKeyUsageVerify); } if (UNLIKELY(result == nullptr)) { diff --git a/src/bun.js/bindings/ModuleLoader.cpp b/src/bun.js/bindings/ModuleLoader.cpp index 115fc7a49b..dba0e84573 100644 --- a/src/bun.js/bindings/ModuleLoader.cpp +++ b/src/bun.js/bindings/ModuleLoader.cpp @@ -462,6 +462,8 @@ JSValue fetchCommonJSModule( auto& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); ErrorableResolvedSource resValue; + memset(&resValue, 0, sizeof(ErrorableResolvedSource)); + ErrorableResolvedSource* res = &resValue; WTF::String sourceCodeStringForDeref; const auto getSourceCodeStringForDeref = [&]() { diff --git a/src/bun.js/bindings/NodeVM.cpp b/src/bun.js/bindings/NodeVM.cpp index 8064061b08..1090752fc2 100644 --- a/src/bun.js/bindings/NodeVM.cpp +++ b/src/bun.js/bindings/NodeVM.cpp @@ -36,12 +36,12 @@ using namespace JSC; class ScriptOptions { public: - String filename; + String filename = String(); OrdinalNumber lineOffset; OrdinalNumber columnOffset; - String cachedData; - bool produceCachedData; - bool importModuleDynamically; + String cachedData = String(); + bool produceCachedData = false; + bool importModuleDynamically = false; static std::optional fromJS(JSC::JSGlobalObject* globalObject, JSC::JSValue optionsArg, bool& failed) { diff --git a/src/bun.js/bindings/RegularExpression.cpp b/src/bun.js/bindings/RegularExpression.cpp index 48b3b8bb82..6fbf1b7733 100644 --- a/src/bun.js/bindings/RegularExpression.cpp +++ b/src/bun.js/bindings/RegularExpression.cpp @@ -10,7 +10,9 @@ extern "C" RegularExpression* Yarr__RegularExpression__init(BunString pattern, u { // TODO: Remove this, we technically are accessing options before we finalize them. // This means you cannot use BUN_JSC_dumpCompiledRegExpPatterns on the flag passed to `bun test -t` - Options::AllowUnfinalizedAccessScope scope; + // NOLINTBEGIN + Options::AllowUnfinalizedAccessScope scope {}; + // NOLINTEND return new RegularExpression(pattern.toWTFString(BunString::ZeroCopy), OptionSet(static_cast(flags))); } extern "C" void Yarr__RegularExpression__deinit(RegularExpression* re) diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 8a8f3c234a..d4d2c30268 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -193,6 +193,7 @@ Structure* createMemoryFootprintStructure(JSC::VM& vm, JSC::JSGlobalObject* glob extern "C" WebCore::Worker* WebWorker__getParentWorker(void*); extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(const char* ptr, size_t length)) { + // NOLINTBEGIN if (has_loaded_jsc) return; has_loaded_jsc = true; @@ -202,6 +203,7 @@ extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(c WTF::initializeMainThread(); JSC::initialize(); { + JSC::Options::AllowUnfinalizedAccessScope scope; JSC::Options::useConcurrentJIT() = true; @@ -240,6 +242,8 @@ extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(c } JSC::Options::assertOptionsAreCoherent(); } + + // NOLINTEND } extern "C" void* Bun__getVM(); @@ -528,10 +532,6 @@ static String computeErrorInfoWithoutPrepareStackTrace(JSC::VM& vm, Zig::GlobalO static String computeErrorInfoWithPrepareStackTrace(JSC::VM& vm, Zig::GlobalObject* globalObject, JSC::JSGlobalObject* lexicalGlobalObject, Vector& stackFrames, unsigned& line, unsigned& column, String& sourceURL, JSObject* errorObject, JSObject* prepareStackTrace) { auto scope = DECLARE_THROW_SCOPE(vm); - size_t stackTraceLimit = globalObject->stackTraceLimit().value(); - if (stackTraceLimit == 0) { - stackTraceLimit = DEFAULT_ERROR_STACK_TRACE_LIMIT; - } JSCStackTrace stackTrace = JSCStackTrace::fromExisting(vm, stackFrames); diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index be8403f6e3..7091f87364 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -1609,7 +1609,7 @@ JSC__JSValue WebCore__FetchHeaders__createValue(JSC__JSGlobalObject* arg0, Strin Ref headers = WebCore::FetchHeaders::create(); WebCore::propagateException(*arg0, throwScope, headers->fill(WebCore::FetchHeaders::Init(WTFMove(pairs)))); - pairs.releaseBuffer(); + JSValue value = WebCore::toJSNewlyCreated(arg0, reinterpret_cast(arg0), WTFMove(headers)); JSFetchHeaders* fetchHeaders = jsCast(value); @@ -1844,7 +1844,7 @@ double JSC__JSValue__getLengthIfPropertyExistsInternal(JSC__JSValue value, JSC__ return 0; } - case static_cast(WebCore::JSDOMWrapperType): { + case WebCore::JSDOMWrapperType: { if (auto* headers = jsDynamicCast(cell)) return static_cast(jsCast(cell)->wrapped().size()); @@ -2951,13 +2951,6 @@ JSC__JSPromise* JSC__JSPromise__rejectedPromise(JSC__JSGlobalObject* arg0, JSC__ return JSC::JSPromise::rejectedPromise(arg0, JSC::JSValue::decode(JSValue1)); } -void JSC__JSPromise__rejectWithCaughtException(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, - bJSC__ThrowScope arg2) -{ - Wrap wrapped = Wrap(arg2); - - arg0->rejectWithCaughtException(arg1, *wrapped.cpp); -} void JSC__JSPromise__resolve(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2) { @@ -3113,14 +3106,6 @@ JSC__JSInternalPromise* JSC__JSInternalPromise__rejectedPromise(JSC__JSGlobalObj JSC::JSInternalPromise::rejectedPromise(arg0, JSC::JSValue::decode(JSValue1))); } -void JSC__JSInternalPromise__rejectWithCaughtException(JSC__JSInternalPromise* arg0, - JSC__JSGlobalObject* arg1, - bJSC__ThrowScope arg2) -{ - Wrap wrapped = Wrap(arg2); - - arg0->rejectWithCaughtException(arg1, *wrapped.cpp); -} void JSC__JSInternalPromise__resolve(JSC__JSInternalPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2) { @@ -3203,12 +3188,7 @@ double JSC__JSValue__asNumber(JSC__JSValue JSValue0) auto value = JSC::JSValue::decode(JSValue0); return value.asNumber(); }; -bJSC__JSObject JSC__JSValue__asObject(JSC__JSValue JSValue0) -{ - auto value = JSC::JSValue::decode(JSValue0); - auto obj = JSC::asObject(value); - return cast(&obj); -}; + JSC__JSString* JSC__JSValue__asString(JSC__JSValue JSValue0) { auto value = JSC::JSValue::decode(JSValue0); @@ -4963,10 +4943,7 @@ restart: scope.clearException(); } - fast = false; - if (anyHits) { - if (prototypeCount++ < 5) { if (JSValue proto = prototypeObject.getPrototype(globalObject)) { if (!(proto == globalObject->objectPrototype() || proto == globalObject->functionPrototype() || (proto.inherits() && jsCast(proto)->target() != globalObject))) { diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index fe2613dfd7..2637700dc6 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -2188,10 +2188,6 @@ pub const JSPromise = extern struct { cppFn("setHandled", .{ this, vm }); } - pub fn rejectWithCaughtException(this: *JSPromise, globalObject: *JSGlobalObject, scope: ThrowScope) void { - return cppFn("rejectWithCaughtException", .{ this, globalObject, scope }); - } - pub fn resolvedPromise(globalThis: *JSGlobalObject, value: JSValue) *JSPromise { return cppFn("resolvedPromise", .{ globalThis, value }); } @@ -2278,7 +2274,6 @@ pub const JSPromise = extern struct { "rejectAsHandled", "rejectAsHandledException", "rejectOnNextTickWithHandled", - "rejectWithCaughtException", "rejectedPromise", "rejectedPromiseValue", "resolve", @@ -2312,10 +2307,6 @@ pub const JSInternalPromise = extern struct { cppFn("setHandled", .{ this, vm }); } - pub fn rejectWithCaughtException(this: *JSInternalPromise, globalObject: *JSGlobalObject, scope: ThrowScope) void { - return cppFn("rejectWithCaughtException", .{ this, globalObject, scope }); - } - pub fn resolvedPromise(globalThis: *JSGlobalObject, value: JSValue) *JSInternalPromise { return cppFn("resolvedPromise", .{ globalThis, value }); } @@ -2494,7 +2485,6 @@ pub const JSInternalPromise = extern struct { pub const Extern = [_][]const u8{ "create", // "then_", - "rejectWithCaughtException", "status", "result", "isHandled", @@ -2536,12 +2526,6 @@ pub const AnyPromise = union(enum) { } } - pub fn rejectWithCaughtException(this: AnyPromise, globalObject: *JSGlobalObject, scope: ThrowScope) void { - switch (this) { - inline else => |promise| promise.rejectWithCaughtException(globalObject, scope), - } - } - pub fn resolve(this: AnyPromise, globalThis: *JSGlobalObject, value: JSValue) void { switch (this) { inline else => |promise| promise.resolve(globalThis, value), @@ -5077,12 +5061,6 @@ pub const JSValue = enum(JSValueReprInt) { }; } - pub fn asObject(this: JSValue) JSObject { - return cppFn("asObject", .{ - this, - }); - } - /// Check if the JSValue is either a signed 32-bit integer or a double and /// return the value as a f64 /// @@ -5353,7 +5331,6 @@ pub const JSValue = enum(JSValueReprInt) { "asCell", "asInternalPromise", "asNumber", - "asObject", "asPromise", "asString", "coerceToDouble", diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h index 8dedb14382..e4a089a079 100644 --- a/src/bun.js/bindings/headers.h +++ b/src/bun.js/bindings/headers.h @@ -251,7 +251,6 @@ CPP_DECL void JSC__JSPromise__rejectAsHandledException(JSC__JSPromise* arg0, JSC CPP_DECL JSC__JSPromise* JSC__JSPromise__rejectedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1); CPP_DECL JSC__JSValue JSC__JSPromise__rejectedPromiseValue(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1); CPP_DECL void JSC__JSPromise__rejectOnNextTickWithHandled(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, bool arg3); -CPP_DECL void JSC__JSPromise__rejectWithCaughtException(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, bJSC__ThrowScope arg2); CPP_DECL void JSC__JSPromise__resolve(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2); CPP_DECL JSC__JSPromise* JSC__JSPromise__resolvedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1); CPP_DECL JSC__JSValue JSC__JSPromise__resolvedPromiseValue(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1); @@ -268,7 +267,6 @@ CPP_DECL void JSC__JSInternalPromise__reject(JSC__JSInternalPromise* arg0, JSC__ CPP_DECL void JSC__JSInternalPromise__rejectAsHandled(JSC__JSInternalPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2); CPP_DECL void JSC__JSInternalPromise__rejectAsHandledException(JSC__JSInternalPromise* arg0, JSC__JSGlobalObject* arg1, JSC__Exception* arg2); CPP_DECL JSC__JSInternalPromise* JSC__JSInternalPromise__rejectedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1); -CPP_DECL void JSC__JSInternalPromise__rejectWithCaughtException(JSC__JSInternalPromise* arg0, JSC__JSGlobalObject* arg1, bJSC__ThrowScope arg2); CPP_DECL void JSC__JSInternalPromise__resolve(JSC__JSInternalPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2); CPP_DECL JSC__JSInternalPromise* JSC__JSInternalPromise__resolvedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1); CPP_DECL JSC__JSValue JSC__JSInternalPromise__result(const JSC__JSInternalPromise* arg0, JSC__VM* arg1); diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig index 86eea29c2b..ad0086d7e4 100644 --- a/src/bun.js/bindings/headers.zig +++ b/src/bun.js/bindings/headers.zig @@ -161,7 +161,6 @@ pub extern fn JSC__JSPromise__rejectAsHandledException(arg0: ?*bindings.JSPromis pub extern fn JSC__JSPromise__rejectedPromise(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*bindings.JSPromise; pub extern fn JSC__JSPromise__rejectedPromiseValue(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) JSC__JSValue; pub extern fn JSC__JSPromise__rejectOnNextTickWithHandled(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue, arg3: bool) void; -pub extern fn JSC__JSPromise__rejectWithCaughtException(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject, arg2: bJSC__ThrowScope) void; pub extern fn JSC__JSPromise__resolve(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; pub extern fn JSC__JSPromise__resolvedPromise(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*bindings.JSPromise; pub extern fn JSC__JSPromise__resolvedPromiseValue(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) JSC__JSValue; @@ -175,7 +174,6 @@ pub extern fn JSC__JSInternalPromise__reject(arg0: [*c]bindings.JSInternalPromis pub extern fn JSC__JSInternalPromise__rejectAsHandled(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; pub extern fn JSC__JSInternalPromise__rejectAsHandledException(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, arg2: [*c]bindings.Exception) void; pub extern fn JSC__JSInternalPromise__rejectedPromise(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) [*c]bindings.JSInternalPromise; -pub extern fn JSC__JSInternalPromise__rejectWithCaughtException(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, arg2: bJSC__ThrowScope) void; pub extern fn JSC__JSInternalPromise__resolve(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; pub extern fn JSC__JSInternalPromise__resolvedPromise(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) [*c]bindings.JSInternalPromise; pub extern fn JSC__JSInternalPromise__result(arg0: [*c]const JSC__JSInternalPromise, arg1: *bindings.VM) JSC__JSValue; diff --git a/src/bun.js/bindings/helpers.h b/src/bun.js/bindings/helpers.h index 34d2be0430..e8c0e40724 100644 --- a/src/bun.js/bindings/helpers.h +++ b/src/bun.js/bindings/helpers.h @@ -23,62 +23,6 @@ class GlobalObject; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-function" -template class Wrap { -public: - Wrap() {}; - - Wrap(ZigType zig) - { - result = zig; - cpp = static_cast(static_cast(&zig)); - }; - - Wrap(ZigType* zig) { cpp = static_cast(static_cast(&zig)); }; - - Wrap(CppType _cpp) - { - auto buffer = alignedBuffer(); - cpp = new (buffer) CppType(_cpp); - }; - - ~Wrap() {}; - - unsigned char* alignedBuffer() - { - return result.bytes + alignof(CppType) - reinterpret_cast(result.bytes) % alignof(CppType); - } - - ZigType result; - CppType* cpp; - - static ZigType wrap(CppType obj) { return *static_cast(static_cast(&obj)); } - - static CppType unwrap(ZigType obj) { return *static_cast(static_cast(&obj)); } - - static CppType* unwrap(ZigType* obj) { return static_cast(static_cast(obj)); } -}; - -template To cast(From v) -{ - return *static_cast(static_cast(v)); -} - -template To ccast(From v) -{ - return *static_cast(static_cast(v)); -} - -static const JSC::ArgList makeArgs(JSC__JSValue* v, size_t count) -{ - JSC::MarkedArgumentBuffer args = JSC::MarkedArgumentBuffer(); - args.ensureCapacity(count); - for (size_t i = 0; i < count; ++i) { - args.append(JSC::JSValue::decode(v[i])); - } - - return JSC::ArgList(args); -} - namespace Zig { // 8 bit byte diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp index 70beec31e9..7c22f9d884 100644 --- a/src/bun.js/bindings/napi.cpp +++ b/src/bun.js/bindings/napi.cpp @@ -200,17 +200,17 @@ static uint32_t getPropertyAttributes(napi_property_attributes attributes_) { const uint32_t attributes = static_cast(attributes_); uint32_t result = 0; - if (!(attributes & napi_key_configurable)) { + if (!(attributes & static_cast(napi_key_configurable))) { result |= JSC::PropertyAttribute::DontDelete; } - if (!(attributes & napi_key_enumerable)) { + if (!(attributes & static_cast(napi_key_enumerable))) { result |= JSC::PropertyAttribute::DontEnum; } - if (!(attributes & napi_key_writable)) { - // result |= JSC::PropertyAttribute::ReadOnly; - } + // if (!(attributes & napi_key_writable)) { + // // result |= JSC::PropertyAttribute::ReadOnly; + // } return result; } @@ -1672,11 +1672,8 @@ extern "C" napi_status napi_create_range_error(napi_env env, napi_value code, Zig::GlobalObject* globalObject = toJS(env); - JSC::EncodedJSValue encodedCode = reinterpret_cast(code); - JSC::JSValue codeValue = JSC::JSValue::decode(encodedCode); - - JSC::EncodedJSValue encodedMessage = reinterpret_cast(msg); - JSC::JSValue messageValue = JSC::JSValue::decode(encodedMessage); + JSC::JSValue codeValue = toJS(code); + JSC::JSValue messageValue = toJS(msg); auto error = JSC::createRangeError(globalObject, messageValue.toWTFString(globalObject)); if (codeValue) { @@ -1778,9 +1775,8 @@ JSC_DEFINE_HOST_FUNCTION(NapiClass_ConstructorFunction, RETURN_IF_EXCEPTION(scope, {}); callFrame->setThisValue(subclass); - size_t count = callFrame->argumentCount(); MarkedArgumentBufferWithSize<12> args; - size_t argc = count + 1; + size_t argc = callFrame->argumentCount() + 1; args.fill(vm, argc, [&](auto* slot) { memcpy(slot, ADDRESS_OF_THIS_VALUE_IN_CALLFRAME(callFrame), sizeof(JSC::JSValue) * argc); }); diff --git a/src/bun.js/bindings/webcore/BroadcastChannel.cpp b/src/bun.js/bindings/webcore/BroadcastChannel.cpp index c393107b64..69b66ac42f 100644 --- a/src/bun.js/bindings/webcore/BroadcastChannel.cpp +++ b/src/bun.js/bindings/webcore/BroadcastChannel.cpp @@ -40,6 +40,7 @@ // #include "WorkerLoaderProxy.h" // #include "WorkerThread.h" #include +#include #include #include #include @@ -72,7 +73,7 @@ static HashMap& ch // return { WTFMove(topOrigin), WTFMove(securityOrigin) }; // } -class BroadcastChannel::MainThreadBridge : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr { +class BroadcastChannel::MainThreadBridge : public ThreadSafeRefCounted, public Identified { public: static Ref create(BroadcastChannel& channel, const String& name, ScriptExecutionContext& context) { @@ -82,21 +83,17 @@ public: void registerChannel(ScriptExecutionContext&); void unregisterChannel(); void postMessage(Ref&&); + void detach() { m_broadcastChannel = nullptr; }; String name() const { return m_name.isolatedCopy(); } - BroadcastChannelIdentifier identifier() const { return m_identifier; } ScriptExecutionContextIdentifier contextId() const { return m_contextId; } - using ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::deref; - using ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::ref; - private: MainThreadBridge(BroadcastChannel&, const String& name, ScriptExecutionContext&); void ensureOnMainThread(Function&&); WeakPtr m_broadcastChannel; - const BroadcastChannelIdentifier m_identifier; const String m_name; // Main thread only. ScriptExecutionContextIdentifier m_contextId; // PartitionedSecurityOrigin m_origin; // Main thread only. @@ -104,7 +101,6 @@ private: BroadcastChannel::MainThreadBridge::MainThreadBridge(BroadcastChannel& channel, const String& name, ScriptExecutionContext& context) : m_broadcastChannel(channel) - , m_identifier(BroadcastChannelIdentifier::generate()) , m_name(name.isolatedCopy()) , m_contextId(context.identifier()) // , m_origin(partitionedSecurityOriginFromContext(*channel.scriptExecutionContext()).isolatedCopy()) @@ -134,8 +130,8 @@ void BroadcastChannel::MainThreadBridge::registerChannel(ScriptExecutionContext& Ref protectedThis { *this }; ScriptExecutionContext::ensureOnMainThread([protectedThis = WTFMove(protectedThis), contextId = context.identifier()](auto& context) mutable { - context.broadcastChannelRegistry().registerChannel(protectedThis->m_name, protectedThis->m_identifier); - channelToContextIdentifier().add(protectedThis->m_identifier, contextId); + context.broadcastChannelRegistry().registerChannel(protectedThis->m_name, protectedThis->identifier()); + channelToContextIdentifier().add(protectedThis->identifier(), contextId); }); } @@ -144,8 +140,8 @@ void BroadcastChannel::MainThreadBridge::unregisterChannel() Ref protectedThis { *this }; ScriptExecutionContext::ensureOnMainThread([protectedThis = WTFMove(protectedThis)](auto& context) { - context.broadcastChannelRegistry().unregisterChannel(protectedThis->m_name, protectedThis->m_identifier); - channelToContextIdentifier().remove(protectedThis->m_identifier); + context.broadcastChannelRegistry().unregisterChannel(protectedThis->m_name, protectedThis->identifier()); + channelToContextIdentifier().remove(protectedThis->identifier()); }); } @@ -154,7 +150,7 @@ void BroadcastChannel::MainThreadBridge::postMessage(Ref& Ref protectedThis { *this }; ScriptExecutionContext::ensureOnMainThread([protectedThis = WTFMove(protectedThis), message = WTFMove(message)](auto& context) mutable { - context.broadcastChannelRegistry().postMessage(protectedThis->m_name, protectedThis->m_identifier, WTFMove(message)); + context.broadcastChannelRegistry().postMessage(protectedThis->m_name, protectedThis->identifier(), WTFMove(message)); }); } @@ -175,6 +171,7 @@ BroadcastChannel::BroadcastChannel(ScriptExecutionContext& context, const String BroadcastChannel::~BroadcastChannel() { close(); + m_mainThreadBridge->detach(); { Locker locker { allBroadcastChannelsLock }; allBroadcastChannels().remove(m_mainThreadBridge->identifier()); diff --git a/src/bun.js/bindings/webcore/BroadcastChannel.h b/src/bun.js/bindings/webcore/BroadcastChannel.h index 764f3db93b..f218005fff 100644 --- a/src/bun.js/bindings/webcore/BroadcastChannel.h +++ b/src/bun.js/bindings/webcore/BroadcastChannel.h @@ -43,7 +43,7 @@ namespace WebCore { class SerializedScriptValue; -class BroadcastChannel : public RefCounted, public EventTarget /*, public ActiveDOMObject*/, public ContextDestructionObserver { +class BroadcastChannel : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr, public EventTarget /*, public ActiveDOMObject*/, public ContextDestructionObserver { WTF_MAKE_ISO_ALLOCATED(BroadcastChannel); public: @@ -55,8 +55,8 @@ public: } ~BroadcastChannel(); - using RefCounted::ref; - using RefCounted::deref; + using ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::ref; + using ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::deref; BroadcastChannelIdentifier identifier() const; String name() const; @@ -83,8 +83,8 @@ private: // EventTarget EventTargetInterface eventTargetInterface() const final { return BroadcastChannelEventTargetInterfaceType; } ScriptExecutionContext* scriptExecutionContext() const; - void refEventTarget() final { RefCounted::ref(); } - void derefEventTarget() final { RefCounted::deref(); } + void refEventTarget() final { ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::ref(); } + void derefEventTarget() final { ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::deref(); } void eventListenersDidChange() final; EventTargetData* eventTargetData() final { return &m_eventTargetData; } diff --git a/src/bun.js/bindings/webcrypto/CommonCryptoDERUtilities.cpp b/src/bun.js/bindings/webcrypto/CommonCryptoDERUtilities.cpp index d0fb25b74d..972e4683aa 100644 --- a/src/bun.js/bindings/webcrypto/CommonCryptoDERUtilities.cpp +++ b/src/bun.js/bindings/webcrypto/CommonCryptoDERUtilities.cpp @@ -42,7 +42,7 @@ size_t extraBytesNeededForEncodedLength(size_t length) if (!length) return 0; size_t result = 1; - while (result < sizeof(length) && length >= (1 << (result * 8))) + while (result < sizeof(length) && length >= (1ull << (result * 8ull))) result += 1; return result; } @@ -60,7 +60,7 @@ void addEncodedASN1Length(Vector& in, size_t length) size_t lastPosition = in.size() + extraBytes - 1; in.grow(in.size() + extraBytes); for (size_t i = 0; i < extraBytes; i++) { - in[lastPosition - i] = length & 0xff; + in[lastPosition - i] = length & 0xffull; length = length >> 8; } } diff --git a/src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp b/src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp index 298e6afe44..2ac46f90e7 100644 --- a/src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp +++ b/src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp @@ -27,7 +27,6 @@ #include "JSDOMConvertStrings.h" #include - namespace WebCore { using namespace JSC; @@ -41,22 +40,22 @@ template<> CryptoAlgorithmParameters convertDictionaryget(&lexicalGlobalObject, Identifier::fromString(vm, "name"_s)); - RETURN_IF_EXCEPTION(throwScope, { }); + RETURN_IF_EXCEPTION(throwScope, {}); } if (!nameValue.isUndefined()) { result.name = convert(lexicalGlobalObject, nameValue); - RETURN_IF_EXCEPTION(throwScope, { }); + RETURN_IF_EXCEPTION(throwScope, {}); } else { throwRequiredMemberTypeError(lexicalGlobalObject, throwScope, "name", "CryptoAlgorithmParameters", "DOMString"); - return { }; + return {}; } return result; }