mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
Use safe NonZero constructor instead of an explicit null check
This commit is contained in:
parent
10ec5a2bb0
commit
b78ac6ba6a
4 changed files with 6 additions and 10 deletions
|
@ -105,8 +105,7 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> {
|
||||||
};
|
};
|
||||||
self.index.set(index + 1);
|
self.index.set(index + 1);
|
||||||
result.map(|_| {
|
result.map(|_| {
|
||||||
assert!(!rval.is_null());
|
NonNull::new(rval.get()).expect("got a null pointer")
|
||||||
unsafe { NonNull::new_unchecked(rval.get()) }
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,6 @@ impl ImageDataMethods for ImageData {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-imagedata-data
|
// https://html.spec.whatwg.org/multipage/#dom-imagedata-data
|
||||||
unsafe fn Data(&self, _: *mut JSContext) -> NonNull<JSObject> {
|
unsafe fn Data(&self, _: *mut JSContext) -> NonNull<JSObject> {
|
||||||
assert!(!self.data.get().is_null());
|
NonNull::new(self.data.get()).expect("got a null pointer")
|
||||||
NonNull::new_unchecked(self.data.get())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,8 +154,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn ArrayAttribute(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
unsafe fn ArrayAttribute(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
||||||
rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16));
|
rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16));
|
||||||
assert!(!array.is_null());
|
NonNull::new(array.get()).expect("got a null pointer")
|
||||||
NonNull::new_unchecked(array.get())
|
|
||||||
}
|
}
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
unsafe fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||||
|
@ -164,8 +163,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn ObjectAttribute(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
unsafe fn ObjectAttribute(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
||||||
rooted!(in(cx) let obj = JS_NewPlainObject(cx));
|
rooted!(in(cx) let obj = JS_NewPlainObject(cx));
|
||||||
assert!(!obj.is_null());
|
NonNull::new(obj.get()).expect("got a null pointer")
|
||||||
NonNull::new_unchecked(obj.get())
|
|
||||||
}
|
}
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
|
unsafe fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
|
|
|
@ -1123,8 +1123,8 @@ impl XMLHttpRequest {
|
||||||
unsafe fn arraybuffer_response(&self, cx: *mut JSContext) -> Option<NonNull<JSObject>> {
|
unsafe fn arraybuffer_response(&self, cx: *mut JSContext) -> Option<NonNull<JSObject>> {
|
||||||
// Step 1
|
// Step 1
|
||||||
let created = self.response_arraybuffer.get();
|
let created = self.response_arraybuffer.get();
|
||||||
if !created.is_null() {
|
if let Some(nonnull) = NonNull::new(created) {
|
||||||
return Some(NonNull::new_unchecked(created));
|
return Some(nonnull)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2
|
// Step 2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue