Skip to content

Commit edd6296

Browse files
committed
index parameter of CSSStyleSheet.insertRule is now optional
1 parent c92a277 commit edd6296

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

.changeset/tricky-buttons-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rrweb-cssom": patch
3+
---
4+
5+
`index` parameter of `CSSStyleSheet.insertRule` is now optional

lib/CSSStyleSheet.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ CSSOM.CSSStyleSheet.prototype.constructor = CSSOM.CSSStyleSheet;
3737
* @return {number} The index within the style sheet's rule collection of the newly inserted rule.
3838
*/
3939
CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
40+
if (index === void 0) {
41+
index = 0;
42+
}
4043
if (index < 0 || index > this.cssRules.length) {
4144
throw new RangeError("INDEX_SIZE_ERR");
4245
}

spec/CSSStyleSheet.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ describe('CSSStyleSheet', function() {
2424
s.insertRule("a {color: blue}", 0);
2525
expect(s.cssRules[0].parentStyleSheet).toBe(s);
2626
});
27+
28+
it('should insert in index 0 by default', function () {
29+
var s = new CSSOM.CSSStyleSheet;
30+
s.insertRule("a {color: blue}", 0);
31+
32+
var insertedIndex = s.insertRule("b {color: black;}");
33+
expect(insertedIndex).toEqual(0);
34+
expect(s.cssRules[0].cssText).toEqual("b {color: black;}");
35+
})
2736
});
2837
});
2938
});

0 commit comments

Comments
 (0)