From 8faf4a995400448e088de754fe1f8440d318799e Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 27 Apr 2018 13:24:00 +0200 Subject: [PATCH 1/2] Fetch: align IDL testing with other standards See https://github.com/whatwg/fetch/pull/719. --- fetch/api/headers/headers-idl.html | 36 ----------- fetch/api/idl.any.js | 18 ++++++ fetch/api/request/request-idl.html | 89 ------------------------- fetch/api/response/response-idl.html | 68 ------------------- interfaces/fetch.idl | 97 ++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 193 deletions(-) delete mode 100644 fetch/api/headers/headers-idl.html create mode 100644 fetch/api/idl.any.js delete mode 100644 fetch/api/request/request-idl.html delete mode 100644 fetch/api/response/response-idl.html create mode 100644 interfaces/fetch.idl diff --git a/fetch/api/headers/headers-idl.html b/fetch/api/headers/headers-idl.html deleted file mode 100644 index 078c9d014951eb..00000000000000 --- a/fetch/api/headers/headers-idl.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - Headers idl interface - - - - - - - - - - - - diff --git a/fetch/api/idl.any.js b/fetch/api/idl.any.js new file mode 100644 index 00000000000000..0067a8b9b4ff93 --- /dev/null +++ b/fetch/api/idl.any.js @@ -0,0 +1,18 @@ +// META: global=window,worker +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js + +promise_test(async() => { + const text = await (await fetch("/interfaces/fetch.idl")).text(); + const idl_array = new IdlArray(); + idl_array.add_idls(text); + idl_array.add_untested_idls("interface AbortSignal {};"); + idl_array.add_untested_idls("interface ReadableStream {};"); + idl_array.add_untested_idls("enum ReferrerPolicy {};"); + idl_array.add_objects({ + Headers: ["new Headers()"], + Request: ["new Request('about:blank')"], + Response: ["new Response()"], + }); + idl_array.test(); +}, "Fetch Standard IDL"); diff --git a/fetch/api/request/request-idl.html b/fetch/api/request/request-idl.html deleted file mode 100644 index 2f1279ab0fe30e..00000000000000 --- a/fetch/api/request/request-idl.html +++ /dev/null @@ -1,89 +0,0 @@ - - - - - Request idl interface - - - - - - - - - - - - - diff --git a/fetch/api/response/response-idl.html b/fetch/api/response/response-idl.html deleted file mode 100644 index bd265fa203dccf..00000000000000 --- a/fetch/api/response/response-idl.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - - Response idl interface - - - - - - - - - - - - - diff --git a/interfaces/fetch.idl b/interfaces/fetch.idl new file mode 100644 index 00000000000000..346d1b08819198 --- /dev/null +++ b/interfaces/fetch.idl @@ -0,0 +1,97 @@ +typedef (sequence> or record) HeadersInit; + +[Constructor(optional HeadersInit init), + Exposed=(Window,Worker)] +interface Headers { + void append(ByteString name, ByteString value); + void delete(ByteString name); + ByteString? get(ByteString name); + boolean has(ByteString name); + void set(ByteString name, ByteString value); + iterable; +}; +typedef (Blob or BufferSource or FormData or URLSearchParams or ReadableStream or USVString) BodyInit; +interface mixin Body { + readonly attribute ReadableStream? body; + readonly attribute boolean bodyUsed; + [NewObject] Promise arrayBuffer(); + [NewObject] Promise blob(); + [NewObject] Promise formData(); + [NewObject] Promise json(); + [NewObject] Promise text(); +}; +typedef (Request or USVString) RequestInfo; + +[Constructor(RequestInfo input, optional RequestInit init), + Exposed=(Window,Worker)] +interface Request { + readonly attribute ByteString method; + readonly attribute USVString url; + [SameObject] readonly attribute Headers headers; + + readonly attribute RequestDestination destination; + readonly attribute USVString referrer; + readonly attribute ReferrerPolicy referrerPolicy; + readonly attribute RequestMode mode; + readonly attribute RequestCredentials credentials; + readonly attribute RequestCache cache; + readonly attribute RequestRedirect redirect; + readonly attribute DOMString integrity; + readonly attribute boolean keepalive; + readonly attribute boolean isReloadNavigation; + readonly attribute AbortSignal signal; + + [NewObject] Request clone(); +}; +Request includes Body; + +dictionary RequestInit { + ByteString method; + HeadersInit headers; + BodyInit? body; + USVString referrer; + ReferrerPolicy referrerPolicy; + RequestMode mode; + RequestCredentials credentials; + RequestCache cache; + RequestRedirect redirect; + DOMString integrity; + boolean keepalive; + AbortSignal? signal; + any window; // can only be set to null +}; + +enum RequestDestination { "", "audio", "audioworklet", "document", "embed", "font", "image", "manifest", "object", "paintworklet", "report", "script", "sharedworker", "style", "track", "video", "worker", "xslt" }; +enum RequestMode { "navigate", "same-origin", "no-cors", "cors" }; +enum RequestCredentials { "omit", "same-origin", "include" }; +enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" }; +enum RequestRedirect { "follow", "error", "manual" }; +[Constructor(optional BodyInit? body = null, optional ResponseInit init), Exposed=(Window,Worker)] +interface Response { + [NewObject] static Response error(); + [NewObject] static Response redirect(USVString url, optional unsigned short status = 302); + + readonly attribute ResponseType type; + + readonly attribute USVString url; + readonly attribute boolean redirected; + readonly attribute unsigned short status; + readonly attribute boolean ok; + readonly attribute ByteString statusText; + [SameObject] readonly attribute Headers headers; + readonly attribute Promise trailer; + + [NewObject] Response clone(); +}; +Response includes Body; + +dictionary ResponseInit { + unsigned short status = 200; + ByteString statusText = "OK"; + HeadersInit headers; +}; + +enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" }; +partial interface mixin WindowOrWorkerGlobalScope { + [NewObject] Promise fetch(RequestInfo input, optional RequestInit init); +}; From 2bba72c8c008a441136aad0248fb77979daa367b Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 27 Apr 2018 13:26:23 +0200 Subject: [PATCH 2/2] nit --- fetch/api/idl.any.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fetch/api/idl.any.js b/fetch/api/idl.any.js index 0067a8b9b4ff93..cae5ca3769abfe 100644 --- a/fetch/api/idl.any.js +++ b/fetch/api/idl.any.js @@ -6,8 +6,8 @@ promise_test(async() => { const text = await (await fetch("/interfaces/fetch.idl")).text(); const idl_array = new IdlArray(); idl_array.add_idls(text); - idl_array.add_untested_idls("interface AbortSignal {};"); - idl_array.add_untested_idls("interface ReadableStream {};"); + idl_array.add_untested_idls("[Exposed=(Window,Worker)] interface AbortSignal {};"); + idl_array.add_untested_idls("[Exposed=(Window,Worker)] interface ReadableStream {};"); idl_array.add_untested_idls("enum ReferrerPolicy {};"); idl_array.add_objects({ Headers: ["new Headers()"],