Skip to content

Commit

Permalink
Cache storage fixes (#2083)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Apr 22, 2023
1 parent 674e2b6 commit eeaa073
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 26 deletions.
6 changes: 3 additions & 3 deletions lib/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Cache {
* @see https://w3c.github.io/ServiceWorker/#dfn-relevant-request-response-list
* @type {requestResponseList}
*/
#relevantRequestResponseList = []
#relevantRequestResponseList

constructor () {
if (arguments[0] !== kConstruct) {
Expand Down Expand Up @@ -314,7 +314,7 @@ class Cache {
let innerRequest = null

// 2.
if (typeof request !== 'string') {
if (request instanceof Request) {
innerRequest = request[kState]
} else { // 3.
innerRequest = new Request(request)[kState]
Expand Down Expand Up @@ -457,7 +457,7 @@ class Cache {
} else {
assert(typeof request === 'string')

r = new Request(r)[kState]
r = new Request(request)[kState]
}

/** @type {CacheBatchOperation[]} */
Expand Down
15 changes: 1 addition & 14 deletions lib/cache/cachestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,7 @@ class CacheStorage {

cacheName = webidl.converters.DOMString(cacheName)

// 1.
// 2.
const cacheExists = this.#caches.has(cacheName)

// 2.1
if (!cacheExists) {
return false
}

// 2.3.1
this.#caches.delete(cacheName)

// 2.3.2
return true
return this.#caches.delete(cacheName)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/wpt/runner/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ runInThisContext(`
}
}
globalThis.window = globalThis
globalThis.location = new URL('${url}')
globalThis.location = new URL('${urlPath.replace(/\\/g, '/')}', '${url}')
globalThis.Window = Object.getPrototypeOf(globalThis).constructor
`)

Expand Down Expand Up @@ -142,7 +142,7 @@ add_completion_callback((_, status) => {
})
})

setGlobalOrigin(new URL(urlPath, url))
setGlobalOrigin(globalThis.location)

// Inject any script the user provided before
// running the tests.
Expand Down
7 changes: 2 additions & 5 deletions test/wpt/server/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const server = createServer(async (req, res) => {
res.setHeader('content-type', 'text/html')
// fall through
}
case '/service-workers/cache-storage/resources/simple.txt':
case '/fetch/content-encoding/resources/foo.octetstream.gz':
case '/fetch/content-encoding/resources/foo.text.gz':
case '/fetch/api/resources/cors-top.txt':
Expand Down Expand Up @@ -361,11 +362,7 @@ const server = createServer(async (req, res) => {
res.end('')
return
}
case '/resources/simple.txt': {
res.end(readFileSync(join(tests, 'service-workers/service-worker', fullUrl.pathname), 'utf-8'))
return
}
case '/resources/fetch-status.py': {
case '/service-workers/cache-storage/resources/fetch-status.py': {
const status = Number(fullUrl.searchParams.get('status'))

res.statusCode = status
Expand Down
3 changes: 2 additions & 1 deletion test/wpt/status/fetch.status.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"fail": [
"origin-when-cross-origin policy on a cross-origin URL",
"origin-when-cross-origin policy on a cross-origin URL after same-origin redirection",
"origin-when-cross-origin policy on a same-origin URL after cross-origin redirection"
"origin-when-cross-origin policy on a same-origin URL after cross-origin redirection",
"origin-when-cross-origin policy on a same-origin URL"
]
},
"request-forbidden-headers.any.js": {
Expand Down
1 change: 0 additions & 1 deletion test/wpt/status/service-workers/cache-storage.status.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"cache-delete.https.any.js": {
"note": "spec bug? - https://github.com/w3c/ServiceWorker/issues/1677 (first fail)",
"fail": [
"Cache.delete called with a string URL",
"Cache.delete with ignoreSearch option (when it is specified as false)"
]
},
Expand Down

0 comments on commit eeaa073

Please sign in to comment.