Changeset 269081 in webkit


Ignore:
Timestamp:
Oct 27, 2020 5:06:03 PM (21 months ago)
Author:
Chris Dumez
Message:

AudioBuffer.getChannelData(x) should keep returning the same JS wrapper for a given channel
https://bugs.webkit.org/show_bug.cgi?id=218265

Reviewed by Geoff Garen.

LayoutTests/imported/w3c:

Rebaseline WPT test that is now fully passing. I have verified that this test passes in Chrome and Firefox
as well.

  • web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-getChannelData-expected.txt:

Source/WebCore:

AudioBuffer.getChannelData(x) should keep returning the same JS wrapper for a given channel.
This is the behavior of Chrome & Firefox and is covered by Web-Platform-Tests.

No new tests, rebaselined existing test.

  • Modules/webaudio/AudioBuffer.cpp:

(WebCore::AudioBuffer::AudioBuffer):
(WebCore::AudioBuffer::releaseMemory):
(WebCore::AudioBuffer::getChannelData):
(WebCore::AudioBuffer::visitChannelWrappers):

  • Modules/webaudio/AudioBuffer.h:
  • Modules/webaudio/AudioBuffer.idl:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r269050 r269081  
     12020-10-27  Chris Dumez  <cdumez@apple.com>
     2
     3        AudioBuffer.getChannelData(x) should keep returning the same JS wrapper for a given channel
     4        https://bugs.webkit.org/show_bug.cgi?id=218265
     5
     6        Reviewed by Geoff Garen.
     7
     8        Rebaseline WPT test that is now fully passing. I have verified that this test passes in Chrome and Firefox
     9        as well.
     10
     11        * web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-getChannelData-expected.txt:
     12
    1132020-10-27  Noam Rosenthal  <noam@webkit.org>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-getChannelData-expected.txt

    r267649 r269081  
    55PASS Audit report
    66PASS > [buffer-eq]
    7 FAIL X buffer.getChannelData(0) === buffer.getChannelData(0) is not equal to true. Got false. assert_true: expected true got false
    8 FAIL X buffer.getChannelData(1) === buffer.getChannelData(1) is not equal to true. Got false. assert_true: expected true got false
    9 FAIL < [buffer-eq] 2 out of 2 assertions were failed. assert_true: expected true got false
     7PASS   buffer.getChannelData(0) === buffer.getChannelData(0) is equal to true.
     8PASS   buffer.getChannelData(1) === buffer.getChannelData(1) is equal to true.
     9PASS < [buffer-eq] All assertions passed. (total 2 assertions)
    1010PASS > [buffer-not-eq]
    1111PASS   buffer1.getChannelData(0) === buffer2.getChannelData(0) is equal to false.
    1212PASS   buffer1.getChannelData(1) === buffer2.getChannelData(1) is equal to false.
    1313PASS < [buffer-not-eq] All assertions passed. (total 2 assertions)
    14 FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed. assert_true: expected true got false
     14PASS # AUDIT TASK RUNNER FINISHED: 2 tasks ran successfully.
    1515
  • trunk/Source/WebCore/ChangeLog

    r269078 r269081  
     12020-10-27  Chris Dumez  <cdumez@apple.com>
     2
     3        AudioBuffer.getChannelData(x) should keep returning the same JS wrapper for a given channel
     4        https://bugs.webkit.org/show_bug.cgi?id=218265
     5
     6        Reviewed by Geoff Garen.
     7
     8        AudioBuffer.getChannelData(x) should keep returning the same JS wrapper for a given channel.
     9        This is the behavior of Chrome & Firefox and is covered by Web-Platform-Tests.
     10
     11        No new tests, rebaselined existing test.
     12
     13        * Modules/webaudio/AudioBuffer.cpp:
     14        (WebCore::AudioBuffer::AudioBuffer):
     15        (WebCore::AudioBuffer::releaseMemory):
     16        (WebCore::AudioBuffer::getChannelData):
     17        (WebCore::AudioBuffer::visitChannelWrappers):
     18        * Modules/webaudio/AudioBuffer.h:
     19        * Modules/webaudio/AudioBuffer.idl:
     20        * Sources.txt:
     21        * WebCore.xcodeproj/project.pbxproj:
     22
    1232020-10-27  Brent Fulgham  <bfulgham@apple.com>
    224
  • trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp

    r265403 r269081  
    9898        m_channels.append(WTFMove(channelDataArray));
    9999    }
     100    m_channelWrappers.resize(m_channels.size());
    100101}
    101102
     
    118119        m_channels.append(WTFMove(channelDataArray));
    119120    }
     121    m_channelWrappers.resize(m_channels.size());
    120122}
    121123
     
    130132    auto locker = holdLock(m_channelsLock);
    131133    m_channels.clear();
    132 }
    133 
    134 ExceptionOr<Ref<Float32Array>> AudioBuffer::getChannelData(unsigned channelIndex)
    135 {
    136     if (channelIndex >= m_channels.size())
     134    m_channelWrappers.clear();
     135}
     136
     137ExceptionOr<JSC::JSValue> AudioBuffer::getChannelData(JSDOMGlobalObject& globalObject, unsigned channelIndex)
     138{
     139    ASSERT(m_channelWrappers.size() == m_channels.size());
     140    if (channelIndex >= m_channelWrappers.size())
    137141        return Exception { IndexSizeError, "Index must be less than number of channels."_s };
    138     auto& channelData = *m_channels[channelIndex];
    139     return Float32Array::create(channelData.unsharedBuffer(), channelData.byteOffset(), channelData.length());
     142
     143    auto& channelData = m_channels[channelIndex];
     144    auto constructJSArray = [&] {
     145        return JSC::JSFloat32Array::create(globalObject.vm(), globalObject.typedArrayStructure(JSC::TypeFloat32), channelData.copyRef());
     146    };
     147
     148    if (globalObject.worldIsNormal()) {
     149        if (!m_channelWrappers[channelIndex])
     150            m_channelWrappers[channelIndex] = { constructJSArray() };
     151        return static_cast<JSC::JSValue>(m_channelWrappers[channelIndex]);
     152    }
     153    return constructJSArray();
     154}
     155
     156void AudioBuffer::visitChannelWrappers(JSC::SlotVisitor& visitor)
     157{
     158    for (auto& channelWrapper : m_channelWrappers)
     159        channelWrapper.visit(visitor);
    140160}
    141161
  • trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h

    r267065 r269081  
    3232#include "AudioBufferOptions.h"
    3333#include "ExceptionOr.h"
     34#include "JSValueInWrappedObject.h"
    3435#include <JavaScriptCore/Float32Array.h>
    3536#include <wtf/Lock.h>
     
    5455    // Channel data access
    5556    unsigned numberOfChannels() const { return m_channels.size(); }
    56     ExceptionOr<Ref<Float32Array>> getChannelData(unsigned channelIndex);
     57    ExceptionOr<JSC::JSValue> getChannelData(JSDOMGlobalObject&, unsigned channelIndex);
    5758    ExceptionOr<void> copyFromChannel(Ref<Float32Array>&&, unsigned channelNumber, unsigned bufferOffset);
    5859    ExceptionOr<void> copyToChannel(Ref<Float32Array>&&, unsigned channelNumber, unsigned startInChannel);
     
    6667
    6768    size_t memoryCost() const;
     69
     70    void visitChannelWrappers(JSC::SlotVisitor&);
    6871   
    6972private:
     
    7780    size_t m_length;
    7881    Vector<RefPtr<Float32Array>> m_channels;
     82    Vector<JSValueInWrappedObject> m_channelWrappers;
    7983};
    8084
  • trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl

    r267813 r269081  
    3030    Conditional=WEB_AUDIO,
    3131    ImplementationLacksVTable,
     32    JSCustomMarkFunction,
    3233    JSGenerateToJSObject,
    3334    ReportExtraMemoryCost,
     
    4142
    4243    // Channel access
    43     [MayThrowException] Float32Array getChannelData(unsigned long channelIndex);
     44    [MayThrowException, CallWith=GlobalObject] any getChannelData(unsigned long channelIndex);
    4445    [MayThrowException, EnabledBySetting=ModernUnprefixedWebAudio] undefined copyFromChannel(Float32Array destination, unsigned long channelNumber, optional unsigned long bufferOffset = 0);
    4546    [MayThrowException, EnabledBySetting=ModernUnprefixedWebAudio] undefined copyToChannel(Float32Array source, unsigned long channelNumber, optional unsigned long bufferOffset = 0);
  • trunk/Source/WebCore/Sources.txt

    r268960 r269081  
    481481bindings/js/JSAnimationTimelineCustom.cpp
    482482bindings/js/JSAttrCustom.cpp
     483bindings/js/JSAudioBufferCustom.cpp
    483484bindings/js/JSAudioTrackCustom.cpp
    484485bindings/js/JSAudioTrackListCustom.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r269025 r269081  
    80268026                46C3765F2085176C00C73829 /* JSRemoteDOMWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRemoteDOMWindow.cpp; sourceTree = "<group>"; };
    80278027                46C376612085176D00C73829 /* JSRemoteDOMWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRemoteDOMWindow.h; sourceTree = "<group>"; };
     8028                46C3A8D32548D4B700C8C53A /* JSAudioBufferCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSAudioBufferCustom.cpp; sourceTree = "<group>"; };
    80288029                46C696C91E7205E400597937 /* CPUMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPUMonitor.h; sourceTree = "<group>"; };
    80298030                46C696CA1E7205E400597937 /* CPUMonitor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPUMonitor.cpp; sourceTree = "<group>"; };
     
    2232822329                                71025ED51F99F147004A250C /* JSAnimationTimelineCustom.cpp */,
    2232922330                                BC2ED6BB0C6BD2F000920BFF /* JSAttrCustom.cpp */,
     22331                                46C3A8D32548D4B700C8C53A /* JSAudioBufferCustom.cpp */,
    2233022332                                BE6DF70E171CA2DA00DD52B8 /* JSAudioTrackCustom.cpp */,
    2233122333                                BE6DF710171CA2DA00DD52B8 /* JSAudioTrackListCustom.cpp */,
Note: See TracChangeset for help on using the changeset viewer.