Fix Trusted usage in audio decoder to queue tasks (#3)

This commit is contained in:
Manish Goregaokar 2018-07-09 23:02:17 -07:00 committed by Fernando Jiménez Moreno
parent 34ba14385a
commit 8f9a081ff0
2 changed files with 39 additions and 26 deletions

View file

@ -195,7 +195,8 @@ impl BaseAudioContext {
}
pub fn resume(&self) {
let window = DomRoot::downcast::<Window>(self.global()).unwrap();
let global = self.global();
let window = global.as_window();
let task_source = window.dom_manipulation_task_source();
let this = Trusted::new(self);
// Set the rendering thread state to 'running' and start
@ -321,6 +322,8 @@ impl BaseAudioContextMethods for BaseAudioContext {
-> Rc<Promise> {
// Step 1.
let promise = Promise::new(&self.global());
let global = self.global();
let window = global.as_window();
if audio_data.len() > 0 {
// Step 2.
@ -337,9 +340,14 @@ impl BaseAudioContextMethods for BaseAudioContext {
let decoded_audio_ = decoded_audio.clone();
let this = Trusted::new(self);
let this_ = this.clone();
let task_source = window.dom_manipulation_task_source();
let task_source_ = window.dom_manipulation_task_source();
let canceller = window.task_canceller();
let canceller_ = window.task_canceller();
let callbacks = AudioDecoderCallbacks::new()
.eos(move || {
let this = this_.root();
let _ = task_source.queue_with_canceller(task!(audio_decode_eos: move || {
let this = this.root();
let decoded_audio = decoded_audio.lock().unwrap();
let buffer = AudioBuffer::new(
&this.global().as_window(),
@ -354,9 +362,11 @@ impl BaseAudioContextMethods for BaseAudioContext {
let _ = callback.Call__(&buffer, ExceptionHandling::Report);
}
resolver.promise.resolve_native(&buffer);
}), &canceller);
})
.error(move || {
let this = this.root();
let _ = task_source_.queue_with_canceller(task!(audio_decode_eos: move || {
let this = this_.root();
let mut resolvers = this.decode_resolvers.borrow_mut();
assert!(resolvers.contains_key(&uuid));
let resolver = resolvers.remove(&uuid).unwrap();
@ -366,6 +376,7 @@ impl BaseAudioContextMethods for BaseAudioContext {
ExceptionHandling::Report);
}
resolver.promise.reject_error(Error::Type("Audio decode error".to_owned()));
}), &canceller_);
})
.progress(move |buffer| {
decoded_audio_

View file

@ -13,6 +13,8 @@
#![deny(unsafe_code)]
#![allow(non_snake_case)]
#![recursion_limit = "128"]
#![doc = "The script crate contains all matters DOM."]
#![plugin(script_plugins)]