Repository: dotnet/runtime
File: src/coreclr/vm/finalizerthread.cpp (C++)

Code before:
    CONTRACTL_END;

    INSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP;
    {
        GCX_COOP();
        // TODO-WASM https://github.com/dotnet/runtime/issues/123712
        // ManagedThreadBase::KickOff(FinalizerThread::FinalizerThreadWorkerIteration, NULL);
    }
    UNINSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP;
}

#endif // TARGET_WASM

void FinalizerThread::EnableFinalization()
{
    WRAPPER_NO_CONTRACT;

#ifndef TARGET_WASM
    hEventFinalizer->Set();
#else  // !TARGET_WASM
    SystemJS_ScheduleFinalization();
#endif // !TARGET_WASM
}

namespace
{
    // This is a linked list of the LCGMethodResolvers that represent DynamicMethodDescs
    // waiting to be destroyed. The resolvers are used since they can be chained together
    // to avoid allocations when destroying multiple DynamicMethodDescs.
    VolatilePtr<LCGMethodResolver> s_delayDestroyDynamicMethod = nullptr;

    bool HasDelayedDynamicMethod()
    {
        LIMITED_METHOD_CONTRACT;
        return s_delayDestroyDynamicMethod != nullptr;
    }

    void AddDelayedDynamicMethod(DynamicMethodDesc* pDMD)
    {
        STANDARD_VM_CONTRACT;
        _ASSERTE(pDMD != nullptr);

        // Get the LCGMethodResolver from the DynamicMethodDesc.
        LCGMethodResolver* lcgResolver = pDMD->GetLCGMethodResolver();

        // Append any existing resolvers to form a linked list.
        if (s_delayDestroyDynamicMethod != nullptr)
            lcgResolver->SetNextDynamicMethodForDelayCleanup((DynamicMethodDesc*)s_delayDestroyDynamicMethod->GetDynamicMethod());

        s_delayDestroyDynamicMethod = lcgResolver;
    }

Review comment (suggestion):
The preprocessor comments in this `#ifndef TARGET_WASM` block are inverted (the `#else` comment says `!TARGET_WASM`, but the `#else` branch is the `TARGET_WASM` case). Please fix the comments to match the actual conditions to avoid confusion when maintaining this code.
```suggestion
#else  // TARGET_WASM
    SystemJS_ScheduleFinalization();
#endif // TARGET_WASM
```

Code after:
    CONTRACTL_END;

    INSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP;
    {
        GCX_COOP();
        // TODO-WASM https://github.com/dotnet/runtime/issues/123712
        // ManagedThreadBase::KickOff(FinalizerThread::FinalizerThreadWorkerIteration, NULL);
    }
    UNINSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP;
}

#endif // TARGET_BROWSER

void FinalizerThread::EnableFinalization()
{
    WRAPPER_NO_CONTRACT;

#ifndef TARGET_WASM
    hEventFinalizer->Set();
#else  // !TARGET_WASM
#ifdef TARGET_BROWSER
    SystemJS_ScheduleFinalization();
#else
    // WASI is not implemented yet
#endif // TARGET_BROWSER
#endif // !TARGET_WASM
}

namespace
{
    // This is a linked list of the LCGMethodResolvers that represent DynamicMethodDescs
    // waiting to be destroyed. The resolvers are used since they can be chained together
    // to avoid allocations when destroying multiple DynamicMethodDescs.
    VolatilePtr<LCGMethodResolver> s_delayDestroyDynamicMethod = nullptr;

    bool HasDelayedDynamicMethod()
    {
        LIMITED_METHOD_CONTRACT;
        return s_delayDestroyDynamicMethod != nullptr;
    }

    void AddDelayedDynamicMethod(DynamicMethodDesc* pDMD)
    {
        STANDARD_VM_CONTRACT;
        _ASSERTE(pDMD != nullptr);

        // Get the LCGMethodResolver from the DynamicMethodDesc.
        LCGMethodResolver* lcgResolver = pDMD->GetLCGMethodResolver();

        // Append any existing resolvers to form a linked list.
        if (s_delayDestroyDynamicMethod != nullptr)