Bug 1599952 initialize AudioWorkletProcessor.port r=baku
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 11 Dec 2019 00:24:09 +0000
changeset 506343 1186352e2403fb912a08cf4c45c79eb8912bfa5e
parent 506342 a50a90562c0d44aea90c6c82da0f9dc9a68c9179
child 506344 29809135f18e36dead03548dadec152fb4ef6b44
push id36903
push userncsoregi@mozilla.com
push dateWed, 11 Dec 2019 09:46:40 +0000
treeherdermozilla-central@f83f2771414c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1599952
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1599952 initialize AudioWorkletProcessor.port r=baku Differential Revision: https://phabricator.services.mozilla.com/D53135
dom/media/webaudio/AudioWorkletGlobalScope.cpp
dom/media/webaudio/AudioWorkletGlobalScope.h
dom/media/webaudio/AudioWorkletProcessor.cpp
dom/media/webaudio/AudioWorkletProcessor.h
dom/webidl/AudioWorkletProcessor.webidl
testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-messageport.https.html.ini
testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-output-channel-count.https.html.ini
testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletprocessor-options.https.html.ini
testing/web-platform/meta/webaudio/the-audio-api/the-channelmergernode-interface/active-processing.https.html.ini
testing/web-platform/meta/webaudio/the-audio-api/the-convolvernode-interface/active-processing.https.html.ini
testing/web-platform/meta/webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface/cors-check.https.html.ini
--- a/dom/media/webaudio/AudioWorkletGlobalScope.cpp
+++ b/dom/media/webaudio/AudioWorkletGlobalScope.cpp
@@ -364,10 +364,14 @@ bool AudioWorkletGlobalScope::ConstructP
   if (NS_WARN_IF(!ToJSValue(cx, processor, &processorVal))) {
     return false;
   }
   MOZ_ASSERT(processorVal.isObject());
   aRetProcessor.set(&processorVal.toObject());
   return true;
 }
 
+RefPtr<MessagePort> AudioWorkletGlobalScope::TakePortForProcessorCtor() {
+  return std::move(mPortForProcessor);
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/media/webaudio/AudioWorkletGlobalScope.h
+++ b/dom/media/webaudio/AudioWorkletGlobalScope.h
@@ -49,16 +49,20 @@ class AudioWorkletGlobalScope final : pu
   // If successful, returns true and sets aRetProcessor, which will be in the
   // compartment for the realm of this global.  Returns false on failure.
   MOZ_CAN_RUN_SCRIPT
   bool ConstructProcessor(const nsAString& aName,
                           NotNull<StructuredCloneHolder*> aSerializedOptions,
                           UniqueMessagePortId& aPortIdentifier,
                           JS::MutableHandle<JSObject*> aRetProcessor);
 
+  // Returns null if not called during ConstructProcessor() or if the port has
+  // already been taken.
+  RefPtr<MessagePort> TakePortForProcessorCtor();
+
  private:
   ~AudioWorkletGlobalScope() = default;
 
   // Returns an AudioParamDescriptorMap filled with AudioParamDescriptor
   // objects, extracted from JS. Returns an empty map in case of error and set
   // aRv accordingly.
   AudioParamDescriptorMap DescriptorsFromJS(
       JSContext* aCx, const JS::Rooted<JS::Value>& aDescriptors,
--- a/dom/media/webaudio/AudioWorkletProcessor.cpp
+++ b/dom/media/webaudio/AudioWorkletProcessor.cpp
@@ -9,40 +9,45 @@
 #include "mozilla/dom/AudioWorkletNodeBinding.h"
 #include "mozilla/dom/AudioWorkletProcessorBinding.h"
 #include "mozilla/dom/MessagePort.h"
 #include "nsIGlobalObject.h"
 
 namespace mozilla {
 namespace dom {
 
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AudioWorkletProcessor, mParent)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AudioWorkletProcessor, mParent, mPort)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AudioWorkletProcessor, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioWorkletProcessor, Release)
 
-AudioWorkletProcessor::AudioWorkletProcessor(nsIGlobalObject* aParent)
-    : mParent(aParent) {}
+AudioWorkletProcessor::AudioWorkletProcessor(nsIGlobalObject* aParent,
+                                             MessagePort* aPort)
+    : mParent(aParent), mPort(aPort) {}
+
+AudioWorkletProcessor::~AudioWorkletProcessor() = default;
 
 /* static */
 already_AddRefed<AudioWorkletProcessor> AudioWorkletProcessor::Constructor(
-    const GlobalObject& aGlobal, const AudioWorkletNodeOptions& aOptions) {
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
+    const GlobalObject& aGlobal, const AudioWorkletNodeOptions& aOptions,
+    ErrorResult& aRv) {
+  nsCOMPtr<WorkletGlobalScope> global =
+      do_QueryInterface(aGlobal.GetAsSupports());
   MOZ_ASSERT(global);
-
+  RefPtr<MessagePort> port = static_cast<AudioWorkletGlobalScope*>(global.get())
+                                 ->TakePortForProcessorCtor();
+  if (!port) {
+    aRv.ThrowTypeError<MSG_ILLEGAL_CONSTRUCTOR>();
+    return nullptr;
+  }
   RefPtr<AudioWorkletProcessor> audioWorkletProcessor =
-      new AudioWorkletProcessor(global);
+      new AudioWorkletProcessor(global, port);
 
   return audioWorkletProcessor.forget();
 }
 
 JSObject* AudioWorkletProcessor::WrapObject(JSContext* aCx,
                                             JS::Handle<JSObject*> aGivenProto) {
   return AudioWorkletProcessor_Binding::Wrap(aCx, this, aGivenProto);
 }
 
-MessagePort* AudioWorkletProcessor::GetPort(ErrorResult& aRv) const {
-  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
-  return nullptr;
-}
-
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/media/webaudio/AudioWorkletProcessor.h
+++ b/dom/media/webaudio/AudioWorkletProcessor.h
@@ -23,27 +23,29 @@ class GlobalObject;
 class MessagePort;
 
 class AudioWorkletProcessor final : public nsWrapperCache {
  public:
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioWorkletProcessor)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioWorkletProcessor)
 
   static already_AddRefed<AudioWorkletProcessor> Constructor(
-      const GlobalObject& aGlobal, const AudioWorkletNodeOptions& aOptions);
+      const GlobalObject& aGlobal, const AudioWorkletNodeOptions& aOptions,
+      ErrorResult& aRv);
 
   nsIGlobalObject* GetParentObject() const { return mParent; }
 
   JSObject* WrapObject(JSContext* aCx,
                        JS::Handle<JSObject*> aGivenProto) override;
 
