diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-03-22 17:28:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-22 17:28:54 -0400 |
commit | e5b606f6a41058bdcc5745ab0da075d0e6ed52fb (patch) | |
tree | bf242b0065589260192f355355518fde78a10ada /components/script/dom | |
parent | f467bdce1ba95e950b01f59ba284873137bca5d5 (diff) | |
parent | 723e03ef010ec8ac36b989f7c889652ea7e527f0 (diff) | |
download | servo-e5b606f6a41058bdcc5745ab0da075d0e6ed52fb.tar.gz servo-e5b606f6a41058bdcc5745ab0da075d0e6ed52fb.zip |
Auto merge of #20389 - christianpoveda:issue_20350, r=jdm
getRandomValues uses ArrayBufferView now
<!-- Please describe your changes on the following line: -->
- Changed the `Crypto.webidl` file to allow getRandomValues to recieve an ArrayBufferView as input
- Removed unnecesary checks from `crypto.rs` and did the necessary changes to match the `webidl` changes.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #20350 (github issue number if applicable).
<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20389)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-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); }; |