Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Option<T> to return from getters #13100

Merged
merged 6 commits into from Aug 31, 2016
Next

Assert that ImageData::data is not null

  • Loading branch information
nox committed Aug 30, 2016
commit 854a3dff681fbc17c7d8cd9706274115efd07169
@@ -37,6 +37,7 @@ impl ImageData {
unsafe {
let cx = global.get_cx();
let js_object: *mut JSObject = JS_NewUint8ClampedArray(cx, width * height * 4);
assert!(!js_object.is_null());

if let Some(vec) = data {
let mut is_shared = false;
@@ -58,6 +59,7 @@ impl ImageData {
let mut is_shared = false;
let data: *const uint8_t =
JS_GetUint8ClampedArrayData(self.Data(cx), &mut is_shared, ptr::null()) as *const uint8_t;
assert!(!data.is_null());
assert!(!is_shared);
let len = self.Width() * self.Height() * 4;
slice::from_raw_parts(data, len as usize).to_vec()
@@ -82,6 +84,7 @@ impl ImageDataMethods for ImageData {

// https://html.spec.whatwg.org/multipage/#dom-imagedata-data
fn Data(&self, _: *mut JSContext) -> *mut JSObject {
assert!(!self.data.get().is_null());
self.data.get()
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.