@@ -10,6 +10,7 @@ const { kState } = require('../fetch/symbols')
10
10
const { fetching } = require ( '../fetch/index' )
11
11
const { urlIsHttpHttpsScheme, createDeferredPromise, readAllBytes } = require ( '../fetch/util' )
12
12
const assert = require ( 'node:assert' )
13
+ const { getGlobalDispatcher } = require ( '../../global' )
13
14
14
15
/**
15
16
* @see https://w3c.github.io/ServiceWorker/#dfn-cache-batch-operation
@@ -42,12 +43,10 @@ class Cache {
42
43
43
44
async match ( request , options = { } ) {
44
45
webidl . brandCheck ( this , Cache )
46
+ webidl . argumentLengthCheck ( arguments , 1 , { header : 'Cache.match' } )
45
47
46
- const prefix = 'Cache.match'
47
- webidl . argumentLengthCheck ( arguments , 1 , prefix )
48
-
49
- request = webidl . converters . RequestInfo ( request , prefix , 'request' )
50
- options = webidl . converters . CacheQueryOptions ( options , prefix , 'options' )
48
+ request = webidl . converters . RequestInfo ( request )
49
+ options = webidl . converters . CacheQueryOptions ( options )
51
50
52
51
const p = this . #internalMatchAll( request , options , 1 )
53
52
@@ -61,20 +60,17 @@ class Cache {
61
60
async matchAll ( request = undefined , options = { } ) {
62
61
webidl . brandCheck ( this , Cache )
63
62
64
- const prefix = 'Cache.matchAll'
65
- if ( request !== undefined ) request = webidl . converters . RequestInfo ( request , prefix , 'request' )
66
- options = webidl . converters . CacheQueryOptions ( options , prefix , 'options' )
63
+ if ( request !== undefined ) request = webidl . converters . RequestInfo ( request )
64
+ options = webidl . converters . CacheQueryOptions ( options )
67
65
68
66
return this . #internalMatchAll( request , options )
69
67
}
70
68
71
69
async add ( request ) {
72
70
webidl . brandCheck ( this , Cache )
71
+ webidl . argumentLengthCheck ( arguments , 1 , { header : 'Cache.add' } )
73
72
74
- const prefix = 'Cache.add'
75
- webidl . argumentLengthCheck ( arguments , 1 , prefix )
76
-
77
- request = webidl . converters . RequestInfo ( request , prefix , 'request' )
73
+ request = webidl . converters . RequestInfo ( request )
78
74
79
75
// 1.
80
76
const requests = [ request ]
@@ -88,9 +84,7 @@ class Cache {
88
84
89
85
async addAll ( requests ) {
90
86
webidl . brandCheck ( this , Cache )
91
-
92
- const prefix = 'Cache.addAll'
93
- webidl . argumentLengthCheck ( arguments , 1 , prefix )
87
+ webidl . argumentLengthCheck ( arguments , 1 , { header : 'Cache.addAll' } )
94
88
95
89
// 1.
96
90
const responsePromises = [ ]
@@ -102,7 +96,7 @@ class Cache {
102
96
for ( let request of requests ) {
103
97
if ( request === undefined ) {
104
98
throw webidl . errors . conversionFailed ( {
105
- prefix,
99
+ prefix : 'Cache.addAll' ,
106
100
argument : 'Argument 1' ,
107
101
types : [ 'undefined is not allowed' ]
108
102
} )
@@ -120,7 +114,7 @@ class Cache {
120
114
// 3.2
121
115
if ( ! urlIsHttpHttpsScheme ( r . url ) || r . method !== 'GET' ) {
122
116
throw webidl . errors . exception ( {
123
- header : prefix ,
117
+ header : 'Cache.addAll' ,
124
118
message : 'Expected http/s scheme when method is not GET.'
125
119
} )
126
120
}
@@ -138,7 +132,7 @@ class Cache {
138
132
// 5.2
139
133
if ( ! urlIsHttpHttpsScheme ( r . url ) ) {
140
134
throw webidl . errors . exception ( {
141
- header : prefix ,
135
+ header : 'Cache.addAll' ,
142
136
message : 'Expected http/s scheme.'
143
137
} )
144
138
}
@@ -156,6 +150,7 @@ class Cache {
156
150
// 5.7
157
151
fetchControllers . push ( fetching ( {
158
152
request : r ,
153
+ dispatcher : getGlobalDispatcher ( ) ,
159
154
processResponse ( response ) {
160
155
// 1.
161
156
if ( response . type === 'error' || response . status === 206 || response . status < 200 || response . status > 299 ) {
@@ -258,12 +253,10 @@ class Cache {
258
253
259
254
async put ( request , response ) {
260
255
webidl . brandCheck ( this , Cache )
256
+ webidl . argumentLengthCheck ( arguments , 2 , { header : 'Cache.put' } )
261
257
262
- const prefix = 'Cache.put'
263
- webidl . argumentLengthCheck ( arguments , 2 , prefix )
264
-
265
- request = webidl . converters . RequestInfo ( request , prefix , 'request' )
266
- response = webidl . converters . Response ( response , prefix , 'response' )
258
+ request = webidl . converters . RequestInfo ( request )
259
+ response = webidl . converters . Response ( response )
267
260
268
261
// 1.
269
262
let innerRequest = null
@@ -278,7 +271,7 @@ class Cache {
278
271
// 4.
279
272
if ( ! urlIsHttpHttpsScheme ( innerRequest . url ) || innerRequest . method !== 'GET' ) {
280
273
throw webidl . errors . exception ( {
281
- header : prefix ,
274
+ header : 'Cache.put' ,
282
275
message : 'Expected an http/s scheme when method is not GET'
283
276
} )
284
277
}
@@ -289,7 +282,7 @@ class Cache {
289
282
// 6.
290
283
if ( innerResponse . status === 206 ) {
291
284
throw webidl . errors . exception ( {
292
- header : prefix ,
285
+ header : 'Cache.put' ,
293
286
message : 'Got 206 status'
294
287
} )
295
288
}
@@ -304,7 +297,7 @@ class Cache {
304
297
// 7.2.1
305
298
if ( fieldValue === '*' ) {
306
299
throw webidl . errors . exception ( {
307
- header : prefix ,
300
+ header : 'Cache.put' ,
308
301
message : 'Got * vary field value'
309
302
} )
310
303
}
@@ -314,7 +307,7 @@ class Cache {
314
307
// 8.
315
308
if ( innerResponse . body && ( isDisturbed ( innerResponse . body . stream ) || innerResponse . body . stream . locked ) ) {
316
309
throw webidl . errors . exception ( {
317
- header : prefix ,
310
+ header : 'Cache.put' ,
318
311
message : 'Response body is locked or disturbed'
319
312
} )
320
313
}
@@ -389,12 +382,10 @@ class Cache {
389
382
390
383
async delete ( request , options = { } ) {
391
384
webidl . brandCheck ( this , Cache )
385
+ webidl . argumentLengthCheck ( arguments , 1 , { header : 'Cache.delete' } )
392
386
393
- const prefix = 'Cache.delete'
394
- webidl . argumentLengthCheck ( arguments , 1 , prefix )
395
-
396
- request = webidl . converters . RequestInfo ( request , prefix , 'request' )
397
- options = webidl . converters . CacheQueryOptions ( options , prefix , 'options' )
387
+ request = webidl . converters . RequestInfo ( request )
388
+ options = webidl . converters . CacheQueryOptions ( options )
398
389
399
390
/**
400
391
* @type {Request }
@@ -456,10 +447,8 @@ class Cache {
456
447
async keys ( request = undefined , options = { } ) {
457
448
webidl . brandCheck ( this , Cache )
458
449
459
- const prefix = 'Cache.keys'
460
-
461
- if ( request !== undefined ) request = webidl . converters . RequestInfo ( request , prefix , 'request' )
462
- options = webidl . converters . CacheQueryOptions ( options , prefix , 'options' )
450
+ if ( request !== undefined ) request = webidl . converters . RequestInfo ( request )
451
+ options = webidl . converters . CacheQueryOptions ( options )
463
452
464
453
// 1.
465
454
let r = null
@@ -515,7 +504,8 @@ class Cache {
515
504
const requestObject = fromInnerRequest (
516
505
request ,
517
506
new AbortController ( ) . signal ,
518
- 'immutable'
507
+ 'immutable' ,
508
+ { settingsObject : request . client }
519
509
)
520
510
// 5.4.2.1
521
511
requestList . push ( requestObject )
@@ -791,7 +781,7 @@ class Cache {
791
781
// 5.5.2
792
782
for ( const response of responses ) {
793
783
// 5.5.2.1
794
- const responseObject = fromInnerResponse ( response , 'immutable' )
784
+ const responseObject = fromInnerResponse ( response , 'immutable' , { settingsObject : { } } )
795
785
796
786
responseList . push ( responseObject . clone ( ) )
797
787
@@ -823,17 +813,17 @@ const cacheQueryOptionConverters = [
823
813
{
824
814
key : 'ignoreSearch' ,
825
815
converter : webidl . converters . boolean ,
826
- defaultValue : ( ) => false
816
+ defaultValue : false
827
817
} ,
828
818
{
829
819
key : 'ignoreMethod' ,
830
820
converter : webidl . converters . boolean ,
831
- defaultValue : ( ) => false
821
+ defaultValue : false
832
822
} ,
833
823
{
834
824
key : 'ignoreVary' ,
835
825
converter : webidl . converters . boolean ,
836
- defaultValue : ( ) => false
826
+ defaultValue : false
837
827
}
838
828
]
839
829
0 commit comments