Rewrite Crypto::GetRandomValues to use typed array API

Fix mut typed_array

Redundant code
This commit is contained in:
deror1869107 2016-12-26 02:53:48 +08:00
parent b319dedda9
commit 684db8bd29
2 changed files with 5 additions and 5 deletions

View file

@ -6,7 +6,6 @@ use core::nonzero::NonZero;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::CryptoBinding;
use dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods;
use dom::bindings::conversions::array_buffer_view_data;
use dom::bindings::error::{Error, Fallible};
use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
@ -46,9 +45,10 @@ impl CryptoMethods for Crypto {
input: *mut JSObject)
-> Fallible<NonZero<*mut JSObject>> {
assert!(!input.is_null());
let mut data = match array_buffer_view_data::<u8>(input) {
Some(data) => data,
None => {
typedarray!(in(_cx) let mut array_buffer_view: ArrayBufferView = input);
let mut data = match array_buffer_view.as_mut() {
Ok(x) => x.as_mut_slice(),
Err(_) => {
return Err(Error::Type("Argument to Crypto.getRandomValues is not an ArrayBufferView"
.to_owned()));
}