aboutsummaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-07-31 12:30:31 -0400
committerGitHub <noreply@github.com>2021-07-31 12:30:31 -0400
commit00c5ae79833a641ccc5f7d31b6eea3e91db4cb71 (patch)
treee21cb14527e2bf6e74b36eeab75e994d52df37b6 /dev
parent2d57d69b9ed3adf1241074f7eb29a588bec817a2 (diff)
DictionaryImporterMediaLoader (#1860)
* Rename param for consistency * Move media loading functionality into DictionaryImporterMediaLoader * Create test class for media loading * Remove unnecessary Blob/Image/URL functionality
Diffstat (limited to 'dev')
-rw-r--r--dev/database-vm.js69
-rw-r--r--dev/translator-vm.js5
-rw-r--r--dev/vm.js18
3 files changed, 14 insertions, 78 deletions
diff --git a/dev/database-vm.js b/dev/database-vm.js
index 07d9bd5a..ebde5a2a 100644
--- a/dev/database-vm.js
+++ b/dev/database-vm.js
@@ -30,63 +30,6 @@ const chrome = {
}
};
-class Image {
- constructor() {
- this._src = '';
- this._loadCallbacks = [];
- }
-
- get src() {
- return this._src;
- }
-
- set src(value) {
- this._src = value;
- this._delayTriggerLoad();
- }
-
- get naturalWidth() {
- return 100;
- }
-
- get naturalHeight() {
- return 100;
- }
-
- addEventListener(eventName, callback) {
- if (eventName === 'load') {
- this._loadCallbacks.push(callback);
- }
- }
-
- removeEventListener(eventName, callback) {
- if (eventName === 'load') {
- const index = this._loadCallbacks.indexOf(callback);
- if (index >= 0) {
- this._loadCallbacks.splice(index, 1);
- }
- }
- }
-
- removeAttribute() {
- // NOP
- }
-
- async _delayTriggerLoad() {
- await Promise.resolve();
- for (const callback of this._loadCallbacks) {
- callback();
- }
- }
-}
-
-class Blob {
- constructor(array, options) {
- this._array = array;
- this._options = options;
- }
-}
-
async function fetch(url2) {
const extDir = path.join(__dirname, '..', 'ext');
let filePath;
@@ -114,8 +57,6 @@ class DatabaseVM extends VM {
constructor(globals={}) {
super(Object.assign({
chrome,
- Image,
- Blob,
fetch,
indexedDB: global.indexedDB,
IDBKeyRange: global.IDBKeyRange,
@@ -127,6 +68,14 @@ class DatabaseVM extends VM {
}
}
+class DatabaseVMDictionaryImporterMediaLoader {
+ async getImageResolution() {
+ // Placeholder values
+ return {width: 100, height: 100};
+ }
+}
+
module.exports = {
- DatabaseVM
+ DatabaseVM,
+ DatabaseVMDictionaryImporterMediaLoader
};
diff --git a/dev/translator-vm.js b/dev/translator-vm.js
index 3c3886ba..d616afc5 100644
--- a/dev/translator-vm.js
+++ b/dev/translator-vm.js
@@ -18,7 +18,7 @@
const fs = require('fs');
const path = require('path');
const assert = require('assert');
-const {DatabaseVM} = require('./database-vm');
+const {DatabaseVM, DatabaseVMDictionaryImporterMediaLoader} = require('./database-vm');
const {createDictionaryArchive} = require('./util');
function clone(value) {
@@ -75,7 +75,8 @@ class TranslatorVM extends DatabaseVM {
const testDictionaryContent = await testDictionary.generateAsync({type: 'arraybuffer'});
// Setup database
- const dictionaryImporter = new DictionaryImporter();
+ const dictionaryImporterMediaLoader = new DatabaseVMDictionaryImporterMediaLoader();
+ const dictionaryImporter = new DictionaryImporter(dictionaryImporterMediaLoader);
const dictionaryDatabase = new DictionaryDatabase();
await dictionaryDatabase.prepare();
diff --git a/dev/vm.js b/dev/vm.js
index 363cc115..9db87cdf 100644
--- a/dev/vm.js
+++ b/dev/vm.js
@@ -116,7 +116,7 @@ function deepStrictEqual(actual, expected) {
}
-function createURLClass(urlMap) {
+function createURLClass() {
const BaseURL = URL;
const result = function URL(url) {
const u = new BaseURL(url);
@@ -133,23 +133,13 @@ function createURLClass(urlMap) {
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={}) {
- this._urlMap = new Map();
- context.URL = createURLClass(this._urlMap);
+ context.URL = createURLClass();
context.crypto = {
getRandomValues: (array) => {
const buffer = crypto.randomBytes(array.byteLength);
@@ -205,10 +195,6 @@ class VM {
return single ? results[0] : results;
}
-
- getUrlObject(url) {
- return this._urlMap.get(url);
- }
}