Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit eabaf3e

Browse files
author
Ehsan Akhgari
committed
Bug 859600 - Make AudioContext an EventTarget; r=smaug
1 parent 615a963 commit eabaf3e

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

content/media/webaudio/AudioContext.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ const unsigned MAX_SCRIPT_PROCESSOR_CHANNELS = 10000;
2929
namespace mozilla {
3030
namespace dom {
3131

32-
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_3(AudioContext,
33-
mWindow, mDestination, mListener)
32+
NS_IMPL_CYCLE_COLLECTION_2(AudioContext, mDestination, mListener)
3433

35-
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AudioContext, AddRef)
36-
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioContext, Release)
34+
NS_IMPL_ADDREF_INHERITED(AudioContext, nsDOMEventTargetHelper)
35+
NS_IMPL_RELEASE_INHERITED(AudioContext, nsDOMEventTargetHelper)
36+
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AudioContext)
37+
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
3738

3839
static uint8_t gWebAudioOutputKey;
3940

4041
AudioContext::AudioContext(nsPIDOMWindow* aWindow)
41-
: mWindow(aWindow)
42-
, mDestination(new AudioDestinationNode(this, MediaStreamGraph::GetInstance()))
42+
: mDestination(new AudioDestinationNode(this, MediaStreamGraph::GetInstance()))
4343
{
4444
// Actually play audio
4545
mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey);
46+
nsDOMEventTargetHelper::BindToOwner(aWindow);
4647
SetIsDOMBinding();
4748

4849
mPannerNodes.Init();

content/media/webaudio/AudioContext.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef AudioContext_h_
88
#define AudioContext_h_
99

10-
#include "nsWrapperCache.h"
10+
#include "nsDOMEventTargetHelper.h"
1111
#include "nsCycleCollectionParticipant.h"
1212
#include "mozilla/Attributes.h"
1313
#include "nsCOMPtr.h"
@@ -51,19 +51,20 @@ class GlobalObject;
5151
class PannerNode;
5252
class ScriptProcessorNode;
5353

54-
class AudioContext MOZ_FINAL : public nsWrapperCache,
54+
class AudioContext MOZ_FINAL : public nsDOMEventTargetHelper,
5555
public EnableWebAudioCheck
5656
{
5757
explicit AudioContext(nsPIDOMWindow* aParentWindow);
5858
~AudioContext();
5959

6060
public:
61-
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioContext)
62-
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioContext)
61+
NS_DECL_ISUPPORTS_INHERITED
62+
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioContext,
63+
nsDOMEventTargetHelper)
6364

6465
nsPIDOMWindow* GetParentObject() const
6566
{
66-
return mWindow;
67+
return GetOwner();
6768
}
6869

6970
void Shutdown();
@@ -164,7 +165,6 @@ class AudioContext MOZ_FINAL : public nsWrapperCache,
164165
friend struct ::mozilla::WebAudioDecodeJob;
165166

166167
private:
167-
nsCOMPtr<nsPIDOMWindow> mWindow;
168168
nsRefPtr<AudioDestinationNode> mDestination;
169169
nsRefPtr<AudioListener> mListener;
170170
MediaBufferDecoder mDecoder;

content/media/webaudio/test/test_AudioContext.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
var ac = new AudioContext();
1616
ok(ac, "Create a AudioContext object");
1717
is(ac.sampleRate, 48000, "Correct sample rate");
18+
ok(ac instanceof EventTarget, "AudioContexts must be EventTargets");
1819
SpecialPowers.clearUserPref("media.webaudio.enabled");
1920
SimpleTest.finish();
2021
});

dom/webidl/AudioContext.webidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ callback DecodeSuccessCallback = void (AudioBuffer decodedData);
1414
callback DecodeErrorCallback = void ();
1515

1616
[Constructor, PrefControlled]
17-
interface AudioContext {
17+
interface AudioContext : EventTarget {
1818

1919
readonly attribute AudioDestinationNode destination;
2020
readonly attribute float sampleRate;

0 commit comments

Comments
 (0)