diff options
author | deror1869107 <sungyuanyao@gmail.com> | 2017-01-23 08:11:44 +0800 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2017-02-10 16:33:57 -0500 |
commit | 6c4ce7247fa3e57075dfebfb60dd9694553fe084 (patch) | |
tree | 3e08700982b0e560c7f3a9b9d8ea1e876cb6c95c /components/script/dom/bindings/conversions.rs | |
parent | aea6797a94f4ab61279525f1daf2670e8e2a4d17 (diff) | |
download | servo-6c4ce7247fa3e57075dfebfb60dd9694553fe084.tar.gz servo-6c4ce7247fa3e57075dfebfb60dd9694553fe084.zip |
Use TypedArray
Diffstat (limited to 'components/script/dom/bindings/conversions.rs')
-rw-r--r-- | components/script/dom/bindings/conversions.rs | 55 |
1 files changed, 1 insertions, 54 deletions
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index f381d9c859c..e1869863c6c 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -47,7 +47,7 @@ use js::glue::{GetProxyPrivate, IsWrapper}; use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT}; use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject}; use js::jsapi::{HandleId, HandleObject, HandleValue, JSContext}; -use js::jsapi::{JSObject, JSString, JS_GetArrayBufferViewType}; +use js::jsapi::{JSObject, JSString}; use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetObjectAsArrayBuffer, JS_GetObjectAsArrayBufferView}; use js::jsapi::{JS_GetReservedSlot, JS_GetTwoByteStringCharsAndLength}; use js::jsapi::{JS_IsArrayObject, JS_NewStringCopyN, JS_StringHasLatin1Chars}; @@ -572,59 +572,6 @@ pub unsafe fn array_buffer_view_data<'a, T>(abv: *mut JSObject) -> Option<&'a mu 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 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>(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) - } else { - None - } - }) -} - -/// 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()) -} - -/// Similar API as the array_buffer_view_xxx functions, but for ArrayBuffer -/// objects. -pub unsafe fn array_buffer_data<'a, T>(ab: *mut JSObject) -> Option<&'a mut [T]> - where T: ArrayBufferViewContents -{ - assert!(!ab.is_null()); - - let mut byte_length = 0; - let mut ptr = ptr::null_mut(); - let ret = JS_GetObjectAsArrayBuffer(ab, &mut byte_length, &mut ptr); - if ret.is_null() { - return None; - } - Some(slice::from_raw_parts_mut(ptr as *mut T, byte_length as usize / mem::size_of::<T>())) -} - -/// Similar API to array_buffer_view_to_vec, but for ArrayBuffer objects. -pub unsafe fn array_buffer_to_vec<T>(ab: *mut JSObject) -> Option<Vec<T>> - where T: ArrayBufferViewContents -{ - array_buffer_data(ab).map(|data| data.to_vec()) -} - /// Returns whether `value` is an array-like object. /// Note: Currently only Arrays are supported. /// TODO: Expand this to support sequences and other array-like objects |