Skip to content

Blob/URL: identify Blobs by our own constructor; make URL's static methods writable (WebIDL) - #251

Open
matthargett wants to merge 5 commits into
BabylonJS:mainfrom
rebeckerspecialties:blob-identity-url-writable-statics
Open

matthargett wants to merge 5 commits into
BabylonJS:mainfrom
rebeckerspecialties:blob-identity-url-writable-statics

Conversation

@matthargett

@matthargett matthargett commented Sep 17, 2026 •

Copy link
Copy Markdown

Problem

Blob::TryGetData (behind URL.createObjectURL) decided whether an object is one of our Blobs by walking its prototype chain against the current global Blob. A page or harness that installs its own Blob class — BabylonNative's Dawn validation harness does, for image loading — then made every instance of that class pass the check, and ObjectWrap::Unwrap on an object that wraps nothing threw a bare Error: Invalid argument out of createObjectURL; meanwhile a genuine native Blob was rejected as "not a Blob".

The same harness assigns its own URL.createObjectURL. Node-API's napi_default makes static methods read-only, so that assignment failed silently and the native method kept receiving the foreign Blob. In browsers WebIDL static operations are writable/enumerable/configurable, so the override would have worked.

Symptom in the wild: the three SOG Gaussian-splat scenes (and "Iridescence NME") of the Dawn validation catalog failing with Unable to load … .sog: Failed to parse SOG zip data. whose cause is Invalid argument.

Change

  • Keep the Blob constructor on the runtime's native object at Initialize and identify instances against that; a null Unwrap yields nullopt (→ the existing TypeError: … argument is not a Blob).
  • Declare the URL statics (canParse, parse, createObjectURL, revokeObjectURL) with napi_writable | napi_enumerable | napi_configurable, matching WebIDL.
  • Two regression tests in the URL.createObjectURL suite (both fail on main: the real Blob is rejected / the assignment is silently ignored).

Verified on macOS (JavaScriptCore): JavaScript suite green, UnitTests 23/23; the four Playground scenes above pass again on the BabylonNative fork with this build. Fork twin: rebeckerspecialties#35.

…thods writable

Blob::TryGetData compared an object's prototype chain against whatever
the global `Blob` binding held at call time. A script that replaces the
global Blob with its own class (BabylonNative's validation harness does,
for image loading) made every instance of that class look like one of
ours, and Unwrap on an object that wraps nothing threw a bare "Invalid
argument" out of URL.createObjectURL -- while a real Blob was rejected
as "not a Blob". The constructor is now kept on the runtime's native
object at Initialize and identity is checked against that; a null
Unwrap yields "not a Blob" like any other foreign object.

The same harness assigns its own URL.createObjectURL. napi_default
makes static methods read-only, so that assignment failed silently and
the native method kept receiving the foreign Blob. WebIDL static
operations are writable, enumerable and configurable; declare the URL
statics that way.

Found by the SOG Gaussian-splat scenes of BabylonNative's Dawn
validation catalog ("Failed to parse SOG zip data", cause "Invalid
argument"); they pass again with this change. Regression tests cover
both halves.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

matthargett added a commit to rebeckerspecialties/JsRuntimeHost that referenced this pull request Sep 17, 2026
@matthargett

matthargett commented Sep 17, 2026 •

Copy link
Copy Markdown
Author

Twin caught a test-only issue on Win32_x86_Chakra: ChakraCore has no globalThis, so the look-alike test threw a ReferenceError before asserting anything. The test now reaches the global object via Function("return this")() (b374eb4); no polyfill change.

@matthargett

Copy link
Copy Markdown
Author

cc @CedricGuillemet since this is another issue blocking splats on WebGPU in BN

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