From ccee2f01ba2f6304720ab17e99dee17bf6687bd8 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Tue, 6 Aug 2019 06:22:11 -0700 Subject: Implement Blob url support for worker (#2729) --- js/blob.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'js/blob.ts') 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(); + 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 { -- cgit v1.2.3