Skip to content

Commit

Permalink
Add WPT for denormal behavior in AudioWorkletGlobalScope
Browse files Browse the repository at this point in the history
Currently Chrome's JS execution in AudioWorkletGlobalScope does not
handle the denormals properly. To make this clear, we are adding this
test to keep a reference point for the future discussion.

Bug: 1446038
Test: external/wpt/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-denormals.https.html
Change-Id: If5b51f3eacb1f13d824562cad9e6dba249a0ba96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4590457
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Reviewed-by: Michael Wilson <mjwilson@chromium.org>
Commit-Queue: Hongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1153539}
  • Loading branch information
hoch authored and chromium-wpt-export-bot committed Jun 5, 2023
1 parent 00a0518 commit 1678307
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

// Test if the JS code execution in AudioWorkletGlobalScope can handle the
// denormals properly. For more details, see:
// https://esdiscuss.org/topic/float-denormal-issue-in-javascript-processor-node-in-web-audio-api
promise_test(async () => {
// In the main thread, the denormals should be non-zeros.
assert_not_equals(Number.MIN_VALUE, 0.0,
'The denormals should be non-zeros.');

const context = new AudioContext();
await context.audioWorklet.addModule(
'./processors/denormal-test-processor.js');

const denormalTestProcessor = new AudioWorkletNode(context, 'denormal-test');

return new Promise(resolve => {
denormalTestProcessor.port.onmessage = resolve;
denormalTestProcessor.connect(context.destination);
}).then(event => {
// In the AudioWorkletGlobalScope, the denormals should be non-zeros too.
assert_true(
event.data.result,
'The denormals should be non-zeros in AudioWorkletGlobalScope.');
});
}, 'Test denormal behavior in AudioWorkletGlobalScope');
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class DenormalTestProcessor extends AudioWorkletProcessor {
process() {
// The denormals should be non-zeros. Otherwise, it's a violation of
// ECMA specification: https://tc39.es/ecma262/#sec-number.min_value
this.port.postMessage({
result: Number.MIN_VALUE !== 0.0
});
return false;
}
}

registerProcessor('denormal-test', DenormalTestProcessor);

0 comments on commit 1678307

Please sign in to comment.