-  MessagePort* GetPort(ErrorResult& aRv) const;
+  MessagePort* Port() const { return mPort; };
 
  private:
-  explicit AudioWorkletProcessor(nsIGlobalObject* aParent);
-  ~AudioWorkletProcessor() = default;
+  explicit AudioWorkletProcessor(nsIGlobalObject* aParent, MessagePort* aPort);
+  ~AudioWorkletProcessor();
   nsCOMPtr<nsIGlobalObject> mParent;
+  RefPtr<MessagePort> mPort;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // AudioWorkletProcessor_h_
--- a/dom/webidl/AudioWorkletProcessor.webidl
+++ b/dom/webidl/AudioWorkletProcessor.webidl
@@ -7,13 +7,13 @@
  * https://webaudio.github.io/web-audio-api/#audioworkletprocessor
  *
  * Copyright © 2018 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 [Exposed=AudioWorklet]
 interface AudioWorkletProcessor {
-    constructor(optional AudioWorkletNodeOptions options = {});
+  [Throws]
+  constructor(optional AudioWorkletNodeOptions options = {});
 
-    [Throws]
-    readonly attribute MessagePort port;
+  readonly attribute MessagePort port;
 };
--- a/testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-messageport.https.html.ini
+++ b/testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-messageport.https.html.ini
@@ -1,14 +1,12 @@
 [audioworklet-messageport.https.html]
   bug: AudioWorklet not enabled on release_or_beta
   expected:
     if release_or_beta: ERROR
-    TIMEOUT
   [Executing "Test postMessage from AudioWorkletProcessor to AudioWorkletNode"]
-    expected: TIMEOUT
+    expected:
+      if release_or_beta: FAIL
 
   [Executing "Test postMessage from AudioWorkletNode to AudioWorkletProcessor"]
-    expected: NOTRUN
+    expected:
+      if release_or_beta: FAIL
 
-  [Audit report]
-    expected: NOTRUN
-
--- a/testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-output-channel-count.https.html.ini
+++ b/testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-output-channel-count.https.html.ini
@@ -1,14 +1,13 @@
 [audioworkletnode-output-channel-count.https.html]
   bug: AudioWorklet not enabled on release_or_beta
   expected:
     if release_or_beta: ERROR
