You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 28, 2025. It is now read-only.
1. Let _lastChunkHandling_ be ? Get(_opts_, *"lastChunkHandling"*).
61
61
1. If _lastChunkHandling_ is *undefined*, set _lastChunkHandling_ to *"loose"*.
62
62
1. If _lastChunkHandling_ is not one of *"loose"*, *"strict"*, or *"stop-before-partial"*, throw a *TypeError* exception.
63
-
1. Let _result_ be ? FromBase64(_string_, _alphabet_, _lastChunkHandling_).
63
+
1. Let _result_ be FromBase64(_string_, _alphabet_, _lastChunkHandling_).
64
+
1. If _result_.[[Error]] is not ~none~, then
65
+
1. Throw _result_.[[Error]].
64
66
1. Let _resultLength_ be the length of _result_.[[Bytes]].
65
67
1. Let _ta_ be ? <emu-metasuppress-effects="user-code">AllocateTypedArray(*"Uint8Array"*, %Uint8Array%, *"%Uint8Array.prototype%"*, _resultLength_)</emu-meta>.
66
68
1. Set the value at each index of _ta_.[[ViewedArrayBuffer]].[[ArrayBufferData]] to the value at the corresponding index of _result_.[[Bytes]].
1. If _string_ is not a String, throw a *TypeError* exception.
104
-
1. Let _result_ be ? FromHex(_string_).
108
+
1. Let _result_ be FromHex(_string_).
109
+
1. If _result_.[[Error]] is not ~none~, then
110
+
1. Throw _result_.[[Error]].
105
111
1. Let _resultLength_ be the length of _result_.[[Bytes]].
106
112
1. Let _ta_ be ? <emu-metasuppress-effects="user-code">AllocateTypedArray(*"Uint8Array"*, %Uint8Array%, *"%Uint8Array.prototype%"*, _resultLength_)</emu-meta>.
107
113
1. Set the value at each index of _ta_.[[ViewedArrayBuffer]].[[ArrayBufferData]] to the value at the corresponding index of _result_.[[Bytes]].
_lastChunkHandling_: *"loose"*, *"strict"*, or *"stop-before-partial"*,
256
264
optional _maxLength_: a non-negative integer,
257
-
): either a normal completion containing a Record with fields [[Read]] (an integral Number) and [[Bytes]] (a List of byte values), or a throw completion
265
+
): a Record with fields [[Read]] (an integral Number), [[Bytes]] (a List of byte values), and [[Error]] (either ~none~or a throw completion)
258
266
</h1>
259
267
<dlclass="header">
260
268
</dl>
@@ -264,7 +272,7 @@ <h1>
264
272
1. NOTE: Because the input is a string, the length of strings is limited to 2<sup>53</sup> - 1 characters, and the output requires no more bytes than the input has characters, this limit can never be reached. However, it is editorially convenient to use a finite value here.
265
273
1. NOTE: The order of validation and decoding in the algorithm below is not observable. Implementations are encouraged to perform them in whatever order is most efficient, possibly interleaving validation with decoding, as long as the behaviour is observably equivalent.
266
274
1. If _maxLength_ is 0, then
267
-
1. Return the Record { [[Read]]: 0, [[Bytes]]: « » }.
275
+
1. Return the Record { [[Read]]: 0, [[Bytes]]: « », [[Error]]: ~none~ }.
268
276
1. Let _read_ be 0.
269
277
1. Let _bytes_ be « ».
270
278
1. Let _chunk_ be the empty String.
@@ -276,43 +284,58 @@ <h1>
276
284
1. If _index_ = _length_, then
277
285
1. If _chunkLength_ > 0, then
278
286
1. If _lastChunkHandling_ is *"stop-before-partial"*, then
279
-
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_ }.
287
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: ~none~ }.
280
288
1. Else if _lastChunkHandling_ is *"loose"*, then
281
289
1. If _chunkLength_ is 1, then
282
-
1. Throw a *SyntaxError* exception.
290
+
1. Let _error_ be a new *SyntaxError* exception.
291
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
283
292
1. Set _bytes_ to the list-concatenation of _bytes_ and ! DecodeBase64Chunk(_chunk_, *false*).
284
293
1. Else,
285
294
1.Assert:_lastChunkHandling_ is *"strict"*.
286
-
1. Throw a *SyntaxError* exception.
287
-
1. Return the Record { [[Read]]: _length_, [[Bytes]]: _bytes_ }.
295
+
1. Let _error_ be a new *SyntaxError* exception.
296
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
297
+
1. Return the Record { [[Read]]: _length_, [[Bytes]]: _bytes_, [[Error]]: ~none~ }.
288
298
1. Let _char_ be the substring of _string_ from _index_ to _index_ + 1.
289
299
1. Set _index_ to _index_ + 1.
290
300
1. If _char_ is *"="*, then
291
301
1. If _chunkLength_ < 2, then
292
-
1. Throw a *SyntaxError* exception.
302
+
1. Let _error_ be a new *SyntaxError* exception.
303
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
293
304
1. Set _index_ to SkipAsciiWhitespace(_string_, _index_).
294
305
1. If _chunkLength_ = 2, then
295
306
1. If _index_ = _length_, then
296
307
1. If _lastChunkHandling_ is *"stop-before-partial"*, then
297
-
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_ }.
298
-
1. Throw a *SyntaxError* exception.
308
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: ~none~ }.
309
+
1. Let _error_ be a new *SyntaxError* exception.
310
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
299
311
1. Set _char_ to the substring of _string_ from _index_ to _index_ + 1.
300
312
1. If _char_ is *"="*, then
301
313
1. Set _index_ to SkipAsciiWhitespace(_string_, _index_ + 1).
302
314
1. If _index_ < _length_, then
303
-
1. Throw a *SyntaxError* exception.
315
+
1. Let _error_ be a new *SyntaxError* exception.
316
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
304
317
1. If _lastChunkHandling_ is *"strict"*, let _throwOnExtraBits_ be *true*.
305
318
1. Else, let _throwOnExtraBits_ be *false*.
306
-
1. Set _bytes_ to the list-concatenation of _bytes_ and ? DecodeBase64Chunk(_chunk_, _throwOnExtraBits_).
307
-
1. Return the Record { [[Read]]: _length_, [[Bytes]]: _bytes_ }.
319
+
1. Let _decodeResult_ be Completion(DecodeBase64Chunk(_chunk_, _throwOnExtraBits_)).
320
+
1. If _decodeResult_ is an abrupt completion, then
321
+
1. Let _error_ be _decodeResult_.[[Value]].
322
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
323
+
1. Set _bytes_ to the list-concatenation of _bytes_ and ! _decodeResult_.
324
+
1. Return the Record { [[Read]]: _length_, [[Bytes]]: _bytes_, [[Error]]: ~none~ }.
308
325
1. If _alphabet_ is *"base64url"*, then
309
-
1. If _char_ is either *"+"* or *"/"*, throw a *SyntaxError* exception.
310
-
1. Else if _char_ is *"-"*, set _char_ to *"+"*.
311
-
1. Else if _char_ is *"_"*, set _char_ to *"/"*.
312
-
1. If the sole code unit of _char_ is not an element of the standard base64 alphabet, throw a *SyntaxError* exception.
326
+
1. If _char_ is either *"+"* or *"/"*, then
327
+
1. Let _error_ be a new *SyntaxError* exception.
328
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
329
+
1. Else if _char_ is *"-"*, then
330
+
1. Set _char_ to *"+"*.
331
+
1. Else if _char_ is *"_"*, then
332
+
1. Set _char_ to *"/"*.
333
+
1. If the sole code unit of _char_ is not an element of the standard base64 alphabet, then
334
+
1. Let _error_ be a new *SyntaxError* exception.
335
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
313
336
1. Let _remaining_ be _maxLength_ - the length of _bytes_.
314
337
1. If _remaining_ = 1 and _chunkLength_ = 2, or if _remaining_ = 2 and _chunkLength_ = 3, then
315
-
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_ }.
338
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: ~none~ }.
316
339
1. Set _chunk_ to the string-concatenation of _chunk_ and _char_.
317
340
1. Set _chunkLength_ to the length of _chunk_.
318
341
1. If _chunkLength_ = 4, then
@@ -321,7 +344,7 @@ <h1>
321
344
1. Set _chunkLength_ to 0.
322
345
1. Set _read_ to _index_.
323
346
1. If the length of _bytes_ = _maxLength_, then
324
-
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_ }.
347
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: ~none~ }.
325
348
</emu-alg>
326
349
</emu-clause>
327
350
@@ -330,23 +353,27 @@ <h1>
330
353
FromHex (
331
354
_string_: a string,
332
355
optional _maxLength_: a non-negative integer,
333
-
): either a normal completion containing a Record with fields [[Read]] (an integral Number) and [[Bytes]] (a List of byte values), or a throw completion
356
+
): a Record with fields [[Read]] (an integral Number), [[Bytes]] (a List of byte values), and [[Error]] (either ~none~or a throw completion)
334
357
</h1>
335
358
<dlclass="header">
336
359
</dl>
337
360
<emu-alg>
338
361
1. If _maxLength_ is not present, let _maxLength_ be 2<sup>53</sup> - 1.
339
362
1. Let _length_ be the length of _string_.
340
-
1. If _length_ modulo 2 is not 0, throw a *SyntaxError* exception.
341
363
1. Let _bytes_ be « ».
342
-
1. Let _index_ be 0.
343
-
1. Repeat, while _index_<_length_ and the length of _bytes_<_maxLength_,
344
-
1. Let _hexits_ be the substring of _string_ from _index_ to _index_ + 2.
345
-
1. If _hexits_ contains any code units which are not in *"0123456789abcdefABCDEF"*, throw a *SyntaxError* exception.
346
-
1. Set _index_ to _index_ + 2.
364
+
1. Let _read_ be 0.
365
+
1. If _length_ modulo 2 is not 0, then
366
+
1. Let _error_ be a new *SyntaxError* exception.
367
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
368
+
1. Repeat, while _read_<_length_ and the length of _bytes_<_maxLength_,
369
+
1. Let _hexits_ be the substring of _string_ from _read_ to _read_ + 2.
370
+
1. If _hexits_ contains any code units which are not in *"0123456789abcdefABCDEF"*, then
371
+
1. Let _error_ be a new *SyntaxError* exception.
372
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: _error_ }.
373
+
1. Set _read_ to _read_ + 2.
347
374
1. Let _byte_ be the integer value represented by _hexits_ in base-16 notation, using the letters A-F and a-f for digits with values 10 through 15.
348
375
1. Append _byte_ to _bytes_.
349
-
1. Return the Record { [[Read]]: _index_, [[Bytes]]: _bytes_ }.
376
+
1. Return the Record { [[Read]]: _read_, [[Bytes]]: _bytes_, [[Error]]: ~none~ }.
0 commit comments