Instantiated subclass of Xray-wrapped DOM constructor is not an instance of the subclass, but the superclass.
Categories
(Core :: XPConnect, defect)
Tracking
()
People
(Reporter: robwu, Unassigned)
References
(Blocks 3 open bugs)
Details
Attachments
(2 files)
Given a XrayWrapper of a DOM constructor, when a class subclasses that, and an instance of that subclass is created, the instance is unexpectedly not an instance of the subclass, but of the native DOM constructor.
STR:
- Load the attached extension (relevant script pasted below) at
about:debugging
. - Visit example.com
- Look at the console.
Expected logs:
- "constructor called"
- "instanceof Sub =" true
- "myMethod() called"
Actual logs:
- "constructor called"
- "instanceof Sub =" false
- TypeError: sub.myMethod is not a function
// In an extension content script, CustomEvent is a XrayWrapper of the native constructor.
class Sub extends CustomEvent {
constructor(name) {
super(name);
console.log("constructor called");
}
myMethod() {
console.log("myMethod() called");
}
}
let sub = new Sub("x"); // logs constructor called
console.log(sub instanceof Sub); // false
sub.myMethod(); // TypeError: sub.myMethod is not a function
Reporter | ||
Updated•1 year ago
|
Updated•1 year ago
|
Comment 2•3 months ago
|
||
I think that the issue here is that in step 3.2 in https://webidl.spec.whatwg.org/#internally-create-a-new-object-implementing-the-interface prototype
in this case is a prototype from within the sandbox, so we create the CustomEvent
object and use a CCW as its proto (because we're creating the CustomEvent
outside of the sandbox and then wrap it inside it). But the Xray for WebIDL objects ignores that prototype chain and simply returns CustomEvent.prototype
.
Comment 3•3 months ago
|
||
Reporter | ||
Updated•1 month ago
|
Reporter | ||
Comment 5•1 month ago
|
||
Peter, I see that you've attached a WIP patch but without further activity. What is blocking the patch?
Comment 6•1 month ago
|
||
Figuring out if it's safe. It's moving away from how Xrays traditionally work, so it's a bit scary.
Description
•