From 966ce7de8a23f63d0f30b1748fe69ccaf07519e0 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 7 Apr 2021 15:22:14 +0200 Subject: feat: blob URL support (#10045) This commit adds blob URL support. Blob URLs are stored in a process global storage, that can be accessed from all workers, and the module loader. Blob URLs can be created using `URL.createObjectURL` and revoked using `URL.revokeObjectURL`. This commit does not add support for `fetch`ing blob URLs. This will be added in a follow up commit. --- op_crates/file/03_blob_url.js | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 op_crates/file/03_blob_url.js (limited to 'op_crates/file/03_blob_url.js') diff --git a/op_crates/file/03_blob_url.js b/op_crates/file/03_blob_url.js new file mode 100644 index 000000000..29019cd84 --- /dev/null +++ b/op_crates/file/03_blob_url.js @@ -0,0 +1,63 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +// @ts-check +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +"use strict"; + +((window) => { + const core = Deno.core; + // const webidl = window.__bootstrap.webidl; + const { _byteSequence } = window.__bootstrap.file; + const { URL } = window.__bootstrap.url; + + /** + * @param {Blob} blob + * @returns {string} + */ + function createObjectURL(blob) { + // const prefix = "Failed to execute 'createObjectURL' on 'URL'"; + // webidl.requiredArguments(arguments.length, 1, { prefix }); + // blob = webidl.converters["Blob"](blob, { + // context: "Argument 1", + // prefix, + // }); + + const url = core.jsonOpSync( + "op_file_create_object_url", + blob.type, + blob[_byteSequence], + ); + + return url; + } + + /** + * @param {string} url + * @returns {void} + */ + function revokeObjectURL(url) { + // const prefix = "Failed to execute 'revokeObjectURL' on 'URL'"; + // webidl.requiredArguments(arguments.length, 1, { prefix }); + // url = webidl.converters["DOMString"](url, { + // context: "Argument 1", + // prefix, + // }); + + core.jsonOpSync( + "op_file_revoke_object_url", + url, + ); + } + + URL.createObjectURL = createObjectURL; + URL.revokeObjectURL = revokeObjectURL; +})(globalThis); -- cgit v1.2.3