Skip to content

Commit

Permalink
Auto merge of #15653 - samliu:cleanup_arraybufferview_type, r=cbrewster
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Feb 21, 2017
2 parents 14bbe9d + 4fc3e7e commit 907c1ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions components/script/dom/crypto.rs
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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 |
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -2080,16 +2080,16 @@ 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())),
};

if !self.validate_framebuffer_complete() {
return Ok(());
}

match { JS_GetArrayBufferViewType(pixels) } {
match array_type {
Type::Uint8 => (),
_ => return Ok(self.webgl_error(InvalidOperation)),
}
Expand Down

0 comments on commit 907c1ef

Please sign in to comment.