summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-13 23:26:32 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-14 11:12:39 -0500
commitddaf44ba7bfa8399ddc5e7f7025229f9aa03c700 (patch)
treeb41ccd3bfca1b7ae7e2a2d70040c4578ba4c9c9e /ext/bg/js/util.js
parent87ece13647aae3f670f03d7f5667f638bee23bcb (diff)
Isolate functions passed across window contexts
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js27
1 files changed, 24 insertions, 3 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index f7f6e770..96d549c9 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -32,11 +32,32 @@ function utilIsolate(value) {
return typeof stringValue === 'string' ? JSON.parse(stringValue) : null;
}
+function utilFunctionIsolate(func) {
+ return function (...args) {
+ try {
+ return func.call(this, ...args);
+ } catch (e) {
+ try {
+ String(func);
+ } catch (e2) {
+ // Dead object
+ return;
+ }
+ throw e;
+ }
+ };
+}
+
function utilBackgroundIsolate(data) {
const backgroundPage = chrome.extension.getBackgroundPage();
return backgroundPage.utilIsolate(data);
}
+function utilBackgroundFunctionIsolate(func) {
+ const backgroundPage = chrome.extension.getBackgroundPage();
+ return backgroundPage.utilFunctionIsolate(func);
+}
+
function utilSetEqual(setA, setB) {
if (setA.size !== setB.size) {
return false;
@@ -110,15 +131,15 @@ function utilDatabasePurge() {
function utilDatabaseDeleteDictionary(dictionaryName, onProgress) {
return utilBackend().translator.database.deleteDictionary(
utilBackgroundIsolate(dictionaryName),
- onProgress
+ utilBackgroundFunctionIsolate(onProgress)
);
}
-async function utilDatabaseImport(data, progress, details) {
+async function utilDatabaseImport(data, onProgress, details) {
data = await utilReadFile(data);
return utilBackend().translator.database.importDictionary(
utilBackgroundIsolate(data),
- progress,
+ utilBackgroundFunctionIsolate(onProgress),
utilBackgroundIsolate(details)
);
}