Make restore_js_channel_data unsafe

This commit is contained in:
Fernando Jiménez Moreno 2018-07-11 10:55:08 +02:00
parent c5abc3eb8b
commit 3fc9ecace0

View file

@ -84,7 +84,7 @@ impl AudioBuffer {
reflect_dom_object(Box::new(buffer), global, AudioBufferBinding::Wrap) reflect_dom_object(Box::new(buffer), global, AudioBufferBinding::Wrap)
} }
/// https://webaudio.github.io/web-audio-api/#dom-audiobuffer-audiobuffer // https://webaudio.github.io/web-audio-api/#dom-audiobuffer-audiobuffer
pub fn Constructor(window: &Window, pub fn Constructor(window: &Window,
options: &AudioBufferOptions) -> Fallible<DomRoot<AudioBuffer>> { options: &AudioBufferOptions) -> Fallible<DomRoot<AudioBuffer>> {
if options.numberOfChannels > MAX_CHANNEL_COUNT { if options.numberOfChannels > MAX_CHANNEL_COUNT {
@ -94,7 +94,7 @@ impl AudioBuffer {
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn restore_js_channel_data(&self, cx: *mut JSContext) -> bool { unsafe fn restore_js_channel_data(&self, cx: *mut JSContext) -> bool {
for (i, channel) in self.js_channels.borrow_mut().iter().enumerate() { for (i, channel) in self.js_channels.borrow_mut().iter().enumerate() {
if !channel.get().is_null() { if !channel.get().is_null() {
// Already have data in JS array. // Already have data in JS array.
@ -104,9 +104,7 @@ impl AudioBuffer {
// Move the channel data from shared_channels to js_channels. // Move the channel data from shared_channels to js_channels.
rooted!(in (cx) let mut array = ptr::null_mut::<JSObject>()); rooted!(in (cx) let mut array = ptr::null_mut::<JSObject>());
let shared_channel = (*self.shared_channels.borrow_mut()).buffers.remove(i); let shared_channel = (*self.shared_channels.borrow_mut()).buffers.remove(i);
if unsafe { if Float32Array::create(cx, CreateWith::Slice(&shared_channel), array.handle_mut()).is_err() {
Float32Array::create(cx, CreateWith::Slice(&shared_channel), array.handle_mut())
}.is_err() {
return false; return false;
} }
channel.set(array.get()); channel.set(array.get());
@ -238,7 +236,7 @@ impl AudioBufferMethods for AudioBuffer {
} }
let cx = self.global().get_cx(); let cx = self.global().get_cx();
if !self.restore_js_channel_data(cx) { if unsafe { !self.restore_js_channel_data(cx) } {
return Err(Error::JSFailed); return Err(Error::JSFailed);
} }