Bug 1614009 - Removed non-spec exception throwing on CopyToChannel. r=padenot,webidl,smaug

Also removed those in CopyFromChannel and changed parameters' name to fit the spec.

Differential Revision: https://phabricator.services.mozilla.com/D84321
This commit is contained in:
Corentin Arnould 2020-09-01 15:09:47 +00:00
Родитель 8a9cac4917
Коммит 27494fab83
3 изменённых файлов: 20 добавлений и 35 удалений

Просмотреть файл

@ -312,46 +312,39 @@ bool AudioBuffer::RestoreJSChannelData(JSContext* aJSContext) {
void AudioBuffer::CopyFromChannel(const Float32Array& aDestination,
uint32_t aChannelNumber,
uint32_t aStartInChannel, ErrorResult& aRv) {
uint32_t aBufferOffset, ErrorResult& aRv) {
if (aChannelNumber >= NumberOfChannels()) {
aRv.ThrowIndexSizeError(
nsPrintfCString("Channel number (%u) is out of range", aChannelNumber));
return;
}
if (aStartInChannel > Length()) {
// FIXME: this is not in the spec. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=1614006
aRv.ThrowIndexSizeError(
nsPrintfCString("Start index (%u) is out of range", aStartInChannel));
return;
}
JS::AutoCheckCannotGC nogc;
aDestination.ComputeState();
uint32_t count = std::min(Length() - aStartInChannel, aDestination.Length());
int64_t length = Length();
int64_t offset = aBufferOffset;
int64_t destLength = aDestination.Length();
uint32_t count = std::max(int64_t(0), std::min(length - offset, destLength));
JSObject* channelArray = mJSChannels[aChannelNumber];
if (channelArray) {
if (JS_GetTypedArrayLength(channelArray) != Length()) {
// The array's buffer was detached.
// FIXME: this is not in the spec. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=1614006
aRv.ThrowIndexSizeError("Channel's backing buffer is detached");
return;
}
bool isShared = false;
const float* sourceData =
JS_GetFloat32ArrayData(channelArray, &isShared, nogc);
// The sourceData arrays should all have originated in
// RestoreJSChannelData, where they are created unshared.
MOZ_ASSERT(!isShared);
PodMove(aDestination.Data(), sourceData + aStartInChannel, count);
PodMove(aDestination.Data(), sourceData + aBufferOffset, count);
return;
}
if (!mSharedChannels.IsNull()) {
CopyChannelDataToFloat(mSharedChannels, aChannelNumber, aStartInChannel,
CopyChannelDataToFloat(mSharedChannels, aChannelNumber, aBufferOffset,
aDestination.Data(), count);
return;
}
@ -361,22 +354,14 @@ void AudioBuffer::CopyFromChannel(const Float32Array& aDestination,
void AudioBuffer::CopyToChannel(JSContext* aJSContext,
const Float32Array& aSource,
uint32_t aChannelNumber,
uint32_t aStartInChannel, ErrorResult& aRv) {
uint32_t aChannelNumber, uint32_t aBufferOffset,
ErrorResult& aRv) {
if (aChannelNumber >= NumberOfChannels()) {
aRv.ThrowIndexSizeError(
nsPrintfCString("Channel number (%u) is out of range", aChannelNumber));
return;
}
if (aStartInChannel > Length()) {
// FIXME: this is not in the spec. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=1614006
aRv.ThrowIndexSizeError(
nsPrintfCString("Start index (%u) is out of range", aStartInChannel));
return;
}
if (!RestoreJSChannelData(aJSContext)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
@ -386,20 +371,20 @@ void AudioBuffer::CopyToChannel(JSContext* aJSContext,
JSObject* channelArray = mJSChannels[aChannelNumber];
if (JS_GetTypedArrayLength(channelArray) != Length()) {
// The array's buffer was detached.
// FIXME: this is not in the spec. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=1614006
aRv.ThrowIndexSizeError("Channel's backing buffer is detached");
return;
}
aSource.ComputeState();
uint32_t count = std::min(Length() - aStartInChannel, aSource.Length());
int64_t length = JS_GetTypedArrayLength(channelArray);
int64_t offset = aBufferOffset;
int64_t srcLength = aSource.Length();
uint32_t count = std::max(int64_t(0), std::min(length - offset, srcLength));
bool isShared = false;
float* channelData = JS_GetFloat32ArrayData(channelArray, &isShared, nogc);
// The channelData arrays should all have originated in
// RestoreJSChannelData, where they are created unshared.
MOZ_ASSERT(!isShared);
PodMove(channelData + aStartInChannel, aSource.Data(), count);
PodMove(channelData + aBufferOffset, aSource.Data(), count);
}
void AudioBuffer::GetChannelData(JSContext* aJSContext, uint32_t aChannel,

Просмотреть файл

@ -93,10 +93,10 @@ class AudioBuffer final : public nsWrapperCache {
JS::MutableHandle<JSObject*> aRetval, ErrorResult& aRv);
void CopyFromChannel(const Float32Array& aDestination,
uint32_t aChannelNumber, uint32_t aStartInChannel,
uint32_t aChannelNumber, uint32_t aBufferOffset,
ErrorResult& aRv);
void CopyToChannel(JSContext* aJSContext, const Float32Array& aSource,
uint32_t aChannelNumber, uint32_t aStartInChannel,
uint32_t aChannelNumber, uint32_t aBufferOffset,
ErrorResult& aRv);
/**

Просмотреть файл

@ -34,7 +34,7 @@ interface AudioBuffer {
Float32Array getChannelData(unsigned long channel);
[Throws]
void copyFromChannel(Float32Array destination, long channelNumber, optional unsigned long startInChannel = 0);
void copyFromChannel(Float32Array destination, unsigned long channelNumber, optional unsigned long startInChannel = 0);
[Throws]
void copyToChannel(Float32Array source, long channelNumber, optional unsigned long startInChannel = 0);
void copyToChannel(Float32Array source, unsigned long channelNumber, optional unsigned long startInChannel = 0);
};