summaryrefslogtreecommitdiff
path: root/js/blob.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-08-06 06:22:11 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-08-06 09:22:11 -0400
commitccee2f01ba2f6304720ab17e99dee17bf6687bd8 (patch)
treedf04bd385c05e13b6a835fc4955cd5eac2c7c582 /js/blob.ts
parent11c850af423f07769f054c494a76cbd9efb8806c (diff)
Implement Blob url support for worker (#2729)
Diffstat (limited to 'js/blob.ts')
-rw-r--r--js/blob.ts7
1 files changed, 7 insertions, 0 deletions
diff --git a/js/blob.ts b/js/blob.ts
index f2668b642..94d03c97f 100644
--- a/js/blob.ts
+++ b/js/blob.ts
@@ -118,6 +118,10 @@ function processBlobParts(
return bytes;
}
+// A WeakMap holding blob to byte array mapping.
+// Ensures it does not impact garbage collection.
+export const blobBytesWeakMap = new WeakMap<domTypes.Blob, Uint8Array>();
+
export class DenoBlob implements domTypes.Blob {
private readonly [bytesSymbol]: Uint8Array;
readonly size: number = 0;
@@ -161,6 +165,9 @@ export class DenoBlob implements domTypes.Blob {
this[bytesSymbol] = bytes;
this.size = bytes.byteLength;
this.type = type;
+
+ // Register bytes for internal private use.
+ blobBytesWeakMap.set(this, bytes);
}
slice(start?: number, end?: number, contentType?: string): DenoBlob {