Skip to content

Commit 67c5b29

Browse files
authored
Normative: throw when trying to write to a detached buffer (#43)
1 parent db3947c commit 67c5b29

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"test": "node --test"
1111
},
1212
"dependencies": {
13-
"@tc39/ecma262-biblio": "^2.1.2663",
13+
"@tc39/ecma262-biblio": "2.1.2672",
1414
"ecmarkup": "^18.0.0",
1515
"jsdom": "^21.1.1",
1616
"prismjs": "^1.29.0"

playground/polyfill-core.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ export function base64ToUint8Array(string, options, into) {
224224
if (!['loose', 'strict', 'stop-before-partial'].includes(lastChunkHandling)) {
225225
throw new TypeError('expected lastChunkHandling to be either "loose", "strict", or "stop-before-partial"');
226226
}
227+
if (into && 'detached' in into.buffer && into.buffer.detached) {
228+
throw new TypeError('toBase64Into called on array backed by detached buffer');
229+
}
227230

228231
let maxLength = into ? into.length : 2 ** 53 - 1;
229232

@@ -260,6 +263,9 @@ export function hexToUint8Array(string, into) {
260263
if (/[^0-9a-fA-F]/.test(string)) {
261264
throw new SyntaxError('string should only contain hex characters');
262265
}
266+
if (into && 'detached' in into.buffer && into.buffer.detached) {
267+
throw new TypeError('fromHexInto called on array backed by detached buffer');
268+
}
263269

264270
let maxLength = into ? into.length : 2 ** 53 - 1;
265271

spec.html

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ <h1>Uint8Array.fromBase64Into ( _string_, _into_ [ , _options_ ] )</h1>
8383
1. If _lastChunkHandling_ is *undefined*, set _lastChunkHandling_ to *"loose"*.
8484
1. If _lastChunkHandling_ is not one of *"loose"*, *"strict"*, or *"stop-before-partial"*, throw a *TypeError* exception.
8585
1. Let _taRecord_ be MakeTypedArrayWithBufferWitnessRecord(_into_, ~seq-cst~).
86+
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception.
8687
1. Let _byteLength_ be TypedArrayByteLength(_taRecord_).
8788
1. Let _maxLength_ be _byteLength_.
8889
1. Let _result_ be ? FromBase64(_string_, _alphabet_, _lastChunkHandling_, _maxLength_).
@@ -121,6 +122,7 @@ <h1>Uint8Array.fromHexInto ( _string_, _into_ )</h1>
121122
1. If _string_ is not a String, throw a *TypeError* exception.
122123
1. Perform ? ValidateUint8Array(_into_).
123124
1. Let _taRecord_ be MakeTypedArrayWithBufferWitnessRecord(_into_, ~seq-cst~).
125+
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception.
124126
1. Let _byteLength_ be TypedArrayByteLength(_taRecord_).
125127
1. Let _maxLength_ be _byteLength_.
126128
1. Let _result_ be ? FromHex(_string_, _maxLength_).

0 commit comments

Comments
 (0)