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, - ) -> Fallible> { + ) -> Fallible { 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::::from(*underlying_object) + .map_err(|_| Error::JSFailed) } - - unsafe { Ok(NonNull::new_unchecked(*input.underlying_object())) } } } diff --git a/third_party/WebIDL/WebIDL.py b/third_party/WebIDL/WebIDL.py index 827ef992d10..5414496fd1d 100644 --- a/third_party/WebIDL/WebIDL.py +++ b/third_party/WebIDL/WebIDL.py @@ -2410,6 +2410,7 @@ class IDLType(IDLObject): "float32array", "float64array", "arrayBuffer", + "arrayBufferView", "dictionary", "enum", "callback", @@ -3641,7 +3642,7 @@ class IDLBuiltinType(IDLType): Types.jsstring: IDLType.Tags.jsstring, Types.object: IDLType.Tags.object, Types.ArrayBuffer: IDLType.Tags.arrayBuffer, - Types.ArrayBufferView: IDLType.Tags.interface, + Types.ArrayBufferView: IDLType.Tags.arrayBufferView, Types.Int8Array: IDLType.Tags.int8array, Types.Uint8Array: IDLType.Tags.uint8array, Types.Uint8ClampedArray: IDLType.Tags.interface,