refactor: add CanGc as argument to Promise::resolve (#35616)

Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
This commit is contained in:
Yerkebulan Tulibergenov 2025-02-23 04:12:21 -08:00 committed by GitHub
parent adb831eefe
commit 0383ba9a5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 330 additions and 294 deletions

View file

@ -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();