aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorTaym Haddadi <haddadi.taym@gmail.com>2024-02-16 12:22:16 +0100
committerGitHub <noreply@github.com>2024-02-16 11:22:16 +0000
commitc3e3e72cf29ce6daacebf8da4d4f175a54babd0d (patch)
tree54386fce8e435f7a8b60c2df92e0cada46775ac4 /components/script/dom
parentfaaf9e9323f05a9b2f60ed73ea47e342e8d3c6d6 (diff)
downloadservo-c3e3e72cf29ce6daacebf8da4d4f175a54babd0d.tar.gz
servo-c3e3e72cf29ce6daacebf8da4d4f175a54babd0d.zip
WebIDL: Use ArrayBufferViewU8 instead of raw JSObject in bindings (#31325)
* WebIDL: Use ArrayBufferViewU8 instead of raw JSObject in bindings Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Remove unused imports Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Address review comments Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> --------- Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py2
-rw-r--r--components/script/dom/crypto.rs11
2 files changed, 7 insertions, 6 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 3b474a543b0..67405d49c60 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -129,6 +129,7 @@ builtinNames = {
IDLType.Tags.float32array: 'Float32Array',
IDLType.Tags.float64array: 'Float64Array',
IDLType.Tags.arrayBuffer: 'ArrayBuffer',
+ IDLType.Tags.arrayBufferView: 'ArrayBufferView',
}
numericTags = [
@@ -6518,6 +6519,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::typedarray::Float32Array',
'js::typedarray::Float64Array',
'js::typedarray::ArrayBuffer',
+ 'js::typedarray::ArrayBufferView',
'crate::dom',
'crate::dom::bindings',
'crate::dom::bindings::codegen::InterfaceObjectMap',
diff --git a/components/script/dom/crypto.rs b/components/script/dom/crypto.rs
index 8005c9e7f7a..e337c6ebb01 100644
--- a/components/script/dom/crypto.rs
+++ b/components/script/dom/crypto.rs
@@ -2,12 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use std::ptr::NonNull;
-
use dom_struct::dom_struct;
use js::jsapi::{JSObject, Type};
use js::rust::CustomAutoRooterGuard;
-use js::typedarray::ArrayBufferView;
+use js::typedarray::{ArrayBufferView, ArrayBufferViewU8, TypedArray};
use servo_rand::{RngCore, ServoRng};
use crate::dom::bindings::cell::DomRefCell;
@@ -47,7 +45,7 @@ impl CryptoMethods for Crypto {
&self,
_cx: JSContext,
mut input: CustomAutoRooterGuard<ArrayBufferView>,
- ) -> Fallible<NonNull<JSObject>> {
+ ) -> Fallible<ArrayBufferView> {
let array_type = input.get_array_type();
if !is_integer_buffer(array_type) {
@@ -58,9 +56,10 @@ impl CryptoMethods for Crypto {
return Err(Error::QuotaExceeded);
}
self.rng.borrow_mut().fill_bytes(&mut data);
+ let underlying_object = unsafe { input.underlying_object() };
+ TypedArray::<ArrayBufferViewU8, *mut JSObject>::from(*underlying_object)
+ .map_err(|_| Error::JSFailed)
}
-
- unsafe { Ok(NonNull::new_unchecked(*input.underlying_object())) }
}
}