Skip to content

Conversation

@tomerqodo
Copy link

@tomerqodo tomerqodo commented Dec 4, 2025

User description

Benchmark PR electron#48788

Type: Clean (correct implementation)

Original PR Title: fix: enable wasm trap handlers in all Node.js processes
Original PR Description: #### Description of Change

Found while investigating microsoft/vscode#273191

Since electron#47186 we had accidentally disabled V8 trap handlers in browser and utility process. This incurs performance cost when executing wasm due to inlined bound checks.

Enable the feature back and align it with upstream based on the feature parameter across all processes features::kWebAssemblyTrapHandler

Current matrix of enabled platforms.

Linux, Windows, MacOS - x86_64
Linux, MacOS - arm64

Release Notes

Notes: Reenable V8 trap handlers for wasm in browser and utility process, improves runtime execution of wasm
Original PR URL: electron#48788


PR Type

Enhancement, Bug fix


Description

  • Enable WebAssembly trap handlers across all Node.js processes

  • Centralize trap handler setup logic into shared utility function

  • Improve wasm execution performance via V8 trap handlers

  • Support Linux x86_64/arm64, Windows, and macOS platforms


Diagram Walkthrough

flowchart LR
  A["Feature Flag Check"] -->|"IsEnabled"| B["SetUpWebAssemblyTrapHandler"]
  B -->|"Windows/macOS"| C["V8 Default Handler"]
  B -->|"Linux"| D["Platform-Specific Setup"]
  D -->|"Crash Reporter"| E["Default Implementation"]
  D -->|"Stack Traces"| F["V8 Signal Handler"]
  D -->|"Stack Dump"| G["Callback Registration"]
  C --> H["Improved wasm Performance"]
  F --> H
  G --> H
Loading

File Walkthrough

Relevant files
Enhancement
electron_browser_main_parts.cc
Enable wasm trap handlers in browser process                         

shell/browser/electron_browser_main_parts.cc

  • Added include for shell/common/v8_util.h
  • Added feature flag check and initialization call in
    PostEarlyInitialization()
  • Enables WebAssembly trap handlers when feature is enabled
+5/-0     
v8_util.cc
Implement centralized WebAssembly trap handler setup         

shell/common/v8_util.cc

  • Added new SetUpWebAssemblyTrapHandler() function with
    platform-specific implementations
  • Windows/macOS use V8's default trap handler
  • Linux conditionally sets up handlers based on crash reporter and stack
    trace settings
  • Includes necessary headers for crash reporter and V8 wasm trap handler
    APIs
+54/-0   
v8_util.h
Export WebAssembly trap handler setup function                     

shell/common/v8_util.h

  • Added function declaration for SetUpWebAssemblyTrapHandler()
  • Exports the new utility function for use across processes
+2/-0     
electron_renderer_client.cc
Refactor renderer to use shared trap handler setup             

shell/renderer/electron_renderer_client.cc

  • Removed platform-specific trap handler implementation code
  • Removed conditional compilation blocks for Linux wasm trap handler
  • Simplified SetUpWebAssemblyTrapHandler() to call shared utility
    function
  • Removed unnecessary includes like base/base_switches.h
+4/-47   
node_service.cc
Enable wasm trap handlers in utility process                         

shell/services/node/node_service.cc

  • Added include for content/public/common/content_features.h
  • Added include for shell/common/v8_util.h
  • Added feature flag check and initialization call in Initialize()
    method
  • Enables WebAssembly trap handlers for utility process
+7/-0     

@qodo-code-review
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No audit logs: The added WebAssembly trap handler setup performs critical runtime configuration without
emitting any audit logging of the action, actor, or outcome, making it unclear when and
how trap handlers were enabled per process.

Referred Code
void SetUpWebAssemblyTrapHandler() {
#if BUILDFLAG(IS_WIN)
  // On Windows we use the default trap handler provided by V8.
  v8::V8::EnableWebAssemblyTrapHandler(true);
#elif BUILDFLAG(IS_MAC)
  // On macOS, Crashpad uses exception ports to handle signals in a
  // different process. As we cannot just pass a callback to this other
  // process, we ask V8 to install its own signal handler to deal with
  // WebAssembly traps.
  v8::V8::EnableWebAssemblyTrapHandler(true);
#elif defined(ENABLE_WEB_ASSEMBLY_TRAP_HANDLER_LINUX)
  const bool crash_reporter_enabled =
      crash_reporter::GetHandlerSocket(nullptr, nullptr);

  if (crash_reporter_enabled) {
    // If either --enable-crash-reporter or --enable-crash-reporter-for-testing
    // is enabled it should take care of signal handling for us, use the default
    // implementation which doesn't register an additional handler.
    v8::V8::EnableWebAssemblyTrapHandler(false);
    return;
  }


 ... (clipped 23 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing error handling: The setup function for WebAssembly trap handlers silently returns or does nothing on
failure paths (e.g., when callback registration fails) without logging or reporting
context, reducing diagnosability in production.

Referred Code
void SetUpWebAssemblyTrapHandler() {
#if BUILDFLAG(IS_WIN)
  // On Windows we use the default trap handler provided by V8.
  v8::V8::EnableWebAssemblyTrapHandler(true);
#elif BUILDFLAG(IS_MAC)
  // On macOS, Crashpad uses exception ports to handle signals in a
  // different process. As we cannot just pass a callback to this other
  // process, we ask V8 to install its own signal handler to deal with
  // WebAssembly traps.
  v8::V8::EnableWebAssemblyTrapHandler(true);
#elif defined(ENABLE_WEB_ASSEMBLY_TRAP_HANDLER_LINUX)
  const bool crash_reporter_enabled =
      crash_reporter::GetHandlerSocket(nullptr, nullptr);

  if (crash_reporter_enabled) {
    // If either --enable-crash-reporter or --enable-crash-reporter-for-testing
    // is enabled it should take care of signal handling for us, use the default
    // implementation which doesn't register an additional handler.
    v8::V8::EnableWebAssemblyTrapHandler(false);
    return;
  }


 ... (clipped 23 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

PR Code Suggestions ✨

No code suggestions found for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants