Closed Bug 1821790 Opened 2 years ago Closed 2 years ago

document.adoptNode (and others causing it) changes the prototype of the adopted node

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1470017

People

(Reporter: ksenia, Unassigned)

References

Details

Attachments

(2 files)

Attached file 118350.html

We've received a report in https://github.com/webcompat/web-bugs/issues/118350 about the discrepancy between Firefox and Chrome when calling instanceof HTMLElement for an element within an iframe.

The reporter provided a testcase and mentioned that this is causing issues for them in production since Firefox 109.

It returns false in Firefox when instanceof HTMLElement is called. And returns true when the iframe window (instanceof iframe.contentWindow.HTMLElement) checked instead. The results in Chrome are exact opposite.

mozregression points to https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=5199ec2d73fa7daf423b72416be41383ac1042dc&tochange=95b6c826ad974a967364cb1f137bd8a766051d0a, so I assume this is related to bug1360715

Setting dom.webidl.crosscontext_hasinstance.enabled to true makes their testcase pass and Firefox starts matching Chrome, but only for instanceof HTMLElement, which returns true. instanceof iframe.contentWindow.HTMLElement is always false in Chrome. Wonder which behaviour is correct here?

Hi Kagami, could you please take a look at this?

Flags: needinfo?(krosylight)

Set release status flags based on info from the regressing bug 1360715

Severity: -- → S2

This is not a regression from bug 1360715, this is more of the node adoption behavior rather than of the instanceof behavior.

el2 instanceof HTMLElement is true on Gecko too before el.appendChild(e2), but the adoption somehow magically changes el2's prototype, which is very surprising.

Flags: needinfo?(krosylight)
No longer regressed by: 1360715
Attached file bug1821790.html

Replaced instanceof with Object.getPrototypeOf(), and turns out Gecko has been doing this forever (as version 25 was doing the same thing).

Summary: Difference in instanceof behaviour cross-contexts in Firefox and Chrome for HTMLElement → document.adoptNode (and others causing it) changes the prototype of the adopted node
Component: DOM: Bindings (WebIDL) → DOM: Core & HTML

Seems it's known:

Status: NEW → RESOLVED
Closed: 2 years ago
Duplicate of bug: 1470017
Resolution: --- → DUPLICATE

I moved the webcompat report to the bug, hope it works better!

Keywords: regression

That's good to know, thanks for investigating!

It sounds like this is old behavior and not actually a regression.

Severity: S2 → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: