Title: [269081] trunk
Revision
269081
Author
cdu...@apple.com
Date
2020-10-27 17:06:03 -0700 (Tue, 27 Oct 2020)

Log 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:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (269080 => 269081)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-10-27 23:50:40 UTC (rev 269080)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-10-28 00:06:03 UTC (rev 269081)
@@ -1,3 +1,15 @@
+2020-10-27  Chris Dumez  <cdu...@apple.com>
+
+        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.
+
+        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:
+
 2020-10-27  Noam Rosenthal  <n...@webkit.org>
 
         compositing/iframes/layout-on-compositing-change.html can assert under ContentfulPaintChecker

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-getChannelData-expected.txt (269080 => 269081)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-getChannelData-expected.txt	2020-10-27 23:50:40 UTC (rev 269080)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-getChannelData-expected.txt	2020-10-28 00:06:03 UTC (rev 269081)
@@ -4,12 +4,12 @@
 PASS Executing "buffer-not-eq"
 PASS Audit report
 PASS > [buffer-eq]
-FAIL X buffer.getChannelData(0) === buffer.getChannelData(0) is not equal to true. Got false. assert_true: expected true got false
-FAIL X buffer.getChannelData(1) === buffer.getChannelData(1) is not equal to true. Got false. assert_true: expected true got false
-FAIL < [buffer-eq] 2 out of 2 assertions were failed. assert_true: expected true got false
+PASS   buffer.getChannelData(0) === buffer.getChannelData(0) is equal to true.
+PASS   buffer.getChannelData(1) === buffer.getChannelData(1) is equal to true.
+PASS < [buffer-eq] All assertions passed. (total 2 assertions)
 PASS > [buffer-not-eq]
 PASS   buffer1.getChannelData(0) === buffer2.getChannelData(0) is equal to false.
 PASS   buffer1.getChannelData(1) === buffer2.getChannelData(1) is equal to false.
 PASS < [buffer-not-eq] All assertions passed. (total 2 assertions)
-FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed. assert_true: expected true got false
+PASS # AUDIT TASK RUNNER FINISHED: 2 tasks ran successfully.
 

Modified: trunk/Source/WebCore/ChangeLog (269080 => 269081)


--- trunk/Source/WebCore/ChangeLog	2020-10-27 23:50:40 UTC (rev 269080)
+++ trunk/Source/WebCore/ChangeLog	2020-10-28 00:06:03 UTC (rev 269081)
@@ -1,3 +1,25 @@
+2020-10-27  Chris Dumez  <cdu...@apple.com>
+
+        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.
+
+        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:
+
 2020-10-27  Brent Fulgham  <bfulg...@apple.com>
 
         Remove leftover DiagnosticLoggingKey after r268458

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp (269080 => 269081)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp	2020-10-27 23:50:40 UTC (rev 269080)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp	2020-10-28 00:06:03 UTC (rev 269081)
@@ -97,6 +97,7 @@
         channelDataArray->setNeuterable(false);
         m_channels.append(WTFMove(channelDataArray));
     }
+    m_channelWrappers.resize(m_channels.size());
 }
 
 AudioBuffer::AudioBuffer(AudioBus& bus)
@@ -117,6 +118,7 @@
         channelDataArray->setRange(bus.channel(i)->data(), m_length, 0);
         m_channels.append(WTFMove(channelDataArray));
     }
+    m_channelWrappers.resize(m_channels.size());
 }
 
 void AudioBuffer::invalidate()
@@ -129,16 +131,34 @@
 {
     auto locker = holdLock(m_channelsLock);
     m_channels.clear();
+    m_channelWrappers.clear();
 }
 
-ExceptionOr<Ref<Float32Array>> AudioBuffer::getChannelData(unsigned channelIndex)
+ExceptionOr<JSC::JSValue> AudioBuffer::getChannelData(JSDOMGlobalObject& globalObject, unsigned channelIndex)
 {
-    if (channelIndex >= m_channels.size())
+    ASSERT(m_channelWrappers.size() == m_channels.size());
+    if (channelIndex >= m_channelWrappers.size())
         return Exception { IndexSizeError, "Index must be less than number of channels."_s };
-    auto& channelData = *m_channels[channelIndex];
-    return Float32Array::create(channelData.unsharedBuffer(), channelData.byteOffset(), channelData.length());
+
+    auto& channelData = m_channels[channelIndex];
+    auto constructJSArray = [&] {
+        return JSC::JSFloat32Array::create(globalObject.vm(), globalObject.typedArrayStructure(JSC::TypeFloat32), channelData.copyRef());
+    };
+
+    if (globalObject.worldIsNormal()) {
+        if (!m_channelWrappers[channelIndex])
+            m_channelWrappers[channelIndex] = { constructJSArray() };
+        return static_cast<JSC::JSValue>(m_channelWrappers[channelIndex]);
+    }
+    return constructJSArray();
 }
 
+void AudioBuffer::visitChannelWrappers(JSC::SlotVisitor& visitor)
+{
+    for (auto& channelWrapper : m_channelWrappers)
+        channelWrapper.visit(visitor);
+}
+
 Float32Array* AudioBuffer::channelData(unsigned channelIndex)
 {
     if (channelIndex >= m_channels.size())

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h (269080 => 269081)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h	2020-10-27 23:50:40 UTC (rev 269080)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h	2020-10-28 00:06:03 UTC (rev 269081)
@@ -31,6 +31,7 @@
 
 #include "AudioBufferOptions.h"
 #include "ExceptionOr.h"
+#include "JSValueInWrappedObject.h"
 #include <_javascript_Core/Float32Array.h>
 #include <wtf/Lock.h>
 #include <wtf/Vector.h>
@@ -53,7 +54,7 @@
 
     // Channel data access
     unsigned numberOfChannels() const { return m_channels.size(); }
-    ExceptionOr<Ref<Float32Array>> getChannelData(unsigned channelIndex);
+    ExceptionOr<JSC::JSValue> getChannelData(JSDOMGlobalObject&, unsigned channelIndex);
     ExceptionOr<void> copyFromChannel(Ref<Float32Array>&&, unsigned channelNumber, unsigned bufferOffset);
     ExceptionOr<void> copyToChannel(Ref<Float32Array>&&, unsigned channelNumber, unsigned startInChannel);
     Float32Array* channelData(unsigned channelIndex);
@@ -65,6 +66,8 @@
     void releaseMemory();
 
     size_t memoryCost() const;
+
+    void visitChannelWrappers(JSC::SlotVisitor&);
     
 private:
     AudioBuffer(unsigned numberOfChannels, size_t length, float sampleRate);
@@ -76,6 +79,7 @@
     mutable Lock m_channelsLock;
     size_t m_length;
     Vector<RefPtr<Float32Array>> m_channels;
+    Vector<JSValueInWrappedObject> m_channelWrappers;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl (269080 => 269081)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl	2020-10-27 23:50:40 UTC (rev 269080)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl	2020-10-28 00:06:03 UTC (rev 269081)
@@ -29,6 +29,7 @@
 [
     Conditional=WEB_AUDIO,
     ImplementationLacksVTable,
+    JSCustomMarkFunction,
     JSGenerateToJSObject,
     ReportExtraMemoryCost,
     Exposed=Window
@@ -40,7 +41,7 @@
     readonly attribute unsigned long numberOfChannels;
 
     // Channel access
-    [MayThrowException] Float32Array getChannelData(unsigned long channelIndex);
+    [MayThrowException, CallWith=GlobalObject] any getChannelData(unsigned long channelIndex);
     [MayThrowException, EnabledBySetting=ModernUnprefixedWebAudio] undefined copyFromChannel(Float32Array destination, unsigned long channelNumber, optional unsigned long bufferOffset = 0);
     [MayThrowException, EnabledBySetting=ModernUnprefixedWebAudio] undefined copyToChannel(Float32Array source, unsigned long channelNumber, optional unsigned long bufferOffset = 0);
 };

Modified: trunk/Source/WebCore/Sources.txt (269080 => 269081)


--- trunk/Source/WebCore/Sources.txt	2020-10-27 23:50:40 UTC (rev 269080)
+++ trunk/Source/WebCore/Sources.txt	2020-10-28 00:06:03 UTC (rev 269081)
@@ -480,6 +480,7 @@
 bindings/js/JSAnimationEffectCustom.cpp
 bindings/js/JSAnimationTimelineCustom.cpp
 bindings/js/JSAttrCustom.cpp
+bindings/js/JSAudioBufferCustom.cpp
 bindings/js/JSAudioTrackCustom.cpp
 bindings/js/JSAudioTrackListCustom.cpp
 bindings/js/JSAudioWorkletProcessorCustom.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (269080 => 269081)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-10-27 23:50:40 UTC (rev 269080)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-10-28 00:06:03 UTC (rev 269081)
@@ -8025,6 +8025,7 @@
 		46C0962023D78DD600657C09 /* HTTPCookieAcceptPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTTPCookieAcceptPolicy.h; sourceTree = "<group>"; };
 		46C3765F2085176C00C73829 /* JSRemoteDOMWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRemoteDOMWindow.cpp; sourceTree = "<group>"; };
 		46C376612085176D00C73829 /* JSRemoteDOMWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRemoteDOMWindow.h; sourceTree = "<group>"; };
+		46C3A8D32548D4B700C8C53A /* JSAudioBufferCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSAudioBufferCustom.cpp; sourceTree = "<group>"; };
 		46C696C91E7205E400597937 /* CPUMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPUMonitor.h; sourceTree = "<group>"; };
 		46C696CA1E7205E400597937 /* CPUMonitor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPUMonitor.cpp; sourceTree = "<group>"; };
 		46C83EFB1A9BBE2900A79A41 /* GeoNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeoNotifier.cpp; sourceTree = "<group>"; };
@@ -22327,6 +22328,7 @@
 				71EFCEDE202B39C700D7C411 /* JSAnimationEffectCustom.cpp */,
 				71025ED51F99F147004A250C /* JSAnimationTimelineCustom.cpp */,
 				BC2ED6BB0C6BD2F000920BFF /* JSAttrCustom.cpp */,
+				46C3A8D32548D4B700C8C53A /* JSAudioBufferCustom.cpp */,
 				BE6DF70E171CA2DA00DD52B8 /* JSAudioTrackCustom.cpp */,
 				BE6DF710171CA2DA00DD52B8 /* JSAudioTrackListCustom.cpp */,
 				83F37A672536B21B00FF5F3B /* JSAudioWorkletProcessorCustom.cpp */,

Added: trunk/Source/WebCore/bindings/js/JSAudioBufferCustom.cpp (0 => 269081)


--- trunk/Source/WebCore/bindings/js/JSAudioBufferCustom.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSAudioBufferCustom.cpp	2020-10-28 00:06:03 UTC (rev 269081)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSAudioBuffer.h"
+
+#if ENABLE(WEB_AUDIO)
+
+namespace WebCore {
+using namespace JSC;
+
+void JSAudioBuffer::visitAdditionalChildren(SlotVisitor& visitor)
+{
+    wrapped().visitChannelWrappers(visitor);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_AUDIO)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to