@@ -57,26 +57,27 @@ export default class CSSStyleSheet {
57
57
* @returns The newly inserterted rule's index.
58
58
*/
59
59
public insertRule ( rule : string , index ?: number ) : number {
60
- const rules = CSSParser . parseFromString ( this , rule ) ;
61
-
62
- if ( rules . length === 0 ) {
63
- throw new this [ PropertySymbol . window ] . DOMException (
64
- 'Invalid CSS rule.' ,
65
- DOMExceptionNameEnum . hierarchyRequestError
60
+ if ( arguments . length === 0 ) {
61
+ throw new this [ PropertySymbol . window ] . TypeError (
62
+ `Failed to execute 'insertRule' on 'CSSStyleSheet': 1 argument required, but only 0 present.`
66
63
) ;
67
64
}
68
65
69
- if ( rules . length > 1 ) {
66
+ const rules = CSSParser . parseFromString ( this , rule ) ;
67
+
68
+ if ( rules . length === 0 || rules . length > 1 ) {
70
69
throw new this [ PropertySymbol . window ] . DOMException (
71
- 'Only one rule is allowed to be added.' ,
70
+ `Failed to execute 'insertRule' on 'CSSStyleSheet': Failed to parse the rule ' ${ rule } '.` ,
72
71
DOMExceptionNameEnum . syntaxError
73
72
) ;
74
73
}
75
74
76
75
if ( index !== undefined ) {
77
76
if ( index > this . cssRules . length ) {
78
77
throw new this [ PropertySymbol . window ] . DOMException (
79
- 'Index is more than the length of CSSRuleList.' ,
78
+ `Failed to execute 'insertRule' on 'CSSStyleSheet': The index provided (${ index } ) is larger than the maximum index (${
79
+ this . cssRules . length - 1
80
+ } ).`,
80
81
DOMExceptionNameEnum . indexSizeError
81
82
) ;
82
83
}
@@ -98,7 +99,12 @@ export default class CSSStyleSheet {
98
99
* @param index Index.
99
100
*/
100
101
public deleteRule ( index : number ) : void {
101
- delete this . cssRules [ index ] ;
102
+ if ( arguments . length === 0 ) {
103
+ throw new this [ PropertySymbol . window ] . TypeError (
104
+ `Failed to execute 'deleteRule' on 'CSSStyleSheet': 1 argument required, but only 0 present.`
105
+ ) ;
106
+ }
107
+ this . cssRules . splice ( index , 1 ) ;
102
108
}
103
109
104
110
/**
@@ -109,6 +115,11 @@ export default class CSSStyleSheet {
109
115
* @returns Promise.
110
116
*/
111
117
public async replace ( text : string ) : Promise < void > {
118
+ if ( arguments . length === 0 ) {
119
+ throw new this [ PropertySymbol . window ] . TypeError (
120
+ `Failed to execute 'replace' on 'CSSStyleSheet': 1 argument required, but only 0 present.`
121
+ ) ;
122
+ }
112
123
this . replaceSync ( text ) ;
113
124
}
114
125
@@ -119,6 +130,11 @@ export default class CSSStyleSheet {
119
130
* @param text CSS text.
120
131
*/
121
132
public replaceSync ( text : string ) : void {
133
+ if ( arguments . length === 0 ) {
134
+ throw new this [ PropertySymbol . window ] . TypeError (
135
+ `Failed to execute 'replaceSync' on 'CSSStyleSheet': 1 argument required, but only 0 present.`
136
+ ) ;
137
+ }
122
138
if ( this . #currentText !== text ) {
123
139
this . #currentText = text ;
124
140
( < CSSRule [ ] > this . cssRules ) = CSSParser . parseFromString ( this , text ) ;
0 commit comments