Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(canvas): apply transforms and native conversion to fillRect

ldm0aaa5e747af0b
diff --git a/moli-renderer-v8/src/context_bootstrap/canvas.rs b/moli-renderer-v8/src/context_bootstrap/canvas.rs
index 3aeebbee4..2e798d1db 100644
--- a/moli-renderer-v8/src/context_bootstrap/canvas.rs
+++ b/moli-renderer-v8/src/context_bootstrap/canvas.rs
@@ -215,12 +215,11 @@ pub(crate) use context2d::{
canvas_context_clear_rect_callback, canvas_context_close_path_callback,
canvas_context_create_image_data_callback, canvas_context_create_linear_gradient_callback,
canvas_context_draw_image_callback, canvas_context_ellipse_callback,
- canvas_context_fill_callback, canvas_context_fill_rect_callback,
- canvas_context_fill_style_getter_callback, canvas_context_fill_style_setter_callback,
- canvas_context_fill_text_callback, canvas_context_font_getter_callback,
- canvas_context_font_setter_callback, canvas_context_get_image_data_callback,
- canvas_context_get_line_dash_callback, canvas_context_global_alpha_getter_callback,
- canvas_context_global_alpha_setter_callback,
+ canvas_context_fill_callback, canvas_context_fill_style_getter_callback,
+ canvas_context_fill_style_setter_callback, canvas_context_fill_text_callback,
+ canvas_context_font_getter_callback, canvas_context_font_setter_callback,
+ canvas_context_get_image_data_callback, canvas_context_get_line_dash_callback,
+ canvas_context_global_alpha_getter_callback, canvas_context_global_alpha_setter_callback,
canvas_context_global_composite_operation_getter_callback,
canvas_context_global_composite_operation_setter_callback,
canvas_context_image_smoothing_enabled_getter_callback,
@@ -242,7 +241,7 @@ pub(crate) use context2d::{
canvas_context_stroke_rect_callback, canvas_context_stroke_style_getter_callback,
canvas_context_stroke_style_setter_callback, canvas_context_stroke_text_callback,
canvas_context_transform_callback, canvas_context_translate_callback,
- canvas_gradient_add_color_stop_callback,
+ canvas_gradient_add_color_stop_callback, install_canvas_fill_rect_bindings,
};
pub(crate) use image_bitmap::window_create_image_bitmap_callback;
pub(crate) use objects::{
diff --git a/moli-renderer-v8/src/context_bootstrap/canvas/context2d.rs b/moli-renderer-v8/src/context_bootstrap/canvas/context2d.rs
index c47b013ef..166f7b7c5 100644
--- a/moli-renderer-v8/src/context_bootstrap/canvas/context2d.rs
+++ b/moli-renderer-v8/src/context_bootstrap/canvas/context2d.rs
@@ -62,6 +62,42 @@ pub(super) fn install_text_metrics_template_bindings<'s>(
);
}
+macro_rules! canvas_fill_rect_declaration {
+ ($name:ident, $interface:path) => {
+ #[derive(WebApiFunctionTemplate)]
+ #[webapi(interface = $interface, enumerable, receiver)]
+ struct $name {
+ #[webapi(method = "fillRect", length = 4, callback = canvas_context_fill_rect_callback)]
+ fill_rect: (),
+ }
+ };
+}
+
+canvas_fill_rect_declaration!(
+ CanvasFillRectDeclaration,
+ web_api_interfaces::CanvasRenderingContext2D
+);
+canvas_fill_rect_declaration!(
+ OffscreenCanvasFillRectDeclaration,
+ web_api_interfaces::OffscreenCanvasRenderingContext2D
+);
+
+pub(crate) fn install_canvas_fill_rect_bindings<'s>(
+ scope: &mut v8::PinScope<'s, '_, ()>,
+ prototype: v8::Local<'s, v8::ObjectTemplate>,
+ interface: &str,
+) {
+ match interface {
+ "CanvasRenderingContext2D" => {
+ CanvasFillRectDeclaration::initialize_prototype_template(scope, prototype);
+ }
+ "OffscreenCanvasRenderingContext2D" => {
+ OffscreenCanvasFillRectDeclaration::initialize_prototype_template(scope, prototype);
+ }
+ _ => unreachable!("only Canvas 2D contexts have fillRect bindings"),
+ }
+}
+
fn text_metrics_width_getter<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
@@ -250,6 +286,19 @@ struct CanvasContextRectPathArgs {
height: f64,
}
+#[derive(webidl::WebIdlArgs)]
+#[webidl(prefix = "CanvasRenderingContext2D.fillRect")]
+struct CanvasContextFillRectArgs {
+ #[webidl(required)]
+ x: f64,
+ #[webidl(required)]
+ y: f64,
+ #[webidl(required)]
+ width: f64,
+ #[webidl(required)]
+ height: f64,
+}
+
#[derive(webidl::WebIdlArgs)]
#[webidl(prefix = "CanvasRenderingContext2D.arc")]
struct CanvasContextArcArgs {
@@ -735,18 +784,38 @@ pub(crate) fn canvas_context_fill_rect_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
_rv: v8::ReturnValue<'_, v8::Value>,
) {
- let Some(canvas) = canvas_owner_from_context(scope, args.this()) else {
+ let context = moli_webapi_declare::web_api_object_target(scope, args.this())
+ .expect("generated fillRect binding validates the receiver");
+ let Some(parsed) = webidl::parse_args::<CanvasContextFillRectArgs>(scope, &args) else {
+ return;
+ };
+ if ![parsed.x, parsed.y, parsed.width, parsed.height]
+ .into_iter()
+ .all(f64::is_finite)
+ || parsed.width == 0.0
+ || parsed.height == 0.0
+ {
+ return;
+ }
+ let Some(canvas) = canvas_owner_from_context(scope, context) else {
return;
};
- let Some(rect) = normalized_rect(scope, &args, "CanvasRenderingContext2D.fillRect") else {
+ let path_state = canvas_path_state(scope, context);
+ let state = path_state.borrow();
+ if state.inverse_transform().is_none() {
return;
+ }
+ let transform = state.transform();
+ drop(state);
+ // Rectangles use local coordinates and must leave the default path untouched.
+ let mut rectangle = super::path::Canvas2dPathState::default();
+ rectangle.rect(parsed.x, parsed.y, parsed.width, parsed.height);
+ let fragment = PaintFragment::Fill {
+ shape: PaintShape::Path(rectangle.paint_path()),
+ brush: PaintBrush::Solid(context_fill_color(scope, context)),
+ transform,
};
- let fill_style = context_string_slot(scope, args.this(), CANVAS_CONTEXT_FILL_STYLE_SLOT)
- .unwrap_or_else(|| DEFAULT_FILL_STYLE.to_owned());
- let color = fill_style_rgba(&fill_style);
- let _ = with_canvas_like_pixels_mut(scope, canvas, |pixels, width, height| {
- paint_rect(pixels, width, height, rect, color);
- });
+ rasterize_canvas_fragment(scope, canvas, fragment);
}
pub(crate) fn canvas_context_clear_rect_callback<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/media_file_template.rs b/moli-renderer-v8/src/context_bootstrap/media_file_template.rs
index 8c4a9c39c..5006c0557 100644
--- a/moli-renderer-v8/src/context_bootstrap/media_file_template.rs
+++ b/moli-renderer-v8/src/context_bootstrap/media_file_template.rs
@@ -4,12 +4,11 @@ use super::canvas::{
canvas_context_clear_rect_callback, canvas_context_close_path_callback,
canvas_context_create_image_data_callback, canvas_context_create_linear_gradient_callback,
canvas_context_draw_image_callback, canvas_context_ellipse_callback,
- canvas_context_fill_callback, canvas_context_fill_rect_callback,
- canvas_context_fill_style_getter_callback, canvas_context_fill_style_setter_callback,
- canvas_context_fill_text_callback, canvas_context_font_getter_callback,
- canvas_context_font_setter_callback, canvas_context_get_image_data_callback,
- canvas_context_get_line_dash_callback, canvas_context_global_alpha_getter_callback,
- canvas_context_global_alpha_setter_callback,
+ canvas_context_fill_callback, canvas_context_fill_style_getter_callback,
+ canvas_context_fill_style_setter_callback, canvas_context_fill_text_callback,
+ canvas_context_font_getter_callback, canvas_context_font_setter_callback,
+ canvas_context_get_image_data_callback, canvas_context_get_line_dash_callback,
+ canvas_context_global_alpha_getter_callback, canvas_context_global_alpha_setter_callback,
canvas_context_global_composite_operation_getter_callback,
canvas_context_global_composite_operation_setter_callback,
canvas_context_image_smoothing_enabled_getter_callback,
@@ -31,10 +30,10 @@ use super::canvas::{
canvas_context_stroke_rect_callback, canvas_context_stroke_style_getter_callback,
canvas_context_stroke_style_setter_callback, canvas_context_stroke_text_callback,
canvas_context_transform_callback, canvas_context_translate_callback,
- canvas_gradient_add_color_stop_callback, install_canvas_template_bindings,
- install_canvas_transform_bindings, offscreen_canvas_convert_to_blob_callback,
- offscreen_canvas_get_context_callback, webgl_boolean_callback,
- webgl_check_framebuffer_status_callback, webgl_create_buffer_callback,
+ canvas_gradient_add_color_stop_callback, install_canvas_fill_rect_bindings,
+ install_canvas_template_bindings, install_canvas_transform_bindings,
+ offscreen_canvas_convert_to_blob_callback, offscreen_canvas_get_context_callback,
+ webgl_boolean_callback, webgl_check_framebuffer_status_callback, webgl_create_buffer_callback,
webgl_create_framebuffer_callback, webgl_create_program_callback,
webgl_create_renderbuffer_callback, webgl_create_shader_callback,
webgl_get_attrib_location_callback, webgl_get_context_attributes_callback,
@@ -248,9 +247,6 @@ struct CanvasRenderingContext2dTemplateDeclaration {
)]
get_line_dash: (),
- #[webapi(method = "fillRect", length = 4, callback = canvas_context_fill_rect_callback)]
- fill_rect: (),
-
#[webapi(
method = "clearRect",
length = 4,
@@ -690,6 +686,7 @@ pub(super) fn install_media_file_template_bindings<'s>(
scope, proto,
);
install_canvas_transform_bindings(scope, proto, spec_name);
+ install_canvas_fill_rect_bindings(scope, proto, spec_name);
}
"WebGLRenderingContext" => {
let proto = template.prototype_template(scope);
diff --git a/moli-renderer-v8/src/script_vm/tests/canvas_fill_rect.js b/moli-renderer-v8/src/script_vm/tests/canvas_fill_rect.js
new file mode 100644
index 000000000..516bb5ce7
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/canvas_fill_rect.js
@@ -0,0 +1,127 @@
+(owner, callee, kind, label) => {
+ const checks = [];
+ const prototype = kind === 'element'
+ ? callee.CanvasRenderingContext2D.prototype
+ : callee.OffscreenCanvasRenderingContext2D.prototype;
+ const fillRect = prototype.fillRect;
+ const assert = (value, message) => { if (!value) throw Error(message); };
+ const equal = (actual, expected) => assert(JSON.stringify(actual) === JSON.stringify(expected),
+ `expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
+ const fresh = () => {
+ const canvas = kind === 'element' ? owner.document.createElement('canvas') : new owner.OffscreenCanvas(64, 64);
+ canvas.width = canvas.height = 64;
+ const ctx = canvas.getContext('2d');
+ return {ctx, pixel: (x, y) => Array.from(ctx.getImageData(x, y, 1, 1).data)};
+ };
+ const check = (name, run) => {
+ try { run(); checks.push({name: `${label}/${name}`, passed: true}); }
+ catch (error) { checks.push({name: `${label}/${name}`, passed: false, error: String(error)}); }
+ };
+ const rejects = (run) => {
+ let error;
+ try { run(); } catch (caught) { error = caught; }
+ assert(error instanceof callee.TypeError, 'expected callee TypeError');
+ };
+ check('descriptor', () => {
+ const descriptor = callee.Object.getOwnPropertyDescriptor(prototype, 'fillRect');
+ assert(typeof descriptor.value === 'function' && descriptor.enumerable && descriptor.writable && descriptor.configurable,
+ 'ordinary enumerable operation');
+ equal(fillRect.length, 4);
+ });
+ for (let arity = 0; arity < 4; arity++) check(`arity-${arity}`, () => {
+ rejects(() => fillRect.apply(fresh().ctx, Array(arity).fill(1)));
+ });
+ for (const forgery of ['prototype', 'inherit-native', 'proxy', 'revoked']) check(`brand-${forgery}`, () => {
+ const {ctx} = fresh();
+ let reads = 0;
+ const value = {valueOf() { reads++; return 1; }};
+ let receiver;
+ if (forgery === 'prototype') receiver = owner.Object.create(owner.Object.getPrototypeOf(ctx));
+ if (forgery === 'inherit-native') receiver = owner.Object.create(ctx);
+ if (forgery === 'proxy') receiver = new owner.Proxy(ctx, {get() { reads++; throw Error('proxy trap'); }});
+ if (forgery === 'revoked') {
+ const pair = owner.Proxy.revocable(ctx, {}); pair.revoke(); receiver = pair.proxy;
+ }
+ rejects(() => fillRect.call(receiver, value, value, value, value));
+ equal(reads, 0);
+ });
+ check('other-interface', () => {
+ const canvas = kind === 'element' ? new owner.OffscreenCanvas(64, 64) : owner.document?.createElement('canvas');
+ if (!canvas) return;
+ let conversions = 0;
+ rejects(() => fillRect.call(canvas.getContext('2d'), {valueOf() { conversions++; return 1; }}, 1, 2, 3));
+ equal(conversions, 0);
+ });
+ for (const [name, transform, rectangle, hit, miss] of [
+ ['translate', [1, 0, 0, 1, 20, 10], [2, 2, 8, 8], [24, 14], [4, 4]],
+ ['scale', [2, 0, 0, 3, 0, 0], [2, 2, 8, 8], [14, 20], [3, 3]],
+ ['rotate', [0, 1, -1, 0, 32, 0], [2, 2, 8, 8], [26, 6], [6, 6]],
+ ['shear', [1, 0, 1, 1, 0, 0], [2, 2, 8, 8], [14, 8], [3, 8]],
+ ['reflect', [-1, 0, 0, 1, 32, 0], [2, 2, 8, 8], [26, 6], [6, 6]],
+ ['negative-size', [1, 0, 0, 1, 16, 12], [10, 10, -8, -8], [22, 18], [6, 6]],
+ ]) check(name, () => {
+ const {ctx, pixel} = fresh(); ctx.fillStyle = 'red'; ctx.setTransform(...transform);
+ fillRect.call(ctx, ...rectangle);
+ equal(pixel(...hit), [255, 0, 0, 255]); equal(pixel(...miss), [0, 0, 0, 0]);
+ });
+ for (const [name, transform] of [['singular', [1, 2, 2, 4, 0, 0]], ['zero-matrix', [0, 0, 0, 0, 0, 0]]])
+ check(name, () => {
+ const {ctx} = fresh(); ctx.setTransform(...transform); fillRect.call(ctx, 2, 2, 8, 8);
+ assert(ctx.getImageData(0, 0, 64, 64).data.every(value => value === 0), 'singular transform drew pixels');
+ });
+ check('fractional-coordinates', () => {
+ const {ctx, pixel} = fresh(); fillRect.call(ctx, 1.75, 1.75, 4.5, 4.5);
+ equal(pixel(2, 2), [0, 0, 0, 255]);
+ const edge = pixel(1, 1)[3]; assert(edge > 0 && edge < 255, `fractional coverage ${edge}`);
+ });
+ check('preserve-default-path', () => {
+ const {ctx, pixel} = fresh(); ctx.rect(2, 2, 8, 8); fillRect.call(ctx, 30, 2, 8, 8);
+ ctx.clearRect(0, 0, 64, 64); ctx.fill();
+ equal(pixel(4, 4), [0, 0, 0, 255]); equal(pixel(32, 4), [0, 0, 0, 0]);
+ });
+ check('global-alpha', () => {
+ const {ctx, pixel} = fresh(); ctx.fillStyle = 'red'; ctx.globalAlpha = .5;
+ fillRect.call(ctx, 2, 2, 8, 8); equal(pixel(4, 4), [255, 0, 0, 128]);
+ });
+ check('source-over', () => {
+ const {ctx, pixel} = fresh(); ctx.fillStyle = 'blue'; fillRect.call(ctx, 2, 2, 8, 8);
+ ctx.fillStyle = 'red'; ctx.globalAlpha = .5; fillRect.call(ctx, 2, 2, 8, 8);
+ equal(pixel(4, 4), [128, 0, 127, 255]);
+ });
+ check('fill-style-alpha', () => {
+ const {ctx, pixel} = fresh(); ctx.fillStyle = 'rgba(255, 0, 0, 0.5)';
+ fillRect.call(ctx, 2, 2, 8, 8); equal(pixel(4, 4), [255, 0, 0, 128]);
+ });
+ for (const value of [NaN, Infinity, -Infinity]) for (let index = 0; index < 4; index++)
+ check(`nonfinite-${String(value)}-${index}`, () => {
+ const {ctx} = fresh(); const args = [2, 2, 8, 8]; args[index] = value;
+ fillRect.call(ctx, ...args);
+ assert(ctx.getImageData(0, 0, 64, 64).data.every(value => value === 0), 'nonfinite argument drew pixels');
+ });
+ for (const [name, rectangle] of [['zero-width', [2, 2, 0, 8]], ['zero-height', [2, 2, 8, 0]]])
+ check(name, () => {
+ const {ctx} = fresh(); fillRect.call(ctx, ...rectangle);
+ assert(ctx.getImageData(0, 0, 64, 64).data.every(value => value === 0), 'zero area drew pixels');
+ });
+ check('conversion-order', () => {
+ const {ctx, pixel} = fresh(); const order = [];
+ const args = [2, 2, 8, 8].map((value, index) => ({valueOf() { order.push(index); return value; }}));
+ fillRect.call(ctx, ...args); equal(order, [0, 1, 2, 3]); equal(pixel(4, 4), [0, 0, 0, 255]);
+ });
+ check('conversion-exception', () => {
+ const {ctx} = fresh(); const marker = {}; let later = false; let caught;
+ try { fillRect.call(ctx, 2, {valueOf() { throw marker; }}, {valueOf() { later = true; return 8; }}, 8); }
+ catch (error) { caught = error; }
+ assert(caught === marker && !later, 'conversion exception or order');
+ });
+ check('nonfinite-converts-all', () => {
+ const {ctx} = fresh(); const order = [];
+ const args = [NaN, 2, 8, 8].map((value, index) => ({valueOf() { order.push(index); return value; }}));
+ fillRect.call(ctx, ...args); equal(order, [0, 1, 2, 3]);
+ });
+ check('primitive-conversion', () => {
+ const {ctx, pixel} = fresh(); fillRect.call(ctx, null, false, true, '4');
+ equal(pixel(0, 1), [0, 0, 0, 255]);
+ });
+ return checks;
+}
diff --git a/moli-renderer-v8/src/script_vm/tests/canvas_fill_rect.rs b/moli-renderer-v8/src/script_vm/tests/canvas_fill_rect.rs
new file mode 100644
index 000000000..11a734488
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/canvas_fill_rect.rs
@@ -0,0 +1,71 @@
+use super::*;
+
+#[test]
+fn canvas_fill_rect_uses_native_receivers_transforms_and_alpha_across_realms() {
+ let mut vm = new_storage_page_task_executor_test_vm("https://canvas-fill-rect.test/");
+ vm.eval("document.body.innerHTML = '<iframe id=child></iframe>'")
+ .unwrap();
+ let source = format!(
+ r#"(() => {{
+ const probe = {};
+ const realms = [globalThis, document.getElementById('child').contentWindow];
+ const checks = [];
+ for(let owner=0;owner<2;owner++) for(let callee=0;callee<2;callee++)
+ for(const kind of ['element','offscreen'])
+ checks.push(...probe(realms[owner],realms[callee],kind,`window-${{owner}}-${{callee}}-${{kind}}`));
+ globalThis.__fillRectChecks = checks;
+ return checks.length;
+ }})()"#,
+ include_str!("canvas_fill_rect.js"),
+ );
+ assert_eq!(vm.eval(&source).unwrap(), "328");
+ assert_eq!(
+ vm.eval("JSON.stringify(__fillRectChecks.filter(row => !row.passed))")
+ .unwrap(),
+ "[]"
+ );
+}
+
+#[test]
+fn canvas_fill_rect_registered_native_proxy_keeps_context_identity() {
+ let mut vm = new_storage_page_task_executor_test_vm("https://canvas-fill-rect-proxy.test/");
+ vm.eval(
+ "globalThis.ctx = new OffscreenCanvas(64,64).getContext('2d');\
+ ctx.setTransform(1,0,0,1,20,10); ctx.fillStyle='red'; ctx.globalAlpha=.5;",
+ )
+ .unwrap();
+ let context_ptr = &vm.page_default_context as *const _;
+ vm.with_context_scope_by_ptr_and_checkpoint_for_test(context_ptr, |scope, _| {
+ let global = scope.get_current_context().global(scope);
+ let key = crate::util::v8str(scope, "ctx");
+ let value = global.get(scope, key.into()).unwrap();
+ let target = v8::Local::<v8::Object>::try_from(value).unwrap();
+ let handler = crate::util::new_null_prototype_object(scope);
+ let proxy = v8::Proxy::new(scope, target, handler).unwrap();
+ moli_webapi_declare::register_web_api_proxy(scope, proxy).unwrap();
+ let key = crate::util::v8str(scope, "nativeProxy");
+ assert_eq!(
+ global.create_data_property(scope, key.into(), proxy.into()),
+ Some(true)
+ );
+ Ok(())
+ })
+ .unwrap();
+ assert_eq!(
+ vm.eval(
+ r#"(() => {
+ const fillRect = OffscreenCanvasRenderingContext2D.prototype.fillRect;
+ fillRect.call(nativeProxy,2,2,8,8);
+ const hit = Array.from(ctx.getImageData(24,14,1,1).data);
+ if(JSON.stringify(hit)!=='[255,0,0,128]') throw Error('native proxy state');
+ let conversions=0, caught;
+ try {fillRect.call(new Proxy(nativeProxy,{}),{valueOf(){conversions++;return 2;}},2,8,8);}
+ catch(error){caught=error;}
+ if(!(caught instanceof TypeError) || conversions!==0) throw Error('author proxy branding');
+ return true;
+ })()"#,
+ )
+ .unwrap(),
+ "true"
+ );
+}
diff --git a/moli-renderer-v8/src/script_vm/tests/canvas_webgl.rs b/moli-renderer-v8/src/script_vm/tests/canvas_webgl.rs
index a515aed40..306f02c5a 100644
--- a/moli-renderer-v8/src/script_vm/tests/canvas_webgl.rs
+++ b/moli-renderer-v8/src/script_vm/tests/canvas_webgl.rs
@@ -1317,7 +1317,7 @@ fn canvas_context_state_uses_private_slots_for_reflection_and_spoofing() {
assert_eq!(
result,
- r##"{"initialOwnSlots":"","defaults":"#000000|10px sans-serif|true|low|1|source-over","beforeSpoof":"#ff0000|20px Arial|false|high|0.5|source-over","ownSlotsAfterSetter":"","beforeSpoofPixel":"255,0,0,255","afterSpoof":"#ff0000|20px Arial|false|high|0.5|source-over","afterSpoofPixel":"255,0,0,255","ownSlotsAfterSpoof":"__moliCanvasContextFillStyle,__moliCanvasContextFont,__moliCanvasContextGlobalAlpha,__moliCanvasContextGlobalCompositeOperation,__moliCanvasContextImageSmoothingEnabled,__moliCanvasContextImageSmoothingQuality","widthSame":true,"fakeFillStyleError":"TypeError","instance":true}"##
+ r##"{"initialOwnSlots":"","defaults":"#000000|10px sans-serif|true|low|1|source-over","beforeSpoof":"#ff0000|20px Arial|false|high|0.5|source-over","ownSlotsAfterSetter":"","beforeSpoofPixel":"255,0,0,128","afterSpoof":"#ff0000|20px Arial|false|high|0.5|source-over","afterSpoofPixel":"255,0,0,128","ownSlotsAfterSpoof":"__moliCanvasContextFillStyle,__moliCanvasContextFont,__moliCanvasContextGlobalAlpha,__moliCanvasContextGlobalCompositeOperation,__moliCanvasContextImageSmoothingEnabled,__moliCanvasContextImageSmoothingQuality","widthSame":true,"fakeFillStyleError":"TypeError","instance":true}"##
);
}
diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rs
index 181cc334e..40c70d47f 100644
--- a/moli-renderer-v8/src/script_vm/tests/mod.rs
+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs
@@ -2135,6 +2135,7 @@ mod blob_response_headers;
mod browser_api;
mod cache_interfaces;
mod canvas_arguments;
+mod canvas_fill_rect;
mod canvas_paths;
mod canvas_transform_snapshots;
mod canvas_webgl;
diff --git a/moli-renderer-v8/src/worker/thread/tests/canvas_fill_rect.rs b/moli-renderer-v8/src/worker/thread/tests/canvas_fill_rect.rs
new file mode 100644
index 000000000..ec5566c13
--- /dev/null
+++ b/moli-renderer-v8/src/worker/thread/tests/canvas_fill_rect.rs
@@ -0,0 +1,19 @@
+use super::*;
+
+#[tokio::test]
+async fn worker_fill_rect_applies_transforms_and_alpha_with_native_receivers() {
+ ensure_v8();
+ let source = format!(
+ r#"const probe = {};
+ const checks = probe(globalThis,globalThis,'offscreen','worker');
+ postMessage({{total:checks.length,failures:checks.filter(row => !row.passed)}});
+ close();"#,
+ include_str!("../../../script_vm/tests/canvas_fill_rect.js"),
+ );
+ let mut worker = spawn_worker(source, "test://canvas_fill_rect".into());
+ let message = timeout(TIMEOUT, worker.recv())
+ .await
+ .expect("timed out")
+ .expect("channel closed");
+ assert_eq!(expect_post_json(message), r#"{"total":41,"failures":[]}"#);
+}
diff --git a/moli-renderer-v8/src/worker/thread/tests/mod.rs b/moli-renderer-v8/src/worker/thread/tests/mod.rs
index f6d2fe628..d9b2d05b4 100644
--- a/moli-renderer-v8/src/worker/thread/tests/mod.rs
+++ b/moli-renderer-v8/src/worker/thread/tests/mod.rs
@@ -1539,4 +1539,5 @@ mod canvas_transform_snapshots;
mod tls;
+mod canvas_fill_rect;
mod xhr_failure;