Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative: throw when trying to write to a detached buffer #43

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "node --test"
},
"dependencies": {
"@tc39/ecma262-biblio": "^2.1.2663",
"@tc39/ecma262-biblio": "2.1.2672",
"ecmarkup": "^18.0.0",
"jsdom": "^21.1.1",
"prismjs": "^1.29.0"
Expand Down
6 changes: 6 additions & 0 deletions playground/polyfill-core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ export function base64ToUint8Array(string, options, into) {
if (!['loose', 'strict', 'stop-before-partial'].includes(lastChunkHandling)) {
throw new TypeError('expected lastChunkHandling to be either "loose", "strict", or "stop-before-partial"');
}
if (into && 'detached' in into.buffer && into.buffer.detached) {
throw new TypeError('toBase64Into called on array backed by detached buffer');
}

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

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

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

Expand Down
2 changes: 2 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ <h1>Uint8Array.fromBase64Into ( _string_, _into_ [ , _options_ ] )</h1>
1. If _lastChunkHandling_ is *undefined*, set _lastChunkHandling_ to *"loose"*.
1. If _lastChunkHandling_ is not one of *"loose"*, *"strict"*, or *"stop-before-partial"*, throw a *TypeError* exception.
1. Let _taRecord_ be MakeTypedArrayWithBufferWitnessRecord(_into_, ~seq-cst~).
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception.
1. Let _byteLength_ be TypedArrayByteLength(_taRecord_).
1. Let _maxLength_ be _byteLength_.
1. Let _result_ be ? FromBase64(_string_, _alphabet_, _lastChunkHandling_, _maxLength_).
Expand Down Expand Up @@ -121,6 +122,7 @@ <h1>Uint8Array.fromHexInto ( _string_, _into_ )</h1>
1. If _string_ is not a String, throw a *TypeError* exception.
1. Perform ? ValidateUint8Array(_into_).
1. Let _taRecord_ be MakeTypedArrayWithBufferWitnessRecord(_into_, ~seq-cst~).
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception.
1. Let _byteLength_ be TypedArrayByteLength(_taRecord_).
1. Let _maxLength_ be _byteLength_.
1. Let _result_ be ? FromHex(_string_, _maxLength_).
Expand Down