mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Replace uses of spidermonkey-specific JS_GetArrayBufferViewType with ArrayBufferView impl's method get_array_type()
This commit is contained in:
parent
ccc1df2dfe
commit
4fc3e7e75d
3 changed files with 11 additions and 12 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1281,7 +1281,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "js"
|
||||
version = "0.1.4"
|
||||
source = "git+https://github.com/servo/rust-mozjs#93e59ef1263e451143d0ed431f1aa564ea101ab8"
|
||||
source = "git+https://github.com/servo/rust-mozjs#101c6b6b58e0b7c5ed1ef2b6b676a7497f90df2f"
|
||||
dependencies = [
|
||||
"cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -11,7 +11,7 @@ use dom::bindings::js::Root;
|
|||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::globalscope::GlobalScope;
|
||||
use js::jsapi::{JSContext, JSObject};
|
||||
use js::jsapi::{JS_GetArrayBufferViewType, Type};
|
||||
use js::jsapi::Type;
|
||||
use servo_rand::{ServoRng, Rng};
|
||||
|
||||
unsafe_no_jsmanaged_fields!(ServoRng);
|
||||
|
@ -46,15 +46,15 @@ impl CryptoMethods for Crypto {
|
|||
-> Fallible<NonZero<*mut JSObject>> {
|
||||
assert!(!input.is_null());
|
||||
typedarray!(in(_cx) let mut array_buffer_view: ArrayBufferView = input);
|
||||
let mut data = match array_buffer_view.as_mut() {
|
||||
Ok(x) => x.as_mut_slice(),
|
||||
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()));
|
||||
}
|
||||
};
|
||||
|
||||
if !is_integer_buffer(input) {
|
||||
if !is_integer_buffer(array_type) {
|
||||
return Err(Error::TypeMismatch);
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,8 @@ impl CryptoMethods for Crypto {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn is_integer_buffer(input: *mut JSObject) -> bool {
|
||||
match unsafe { JS_GetArrayBufferViewType(input) } {
|
||||
fn is_integer_buffer(array_type: Type) -> bool {
|
||||
match array_type {
|
||||
Type::Uint8 |
|
||||
Type::Uint8Clamped |
|
||||
Type::Int8 |
|
||||
|
|
|
@ -37,7 +37,7 @@ use dom::window::Window;
|
|||
use euclid::size::Size2D;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use js::conversions::ConversionBehavior;
|
||||
use js::jsapi::{JSContext, JSObject, JS_GetArrayBufferViewType, Type, Rooted};
|
||||
use js::jsapi::{JSContext, JSObject, Type, Rooted};
|
||||
use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UndefinedValue};
|
||||
use js::typedarray::{TypedArray, TypedArrayElement, Float32, Int32};
|
||||
use net_traits::image::base::PixelFormat;
|
||||
|
@ -2080,8 +2080,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
}
|
||||
|
||||
typedarray!(in(cx) let mut pixels_data: ArrayBufferView = pixels);
|
||||
let mut data = match { pixels_data.as_mut() } {
|
||||
Ok(data) => data.as_mut_slice(),
|
||||
let (array_type, mut data) = match { pixels_data.as_mut() } {
|
||||
Ok(data) => (data.get_array_type(), data.as_mut_slice()),
|
||||
Err(_) => return Err(Error::Type("Not an ArrayBufferView".to_owned())),
|
||||
};
|
||||
|
||||
|
@ -2089,7 +2089,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
match { JS_GetArrayBufferViewType(pixels) } {
|
||||
match array_type {
|
||||
Type::Uint8 => (),
|
||||
_ => return Ok(self.webgl_error(InvalidOperation)),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue