Skip to content

Commit

Permalink
Merge pull request #958 from exokitxr/head-body
Browse files Browse the repository at this point in the history
Add default DOM <head> and <body>
  • Loading branch information
Avaer Kazmer committed Apr 21, 2019
2 parents 2c3e3d8 + 7207145 commit c886bc7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,12 @@ class HTMLLoadableElement extends HTMLElement {
}
module.exports.HTMLLoadableElement = HTMLLoadableElement;

class HTMLHeadElement extends HTMLElement {
constructor(window) {
super(window, 'HEAD');
}
}

class HTMLBodyElement extends HTMLElement {
constructor(window) {
super(window, 'BODY');
Expand Down Expand Up @@ -3104,6 +3110,7 @@ const getBoundDOMElements = window => {
return {
Element: bind(Element, b => function Element() { return b.apply(this, arguments); }),
HTMLElement: bind(HTMLElement, b => function HTMLElement() { return b.apply(this, arguments); }),
HTMLHeadElement: bind(HTMLHeadElement, b => function HTMLHeadElement() { return b.apply(this, arguments); }),
HTMLBodyElement: bind(HTMLBodyElement, b => function HTMLBodyElement() { return b.apply(this, arguments); }),
HTMLAnchorElement: bind(HTMLAnchorElement, b => function HTMLAnchorElement() { return b.apply(this, arguments); }),
HTMLStyleElement: bind(HTMLStyleElement, b => function HTMLStyleElement() { return b.apply(this, arguments); }),
Expand Down
4 changes: 2 additions & 2 deletions src/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module.exports._parseDocumentAst = _parseDocumentAst;
function initDocument (document, window) {
const html = document.childNodes.find(el => el.tagName === 'HTML');
const documentElement = html || (document.childNodes.length > 0 ? document.childNodes[0] : null);
const head = html ? html.childNodes.find(el => el.tagName === 'HEAD') : null;
const body = html ? html.childNodes.find(el => el.tagName === 'BODY') : null;
const head = html ? html.childNodes.find(el => el.tagName === 'HEAD') : new window.HTMLHeadElement();
const body = html ? html.childNodes.find(el => el.tagName === 'BODY') : new window.HTMLBodyElement();

document.documentElement = documentElement;
document.readyState = 'loading';
Expand Down
3 changes: 3 additions & 0 deletions src/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ const _makeWindow = (options = {}, parent = null, top = null) => {
const {
Element,
HTMLElement,
HTMLHeadElement,
HTMLBodyElement,
HTMLAnchorElement,
HTMLStyleElement,
Expand All @@ -788,6 +789,7 @@ const _makeWindow = (options = {}, parent = null, top = null) => {
} = getBoundDOMElements(window);
window.Element = Element;
window.HTMLElement = HTMLElement;
window.HTMLHeadElement = HTMLHeadElement;
window.HTMLBodyElement = HTMLBodyElement;
window.HTMLAnchorElement = HTMLAnchorElement;
window.HTMLStyleElement = HTMLStyleElement;
Expand All @@ -810,6 +812,7 @@ const _makeWindow = (options = {}, parent = null, top = null) => {
window.Comment = Comment;
window[symbols.htmlTagsSymbol] = {
DOCUMENT: Document,
HEAD: HTMLHeadElement,
BODY: HTMLBodyElement,
A: HTMLAnchorElement,
STYLE: HTMLStyleElement,
Expand Down

0 comments on commit c886bc7

Please sign in to comment.