aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlcanvaselement.rs
diff options
context:
space:
mode:
authormarmeladema <xademax@gmail.com>2019-07-27 15:44:54 +0100
committermarmeladema <xademax@gmail.com>2019-08-09 00:02:08 +0100
commit1d92796b0308f9138ae9a7feee2218651d16f357 (patch)
treecb33d3d603314934a7b784eeae53a8f5f94594f1 /components/script/dom/htmlcanvaselement.rs
parentd1282dc8cce120189f0c72b98f790561df557728 (diff)
downloadservo-1d92796b0308f9138ae9a7feee2218651d16f357.tar.gz
servo-1d92796b0308f9138ae9a7feee2218651d16f357.zip
Remove some usage of unsafe code in HTMLCanvasElement
Diffstat (limited to 'components/script/dom/htmlcanvaselement.rs')
-rw-r--r--components/script/dom/htmlcanvaselement.rs59
1 files changed, 26 insertions, 33 deletions
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs
index 4e9abe5f3c9..1c07a88cc1c 100644
--- a/components/script/dom/htmlcanvaselement.rs
+++ b/components/script/dom/htmlcanvaselement.rs
@@ -28,7 +28,7 @@ use crate::dom::webgl2renderingcontext::WebGL2RenderingContext;
use crate::dom::webglrenderingcontext::{
LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext,
};
-use crate::script_runtime::JSContext as SafeJSContext;
+use crate::script_runtime::JSContext;
use base64;
use canvas_traits::canvas::{CanvasId, CanvasMsg, FromScriptMsg};
use canvas_traits::webgl::{GLContextAttributes, WebGLVersion};
@@ -39,7 +39,6 @@ use image::png::PNGEncoder;
use image::ColorType;
use ipc_channel::ipc::IpcSharedMemory;
use js::error::throw_type_error;
-use js::jsapi::JSContext;
use js::rust::HandleValue;
use profile_traits::ipc;
use script_layout_interface::{HTMLCanvasData, HTMLCanvasDataSource};
@@ -207,10 +206,9 @@ impl HTMLCanvasElement {
Some(context)
}
- #[allow(unsafe_code)]
- unsafe fn get_or_init_webgl_context(
+ fn get_or_init_webgl_context(
&self,
- cx: *mut JSContext,
+ cx: JSContext,
options: HandleValue,
) -> Option<DomRoot<WebGLRenderingContext>> {
if let Some(ctx) = self.context() {
@@ -227,10 +225,9 @@ impl HTMLCanvasElement {
Some(context)
}
- #[allow(unsafe_code)]
- unsafe fn get_or_init_webgl2_context(
+ fn get_or_init_webgl2_context(
&self,
- cx: *mut JSContext,
+ cx: JSContext,
options: HandleValue,
) -> Option<DomRoot<WebGL2RenderingContext>> {
if !pref!(dom.webgl2.enabled) {
@@ -260,20 +257,19 @@ impl HTMLCanvasElement {
}
#[allow(unsafe_code)]
- unsafe fn get_gl_attributes(
- cx: *mut JSContext,
- options: HandleValue,
- ) -> Option<GLContextAttributes> {
- match WebGLContextAttributes::new(SafeJSContext::from_ptr(cx), options) {
- Ok(ConversionResult::Success(ref attrs)) => Some(From::from(attrs)),
- Ok(ConversionResult::Failure(ref error)) => {
- throw_type_error(cx, &error);
- None
- },
- _ => {
- debug!("Unexpected error on conversion of WebGLContextAttributes");
- None
- },
+ fn get_gl_attributes(cx: JSContext, options: HandleValue) -> Option<GLContextAttributes> {
+ unsafe {
+ match WebGLContextAttributes::new(cx, options) {
+ Ok(ConversionResult::Success(ref attrs)) => Some(From::from(attrs)),
+ Ok(ConversionResult::Failure(ref error)) => {
+ throw_type_error(*cx, &error);
+ None
+ },
+ _ => {
+ debug!("Unexpected error on conversion of WebGLContextAttributes");
+ None
+ },
+ }
}
}
@@ -329,10 +325,9 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
make_uint_setter!(SetHeight, "height", DEFAULT_HEIGHT);
// https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext
- #[allow(unsafe_code)]
fn GetContext(
&self,
- cx: SafeJSContext,
+ cx: JSContext,
id: DOMString,
options: HandleValue,
) -> Option<RenderingContext> {
@@ -340,14 +335,12 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
"2d" => self
.get_or_init_2d_context()
.map(RenderingContext::CanvasRenderingContext2D),
- "webgl" | "experimental-webgl" => unsafe {
- self.get_or_init_webgl_context(*cx, options)
- .map(RenderingContext::WebGLRenderingContext)
- },
- "webgl2" | "experimental-webgl2" => unsafe {
- self.get_or_init_webgl2_context(*cx, options)
- .map(RenderingContext::WebGL2RenderingContext)
- },
+ "webgl" | "experimental-webgl" => self
+ .get_or_init_webgl_context(cx, options)
+ .map(RenderingContext::WebGLRenderingContext),
+ "webgl2" | "experimental-webgl2" => self
+ .get_or_init_webgl2_context(cx, options)
+ .map(RenderingContext::WebGL2RenderingContext),
_ => None,
}
}
@@ -355,7 +348,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
// https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl
fn ToDataURL(
&self,
- _context: SafeJSContext,
+ _context: JSContext,
_mime_type: Option<DOMString>,
_quality: HandleValue,
) -> Fallible<USVString> {