Skip to content

Commit

Permalink
Merge pull request #779 from CSchulz/patch-7
Browse files Browse the repository at this point in the history
#778@minor: Add Audio class to window.
  • Loading branch information
capricorn86 committed Feb 25, 2023
2 parents 1814f62 + 6e076c3 commit 13bcfe7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/happy-dom/src/nodes/html-audio-element/Audio.ts
@@ -0,0 +1,22 @@
import HTMLAudioElement from './HTMLAudioElement';

/**
* Image as constructor.
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement/Audio.
*/
export default class Audio extends HTMLAudioElement {
/**
* Constructor.
*
* @param [url] source URL.
*/
constructor(url: string = null) {
super();

if (url !== null) {
this.src = url;
}
}
}
7 changes: 6 additions & 1 deletion packages/happy-dom/src/window/Window.ts
Expand Up @@ -23,6 +23,7 @@ import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
import HTMLMetaElement from '../nodes/html-meta-element/HTMLMetaElement';
import HTMLMediaElement from '../nodes/html-media-element/HTMLMediaElement';
import HTMLAudioElement from '../nodes/html-audio-element/HTMLAudioElement';
import { default as AudioImplementation } from '../nodes/html-audio-element/Audio';
import HTMLVideoElement from '../nodes/html-video-element/HTMLVideoElement';
import HTMLBaseElement from '../nodes/html-base-element/HTMLBaseElement';
import HTMLIFrameElement from '../nodes/html-iframe-element/HTMLIFrameElement';
Expand Down Expand Up @@ -275,6 +276,7 @@ export default class Window extends EventTarget implements IWindow {
public readonly Range;
public readonly FileReader;
public readonly Image;
public readonly Audio;

// Events
public onload: (event: Event) => void = null;
Expand Down Expand Up @@ -469,10 +471,12 @@ export default class Window extends EventTarget implements IWindow {
class XMLHttpRequest extends XMLHttpRequestImplementation {
public static _ownerDocument: IDocument = document;
}

class Range extends RangeImplementation {
public static _ownerDocument: IDocument = document;
}
class Audio extends AudioImplementation {
public static _ownerDocument: IDocument = document;
}
/* eslint-enable jsdoc/require-jsdoc */

this.Response = Response;
Expand All @@ -482,6 +486,7 @@ export default class Window extends EventTarget implements IWindow {
this.DOMParser = DOMParser;
this.XMLHttpRequest = XMLHttpRequest;
this.Range = Range;
this.Audio = Audio;

this._setupVMContext();

Expand Down

0 comments on commit 13bcfe7

Please sign in to comment.