SIGN IN SIGN UP
denoland / deno UNCLAIMED

A modern runtime for JavaScript and TypeScript.

0 0 16 Rust

refactor(ext/web): port ImageData to Rust with CPPGC/objectwrap (#33777)

## Summary

- Moves the `ImageData` class from a JS IIFE
(`ext/web/16_image_data.js`) into a CPPGC-backed Rust struct in
`ext/web/image_data.rs`, registered via `op2`'s `objects = [...]`.
- Mirrors the established pattern from the geometry interfaces
(`DOMRect`/`DOMPoint`/etc.): WebIDL-derived enums and dictionary, manual
`trace` over `v8::TracedReference`, and an ESM (`image_data.js`) that
wires up the custom inspect proxy and `webidl.configureInterface`.
- `runtime/js/98_global_scope_shared.js` now lazy-loads `ImageData`
(consistent with how `DOMRect` and friends are exposed).
- `ext/image/01_image.js` switches off the private `_data` / `_width` /
`_height` symbols and uses the public `width` / `height` / `data`
getters instead.
- Registers a new `DOMExceptionIndexSizeError` error builder so the Rust
constructor can throw the same `IndexSizeError` cases the JS
implementation did.

The two `ImageData` constructor overloads (`(sw, sh [, settings])` and
`(data, sw [, sh [, settings]])`) and every existing error path are
preserved. `Uint8ClampedArray` and `Float16Array` data are kept by
reference (no copy) via `v8::TracedReference<v8::Object>`.

## Test plan

- [x] `cargo build --bin deno`
- [x] `tools/format.js --check`
- [x] `tools/lint.js`
- [x] Smoke test the WPT-style cases from
`tests/unit/image_data_test.ts`
  (both overloads, default `srgb` / `rgba-unorm8`, custom `display-p3` /
  `rgba-float16`, and every `DOMException` error path).
- [x] `createImageBitmap(imageData)` (basic + crop) round-trips through
the new
  public `image.data` accessor in `ext/image/01_image.js`.
- [x] `tests/testdata/workers/image_data_worker.ts` (ImageData inside a
Worker).

---------

Co-authored-by: Leo Kettmeir <crowlkats@toaxl.com>
C
crowlbot committed
3b2cbfe25c76710e244c9e6c35b7ec7b12b262f4
Parent: d513f20
Committed by GitHub <noreply@github.com> on 6/1/2026, 12:51:52 PM