Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: capricorn86/happy-dom
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.8.0
Choose a base ref
...
head repository: capricorn86/happy-dom
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.9.0
Choose a head ref
  • 4 commits
  • 2 files changed
  • 2 contributors

Commits on Feb 24, 2023

  1. Copy the full SHA
    c7f2e70 View commit details

Commits on Feb 25, 2023

  1. Copy the full SHA
    2407e37 View commit details
  2. Copy the full SHA
    6e076c3 View commit details
  3. Merge pull request #779 from CSchulz/patch-7

    #778@minor: Add Audio class to window.
    capricorn86 authored Feb 25, 2023
    Copy the full SHA
    13bcfe7 View commit details
Showing with 28 additions and 1 deletion.
  1. +22 −0 packages/happy-dom/src/nodes/html-audio-element/Audio.ts
  2. +6 −1 packages/happy-dom/src/window/Window.ts
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
@@ -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';
@@ -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;
@@ -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;
@@ -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();