Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#778@minor: Add Audio class to window. #779

Merged
merged 3 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/happy-dom/src/nodes/html-audio-element/Audio.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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