Util refactor and fix (#638)

* Remove unused functions

* Fix clone function not being visible on the window object
This commit is contained in:
toasted-nutbread 2020-07-03 11:57:15 -04:00 committed by GitHub
parent c13160d784
commit 897d85d1ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 22 deletions

View File

@ -15,33 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
function utilFunctionIsolate(func) {
return function isolatedFunction(...args) {
try {
args = args.map((v) => clone(v));
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.clone(data);
}
function utilBackgroundFunctionIsolate(func) {
const backgroundPage = chrome.extension.getBackgroundPage();
return backgroundPage.utilFunctionIsolate(func);
}
function utilBackend() {
const backend = chrome.extension.getBackgroundPage().yomichanBackend;
if (!backend.isPrepared()) {

View File

@ -192,6 +192,11 @@ const clone = (() => {
return clone;
})();
// Expose clone function on the global object, since util.js's utilBackgroundIsolate needs access to it.
if (typeof window === 'object' && window !== null) {
window.clone = clone;
}
/*
* Async utilities