Bug 1565956 updated quoted AudioWorkletProcessor instantiation steps r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 15 Nov 2019 13:34:01 +0000
changeset 502355 9f72416c9e8a507772a72ac8d6f3d5f48f05e5b5
parent 502354 a77200f8f3eb7b00e27169f98d1272ceedab59d6
child 502356 75a422b353a50e0367459ae4c7909151deda575e
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1565956
milestone72.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 1565956 updated quoted AudioWorkletProcessor instantiation steps r=padenot Depends on D53129 Differential Revision: https://phabricator.services.mozilla.com/D53130
dom/media/webaudio/AudioWorkletGlobalScope.cpp
dom/media/webaudio/AudioWorkletGlobalScope.h
dom/media/webaudio/AudioWorkletNode.cpp
--- a/dom/media/webaudio/AudioWorkletGlobalScope.cpp
+++ b/dom/media/webaudio/AudioWorkletGlobalScope.cpp
@@ -282,75 +282,69 @@ AudioParamDescriptorMap AudioWorkletGlob
       return AudioParamDescriptorMap();
     }
   }
 
   return res;
 }
 
 bool AudioWorkletGlobalScope::ConstructProcessor(
-    const nsAString& aName,
-    NotNull<StructuredCloneHolder*> aOptionsSerialization,
+    const nsAString& aName, NotNull<StructuredCloneHolder*> aSerializedOptions,
     JS::MutableHandle<JSObject*> aRetProcessor) {
   /**
-   * See the second algorithm at
-   * https://webaudio.github.io/web-audio-api/#instantiation-of-AudioWorkletNode-and-AudioWorkletProcessor
+   * See
+   * https://webaudio.github.io/web-audio-api/#AudioWorkletProcessor-instantiation
    */
   AutoJSAPI jsapi;
   if (NS_WARN_IF(!jsapi.Init(this))) {
     return false;
   }
   JSContext* cx = jsapi.cx();
   ErrorResult rv;
   /** TODO https://bugzilla.mozilla.org/show_bug.cgi?id=1565956
-   * 1. Let processorPort be
-   *    StructuredDeserializeWithTransfer(processorPortSerialization,
-   *                                      the current Realm).
+   * 4. Let deserializedPort be the result of
+   *    StructuredDeserialize(serializedPort, the current Realm).
    */
   /**
-   * 2. Let options be StructuredDeserialize(optionsSerialization,
-   *                                         the current Realm).
+   * 5. Let deserializedOptions be the result of
+   *    StructuredDeserialize(serializedOptions, the current Realm).
    */
-  JS::Rooted<JS::Value> optionsVal(cx);
-  aOptionsSerialization->Read(this, cx, &optionsVal, rv);
+  JS::Rooted<JS::Value> deserializedOptions(cx);
+  aSerializedOptions->Read(this, cx, &deserializedOptions, rv);
   if (rv.MaybeSetPendingException(cx)) {
     return false;
   }
   /**
-   * 3. Let processorConstructor be the result of looking up nodeName on the
+   * 6. Let processorCtor be the result of looking up processorName on the
    *    AudioWorkletGlobalScope's node name to processor definition map.
    */
-  RefPtr<AudioWorkletProcessorConstructor> processorConstructor =
+  RefPtr<AudioWorkletProcessorConstructor> processorCtor =
       mNameToProcessorMap.Get(aName);
   // AudioWorkletNode has already checked the definition exists.
   // See also https://github.com/WebAudio/web-audio-api/issues/1854
-  MOZ_ASSERT(processorConstructor);
+  MOZ_ASSERT(processorCtor);
+  /** TODO https://bugzilla.mozilla.org/show_bug.cgi?id=1565956
+   * 7. Store nodeReference and deserializedPort to node reference and
+   *    transferred port of this AudioWorkletGlobalScope's pending processor
+   *    construction data respectively.
+   */
   /**
-   * 4. Let processor be the result of Construct(processorConstructor,
-   *                                             « options »).
+   * 8. Construct a callback function from processorCtor with the argument
+   *    of deserializedOptions.
    */
   // The options were an object before serialization and so will be an object
   // if deserialization succeeded above.  toObject() asserts.
-  JS::Rooted<JSObject*> options(cx, &optionsVal.toObject());
-  // Using https://heycam.github.io/webidl/#construct-a-callback-function
-  // See
-  // https://github.com/WebAudio/web-audio-api/pull/1843#issuecomment-478590304
-  RefPtr<AudioWorkletProcessor> processor = processorConstructor->Construct(
+  JS::Rooted<JSObject*> options(cx, &deserializedOptions.toObject());
+  RefPtr<AudioWorkletProcessor> processor = processorCtor->Construct(
       options, rv, "AudioWorkletProcessor construction",
       CallbackFunction::eReportExceptions);
   if (rv.Failed()) {
     rv.SuppressException();  // already reported
     return false;
   }
-  /** TODO https://bugzilla.mozilla.org/show_bug.cgi?id=1565956
-   * but see https://github.com/WebAudio/web-audio-api/issues/1973
-   *
-   * 5. Set processor’s port to processorPort.
-   */
-
   JS::Rooted<JS::Value> processorVal(cx);
   if (NS_WARN_IF(!ToJSValue(cx, processor, &processorVal))) {
     return false;
   }
   MOZ_ASSERT(processorVal.isObject());
   aRetProcessor.set(&processorVal.toObject());
   return true;
 }
--- a/dom/media/webaudio/AudioWorkletGlobalScope.h
+++ b/dom/media/webaudio/AudioWorkletGlobalScope.h
@@ -43,17 +43,17 @@ class AudioWorkletGlobalScope final : pu
   double CurrentTime() const;
 
   float SampleRate() const;
 
   // 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*> aOptionsSerialization,
+                          NotNull<StructuredCloneHolder*> aSerializedOptions,
                           JS::MutableHandle<JSObject*> aRetProcessor);
 
  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.
