summaryrefslogtreecommitdiff
path: root/dev/vm.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-14 18:41:15 -0400
committerGitHub <noreply@github.com>2021-03-14 18:41:15 -0400
commit07df1e011794f5a77f7fb7da5cd9ea353a8747e2 (patch)
tree98a679d4ef07629b8f0121e244038c557c972bd8 /dev/vm.js
parent52a4d874eada5be121e15d73d1d10e9a8d84bdb8 (diff)
Fix dictionary image support (#1526)
* Fix content security policy for images * Add createBlobFromBase64Content to MediaUtil * Update MediaLoader to use MediaUtil * Use blob URLs when importing dictionaries * Update VM's URL to support createObjectURL and revokeObjectURL * Fix test
Diffstat (limited to 'dev/vm.js')
-rw-r--r--dev/vm.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/dev/vm.js b/dev/vm.js
index b3fc63e7..98a1f7bf 100644
--- a/dev/vm.js
+++ b/dev/vm.js
@@ -19,6 +19,7 @@ const fs = require('fs');
const vm = require('vm');
const path = require('path');
const assert = require('assert');
+const crypto = require('crypto');
function getContextEnvironmentRecords(context, names) {
@@ -115,9 +116,9 @@ function deepStrictEqual(actual, expected) {
}
-function createURLClass() {
+function createURLClass(urlMap) {
const BaseURL = URL;
- return function URL(url) {
+ const result = function URL(url) {
const u = new BaseURL(url);
this.hash = u.hash;
this.host = u.host;
@@ -132,12 +133,23 @@ function createURLClass() {
this.searchParams = u.searchParams;
this.username = u.username;
};
+ result.createObjectURL = (object) => {
+ const id = crypto.randomBytes(16).toString('hex');
+ const url = `blob:${id}`;
+ urlMap.set(url, object);
+ return url;
+ };
+ result.revokeObjectURL = (url) => {
+ urlMap.delete(url);
+ };
+ return result;
}
class VM {
constructor(context={}) {
- context.URL = createURLClass();
+ this._urlMap = new Map();
+ context.URL = createURLClass(this._urlMap);
this._context = vm.createContext(context);
this._assert = {
deepStrictEqual
@@ -186,6 +198,10 @@ class VM {
return single ? results[0] : results;
}
+
+ getUrlObject(url) {
+ return this._urlMap.get(url);
+ }
}