Skip to content

Flesh out URL polyfill and add performance.now polyfill#130

Merged
ryantrem merged 16 commits intoBabylonJS:mainfrom
ryantrem:polyfills
Dec 12, 2025
Merged

Flesh out URL polyfill and add performance.now polyfill#130
ryantrem merged 16 commits intoBabylonJS:mainfrom
ryantrem:polyfills

Conversation

@ryantrem
Copy link
Copy Markdown
Member

@ryantrem ryantrem commented Dec 9, 2025

  • Flesh out the URL polyfill (moslty by Claude).
  • Add a bunch more unit tests for URL (by Claude).
  • Add a polyfill for performance.now() (by Claude).
  • Add some unit tests for performance.now() (by Claude).
  • Uncomment JSGlobalContextSetInspectable and add platform and os version checks.
  • Fix a bug where finalizers should be removed when napi_remove_wrap is called (per https://nodejs.org/api/n-api.html#napi_remove_wrap). Otherwise, a crash occurs if a constructor throws an error (which can happen with URL when the passed in string is not a valid url). This also addresses Node-API napi_remove_wrap is not being handled correctly #82.
  • Fix a bug where we try to assign to the result in napi_remove_wrap when the void** result is null. We just need to check result before assigning to it. result can be null in certain situations, such as if a constructor throws (same scenario as above).
  • Fix a small issue where the webpack watch command does not work (at least on MacOS).

…versions of iOS

In napi_remove_wrap the result param is optional, so check it before trying to assign to it (it is null when a constructor throws an error for example)

Remove finalizers when napi_remove_wrap is called (this is what the napi spec says to do, and this corresponds to existing issue BabylonJS#82)

Flesh out the URL polyfill and add tests
@ryantrem ryantrem requested a review from bghgary December 9, 2025 17:14
Copy link
Copy Markdown
Contributor

@bghgary bghgary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only skimmed the URL parsing code. I think we have to be careful with this code as it can introduce issues that we don't see. I still think we should use platform specific URL code to avoid this issue entirely.

Comment thread Polyfills/URL/Source/URL.cpp Outdated
@ryantrem ryantrem enabled auto-merge (squash) December 12, 2025 19:17
@ryantrem ryantrem merged commit ae0253a into BabylonJS:main Dec 12, 2025
19 checks passed
bghgary added a commit that referenced this pull request Apr 17, 2026
[Created by Copilot on behalf of @bghgary]

Re-enable the "should trigger error callback with invalid server"
WebSocket test that was commented out in #130 due to the flake reported
in #131.

## Why this is safe to re-enable

Two WebSocket-related fixes landed on `main` since the flake was
observed:

- **#150** — pulled in UrlLib BabylonJS/UrlLib#26, which consolidates
`onError`/`onClose` dispatch on Windows and Apple. Before this, the
Windows and Apple implementations only fired `onError` on connection
failures without a matching `onClose`, leaving consumers (and this test)
in inconsistent terminal-event states.
- **#160** — made the JS-layer `close()` idempotent and `send()`
spec-compliant when CLOSING/CLOSED, fixing cross-state dispatch bugs.

## Verification

Repro PR #161 expanded this test to 20 sequential iterations on the same
branch to exercise the historical 1/3 flake rate. If the flake
persisted, P(all 20 pass) ≈ 0.03%. CI on #161 ran across every
platform/engine combo — Chakra/V8/JSI on UWP/Win32, Linux (gcc, clang,
sanitizers, TSan), macOS (Xcode 16.4, sanitizers, TSan), iOS (Xcode
15.2, 16.4) — and **all 20 iterations passed on every job** ([workflow
run
24587856930](https://github.com/BabylonJS/JsRuntimeHost/actions/runs/24587856930)).

This PR restores the original single test (no loop, default mocha
timeout) as it was before #130.

Fixes #131.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants