Skip to content

Commit b306b1a

Browse files
authored
Merge pull request #1177 from mash-graz/feature-getName
Implements customElements.getName() and fixes letter case handling.
2 parents 6cbcc10 + 2279309 commit b306b1a

28 files changed

+723
-503
lines changed

packages/happy-dom/src/PropertySymbol.ts

+2
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,5 @@ export const content = Symbol('content');
149149
export const mode = Symbol('mode');
150150
export const host = Symbol('host');
151151
export const setURL = Symbol('setURL');
152+
export const localName = Symbol('localName');
153+
export const registedClass = Symbol('registedClass');

packages/happy-dom/src/browser/detached-browser/DetachedBrowserPage.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ export default class DetachedBrowserPage implements IBrowserPage {
8686
.then(() => {
8787
// As we are in a detached page, a context or browser should not exist without a page as there are no references to them.
8888
if (context.pages[0] === this) {
89-
context.close();
89+
context.close().then(resolve).catch(reject);
90+
} else {
91+
resolve();
9092
}
91-
resolve();
9293
})
93-
.catch((error) => reject(error));
94+
.catch(reject);
9495
});
9596
}
9697

packages/happy-dom/src/browser/utilities/BrowserFrameExceptionObserver.ts

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export default class BrowserFrameExceptionObserver {
3434
return;
3535
}
3636

