mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
CanGc fixes starting from imagedata.rs (#33808)
* CanGc fixes starting from imagedata.rs Signed-off-by: L Ashwin B <lashwinib@gmail.com> * Update components/script/dom/imagedata.rs Co-authored-by: Josh Matthews <josh@joshmatthews.net> Signed-off-by: chickenleaf <lashwinib@gmail.com> --------- Signed-off-by: L Ashwin B <lashwinib@gmail.com> Signed-off-by: chickenleaf <lashwinib@gmail.com> Co-authored-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
27b25e869b
commit
20a15619f0
5 changed files with 65 additions and 24 deletions
|
@ -57,6 +57,7 @@ use crate::dom::node::{window_from_node, Node, NodeDamage};
|
||||||
use crate::dom::offscreencanvas::{OffscreenCanvas, OffscreenCanvasContext};
|
use crate::dom::offscreencanvas::{OffscreenCanvas, OffscreenCanvasContext};
|
||||||
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
|
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
|
||||||
use crate::dom::textmetrics::TextMetrics;
|
use crate::dom::textmetrics::TextMetrics;
|
||||||
|
use crate::script_runtime::CanGc;
|
||||||
use crate::unpremultiplytable::UNPREMULTIPLY_TABLE;
|
use crate::unpremultiplytable::UNPREMULTIPLY_TABLE;
|
||||||
|
|
||||||
#[crown::unrooted_must_root_lint::must_root]
|
#[crown::unrooted_must_root_lint::must_root]
|
||||||
|
@ -1232,11 +1233,12 @@ impl CanvasState {
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
sw: i32,
|
sw: i32,
|
||||||
sh: i32,
|
sh: i32,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Fallible<DomRoot<ImageData>> {
|
) -> Fallible<DomRoot<ImageData>> {
|
||||||
if sw == 0 || sh == 0 {
|
if sw == 0 || sh == 0 {
|
||||||
return Err(Error::IndexSize);
|
return Err(Error::IndexSize);
|
||||||
}
|
}
|
||||||
ImageData::new(global, sw.unsigned_abs(), sh.unsigned_abs(), None)
|
ImageData::new(global, sw.unsigned_abs(), sh.unsigned_abs(), None, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||||
|
@ -1244,8 +1246,9 @@ impl CanvasState {
|
||||||
&self,
|
&self,
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
imagedata: &ImageData,
|
imagedata: &ImageData,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Fallible<DomRoot<ImageData>> {
|
) -> Fallible<DomRoot<ImageData>> {
|
||||||
ImageData::new(global, imagedata.Width(), imagedata.Height(), None)
|
ImageData::new(global, imagedata.Width(), imagedata.Height(), None, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
||||||
|
@ -1257,6 +1260,7 @@ impl CanvasState {
|
||||||
sy: i32,
|
sy: i32,
|
||||||
sw: i32,
|
sw: i32,
|
||||||
sh: i32,
|
sh: i32,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Fallible<DomRoot<ImageData>> {
|
) -> Fallible<DomRoot<ImageData>> {
|
||||||
// FIXME(nox): There are many arithmetic operations here that can
|
// FIXME(nox): There are many arithmetic operations here that can
|
||||||
// overflow or underflow, this should probably be audited.
|
// overflow or underflow, this should probably be audited.
|
||||||
|
@ -1274,7 +1278,7 @@ impl CanvasState {
|
||||||
Some(rect) => rect,
|
Some(rect) => rect,
|
||||||
None => {
|
None => {
|
||||||
// All the pixels are outside the canvas surface.
|
// All the pixels are outside the canvas surface.
|
||||||
return ImageData::new(global, size.width, size.height, None);
|
return ImageData::new(global, size.width, size.height, None, can_gc);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1283,6 +1287,7 @@ impl CanvasState {
|
||||||
size.width,
|
size.width,
|
||||||
size.height,
|
size.height,
|
||||||
Some(self.get_rect(canvas_size, read_rect)),
|
Some(self.get_rect(canvas_size, read_rect)),
|
||||||
|
can_gc,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,10 @@ DOMInterfaces = {
|
||||||
'inRealms': ['WhenDefined'],
|
'inRealms': ['WhenDefined'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'CanvasRenderingContext2D': {
|
||||||
|
'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData'],
|
||||||
|
},
|
||||||
|
|
||||||
'DOMImplementation': {
|
'DOMImplementation': {
|
||||||
'canGc': ['CreateDocument', 'CreateHTMLDocument'],
|
'canGc': ['CreateDocument', 'CreateHTMLDocument'],
|
||||||
},
|
},
|
||||||
|
@ -145,6 +149,10 @@ DOMInterfaces = {
|
||||||
'inRealms': ['StartRendering'],
|
'inRealms': ['StartRendering'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'OffscreenCanvasRenderingContext2D': {
|
||||||
|
'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData'],
|
||||||
|
},
|
||||||
|
|
||||||
'Promise': {
|
'Promise': {
|
||||||
'spiderMonkeyInterface': True,
|
'spiderMonkeyInterface': True,
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,6 +26,7 @@ use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
|
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
|
||||||
use crate::dom::imagedata::ImageData;
|
use crate::dom::imagedata::ImageData;
|
||||||
use crate::dom::textmetrics::TextMetrics;
|
use crate::dom::textmetrics::TextMetrics;
|
||||||
|
use crate::script_runtime::CanGc;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#canvasrenderingcontext2d
|
// https://html.spec.whatwg.org/multipage/#canvasrenderingcontext2d
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -467,18 +468,30 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||||
fn CreateImageData(&self, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
fn CreateImageData(&self, sw: i32, sh: i32, can_gc: CanGc) -> Fallible<DomRoot<ImageData>> {
|
||||||
self.canvas_state.create_image_data(&self.global(), sw, sh)
|
self.canvas_state
|
||||||
|
.create_image_data(&self.global(), sw, sh, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||||
fn CreateImageData_(&self, imagedata: &ImageData) -> Fallible<DomRoot<ImageData>> {
|
fn CreateImageData_(
|
||||||
|
&self,
|
||||||
|
imagedata: &ImageData,
|
||||||
|
can_gc: CanGc,
|
||||||
|
) -> Fallible<DomRoot<ImageData>> {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.create_image_data_(&self.global(), imagedata)
|
.create_image_data_(&self.global(), imagedata, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
||||||
fn GetImageData(&self, sx: i32, sy: i32, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
fn GetImageData(
|
||||||
|
&self,
|
||||||
|
sx: i32,
|
||||||
|
sy: i32,
|
||||||
|
sw: i32,
|
||||||
|
sh: i32,
|
||||||
|
can_gc: CanGc,
|
||||||
|
) -> Fallible<DomRoot<ImageData>> {
|
||||||
self.canvas_state.get_image_data(
|
self.canvas_state.get_image_data(
|
||||||
self.canvas
|
self.canvas
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -488,6 +501,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
sy,
|
sy,
|
||||||
sw,
|
sw,
|
||||||
sh,
|
sh,
|
||||||
|
can_gc,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ impl ImageData {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
mut data: Option<Vec<u8>>,
|
mut data: Option<Vec<u8>>,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Fallible<DomRoot<ImageData>> {
|
) -> Fallible<DomRoot<ImageData>> {
|
||||||
let len = width * height * 4;
|
let len = width * height * 4;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -48,16 +49,9 @@ impl ImageData {
|
||||||
d.resize(len as usize, 0);
|
d.resize(len as usize, 0);
|
||||||
let data = CreateWith::Slice(&d[..]);
|
let data = CreateWith::Slice(&d[..]);
|
||||||
Uint8ClampedArray::create(*cx, data, js_object.handle_mut()).unwrap();
|
Uint8ClampedArray::create(*cx, data, js_object.handle_mut()).unwrap();
|
||||||
Self::new_with_jsobject(
|
Self::new_with_jsobject(global, None, width, Some(height), js_object.get(), can_gc)
|
||||||
global,
|
|
||||||
None,
|
|
||||||
width,
|
|
||||||
Some(height),
|
|
||||||
js_object.get(),
|
|
||||||
CanGc::note(),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
Self::new_without_jsobject(global, None, width, height, CanGc::note())
|
Self::new_without_jsobject(global, None, width, height, can_gc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ use crate::dom::htmlcanvaselement::HTMLCanvasElement;
|
||||||
use crate::dom::imagedata::ImageData;
|
use crate::dom::imagedata::ImageData;
|
||||||
use crate::dom::offscreencanvas::OffscreenCanvas;
|
use crate::dom::offscreencanvas::OffscreenCanvas;
|
||||||
use crate::dom::textmetrics::TextMetrics;
|
use crate::dom::textmetrics::TextMetrics;
|
||||||
|
use crate::script_runtime::CanGc;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct OffscreenCanvasRenderingContext2D {
|
pub struct OffscreenCanvasRenderingContext2D {
|
||||||
|
@ -342,20 +343,39 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||||
fn CreateImageData(&self, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
fn CreateImageData(&self, sw: i32, sh: i32, can_gc: CanGc) -> Fallible<DomRoot<ImageData>> {
|
||||||
self.canvas_state.create_image_data(&self.global(), sw, sh)
|
self.canvas_state
|
||||||
|
.create_image_data(&self.global(), sw, sh, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||||
fn CreateImageData_(&self, imagedata: &ImageData) -> Fallible<DomRoot<ImageData>> {
|
fn CreateImageData_(
|
||||||
|
&self,
|
||||||
|
imagedata: &ImageData,
|
||||||
|
can_gc: CanGc,
|
||||||
|
) -> Fallible<DomRoot<ImageData>> {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.create_image_data_(&self.global(), imagedata)
|
.create_image_data_(&self.global(), imagedata, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
||||||
fn GetImageData(&self, sx: i32, sy: i32, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
fn GetImageData(
|
||||||
self.canvas_state
|
&self,
|
||||||
.get_image_data(self.canvas.get_size(), &self.global(), sx, sy, sw, sh)
|
sx: i32,
|
||||||
|
sy: i32,
|
||||||
|
sw: i32,
|
||||||
|
sh: i32,
|
||||||
|
can_gc: CanGc,
|
||||||
|
) -> Fallible<DomRoot<ImageData>> {
|
||||||
|
self.canvas_state.get_image_data(
|
||||||
|
self.canvas.get_size(),
|
||||||
|
&self.global(),
|
||||||
|
sx,
|
||||||
|
sy,
|
||||||
|
sw,
|
||||||
|
sh,
|
||||||
|
can_gc,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue