Truly independent web browser
LibWeb: Keep offline rendering retryable after buffer creation fails
Shannon Booth7607fbe3f7e5
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_audio/offline_audio_context.rs b/Libraries/LibWeb/Bindings/Rust/src/web_audio/offline_audio_context.rsindex eae1fe08c0d..ac9ce928ef1 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_audio/offline_audio_context.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_audio/offline_audio_context.rs@@ -204,7 +204,12 @@ impl OfflineAudioContext {));}- // 2. If the [[rendering started]] slot on the OfflineAudioContext is true, return a rejected promise with InvalidStateError, and abort these steps.+ // 2. Let promise be a new promise.+ // NB: The bindings create the promise.++ // FIXME: 3. If the [[control thread state]] on the OfflineAudioContext is closed, reject promise with InvalidStateError and abort these steps.+ // 4. If the OfflineAudioContext’s length is not null and [[committed frames]] is greater than or equal to OfflineAudioContext’s length, reject promise with InvalidStateError and abort these steps.+ // NB: One-shot rendering commits the entire length on success.if self.rendering_started.get() {reject_promise_with_exception(cx.vm(),@@ -217,12 +222,16 @@ impl OfflineAudioContext {return Ok(());}- // 3. Set the [[rendering started]] slot of the OfflineAudioContext to true.- self.rendering_started.set(true);+ // FIXME: 5. Let bufferLength be a number initialized to the value of the chunkSize.+ // FIXME: 5.1. If the OfflineAudioContext’s length is null:+ // FIXME: 5.1.1. If chunkSize is null, set bufferLength to render quantum size.+ // FIXME: 5.2. Otherwise, if the OfflineAudioContext’s length is not null:+ // FIXME: 5.2.1. If chunkSize is not null and [[committed frames]] + chunkSize is less than the OfflineAudioContext’s length, set bufferLength to chunkSize.+ // FIXME: 5.2.2. Otherwise, set bufferLength to length - [[committed frames]].+ // FIXME: 6. If bufferLength is not a multiple of render quantum size, round it up to the next multiple of the render quantum size.- // 5. Create a new AudioBuffer, with a number of channels, length and sample rate equal respectively to the- // numberOfChannels, length and sampleRate values passed to this instance’s constructor in the contextOptions- // parameter.+ // 7. Create a new AudioBuffer buffer, with a number of channels and sample rate equal respectively to the numberOfChannels and sampleRate values passed to this instance’s constructor in the contextOptions parameter; and length equal to bufferLength.+ // NB: Without chunked rendering, bufferLength is the context’s length.let buffer_result = self.context.create_buffer(cx,self.number_of_channels,@@ -230,7 +239,7 @@ impl OfflineAudioContext {self.context.sample_rate_value(),);- // 6. If an exception was thrown during the preceding AudioBuffer constructor call, reject promise with this exception.+ // 8. If an exception was thrown during the preceding AudioBuffer constructor call, reject promise with this exception and return promise.let buffer = match buffer_result {Ok(buffer) => buffer,Err(error) => {@@ -239,14 +248,21 @@ impl OfflineAudioContext {}};- // Assign this buffer to an internal slot [[rendered buffer]] in the OfflineAudioContext.- self.rendered_buffer.set(Some(buffer));+ // 9. Set [[rendering started]] to true.+ self.rendering_started.set(true);- // 7. Otherwise, in the case that the buffer was successfully constructed, begin offline rendering.+ // 10. Set [[committed frames]] to the sum of [[committed frames]] and the buffer’s length.+ // NB: The one-shot rendering guard also records that all frames have been committed.++ // 11. Append buffer to [[rendered buffers]] and begin offline rendering for buffer.+ // NB: The one-shot renderer stores a single buffer.+ self.rendered_buffer.set(Some(buffer));self.begin_offline_rendering(cx.vm(), promise);- // 8. Append promise to [[pending promises]].+ // 12. Append promise to [[pending promises]].self.context.pending_promises.borrow_mut(cx.vm()).push(promise);++ // 13. Return promise.Ok(())}diff --git a/Tests/LibWeb/Text/expected/WebAudio/OfflineAudioContext-retry-after-allocation-failure.txt b/Tests/LibWeb/Text/expected/WebAudio/OfflineAudioContext-retry-after-allocation-failure.txtnew file mode 100644index 00000000000..9b4e87c4d7f--- /dev/null+++ b/Tests/LibWeb/Text/expected/WebAudio/OfflineAudioContext-retry-after-allocation-failure.txt@@ -0,0 +1,2 @@+First attempt failed: true+Second attempt failed the same way: truediff --git a/Tests/LibWeb/Text/input/WebAudio/OfflineAudioContext-retry-after-allocation-failure.html b/Tests/LibWeb/Text/input/WebAudio/OfflineAudioContext-retry-after-allocation-failure.htmlnew file mode 100644index 00000000000..2f42a9fee47--- /dev/null+++ b/Tests/LibWeb/Text/input/WebAudio/OfflineAudioContext-retry-after-allocation-failure.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ promiseTest(async () => {+ const context = new OfflineAudioContext(1, 0xffffffff, 8000);+ const attempts = [];+ for (let attempt = 0; attempt < 2; ++attempt) {+ try {+ await context.startRendering();+ attempts.push("succeeded");+ } catch (error) {+ attempts.push(error.name);+ }+ }+ println(`First attempt failed: ${attempts[0] !== "succeeded"}`);+ println(`Second attempt failed the same way: ${attempts[1] === attempts[0]}`);+ });+</script>