37+
if (!this.browserFrame.window) {
38+
throw new Error(
39+
'Browser frame was not closed correctly. Window is undefined on browser frame, but exception observer is still watching.'
40+
);
41+
}
42+
3743
if (
3844
error instanceof this.browserFrame.window.Error ||
3945
error instanceof this.browserFrame.window.DOMException
@@ -56,6 +62,12 @@ export default class BrowserFrameExceptionObserver {
5662
// The "uncaughtException" event is not always triggered for unhandled rejections.
5763
// Therefore we want to use the "unhandledRejection" event as well.
5864
this.uncaughtRejectionListener = (error: unknown) => {
65+
if (!this.browserFrame.window) {
66+
throw new Error(
67+
'Browser frame was not closed correctly. Window is undefined on browser frame, but exception observer is still watching.'
68+
);
69+
}
70+
5971
if (
6072
error instanceof this.browserFrame.window.Error ||
6173
error instanceof this.browserFrame.window.DOMException

packages/happy-dom/src/browser/utilities/BrowserFrameFactory.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ export default class BrowserFrameFactory {
4141
}
4242
}
4343

44-
// We need to destroy the Window instance before triggering any async tasks as Window.close() is not async.
45-
frame.window[PropertySymbol.destroy]();
46-
(<IBrowserPage | null>frame.page) = null;
47-
(<IBrowserWindow | null>frame.window) = null;
48-
frame[PropertySymbol.openerFrame] = null;
49-
frame[PropertySymbol.openerWindow] = null;
50-
5144
if (!frame.childFrames.length) {
5245
return frame[PropertySymbol.asyncTaskManager]
5346
.destroy()
5447
.then(() => {
5548
frame[PropertySymbol.exceptionObserver]?.disconnect();
49+
if (frame.window) {
50+
frame.window[PropertySymbol.destroy]();
51+
(<IBrowserPage | null>frame.page) = null;
52+
(<IBrowserWindow | null>frame.window) = null;
53+
frame[PropertySymbol.openerFrame] = null;
54+
frame[PropertySymbol.openerWindow] = null;
55+
}
5656
resolve();
5757
})
5858
.catch((error) => reject(error));
@@ -62,6 +62,13 @@ export default class BrowserFrameFactory {
6262
.then(() => {
6363
return frame[PropertySymbol.asyncTaskManager].destroy().then(() => {
6464
frame[PropertySymbol.exceptionObserver]?.disconnect();
65+
if (frame.window) {
66+
frame.window[PropertySymbol.destroy]();
67+
(<IBrowserPage | null>frame.page) = null;
68+
(<IBrowserWindow | null>frame.window) = null;
69+
frame[PropertySymbol.openerFrame] = null;
70+
frame[PropertySymbol.openerWindow] = null;
71+
}
6572
resolve();
6673
});
6774
})

packages/happy-dom/src/config/ElementTag.ts

-130
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
export default <{ [key: string]: string }>{
2+
a: 'HTMLAnchorElement',
3+
abbr: 'HTMLElement',
4+
address: 'HTMLElement',
5+
area: 'HTMLElement',
6+
article: 'HTMLElement',
7+
aside: 'HTMLElement',
8+
audio: 'HTMLAudioElement',
9+
b: 'HTMLElement',
10+
base: 'HTMLBaseElement',
11+
bdi: 'HTMLElement',
12+
bdo: 'HTMLElement',
13+
blockquaote: 'HTMLElement',
14+
body: 'HTMLElement',
15+
template: 'HTMLTemplateElement',
16+
form: 'HTMLFormElement',
17+
input: 'HTMLInputElement',
18+
textarea: 'HTMLTextAreaElement',
19+
script: 'HTMLScriptElement',
20+
img: 'HTMLImageElement',
21+
link: 'HTMLLinkElement',
22+
style: 'HTMLStyleElement',
23+
label: 'HTMLLabelElement',
24+
slot: 'HTMLSlotElement',
25+
meta: 'HTMLMetaElement',
26+
blockquote: 'HTMLElement',
27+
br: 'HTMLElement',
28+
button: 'HTMLButtonElement',
29+
canvas: 'HTMLElement',
30+
caption: 'HTMLElement',
31+
cite: 'HTMLElement',
32+
code: 'HTMLElement',
33+
col: 'HTMLElement',
34+
colgroup: 'HTMLElement',
35+
data: 'HTMLElement',
36+
datalist: 'HTMLElement',
37+
dd: 'HTMLElement',
38+
del: 'HTMLElement',
39+
details: 'HTMLElement',
40+
dfn: 'HTMLElement',
41+
dialog: 'HTMLDialogElement',
42+
div: 'HTMLElement',
43+
dl: 'HTMLElement',
44+
dt: 'HTMLElement',
45+
em: 'HTMLElement',
46+
embed: 'HTMLElement',
47+
fieldset: 'HTMLElement',
48+
figcaption: 'HTMLElement',
49+
figure: 'HTMLElement',
50+
footer: 'HTMLElement',
51+
h1: 'HTMLElement',
52+
h2: 'HTMLElement',
53+
h3: 'HTMLElement',
54+
h4: 'HTMLElement',
55+
h5: 'HTMLElement',
56+
h6: 'HTMLElement',
57+
head: 'HTMLElement',
58+
header: 'HTMLElement',
59+
hgroup: 'HTMLElement',
60+
hr: 'HTMLElement',
61+
html: 'HTMLElement',
62+
i: 'HTMLElement',
63+
iframe: 'HTMLIFrameElement',
64+
ins: 'HTMLElement',
65+
kbd: 'HTMLElement',
66+
legend: 'HTMLElement',
67+
li: 'HTMLElement',
68+
main: 'HTMLElement',
69+
map: 'HTMLElement',
70+
mark: 'HTMLElement',
71+
math: 'HTMLElement',
72+
menu: 'HTMLElement',
73+
menuitem: 'HTMLElement',
74+
meter: 'HTMLElement',
75+
nav: 'HTMLElement',
76+
noscript: 'HTMLElement',
77+
object: 'HTMLElement',
78+
ol: 'HTMLElement',
79+
optgroup: 'HTMLOptGroupElement',
80+
option: 'HTMLOptionElement',
81+
output: 'HTMLElement',
82+
p: 'HTMLElement',
83+
param: 'HTMLElement',
84+
picture: 'HTMLElement',
85+
pre: 'HTMLElement',
86+
progress: 'HTMLElement',
87+
q: 'HTMLElement',
88+
rb: 'HTMLElement',
89+
rp: 'HTMLElement',
90+
rt: 'HTMLElement',
91+
rtc: 'HTMLElement',
92+
ruby: 'HTMLElement',
93+
s: 'HTMLElement',
94+
samp: 'HTMLElement',
95+
section: 'HTMLElement',
96+
select: 'HTMLSelectElement',
97+
small: 'HTMLElement',
98+
source: 'HTMLElement',
99+
span: 'HTMLElement',
100+
strong: 'HTMLElement',
101+
sub: 'HTMLElement',
102+
summary: 'HTMLElement',
103+
sup: 'HTMLElement',
104+
table: 'HTMLElement',
105+
tbody: 'HTMLElement',
106+
td: 'HTMLElement',
107+
tfoot: 'HTMLElement',
108+
th: 'HTMLElement',
109+
thead: 'HTMLElement',
110+
time: 'HTMLElement',
111+
title: 'HTMLElement',
112+
tr: 'HTMLElement',
113+
track: 'HTMLElement',
114+
u: 'HTMLElement',
115+
ul: 'HTMLElement',
116+
var: 'HTMLElement',
117+
video: 'HTMLVideoElement',
118+
wbr: 'HTMLElement'
119+
};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export default {
22
html: 'http://www.w3.org/1999/xhtml',
33
svg: 'http://www.w3.org/2000/svg',
4-
mathML: 'http://www.w3.org/1998/Math/MathML'
4+
mathML: 'http://www.w3.org/1998/Math/MathML',
5+
xmlns: 'http://www.w3.org/2000/xmlns/'
56
};

0 commit comments

Comments
 (0)