UNPKG

happy-dom-without-node

Version:

Happy DOM is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG DOM and HTML.

35 lines (31 loc) 782 B
import Document from '../nodes/document/Document.js'; /** * Node factory used for setting the owner document to nodes. */ export default class NodeFactory { public static ownerDocuments: Document[] = []; /** * Creates a node instance with the given owner document. * * @param ownerDocument Owner document. * @param nodeClass Node class. * @param [args] Node arguments. * @returns Node instance. */ public static createNode<T>( ownerDocument: Document, nodeClass: new (...args) => T, ...args: any[] ): T { this.ownerDocuments.push(ownerDocument); return new nodeClass(...args); } /** * Pulls an owner document from the queue. * * @returns Document. */ public static pullOwnerDocument(): Document { return this.ownerDocuments.pop(); } }