-    TIMEOUT
-  [Executing "Dynamically change the channel count to if unspecified."]
-    expected: TIMEOUT
+  [X The expected output channel count is not equal to 17. Got 1.]
+    expected: FAIL
 
-  [Executing "Givien outputChannelCount must be honored."]
-    expected: NOTRUN
+  [< [Dynamically change the channel count to if unspecified.\] 1 out of 1 assertions were failed.]
+    expected: FAIL
 
-  [Audit report]
-    expected: NOTRUN
+  [# AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed.]
+    expected: FAIL
 
--- a/testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletprocessor-options.https.html.ini
+++ b/testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletprocessor-options.https.html.ini
@@ -1,20 +1,20 @@
 [audioworkletprocessor-options.https.html]
-  expected:
-    if release_or_beta: OK
-    TIMEOUT
   [Executing "valid-processor-data"]
     bug: AudioWorklet not enabled on release_or_beta
     expected:
       if release_or_beta: FAIL
-      TIMEOUT
 
   [Executing "empty-option"]
     bug: AudioWorklet not enabled on release_or_beta
     expected:
       if release_or_beta: FAIL
-      NOTRUN
+
+  [X Number of properties in data from processor is not equal to 2. Got 3.]
+    expected: FAIL
 
-  [Audit report]
-    expected:
-      if release_or_beta: PASS
-      NOTRUN
+  [< [empty-option\] 1 out of 3 assertions were failed.]
+    expected: FAIL
+
+  [# AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed.]
+    expected: FAIL
+
--- a/testing/web-platform/meta/webaudio/the-audio-api/the-channelmergernode-interface/active-processing.https.html.ini
+++ b/testing/web-platform/meta/webaudio/the-audio-api/the-channelmergernode-interface/active-processing.https.html.ini
@@ -1,19 +1,19 @@
 [active-processing.https.html]
-  expected:
-    if release_or_beta: OK
-    TIMEOUT
   [Executing "initialize"]
     bug: AudioWorklet not enabled on release_or_beta
     expected:
       if release_or_beta: FAIL
 
   [Executing "test"]
     expected:
       if release_or_beta: FAIL
-      TIMEOUT
+
+  [X Test 1: Number of convolver output channels is not equal to 1. Got 0.]
+    expected: FAIL
 
-  [Audit report]
-    expected:
-      if release_or_beta: PASS
-      NOTRUN
+  [< [test\] 1 out of 3 assertions were failed.]
+    expected: FAIL
 
+  [# AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed.]
+    expected: FAIL
+
--- a/testing/web-platform/meta/webaudio/the-audio-api/the-convolvernode-interface/active-processing.https.html.ini
+++ b/testing/web-platform/meta/webaudio/the-audio-api/the-convolvernode-interface/active-processing.https.html.ini
@@ -1,19 +1,19 @@
 [active-processing.https.html]
-  expected:
-    if release_or_beta: OK
-    TIMEOUT
   [Executing "initialize"]
     bug: AudioWorklet not enabled on release_or_beta
     expected:
       if release_or_beta: FAIL
 
   [Executing "test"]
     expected:
       if release_or_beta: FAIL
-      TIMEOUT
+
+  [X Number of distinct values is not equal to 2. Got 0.]
+    expected: FAIL
 
-  [Audit report]
-    expected:
-      if release_or_beta: PASS
-      NOTRUN
+  [# AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed.]
+    expected: FAIL
 
+  [< [test\] 1 out of 1 assertions were failed.]
+    expected: FAIL
+
--- a/testing/web-platform/meta/webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface/cors-check.https.html.ini
+++ b/testing/web-platform/meta/webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface/cors-check.https.html.ini
@@ -1,11 +1,22 @@
 [cors-check.https.html]
   bug: AudioWorklet not enabled on release_or_beta
   expected:
     if release_or_beta: ERROR
-    TIMEOUT
-  [Executing "start-playback-and-capture"]
-    expected: TIMEOUT
+  [X Recorded channel #0 should have contain at least one value different from 0.]
+    expected: FAIL
+
+  [X Recorded channel #3 should have contain at least one value different from 0.]
+    expected: FAIL
+
+  [< [start-playback-and-capture\] 4 out of 4 assertions were failed.]
+    expected: FAIL
 
-  [Audit report]
-    expected: NOTRUN
+  [# AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed.]
+    expected: FAIL
 
+  [X Recorded channel #2 should have contain at least one value different from 0.]
+    expected: FAIL
+
+  [X Recorded channel #1 should have contain at least one value different from 0.]
+    expected: FAIL
+