refactor: add CanGc as argument to OffscreenCanvas methods (#35731)

Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
This commit is contained in:
Yerkebulan Tulibergenov 2025-03-01 00:05:22 -08:00 committed by GitHub
parent 494ebaa751
commit 4f8d816385
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View file

@ -107,13 +107,14 @@ impl OffscreenCanvas {
pub(crate) fn get_or_init_2d_context( pub(crate) fn get_or_init_2d_context(
&self, &self,
can_gc: CanGc,
) -> Option<DomRoot<OffscreenCanvasRenderingContext2D>> { ) -> Option<DomRoot<OffscreenCanvasRenderingContext2D>> {
if let Some(ctx) = self.context() { if let Some(ctx) = self.context() {
return match *ctx { return match *ctx {
OffscreenCanvasContext::OffscreenContext2d(ref ctx) => Some(DomRoot::from_ref(ctx)), OffscreenCanvasContext::OffscreenContext2d(ref ctx) => Some(DomRoot::from_ref(ctx)),
}; };
} }
let context = OffscreenCanvasRenderingContext2D::new(&self.global(), self, CanGc::note()); let context = OffscreenCanvasRenderingContext2D::new(&self.global(), self, can_gc);
*self.context.borrow_mut() = Some(OffscreenCanvasContext::OffscreenContext2d( *self.context.borrow_mut() = Some(OffscreenCanvasContext::OffscreenContext2d(
Dom::from_ref(&*context), Dom::from_ref(&*context),
)); ));
@ -161,10 +162,11 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
_cx: JSContext, _cx: JSContext,
id: DOMString, id: DOMString,
_options: HandleValue, _options: HandleValue,
can_gc: CanGc,
) -> Fallible<Option<OffscreenRenderingContext>> { ) -> Fallible<Option<OffscreenRenderingContext>> {
match &*id { match &*id {
"2d" => Ok(self "2d" => Ok(self
.get_or_init_2d_context() .get_or_init_2d_context(can_gc)
.map(OffscreenRenderingContext::OffscreenCanvasRenderingContext2D)), .map(OffscreenRenderingContext::OffscreenCanvasRenderingContext2D)),
/*"webgl" | "experimental-webgl" => self /*"webgl" | "experimental-webgl" => self
.get_or_init_webgl_context(cx, options) .get_or_init_webgl_context(cx, options)
@ -184,7 +186,7 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
} }
// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-width // https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-width
fn SetWidth(&self, value: u64) { fn SetWidth(&self, value: u64, can_gc: CanGc) {
self.width.set(value); self.width.set(value);
if let Some(canvas_context) = self.context() { if let Some(canvas_context) = self.context() {
@ -196,7 +198,7 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
} }
if let Some(canvas) = &self.placeholder { if let Some(canvas) = &self.placeholder {
canvas.set_natural_width(value as _, CanGc::note()); canvas.set_natural_width(value as _, can_gc);
} }
} }
@ -206,7 +208,7 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
} }
// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-height // https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-height
fn SetHeight(&self, value: u64) { fn SetHeight(&self, value: u64, can_gc: CanGc) {
self.height.set(value); self.height.set(value);
if let Some(canvas_context) = self.context() { if let Some(canvas_context) = self.context() {
@ -218,7 +220,7 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
} }
if let Some(canvas) = &self.placeholder { if let Some(canvas) = &self.placeholder {
canvas.set_natural_height(value as _, CanGc::note()); canvas.set_natural_height(value as _, can_gc);
} }
} }
} }

View file

@ -414,6 +414,10 @@ DOMInterfaces = {
'canGc': ['StartRendering'], 'canGc': ['StartRendering'],
}, },
'OffscreenCanvas': {
'canGc': ['GetContext', 'SetHeight', 'SetWidth'],
},
'OffscreenCanvasRenderingContext2D': { 'OffscreenCanvasRenderingContext2D': {
'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData', 'GetTransform', 'SetFont', 'FillText', 'MeasureText', 'SetStrokeStyle', 'SetFillStyle', 'SetShadowColor'], 'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData', 'GetTransform', 'SetFont', 'FillText', 'MeasureText', 'SetStrokeStyle', 'SetFillStyle', 'SetShadowColor'],
}, },