Closed Bug 2036318 Opened 17 days ago Closed 12 days ago

ObservableArray has null prototype but still behaves like an Array

Categories

(Core :: DOM: Bindings (WebIDL), defect)

defect

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox152 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

Details

Attachments

(1 file)

An ObservableArray has a null prototype in Firefox (Array.prototype in Chrome and Safari):

console.log(document.adoptedStyleSheets.__proto__); // null
console.log(Object.getPrototypeOf(document.adoptedStyleSheets)); // null

Yet is still inherits from Array.prototype:

Array.prototype.customPush = function (s) { return this.push(s); };

sheet = new CSSStyleSheet();
sheet.replaceSync("*{background:pink}");
document.adoptedStyleSheets.customPush(sheet); // page turns pink

Even after replacing its prototype, methods are still exposed from Array.prototype instead of whatever the prototype was set to (but somehow DevTools' autocompletion suggests method from the specified prototype):

Array.prototype.customPush2 = function (s) { return this.push(s); };
Object.setPrototypeOf(document.adoptedStyleSheets, { test: 1 });
console.log(document.adoptedStyleSheets.__proto__); // { test: 1 }
console.log(document.adoptedStyleSheets.test); // undefined (1 in Chrome+Safari)
console.log(document.adoptedStyleSheets.customPush2); // function (undefined in Chrome+Safari)

sheet = new CSSStyleSheet();
sheet.replaceSync("*{background:red}");
document.adoptedStyleSheets.customPush2(sheet); // page turns red (error in Chrome+Safari)

I found this while looking at bug 1751346; this is a follow-up to https://phabricator.services.mozilla.com/D291049#10323557

Assignee: nobody → rob
Status: NEW → ASSIGNED
Severity: -- → S3
Status: ASSIGNED → RESOLVED
Closed: 12 days ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: