mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
parent
ad8d0c90d1
commit
03edd48edd
21 changed files with 688 additions and 308 deletions
|
@ -18,9 +18,13 @@ const primordials = globalThis.__bootstrap.primordials;
|
|||
const {
|
||||
ArrayBufferPrototype,
|
||||
ArrayBufferPrototypeSlice,
|
||||
ArrayBufferPrototypeGetByteLength,
|
||||
ArrayBufferIsView,
|
||||
ArrayPrototypePush,
|
||||
AsyncGeneratorPrototypeNext,
|
||||
DataViewPrototypeGetBuffer,
|
||||
DataViewPrototypeGetByteLength,
|
||||
DataViewPrototypeGetByteOffset,
|
||||
Date,
|
||||
DatePrototypeGetTime,
|
||||
FinalizationRegistry,
|
||||
|
@ -37,6 +41,10 @@ const {
|
|||
Symbol,
|
||||
SymbolFor,
|
||||
TypedArrayPrototypeSet,
|
||||
TypedArrayPrototypeGetBuffer,
|
||||
TypedArrayPrototypeGetByteLength,
|
||||
TypedArrayPrototypeGetByteOffset,
|
||||
TypedArrayPrototypeGetSymbolToStringTag,
|
||||
TypeError,
|
||||
Uint8Array,
|
||||
} = primordials;
|
||||
|
@ -100,6 +108,7 @@ function convertLineEndingsToNative(s) {
|
|||
/** @param {(BlobReference | Blob)[]} parts */
|
||||
async function* toIterator(parts) {
|
||||
for (let i = 0; i < parts.length; ++i) {
|
||||
// deno-lint-ignore prefer-primordials
|
||||
yield* parts[i].stream();
|
||||
}
|
||||
}
|
||||
|
@ -120,15 +129,31 @@ function processBlobParts(parts, endings) {
|
|||
if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, element)) {
|
||||
const chunk = new Uint8Array(ArrayBufferPrototypeSlice(element, 0));
|
||||
ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk));
|
||||
size += element.byteLength;
|
||||
size += ArrayBufferPrototypeGetByteLength(element);
|
||||
} else if (ArrayBufferIsView(element)) {
|
||||
const chunk = new Uint8Array(
|
||||
element.buffer,
|
||||
element.byteOffset,
|
||||
element.byteLength,
|
||||
);
|
||||
size += element.byteLength;
|
||||
ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk));
|
||||
if (TypedArrayPrototypeGetSymbolToStringTag(element) !== undefined) {
|
||||
// TypedArray
|
||||
const chunk = new Uint8Array(
|
||||
TypedArrayPrototypeGetBuffer(/** @type {Uint8Array} */ (element)),
|
||||
TypedArrayPrototypeGetByteOffset(/** @type {Uint8Array} */ (element)),
|
||||
TypedArrayPrototypeGetByteLength(/** @type {Uint8Array} */ (element)),
|
||||
);
|
||||
size += TypedArrayPrototypeGetByteLength(
|
||||
/** @type {Uint8Array} */ (element),
|
||||
);
|
||||
ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk));
|
||||
} else {
|
||||
// DataView
|
||||
const chunk = new Uint8Array(
|
||||
DataViewPrototypeGetBuffer(/** @type {DataView} */ (element)),
|
||||
DataViewPrototypeGetByteOffset(/** @type {DataView} */ (element)),
|
||||
DataViewPrototypeGetByteLength(/** @type {DataView} */ (element)),
|
||||
);
|
||||
size += DataViewPrototypeGetByteLength(
|
||||
/** @type {DataView} */ (element),
|
||||
);
|
||||
ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk));
|
||||
}
|
||||
} else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, element)) {
|
||||
ArrayPrototypePush(processedParts, element);
|
||||
size += element.size;
|
||||
|
@ -136,7 +161,7 @@ function processBlobParts(parts, endings) {
|
|||
const chunk = core.encode(
|
||||
endings == "native" ? convertLineEndingsToNative(element) : element,
|
||||
);
|
||||
size += chunk.byteLength;
|
||||
size += TypedArrayPrototypeGetByteLength(chunk);
|
||||
ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk));
|
||||
} else {
|
||||
throw new TypeError("Unreachable code (invalid element type)");
|
||||
|
@ -341,7 +366,7 @@ class Blob {
|
|||
partIterator,
|
||||
);
|
||||
if (done) return controller.close();
|
||||
if (value.byteLength > 0) {
|
||||
if (TypedArrayPrototypeGetByteLength(value) > 0) {
|
||||
return controller.enqueue(value);
|
||||
}
|
||||
}
|
||||
|
@ -368,7 +393,7 @@ class Blob {
|
|||
partIterator,
|
||||
);
|
||||
if (done) break;
|
||||
const byteLength = value.byteLength;
|
||||
const byteLength = TypedArrayPrototypeGetByteLength(value);
|
||||
if (byteLength > 0) {
|
||||
TypedArrayPrototypeSet(bytes, value, offset);
|
||||
offset += byteLength;
|
||||
|
@ -383,7 +408,7 @@ class Blob {
|
|||
async arrayBuffer() {
|
||||
webidl.assertBranded(this, BlobPrototype);
|
||||
const buf = await this.#u8Array(this.size);
|
||||
return buf.buffer;
|
||||
return TypedArrayPrototypeGetBuffer(buf);
|
||||
}
|
||||
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
|
@ -554,7 +579,7 @@ class BlobReference {
|
|||
*/
|
||||
static fromUint8Array(data) {
|
||||
const id = ops.op_blob_create_part(data);
|
||||
return new BlobReference(id, data.byteLength);
|
||||
return new BlobReference(id, TypedArrayPrototypeGetByteLength(data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue