浏览代码

LibWeb: Implement AudioNode.context

This is just a simple getter which returns the audio context that
created this audio node.
Shannon Booth 1 年之前
父节点
当前提交
b48ba823b9

+ 1 - 0
Tests/LibWeb/Text/expected/WebAudio/OscillatorNode.txt

@@ -3,3 +3,4 @@ AudioScheduledSourceNode
 AudioNode
 EventTarget
 Object
+context: '[object OfflineAudioContext], is same as original: true

+ 4 - 0
Tests/LibWeb/Text/input/WebAudio/OscillatorNode.html

@@ -5,11 +5,15 @@
 
         const oscillator = audioContext.createOscillator();
 
+        // Check prototype
         let prototype = Object.getPrototypeOf(oscillator);
 
         while (prototype) {
             println(prototype.constructor.name);
             prototype = Object.getPrototypeOf(prototype);
         }
+
+        // Context getter
+        println(`context: '${oscillator.context}, is same as original: ${audioContext === oscillator.context}`);
     });
 </script>

+ 7 - 0
Userland/Libraries/LibWeb/WebAudio/AudioNode.h

@@ -41,6 +41,13 @@ public:
     void disconnect(JS::NonnullGCPtr<AudioParam> destination_param);
     void disconnect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output);
 
+    // https://webaudio.github.io/web-audio-api/#dom-audionode-context
+    JS::NonnullGCPtr<BaseAudioContext const> context() const
+    {
+        // The BaseAudioContext which owns this AudioNode.
+        return m_context;
+    }
+
 protected:
     AudioNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>);
 

+ 1 - 1
Userland/Libraries/LibWeb/WebAudio/AudioNode.idl

@@ -37,7 +37,7 @@ interface AudioNode : EventTarget {
                          unsigned long input);
     undefined disconnect(AudioParam destinationParam);
     undefined disconnect(AudioParam destinationParam, unsigned long output);
-    // FIXME: readonly attribute BaseAudioContext context;
+    readonly attribute BaseAudioContext context;
     // FIXME: readonly attribute unsigned long numberOfInputs;
     // FIXME: readonly attribute unsigned long numberOfOutputs;
     // FIXME: attribute unsigned long channelCount;