mirror of
https://github.com/denoland/deno.git
synced 2025-01-07 06:46:59 -05:00
fix(streams): add support Float64Array
to ReadableStreamByobReader
(#18188)
This commit is contained in:
parent
8b7524bcef
commit
5ef4cefa26
1 changed files with 81 additions and 30 deletions
|
@ -25,13 +25,18 @@ const {
|
||||||
ArrayPrototypePush,
|
ArrayPrototypePush,
|
||||||
ArrayPrototypeShift,
|
ArrayPrototypeShift,
|
||||||
AsyncGeneratorPrototype,
|
AsyncGeneratorPrototype,
|
||||||
BigInt64ArrayPrototype,
|
BigInt64Array,
|
||||||
BigUint64ArrayPrototype,
|
BigUint64Array,
|
||||||
DataView,
|
DataView,
|
||||||
|
DataViewPrototypeGetBuffer,
|
||||||
|
DataViewPrototypeGetByteLength,
|
||||||
|
DataViewPrototypeGetByteOffset,
|
||||||
|
Float32Array,
|
||||||
|
Float64Array,
|
||||||
FinalizationRegistry,
|
FinalizationRegistry,
|
||||||
Int8ArrayPrototype,
|
Int8Array,
|
||||||
Int16ArrayPrototype,
|
Int16Array,
|
||||||
Int32ArrayPrototype,
|
Int32Array,
|
||||||
NumberIsInteger,
|
NumberIsInteger,
|
||||||
NumberIsNaN,
|
NumberIsNaN,
|
||||||
MathMin,
|
MathMin,
|
||||||
|
@ -57,12 +62,15 @@ const {
|
||||||
SymbolAsyncIterator,
|
SymbolAsyncIterator,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
TypeError,
|
TypeError,
|
||||||
|
TypedArrayPrototypeGetBuffer,
|
||||||
|
TypedArrayPrototypeGetByteLength,
|
||||||
|
TypedArrayPrototypeGetByteOffset,
|
||||||
|
TypedArrayPrototypeGetSymbolToStringTag,
|
||||||
TypedArrayPrototypeSet,
|
TypedArrayPrototypeSet,
|
||||||
Uint8Array,
|
Uint8Array,
|
||||||
Uint8ArrayPrototype,
|
Uint16Array,
|
||||||
Uint16ArrayPrototype,
|
Uint32Array,
|
||||||
Uint32ArrayPrototype,
|
Uint8ClampedArray,
|
||||||
Uint8ClampedArrayPrototype,
|
|
||||||
WeakMap,
|
WeakMap,
|
||||||
WeakMapPrototypeGet,
|
WeakMapPrototypeGet,
|
||||||
WeakMapPrototypeHas,
|
WeakMapPrototypeHas,
|
||||||
|
@ -855,7 +863,7 @@ async function readableStreamCollectIntoUint8Array(stream) {
|
||||||
|
|
||||||
if (done) break;
|
if (done) break;
|
||||||
|
|
||||||
if (!ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, chunk)) {
|
if (TypedArrayPrototypeGetSymbolToStringTag(chunk) !== "Uint8Array") {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
"Can't convert value to Uint8Array while consuming the stream",
|
"Can't convert value to Uint8Array while consuming the stream",
|
||||||
);
|
);
|
||||||
|
@ -1669,31 +1677,74 @@ function readableByteStreamControllerPullInto(
|
||||||
readIntoRequest,
|
readIntoRequest,
|
||||||
) {
|
) {
|
||||||
const stream = controller[_stream];
|
const stream = controller[_stream];
|
||||||
let elementSize = 1;
|
|
||||||
let ctor = DataView;
|
|
||||||
|
|
||||||
if (
|
|
||||||
ObjectPrototypeIsPrototypeOf(Int8ArrayPrototype, view) ||
|
|
||||||
ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, view) ||
|
|
||||||
ObjectPrototypeIsPrototypeOf(Uint8ClampedArrayPrototype, view) ||
|
|
||||||
ObjectPrototypeIsPrototypeOf(Int16ArrayPrototype, view) ||
|
|
||||||
ObjectPrototypeIsPrototypeOf(Uint16ArrayPrototype, view) ||
|
|
||||||
ObjectPrototypeIsPrototypeOf(Int32ArrayPrototype, view) ||
|
|
||||||
ObjectPrototypeIsPrototypeOf(Uint32ArrayPrototype, view) ||
|
|
||||||
ObjectPrototypeIsPrototypeOf(BigInt64ArrayPrototype, view) ||
|
|
||||||
ObjectPrototypeIsPrototypeOf(BigUint64ArrayPrototype, view)
|
|
||||||
) {
|
|
||||||
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
||||||
ctor = view.constructor;
|
|
||||||
}
|
|
||||||
const byteOffset = view.byteOffset;
|
|
||||||
const byteLength = view.byteLength;
|
|
||||||
|
|
||||||
|
let ctor;
|
||||||
|
/** @type {number} */
|
||||||
|
let elementSize;
|
||||||
/** @type {ArrayBufferLike} */
|
/** @type {ArrayBufferLike} */
|
||||||
let buffer;
|
let buffer;
|
||||||
|
/** @type {number} */
|
||||||
|
let byteLength;
|
||||||
|
/** @type {number} */
|
||||||
|
let byteOffset;
|
||||||
|
|
||||||
|
const tag = TypedArrayPrototypeGetSymbolToStringTag(view);
|
||||||
|
if (tag === undefined) {
|
||||||
|
ctor = DataView;
|
||||||
|
elementSize = 1;
|
||||||
|
buffer = DataViewPrototypeGetBuffer(/** @type {DataView} */ (view));
|
||||||
|
byteLength = DataViewPrototypeGetByteLength(/** @type {DataView} */ (view));
|
||||||
|
byteOffset = DataViewPrototypeGetByteOffset(/** @type {DataView} */ (view));
|
||||||
|
} else {
|
||||||
|
switch (tag) {
|
||||||
|
case "Int8Array":
|
||||||
|
ctor = Int8Array;
|
||||||
|
break;
|
||||||
|
case "Uint8Array":
|
||||||
|
ctor = Uint8Array;
|
||||||
|
break;
|
||||||
|
case "Uint8ClampedArray":
|
||||||
|
ctor = Uint8ClampedArray;
|
||||||
|
break;
|
||||||
|
case "Int16Array":
|
||||||
|
ctor = Int16Array;
|
||||||
|
break;
|
||||||
|
case "Uint16Array":
|
||||||
|
ctor = Uint16Array;
|
||||||
|
break;
|
||||||
|
case "Int32Array":
|
||||||
|
ctor = Int32Array;
|
||||||
|
break;
|
||||||
|
case "Uint32Array":
|
||||||
|
ctor = Uint32Array;
|
||||||
|
break;
|
||||||
|
case "Float32Array":
|
||||||
|
ctor = Float32Array;
|
||||||
|
break;
|
||||||
|
case "Float64Array":
|
||||||
|
ctor = Float64Array;
|
||||||
|
break;
|
||||||
|
case "BigInt64Array":
|
||||||
|
ctor = BigInt64Array;
|
||||||
|
break;
|
||||||
|
case "BigUint64Array":
|
||||||
|
ctor = BigUint64Array;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new TypeError("unreachable");
|
||||||
|
}
|
||||||
|
elementSize = ctor.BYTES_PER_ELEMENT;
|
||||||
|
buffer = TypedArrayPrototypeGetBuffer(/** @type {Uint8Array} */ (view));
|
||||||
|
byteLength = TypedArrayPrototypeGetByteLength(
|
||||||
|
/** @type {Uint8Array} */ (view),
|
||||||
|
);
|
||||||
|
byteOffset = TypedArrayPrototypeGetByteOffset(
|
||||||
|
/** @type {Uint8Array} */ (view),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
buffer = transferArrayBuffer(view.buffer);
|
buffer = transferArrayBuffer(buffer);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
readIntoRequest.errorSteps(e);
|
readIntoRequest.errorSteps(e);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue