← Back to Pull requests

Give WebSocket onopen, onmessage, onclose and onerror attributes #8851

Open
unknown opened this pull request with 230 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 24, 2026 04:04 UTC
Author

WebSocket had no on<type> accessors. ws.onmessage = fn only worked because EventTarget dispatch reads a plain on<type> property and runs it before every listener. So ws.onopen read undefined instead of null, ws.onopen = 2 kept the 2, and the four cases in websockets/eventhandlers.any.js plus the idlharness on attribute cases failed.

In this patch WebSocket gets the four attributes on its prototype, backed by EventTarget::setEventHandlerAttribute() the same way AbortSignal.onabort is. A non-object reads back as null, and a non-callable object is kept but never called. The handler runs from its own position in the listener list. The first commit only names the handler value type on EventTarget so both classes can share it.

No compat flag. MessagePort.onmessage and EventSource.on made the same move without one. Here is what a Worker can see change:

  • the attributes read null before anything is assigned

  • assigning a primitive reads back null; it was never called before either

  • when on<type> and addEventListener() are both used for one type, the handler runs in registration order instead of first

  • assignment no longer creates an own property, so it doesn't show in Object.keys(), and delete ws.onmessage no longer removes the handler

  • util.inspect() of a WebSocket lists the four attributes
  • this inside a handler doesn't change. An own on<type> property defined without the setter, such as a class field on a subclass, still goes through the legacy lookup.

    The new websocket-handlers-test covers defaults, primitives, non-callable objects, handler position and close. Its defaults, primitives and position cases fail without the change. The 4 eventhandlers.any.js and 8 idlharness expected failures are removed, and the websocket, events, abort, http and dom/events tests pass.

    Diff: 230 lines (+172 / -58) across 2 files Reviewer: jasnell Review duration: 1899m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.37) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 230 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.326
    Real PR Conversation Timeline
    1 comments
    "Review active on #8851"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37% (MEDIUM) · Higher = larger blast radius
    37%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.1% · Safe to merge
    21.1%