File tree Expand file tree Collapse file tree 2 files changed +30
-7
lines changed
Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -213,17 +213,13 @@ fn headers_symbol_iterator(
213213 || js_error ! ( TypeError : "`Headers.prototype[Symbol.iterator]` requires a `Headers` object" ) ,
214214 ) ?;
215215
216- if ! this_object. is :: < JsHeaders > ( ) {
216+ let Ok ( headers ) = this_object. clone ( ) . downcast :: < JsHeaders > ( ) else {
217217 return Err (
218218 js_error ! ( TypeError : "`Headers.prototype[Symbol.iterator]` requires a `Headers` object" ) ,
219219 ) ;
220- }
220+ } ;
221221
222- HeadersIterator :: create_headers_iterator (
223- this_object. clone ( ) . downcast ( ) . expect ( "checked above" ) ,
224- IterationKind :: KeyAndValue ,
225- context,
226- )
222+ HeadersIterator :: create_headers_iterator ( headers, IterationKind :: KeyAndValue , context)
227223}
228224
229225/// Register the `fetch` function in the realm, as well as ALL supporting classes.
Original file line number Diff line number Diff line change @@ -119,3 +119,30 @@ fn headers_invalid_inputs_throw_type_error_objects() {
119119 ) ,
120120 ] ) ;
121121}
122+
123+ #[ test]
124+ fn headers_iterator_throws_on_invalid_this ( ) {
125+ run_test_actions ( [
126+ TestAction :: harness ( ) ,
127+ TestAction :: inspect_context ( register) ,
128+ TestAction :: run (
129+ r#"
130+ try {
131+ const iterator = Headers.prototype[Symbol.iterator].call({});
132+ throw Error("expected the call above to throw");
133+ } catch (e) {
134+ assert(e instanceof TypeError);
135+ assertEq(e.message, "`Headers.prototype[Symbol.iterator]` requires a `Headers` object");
136+ }
137+
138+ try {
139+ const iterator = Headers.prototype[Symbol.iterator].call(1);
140+ throw Error("expected the call above to throw");
141+ } catch (e) {
142+ assert(e instanceof TypeError);
143+ assertEq(e.message, "`Headers.prototype[Symbol.iterator]` requires a `Headers` object");
144+ }
145+ "# ,
146+ ) ,
147+ ] ) ;
148+ }
You can’t perform that action at this time.
0 commit comments