Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 9cec4a8

Browse files
Use fetch infrastructure to fetch source maps (#27)
1 parent 185988c commit 9cec4a8

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

source-map.bs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ spec:html; type:element;
2323
text:style
2424
text:title
2525
text:link
26+
2627
spec:bikeshed-1; type:dfn; for:railroad; text:optional
28+
29+
spec:fetch; type:dfn; for:/; text:request
30+
spec:fetch; type:dfn; for:/; text:response
31+
32+
spec:url; type:dfn; for:/; text:url
2733
</pre>
2834

2935
<pre class="biblio">
@@ -245,18 +251,6 @@ Resolving Sources {#resolving-sources}
245251
If the sources are not absolute URLs after prepending the [=sourceRoot=], the sources are
246252
resolved relative to the SourceMap (like resolving the script `src` attribute in an HTML document).
247253

248-
Encoding {#encoding}
249-
--------------------
250-
251-
For simplicity, the character set encoding is always UTF-8.
252-
253-
Compression {#compression}
254-
--------------------------
255-
256-
The file is allowed to be GZIP compressed. It is not expected that in-browser consumers of
257-
the source map will support GZIP compression directly but that they will consume an
258-
uncompressed map that may be GZIP'd for transport.
259-
260254
Extensions {#extensions}
261255
------------------------
262256

@@ -434,21 +428,35 @@ However, It is unclear what a "source map reference" looks like in anything othe
434428
More specifically, what a source map reference looks like in a language that doesn't support
435429
JavaScript-style single-line comments.
436430

437-
JSON over HTTP Transport
438-
========================
439-
440-
For historic reasons, when delivering source maps over HTTP, servers may prepend a line
441-
starting with the string `)]}'` to the source map. A client fetching a source map via
442-
HTTP thus should check if the response starts with this string and then ignore the
443-
first line.
444-
445-
```
446-
)]}'garbage here
447-
{"version": 3, ...}
448-
```
449-
450-
Is to be interpreted as
451-
452-
```
453-
{"version": 3, ...}
454-
```
431+
Fetching Source Maps {#fetching-source-maps}
432+
============================================
433+
434+
To fetch a source map given a [=URL=] |url|, run the following steps:
435+
436+
1. Let |promise| be [=a new promise=].
437+
1. Let |request| be a new [=request=] whose [=request/URL=] is |url|.
438+
1. [=Fetch=] |request| with [=processResponseConsumeBody=] set to the following steps given [=response=] <var ignore>response</var> and null, failure, or a [=byte sequence=] |bodyBytes|:
439+
1. If |bodyBytes| is null or failure, [=reject=] |promise| with a {{TypeError}} and abort these steps.
440+
1. If |url|'s [=url/scheme=] is an [=HTTP(S) scheme=] and |bodyBytes| [=byte sequence/starts with=] \`<code>)]}'</code>\`, then:
441+
1. [=While=] |bodyBytes|'s [=byte sequence/length=] is not 0 and |bodyBytes|'s 0th byte is not an [=HTTP newline byte=]:
442+
1. remove the 0th byte from |bodyBytes|.
443+
444+
<div class="note">
445+
<span class="marker">Note:</span> For historic reasons, when delivering source maps over HTTP(S), servers may prepend a line
446+
starting with the string `)]}'` to the source map.
447+
448+
```
449+
)]}'garbage here
450+
{"version": 3, ...}
451+
```
452+
453+
is interpreted as
454+
455+
```
456+
{"version": 3, ...}
457+
```
458+
</div>
459+
1. Let |sourceMap| be the result of [=parsing JSON bytes to a JavaScript value=] given |bodyBytes|.
460+
1. If the previous step threw an error, [=reject=] |promise| with that error.
461+
1. Otherwise, [=resolve=] |promise| with |sourceMap|.
462+
1. Return |promise|.

0 commit comments

Comments
 (0)