mirror of
https://github.com/servo/servo.git
synced 2025-07-22 06:43:40 +01:00
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>
This commit is contained in:
parent
faaf9e9323
commit
c3e3e72cf2
3 changed files with 9 additions and 7 deletions
|
@ -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',
|
||||
|
|
|
@ -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())) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
3
third_party/WebIDL/WebIDL.py
vendored
3
third_party/WebIDL/WebIDL.py
vendored
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue