diff options
author | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-09-17 13:59:42 -0700 |
---|---|---|
committer | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-10-09 12:32:37 +0200 |
commit | 602246a14ccf3027232d642eaa30ed97dab48c2d (patch) | |
tree | 86e2592ccb57c395750012a650f5917ea75d707b /components/script/dom/bindings/conversions.rs | |
parent | ea8f115b8cb30513d077e42884d062d6d10ccee4 (diff) | |
download | servo-602246a14ccf3027232d642eaa30ed97dab48c2d.tar.gz servo-602246a14ccf3027232d642eaa30ed97dab48c2d.zip |
script: Mark as unsafe multiple array_buffer_view_to_xxx functions that take a raw JSObject pointer.
Diffstat (limited to 'components/script/dom/bindings/conversions.rs')
-rw-r--r-- | components/script/dom/bindings/conversions.rs | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 0b050a4fc64..e87feadf9e0 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -532,9 +532,11 @@ unsafe impl ArrayBufferViewContents for f64 { } } -/// Returns a mutable slice of the Array Buffer View data, viewed as T, without checking the real -/// type of it. -pub unsafe fn array_buffer_view_data<'a, T: ArrayBufferViewContents>(abv: *mut JSObject) -> Option<&'a mut [T]> { +/// Returns a mutable slice of the Array Buffer View data, viewed as T, without +/// checking the real type of it. +pub unsafe fn array_buffer_view_data<'a, T>(abv: *mut JSObject) -> Option<&'a mut [T]> + where T: ArrayBufferViewContents +{ assert!(!abv.is_null()); let mut byte_length = 0; @@ -548,17 +550,19 @@ pub unsafe fn array_buffer_view_data<'a, T: ArrayBufferViewContents>(abv: *mut J Some(slice::from_raw_parts_mut(ptr as *mut T, byte_length as usize / mem::size_of::<T>())) } -/// Returns a copy of the ArrayBufferView data, viewed as T, without checking the real type of it. -pub fn array_buffer_view_to_vec<T: ArrayBufferViewContents>(abv: *mut JSObject) -> Option<Vec<T>> { - unsafe { - array_buffer_view_data(abv).map(|data| data.to_vec()) - } +/// Returns a copy of the ArrayBufferView data, viewed as T, without checking +/// the real type of it. +pub unsafe fn array_buffer_view_to_vec<T>(abv: *mut JSObject) -> Option<Vec<T>> + where T: ArrayBufferViewContents +{ + array_buffer_view_data(abv).map(|data| data.to_vec()) } -/// Returns a mutable slice of the Array Buffer View data, viewed as T, checking that the real type -/// of it is ty. -pub unsafe fn array_buffer_view_data_checked<'a, T: ArrayBufferViewContents>(abv: *mut JSObject) - -> Option<&'a mut [T]> { +/// Returns a mutable slice of the Array Buffer View data, viewed as T, checking +/// that the real type of it is ty. +pub unsafe fn array_buffer_view_data_checked<'a, T>(abv: *mut JSObject) -> Option<&'a mut [T]> + where T: ArrayBufferViewContents +{ array_buffer_view_data::<T>(abv).and_then(|data| { if T::is_type_compatible(JS_GetArrayBufferViewType(abv)) { Some(data) @@ -568,12 +572,12 @@ pub unsafe fn array_buffer_view_data_checked<'a, T: ArrayBufferViewContents>(abv }) } -/// Returns a copy of the ArrayBufferView data, viewed as T, checking that the real type -/// of it is ty. -pub fn array_buffer_view_to_vec_checked<T: ArrayBufferViewContents>(abv: *mut JSObject) -> Option<Vec<T>> { - unsafe { - array_buffer_view_data_checked(abv).map(|data| data.to_vec()) - } +/// Returns a copy of the ArrayBufferView data, viewed as T, checking that the +/// real type of it is ty. +pub unsafe fn array_buffer_view_to_vec_checked<T>(abv: *mut JSObject) -> Option<Vec<T>> + where T: ArrayBufferViewContents +{ + array_buffer_view_data_checked(abv).map(|data| data.to_vec()) } /// Returns whether `value` is an array-like object. |