diff options
author | Christian Poveda <christianpoveda@protonmail.com> | 2018-03-22 12:12:16 -0500 |
---|---|---|
committer | Christian Poveda <christianpoveda@protonmail.com> | 2018-03-22 12:12:16 -0500 |
commit | 723e03ef010ec8ac36b989f7c889652ea7e527f0 (patch) | |
tree | b431a571c68cd6989d4e5b9e9d77b23247677c47 | |
parent | 4e26212d5e661b21392f59bdbe5518d047fe0531 (diff) | |
download | servo-723e03ef010ec8ac36b989f7c889652ea7e527f0.tar.gz servo-723e03ef010ec8ac36b989f7c889652ea7e527f0.zip |
getRandomValues uses ArrayBufferView now
-rw-r--r-- | components/script/dom/crypto.rs | 28 | ||||
-rw-r--r-- | components/script/dom/webidls/Crypto.webidl | 3 |
2 files changed, 12 insertions, 19 deletions
diff --git a/components/script/dom/crypto.rs b/components/script/dom/crypto.rs index 71e67e46b9a..2ee87a1719b 100644 --- a/components/script/dom/crypto.rs +++ b/components/script/dom/crypto.rs @@ -12,6 +12,8 @@ use dom::globalscope::GlobalScope; use dom_struct::dom_struct; use js::jsapi::{JSContext, JSObject}; use js::jsapi::Type; +use js::rust::CustomAutoRooterGuard; +use js::typedarray::ArrayBufferView; use servo_rand::{ServoRng, Rng}; use std::ptr::NonNull; @@ -43,29 +45,21 @@ impl CryptoMethods for Crypto { // https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#Crypto-method-getRandomValues unsafe fn GetRandomValues(&self, _cx: *mut JSContext, - input: *mut JSObject) + mut input: CustomAutoRooterGuard<ArrayBufferView>) -> Fallible<NonNull<JSObject>> { - assert!(!input.is_null()); - typedarray!(in(_cx) let mut array_buffer_view: ArrayBufferView = input); - let (array_type, mut data) = match array_buffer_view.as_mut() { - Ok(x) => (x.get_array_type(), x.as_mut_slice()), - Err(_) => { - return Err(Error::Type("Argument to Crypto.getRandomValues is not an ArrayBufferView" - .to_owned())); - } - }; + let array_type = input.get_array_type(); if !is_integer_buffer(array_type) { return Err(Error::TypeMismatch); + } else { + let mut data = input.as_mut_slice(); + if data.len() > 65536 { + return Err(Error::QuotaExceeded); + } + self.rng.borrow_mut().fill_bytes(&mut data); } - if data.len() > 65536 { - return Err(Error::QuotaExceeded); - } - - self.rng.borrow_mut().fill_bytes(&mut data); - - Ok(NonNull::new_unchecked(input)) + Ok(NonNull::new_unchecked(*input.underlying_object())) } } diff --git a/components/script/dom/webidls/Crypto.webidl b/components/script/dom/webidls/Crypto.webidl index 94611750e8f..2d17fd4da55 100644 --- a/components/script/dom/webidls/Crypto.webidl +++ b/components/script/dom/webidls/Crypto.webidl @@ -18,7 +18,6 @@ WorkerGlobalScope implements GlobalCrypto; [Exposed=(Window,Worker)] interface Crypto { //readonly attribute SubtleCrypto subtle; - //ArrayBufferView getRandomValues(ArrayBufferView array); [Throws] - ArrayBufferView getRandomValues(object array); + ArrayBufferView getRandomValues(ArrayBufferView array); }; |