2021-04-07 09:22:14 -04:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
/// <reference no-default-lib="true" />
|
|
|
|
/// <reference path="../../core/lib.deno_core.d.ts" />
|
|
|
|
/// <reference path="../webidl/internal.d.ts" />
|
|
|
|
/// <reference path="../web/internal.d.ts" />
|
|
|
|
/// <reference path="../web/lib.deno_web.d.ts" />
|
|
|
|
/// <reference path="../url/internal.d.ts" />
|
|
|
|
/// <reference path="../url/lib.deno_url.d.ts" />
|
|
|
|
/// <reference path="./internal.d.ts" />
|
|
|
|
/// <reference lib="esnext" />
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
((window) => {
|
|
|
|
const core = Deno.core;
|
2021-04-07 19:23:26 -04:00
|
|
|
const webidl = window.__bootstrap.webidl;
|
2021-07-05 09:34:37 -04:00
|
|
|
const { getParts } = window.__bootstrap.file;
|
2021-04-07 09:22:14 -04:00
|
|
|
const { URL } = window.__bootstrap.url;
|
|
|
|
|
2021-04-28 10:08:51 -04:00
|
|
|
/**
|
2021-04-07 09:22:14 -04:00
|
|
|
* @param {Blob} blob
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
function createObjectURL(blob) {
|
2021-04-07 19:23:26 -04:00
|
|
|
const prefix = "Failed to execute 'createObjectURL' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
blob = webidl.converters["Blob"](blob, {
|
|
|
|
context: "Argument 1",
|
|
|
|
prefix,
|
|
|
|
});
|
2021-04-07 09:22:14 -04:00
|
|
|
|
2021-04-12 15:55:05 -04:00
|
|
|
const url = core.opSync(
|
2021-07-05 09:34:37 -04:00
|
|
|
"op_blob_create_object_url",
|
2021-04-07 09:22:14 -04:00
|
|
|
blob.type,
|
2021-07-05 09:34:37 -04:00
|
|
|
getParts(blob),
|
2021-04-07 09:22:14 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2021-04-28 10:08:51 -04:00
|
|
|
/**
|
2021-04-07 09:22:14 -04:00
|
|
|
* @param {string} url
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function revokeObjectURL(url) {
|
2021-04-07 19:23:26 -04:00
|
|
|
const prefix = "Failed to execute 'revokeObjectURL' on 'URL'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
url = webidl.converters["DOMString"](url, {
|
|
|
|
context: "Argument 1",
|
|
|
|
prefix,
|
|
|
|
});
|
2021-04-07 09:22:14 -04:00
|
|
|
|
2021-07-05 09:34:37 -04:00
|
|
|
core.opSync("op_blob_revoke_object_url", url);
|
2021-04-07 09:22:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
URL.createObjectURL = createObjectURL;
|
|
|
|
URL.revokeObjectURL = revokeObjectURL;
|
|
|
|
})(globalThis);
|