зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #20389 - getRandomValues uses ArrayBufferView now (from christianpoveda:issue_20350); r=jdm
<!-- 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. --> Source-Repo: https://github.com/servo/servo Source-Revision: e5b606f6a41058bdcc5745ab0da075d0e6ed52fb --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : cdc7f6e7693960b99ee9bc172f4c73216121da77
This commit is contained in:
Родитель
16362b2402
Коммит
134842bf17
|
@ -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);
|
||||
}
|
||||
|
||||
Ok(NonNull::new_unchecked(input))
|
||||
Ok(NonNull::new_unchecked(*input.underlying_object()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче