Commit 46af3e52 authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

PeriodicWave must throw error if arrays are too short

The real and imaginary arrays used to construct a PeriodicWave must
have a length of at least 2.  Otherwise, throw an IndexSizeError.

The error message now looks like:

"The length of the real array provided (1) is less than the minimum bound (2)."

Test now passes so remove the expected results.

Bug: 1112826
Change-Id: Ic336dcd955276aef74b132e39bfed09ca3b67732
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337076
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794748}
parent 5ab2f369
......@@ -36,6 +36,7 @@
#include "third_party/blink/renderer/modules/webaudio/periodic_wave.h"
#include "third_party/blink/renderer/platform/audio/fft_frame.h"
#include "third_party/blink/renderer/platform/audio/vector_math.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#if defined(CPU_ARM_NEON)
......@@ -70,6 +71,22 @@ PeriodicWave* PeriodicWave::Create(BaseAudioContext& context,
return nullptr;
}
if (real.size() < 2) {
exception_state.ThrowDOMException(
DOMExceptionCode::kIndexSizeError,
ExceptionMessages::IndexExceedsMinimumBound("length of the real array",
real.size(), 2u));
return nullptr;
}
if (imag.size() < 2) {
exception_state.ThrowDOMException(
DOMExceptionCode::kIndexSizeError,
ExceptionMessages::IndexExceedsMinimumBound("length of the imag array",
imag.size(), 2u));
return nullptr;
}
PeriodicWave* periodic_wave =
MakeGarbageCollected<PeriodicWave>(context.sampleRate());
periodic_wave->CreateBandLimitedTables(real.data(), imag.data(), real.size(),
......
This is a testharness.js-based test.
PASS # AUDIT TASK RUNNER STARTED.
PASS Executing "create with factory method"
PASS Executing "different length with factory method"
PASS Executing "too small with factory method"
PASS Executing "create with constructor"
PASS Executing "different length with constructor"
PASS Executing "too small with constructor"
PASS Executing "output test"
PASS Audit report
PASS > [create with factory method]
PASS context.createPeriodicWave(new Float32Array(4096), new Float32Array(4096)) did not throw an exception.
PASS < [create with factory method] All assertions passed. (total 1 assertions)
PASS > [different length with factory method]
PASS context.createPeriodicWave(new Float32Array(512), new Float32Array(4)) threw IndexSizeError: "Failed to execute 'createPeriodicWave' on 'BaseAudioContext': length of real array (512) and length of imaginary array (4) must match.".
PASS < [different length with factory method] All assertions passed. (total 1 assertions)
PASS > [too small with factory method]
FAIL X context.createPeriodicWave(new Float32Array(1), new Float32Array(1)) did not throw an exception. assert_true: expected true got false
FAIL < [too small with factory method] 1 out of 1 assertions were failed. assert_true: expected true got false
PASS > [create with constructor]
PASS new PeriodicWave(context, { real : new Float32Array(4096), imag : new Float32Array(4096) }) did not throw an exception.
PASS < [create with constructor] All assertions passed. (total 1 assertions)
PASS > [different length with constructor]
PASS new PeriodicWave(context, { real : new Float32Array(4096), imag : new Float32Array(4) }) threw IndexSizeError: "Failed to construct 'PeriodicWave': length of real array (4096) and length of imaginary array (4) must match.".
PASS < [different length with constructor] All assertions passed. (total 1 assertions)
PASS > [too small with constructor]
FAIL X new PeriodicWave(context, { real : new Float32Array(1), imag : new Float32Array(1) }) did not throw an exception. assert_true: expected true got false
FAIL < [too small with constructor] 1 out of 1 assertions were failed. assert_true: expected true got false
PASS > [output test]
PASS rendering PeriodicWave is identical to the array AudioBuffer.
PASS < [output test] All assertions passed. (total 1 assertions)
FAIL # AUDIT TASK RUNNER FINISHED: 2 out of 7 tasks were failed. assert_true: expected true got false
Harness: the test ran to completion.
......@@ -17,7 +17,7 @@
let osc;
let gain;
let offlinePromise;
let wave = new Float32Array(1);
let wave = new Float32Array(5);
let audit = Audit.createTaskRunner();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment