mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
refactor: add CanGc as argument to Promise::resolve (#35616)
Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
This commit is contained in:
parent
adb831eefe
commit
0383ba9a5b
57 changed files with 330 additions and 294 deletions
|
@ -179,36 +179,37 @@ impl OfflineAudioContextMethods<crate::DomTypeHolder> for OfflineAudioContext {
|
|||
.name("OfflineACResolver".to_owned())
|
||||
.spawn(move || {
|
||||
let _ = receiver.recv();
|
||||
task_source.queue(
|
||||
task!(resolve: move || {
|
||||
let this = this.root();
|
||||
let processed_audio = processed_audio.lock().unwrap();
|
||||
let mut processed_audio: Vec<_> = processed_audio
|
||||
.chunks(this.length as usize)
|
||||
.map(|channel| channel.to_vec())
|
||||
.collect();
|
||||
// it can end up being empty if the task failed
|
||||
if processed_audio.len() != this.length as usize {
|
||||
processed_audio.resize(this.length as usize, Vec::new())
|
||||
}
|
||||
let buffer = AudioBuffer::new(
|
||||
this.global().as_window(),
|
||||
this.channel_count,
|
||||
this.length,
|
||||
*this.context.SampleRate(),
|
||||
Some(processed_audio.as_slice()),
|
||||
CanGc::note());
|
||||
(*this.pending_rendering_promise.borrow_mut()).take().unwrap().resolve_native(&buffer);
|
||||
let global = &this.global();
|
||||
let window = global.as_window();
|
||||
let event = OfflineAudioCompletionEvent::new(window,
|
||||
atom!("complete"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable,
|
||||
&buffer, CanGc::note());
|
||||
event.upcast::<Event>().fire(this.upcast(), CanGc::note());
|
||||
})
|
||||
);
|
||||
task_source.queue(task!(resolve: move || {
|
||||
let this = this.root();
|
||||
let processed_audio = processed_audio.lock().unwrap();
|
||||
let mut processed_audio: Vec<_> = processed_audio
|
||||
.chunks(this.length as usize)
|
||||
.map(|channel| channel.to_vec())
|
||||
.collect();
|
||||
// it can end up being empty if the task failed
|
||||
if processed_audio.len() != this.length as usize {
|
||||
processed_audio.resize(this.length as usize, Vec::new())
|
||||
}
|
||||
let buffer = AudioBuffer::new(
|
||||
this.global().as_window(),
|
||||
this.channel_count,
|
||||
this.length,
|
||||
*this.context.SampleRate(),
|
||||
Some(processed_audio.as_slice()),
|
||||
CanGc::note());
|
||||
(*this.pending_rendering_promise.borrow_mut())
|
||||
.take()
|
||||
.unwrap()
|
||||
.resolve_native(&buffer, CanGc::note());
|
||||
let global = &this.global();
|
||||
let window = global.as_window();
|
||||
let event = OfflineAudioCompletionEvent::new(window,
|
||||
atom!("complete"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable,
|
||||
&buffer, CanGc::note());
|
||||
event.upcast::<Event>().fire(this.upcast(), CanGc::note());
|
||||
}));
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue