diff --git a/lib/cache/cache.js b/lib/cache/cache.js index d10b39b334b..432b9a8ba44 100644 --- a/lib/cache/cache.js +++ b/lib/cache/cache.js @@ -6,9 +6,9 @@ const { kEnumerableProperty, isDisturbed } = require('../core/util') const { kHeadersList } = require('../core/symbols') const { webidl } = require('../fetch/webidl') const { Response, cloneResponse } = require('../fetch/response') -const { Request } = require('../fetch/request') +const { Request, fromInnerRequest } = require('../fetch/request') const { Headers } = require('../fetch/headers') -const { kState, kHeaders, kGuard, kRealm, kSignal } = require('../fetch/symbols') +const { kState, kHeaders, kGuard, kRealm } = require('../fetch/symbols') const { fetching } = require('../fetch/index') const { urlIsHttpHttpsScheme, createDeferredPromise, readAllBytes } = require('../fetch/util') const assert = require('assert') @@ -444,7 +444,7 @@ class Cache { * @see https://w3c.github.io/ServiceWorker/#dom-cache-keys * @param {any} request * @param {import('../../types/cache').CacheQueryOptions} options - * @returns {readonly Request[]} + * @returns {Promise} */ async keys (request = undefined, options = {}) { webidl.brandCheck(this, Cache) @@ -503,15 +503,12 @@ class Cache { // 5.4.2 for (const request of requests) { - const requestObject = new Request(kConstruct) - requestObject[kState] = request - requestObject[kHeaders] = new Headers(kConstruct) - requestObject[kHeaders][kHeadersList] = request.headersList - requestObject[kHeaders][kGuard] = 'immutable' - requestObject[kRealm] = request.client - requestObject[kSignal] = new AbortController().signal - requestObject[kSignal][kRealm] = requestObject[kRealm] - + const requestObject = fromInnerRequest( + request, + new AbortController().signal, + 'immutable' + ) + requestObject[kRealm] = { settingsObject: request.client } // 5.4.2.1 requestList.push(requestObject) } diff --git a/lib/cache/cachestorage.js b/lib/cache/cachestorage.js index 7e7f0cff2b5..4f3351a6a9b 100644 --- a/lib/cache/cachestorage.js +++ b/lib/cache/cachestorage.js @@ -114,7 +114,7 @@ class CacheStorage { /** * @see https://w3c.github.io/ServiceWorker/#cache-storage-keys - * @returns {string[]} + * @returns {Promise} */ async keys () { webidl.brandCheck(this, CacheStorage) diff --git a/lib/fetch/request.js b/lib/fetch/request.js index f5522486c1d..a9b7c98fdb7 100644 --- a/lib/fetch/request.js +++ b/lib/fetch/request.js @@ -844,6 +844,22 @@ function cloneRequest (request) { return newRequest } +/** + * @param {any} innerRequest + * @param {AbortSignal} signal + * @param {'request' | 'immutable' | 'request-no-cors' | 'response' | 'none'} guard + * @returns {Request} + */ +function fromInnerRequest (innerRequest, signal, guard) { + const request = new Request(kConstruct) + request[kState] = innerRequest + request[kHeaders] = new Headers(kConstruct) + request[kHeaders][kHeadersList] = innerRequest.headersList + request[kHeaders][kGuard] = guard + request[kSignal] = signal + return request +} + Object.defineProperties(Request.prototype, { method: kEnumerableProperty, url: kEnumerableProperty, @@ -970,4 +986,4 @@ webidl.converters.RequestInit = webidl.dictionaryConverter([ } ]) -module.exports = { Request, makeRequest } +module.exports = { Request, makeRequest, fromInnerRequest }