Skip to content

Commit b249f36

Browse files
fix(polyfill): change attachInternals to not be a getter
1 parent 92f705f commit b249f36

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Diff for: src/element-internals.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,15 @@ if (!isElementInternalsSupported()) {
312312
* Attaches an ElementInternals instance to a custom element. Calling this method
313313
* on a built-in element will throw an error.
314314
*/
315-
Object.defineProperty(HTMLElement.prototype, 'attachInternals', {
316-
get() {
317-
return (): IElementInternals => {
318-
if (this.tagName.indexOf('-') === -1) {
319-
throw new Error(`Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.`);
320-
}
321-
return new ElementInternals(this) as IElementInternals;
322-
};
315+
HTMLElement.prototype.attachInternals = function(): IElementInternals {
316+
if (this.tagName.indexOf('-') === -1) {
317+
throw new Error(`Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.`);
318+
}
319+
if (internalsMap.has(this)) {
320+
throw new DOMException(`DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.`);
323321
}
324-
});
322+
return new ElementInternals(this) as IElementInternals;
323+
}
325324

326325
const attachShadow = Element.prototype.attachShadow;
327326
Element.prototype.attachShadow = attachShadowObserver;

0 commit comments

Comments
 (0)