Auto merge of #15653 - samliu:cleanup_arraybufferview_type, r=cbrewster

Cleanup arraybufferview type

<!-- Please describe your changes on the following line: -->
Replace uses of spidermonkey-specific JS_GetArrayBufferViewType with ArrayBufferView impl's method get_array_type().

Tests pass:
./mach test-wpt tests/wpt/web-platform-tests/WebCrypto
./mach test-wpt tests/wpt/web-platform-tests/webgl

---
<!-- 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 #15605 (github issue number if applicable).
- [x] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15653)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-02-21 06:54:30 -08:00 committed by GitHub
commit 907c1ef3d2
3 changed files with 11 additions and 12 deletions

View file

@ -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 |

View file

@ -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)),
}