--- a/dom/media/webaudio/AudioWorkletNode.cpp
+++ b/dom/media/webaudio/AudioWorkletNode.cpp
@@ -21,19 +21,19 @@ class WorkletNodeEngine final : public A
                     const Optional<Sequence<uint32_t>>& aOutputChannelCount)
       : AudioNodeEngine(aNode) {
     if (aOutputChannelCount.WasPassed()) {
       mOutputChannelCount = aOutputChannelCount.Value();
     }
   }
 
   MOZ_CAN_RUN_SCRIPT
-  void ConstructProcessor(
-      AudioWorkletImpl* aWorkletImpl, const nsAString& aName,
-      NotNull<StructuredCloneHolder*> aOptionsSerialization);
+  void ConstructProcessor(AudioWorkletImpl* aWorkletImpl,
+                          const nsAString& aName,
+                          NotNull<StructuredCloneHolder*> aSerializedOptions);
 
   void ProcessBlock(AudioNodeTrack* aTrack, GraphTime aFrom,
                     const AudioBlock& aInput, AudioBlock* aOutput,
                     bool* aFinished) override {
     MOZ_ASSERT(InputCount() <= 1);
     MOZ_ASSERT(OutputCount() <= 1);
     ProcessBlocksOnPorts(aTrack, MakeSpan(&aInput, InputCount()),
                          MakeSpan(aOutput, OutputCount()), aFinished);
@@ -113,23 +113,23 @@ void WorkletNodeEngine::SendProcessorErr
    * Note that once an exception is thrown, the processor will output silence
    * throughout its lifetime.
    */
   ReleaseJSResources();
 }
 
 void WorkletNodeEngine::ConstructProcessor(
     AudioWorkletImpl* aWorkletImpl, const nsAString& aName,
-    NotNull<StructuredCloneHolder*> aOptionsSerialization) {
+    NotNull<StructuredCloneHolder*> aSerializedOptions) {
   MOZ_ASSERT(mInputs.mPorts.empty() && mOutputs.mPorts.empty());
   RefPtr<AudioWorkletGlobalScope> global = aWorkletImpl->GetGlobalScope();
   MOZ_ASSERT(global);  // global has already been used to register processor
   JS::RootingContext* cx = RootingCx();
   mProcessor.init(cx);
-  if (!global->ConstructProcessor(aName, aOptionsSerialization, &mProcessor) ||
+  if (!global->ConstructProcessor(aName, aSerializedOptions, &mProcessor) ||
       // mInputs and mOutputs outer arrays are fixed length and so much of the
       // initialization need only be performed once (i.e. here).
       NS_WARN_IF(!mInputs.mPorts.growBy(InputCount())) ||
       NS_WARN_IF(!mOutputs.mPorts.growBy(OutputCount()))) {
     SendProcessorError();
     return;
   }
   mGlobal = std::move(global);