Skip to content

Commit e91dec8

Browse files
Gindendomenic
authored andcommitted
Make StyleSheetList.prototype.item correctly return null when appropriate
Per spec, "If there is no indexth object in the collection, then the method must return null."
1 parent 37532c7 commit e91dec8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/jsdom/level2/style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module.exports = core => {
6262
StyleSheetList.prototype.__proto__ = Array.prototype;
6363

6464
StyleSheetList.prototype.item = function item(i) {
65-
return this[i];
65+
return Object.prototype.hasOwnProperty.call(this, i) ? this[i] : null;
6666
};
6767

6868
core.StyleSheetList = StyleSheetList;

test/level2/style.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,13 @@ exports.tests = {
475475
t.done();
476476
},
477477

478+
"StyleSheetList.prototype.item returns null on index out of bounds": t => {
479+
const document = jsdom.jsdom();
480+
t.strictEqual(document.styleSheets[0], undefined);
481+
t.strictEqual(document.styleSheets.item(0), null);
482+
t.done();
483+
},
484+
478485
"setting background to null works correctly (GH-1499)": t => {
479486
const document = jsdom.jsdom();
480487
document.body.innerHTML = `<div id="ctrl" style="background:#111;border:1px"></div>`;

0 commit comments

Comments
 (0)