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

Implements customElements.getName() and fixes letter case handling. #1177

Merged
merged 10 commits into from
Feb 21, 2024
Merged
2 changes: 2 additions & 0 deletions packages/happy-dom/src/PropertySymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,5 @@ export const content = Symbol('content');
export const mode = Symbol('mode');
export const host = Symbol('host');
export const setURL = Symbol('setURL');
export const localName = Symbol('localName');
export const registedClass = Symbol('registedClass');
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ export default class DetachedBrowserPage implements IBrowserPage {
.then(() => {
// As we are in a detached page, a context or browser should not exist without a page as there are no references to them.
if (context.pages[0] === this) {
context.close();
context.close().then(resolve).catch(reject);
} else {
resolve();
}
resolve();
})
.catch((error) => reject(error));
.catch(reject);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export default class BrowserFrameExceptionObserver {
return;
}

if (!this.browserFrame.window) {
throw new Error(
'Browser frame was not closed correctly. Window is undefined on browser frame, but exception observer is still watching.'
);
}

if (
error instanceof this.browserFrame.window.Error ||
error instanceof this.browserFrame.window.DOMException
Expand All @@ -56,6 +62,12 @@ export default class BrowserFrameExceptionObserver {
// The "uncaughtException" event is not always triggered for unhandled rejections.
// Therefore we want to use the "unhandledRejection" event as well.
this.uncaughtRejectionListener = (error: unknown) => {
if (!this.browserFrame.window) {
throw new Error(
'Browser frame was not closed correctly. Window is undefined on browser frame, but exception observer is still watching.'
);
}

if (
error instanceof this.browserFrame.window.Error ||
error instanceof this.browserFrame.window.DOMException
Expand Down
21 changes: 14 additions & 7 deletions packages/happy-dom/src/browser/utilities/BrowserFrameFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ export default class BrowserFrameFactory {
}
}

// We need to destroy the Window instance before triggering any async tasks as Window.close() is not async.
frame.window[PropertySymbol.destroy]();
(<IBrowserPage | null>frame.page) = null;
(<IBrowserWindow | null>frame.window) = null;
frame[PropertySymbol.openerFrame] = null;
frame[PropertySymbol.openerWindow] = null;

if (!frame.childFrames.length) {
return frame[PropertySymbol.asyncTaskManager]
.destroy()
.then(() => {
frame[PropertySymbol.exceptionObserver]?.disconnect();
if (frame.window) {
frame.window[PropertySymbol.destroy]();
(<IBrowserPage | null>frame.page) = null;
(<IBrowserWindow | null>frame.window) = null;
frame[PropertySymbol.openerFrame] = null;
frame[PropertySymbol.openerWindow] = null;
}
resolve();
})
.catch((error) => reject(error));
Expand All @@ -62,6 +62,13 @@ export default class BrowserFrameFactory {
.then(() => {
return frame[PropertySymbol.asyncTaskManager].destroy().then(() => {
frame[PropertySymbol.exceptionObserver]?.disconnect();
if (frame.window) {
frame.window[PropertySymbol.destroy]();
(<IBrowserPage | null>frame.page) = null;
(<IBrowserWindow | null>frame.window) = null;
frame[PropertySymbol.openerFrame] = null;
frame[PropertySymbol.openerWindow] = null;
}
resolve();
});
})
Expand Down
130 changes: 0 additions & 130 deletions packages/happy-dom/src/config/ElementTag.ts

This file was deleted.

119 changes: 119 additions & 0 deletions packages/happy-dom/src/config/HTMLElementLocalNameToClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
export default <{ [key: string]: string }>{
a: 'HTMLAnchorElement',
abbr: 'HTMLElement',
address: 'HTMLElement',
area: 'HTMLElement',
article: 'HTMLElement',
aside: 'HTMLElement',
audio: 'HTMLAudioElement',
b: 'HTMLElement',
base: 'HTMLBaseElement',
bdi: 'HTMLElement',
bdo: 'HTMLElement',
blockquaote: 'HTMLElement',
body: 'HTMLElement',
template: 'HTMLTemplateElement',
form: 'HTMLFormElement',
input: 'HTMLInputElement',
textarea: 'HTMLTextAreaElement',
script: 'HTMLScriptElement',
img: 'HTMLImageElement',
link: 'HTMLLinkElement',
style: 'HTMLStyleElement',
label: 'HTMLLabelElement',
slot: 'HTMLSlotElement',
meta: 'HTMLMetaElement',
blockquote: 'HTMLElement',
br: 'HTMLElement',
button: 'HTMLButtonElement',
canvas: 'HTMLElement',
caption: 'HTMLElement',
cite: 'HTMLElement',
code: 'HTMLElement',
col: 'HTMLElement',
colgroup: 'HTMLElement',
data: 'HTMLElement',
datalist: 'HTMLElement',
dd: 'HTMLElement',
del: 'HTMLElement',
details: 'HTMLElement',
dfn: 'HTMLElement',
dialog: 'HTMLDialogElement',
div: 'HTMLElement',
dl: 'HTMLElement',
dt: 'HTMLElement',
em: 'HTMLElement',
embed: 'HTMLElement',
fieldset: 'HTMLElement',
figcaption: 'HTMLElement',
figure: 'HTMLElement',
footer: 'HTMLElement',
h1: 'HTMLElement',
h2: 'HTMLElement',
h3: 'HTMLElement',
h4: 'HTMLElement',
h5: 'HTMLElement',
h6: 'HTMLElement',
head: 'HTMLElement',
header: 'HTMLElement',
hgroup: 'HTMLElement',
hr: 'HTMLElement',
html: 'HTMLElement',
i: 'HTMLElement',
iframe: 'HTMLIFrameElement',
ins: 'HTMLElement',
kbd: 'HTMLElement',
legend: 'HTMLElement',
li: 'HTMLElement',
main: 'HTMLElement',
map: 'HTMLElement',
mark: 'HTMLElement',
math: 'HTMLElement',
menu: 'HTMLElement',
menuitem: 'HTMLElement',
meter: 'HTMLElement',
nav: 'HTMLElement',
noscript: 'HTMLElement',
object: 'HTMLElement',
ol: 'HTMLElement',
optgroup: 'HTMLOptGroupElement',
option: 'HTMLOptionElement',
output: 'HTMLElement',
p: 'HTMLElement',
param: 'HTMLElement',
picture: 'HTMLElement',
pre: 'HTMLElement',
progress: 'HTMLElement',
q: 'HTMLElement',
rb: 'HTMLElement',
rp: 'HTMLElement',
rt: 'HTMLElement',
rtc: 'HTMLElement',
ruby: 'HTMLElement',
s: 'HTMLElement',
samp: 'HTMLElement',
section: 'HTMLElement',
select: 'HTMLSelectElement',
small: 'HTMLElement',
source: 'HTMLElement',
span: 'HTMLElement',
strong: 'HTMLElement',
sub: 'HTMLElement',
summary: 'HTMLElement',
sup: 'HTMLElement',
table: 'HTMLElement',
tbody: 'HTMLElement',
td: 'HTMLElement',
tfoot: 'HTMLElement',
th: 'HTMLElement',
thead: 'HTMLElement',
time: 'HTMLElement',
title: 'HTMLElement',
tr: 'HTMLElement',
track: 'HTMLElement',
u: 'HTMLElement',
ul: 'HTMLElement',
var: 'HTMLElement',
video: 'HTMLVideoElement',
wbr: 'HTMLElement'
};
3 changes: 2 additions & 1 deletion packages/happy-dom/src/config/NamespaceURI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
html: 'http://www.w3.org/1999/xhtml',
svg: 'http://www.w3.org/2000/svg',
mathML: 'http://www.w3.org/1998/Math/MathML'
mathML: 'http://www.w3.org/1998/Math/MathML',
xmlns: 'http://www.w3.org/2000/xmlns/'
};
Loading
Loading