aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-07 21:36:20 -0500
committerGitHub <noreply@github.com>2021-01-07 21:36:20 -0500
commitb20622b2c84ce3ca1781c7bf8e10fed0af1e5001 (patch)
tree938cdc95f289cdfd482aff77a6ebe44aff80e889 /ext/bg/js/backend.js
parent7d706df66b4cd68d6ac430c2e3e8b9f3a7f4b6ae (diff)
Core refactor (#1207)
* Copy set intersection functions * Remove unused functions * Simplify url check * Remove parseUrl * Simplify stringReverse * Remove hasOwn due to infrequent use * Rename errorToJson/jsonToError to de/serializeError For clarity on intended use. * Fix time argument on timeout * Add missing return value * Throw an error for unexpected argument values * Add documentation comments
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 690f6a3c..db83d0b7 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -305,7 +305,7 @@ class Backend {
try {
this._validatePrivilegedMessageSender(sender);
} catch (error) {
- callback({error: errorToJson(error)});
+ callback({error: serializeError(error)});
return false;
}
}
@@ -628,7 +628,7 @@ class Backend {
}
_onApiLog({error, level, context}) {
- yomichan.log(jsonToError(error), level, context);
+ yomichan.log(deserializeError(error), level, context);
}
_onApiLogIndicatorClear() {
@@ -667,7 +667,7 @@ class Backend {
const result = this._modifySetting(target);
results.push({result: clone(result)});
} catch (e) {
- results.push({error: errorToJson(e)});
+ results.push({error: serializeError(e)});
}
}
await this._saveOptions(source);
@@ -681,7 +681,7 @@ class Backend {
const result = this._getSetting(target);
results.push({result: clone(result)});
} catch (e) {
- results.push({error: errorToJson(e)});
+ results.push({error: serializeError(e)});
}
}
return results;
@@ -730,8 +730,10 @@ class Backend {
const isTabMatch = (url2) => {
if (url2 === null || !url2.startsWith(baseUrl)) { return false; }
- const {baseUrl: baseUrl2, queryParams: queryParams2} = parseUrl(url2);
- return baseUrl2 === baseUrl && (queryParams2.mode === mode || (!queryParams2.mode && mode === 'existingOrNewTab'));
+ const parsedUrl = new URL(url2);
+ const baseUrl2 = `${parsedUrl.origin}${parsedUrl.pathname}`;
+ const mode2 = parsedUrl.searchParams.get('mode');
+ return baseUrl2 === baseUrl && (mode2 === mode || (!mode2 && mode === 'existingOrNewTab'));
};
const openInTab = async () => {
@@ -1052,7 +1054,7 @@ class Backend {
const cleanup = (error) => {
if (port === null) { return; }
if (error !== null) {
- port.postMessage({type: 'error', data: errorToJson(error)});
+ port.postMessage({type: 'error', data: serializeError(error)});
}
if (!hasStarted) {
port.onMessage.removeListener(onMessage);