Browse Source

refactor: code cosmetics/clarifications

tophf 3 years ago
parent
commit
356cd860f0

+ 3 - 3
src/background/utils/storage-cache.js

@@ -87,7 +87,7 @@ storage.api = {
     });
     batch(false);
     if (keys.length) {
-      await api.set(toWrite);
+      await api[SET](toWrite);
       fire({ keys });
     }
     if (unflushed) flushLater();
@@ -186,8 +186,8 @@ async function flush() {
   const toRemove = keys.filter(key => !valuesToFlush[key] && delete valuesToFlush[key]);
   const toFlush = valuesToFlush;
   valuesToFlush = {};
-  if (!isEmpty(toFlush)) await api.set(toFlush);
-  if (toRemove.length) await api.remove(toRemove);
+  if (!isEmpty(toFlush)) await api[SET](toFlush);
+  if (toRemove.length) await api[REMOVE](toRemove);
   if (valuesToWatch) setTimeout(notifyWatchers, 0, toFlush, toRemove);
   fire({ keys });
 }

+ 1 - 1
src/injected/content/safe-globals-content.js

@@ -52,7 +52,7 @@ export const logging = assign(createNullObj(), console);
 export const { chrome } = global;
 export const VM_UUID = chrome.runtime.getURL('');
 /** Unlike the built-in `instanceof` operator this doesn't call @@hasInstance which may be spoofed */
-export const isInstance = function _(instance, safeOriginalProto) {
+export const isInstance = (instance, safeOriginalProto) => {
   for (let obj = instance; isObject(obj) && (obj = getPrototypeOf(obj));) {
     if (obj === safeOriginalProto) {
       return true;

+ 1 - 1
src/injected/safe-globals-injected.js

@@ -122,7 +122,7 @@ export const safeDefineProperty = (obj, key, desc) => (
   defineProperty(obj, key, createNullObj(desc))
 );
 
-/** A safe replacement for ::push() which may call a setter */
+/** Unlike ::push() this one doesn't call possibly spoofed Array.prototype setters */
 export const safePush = (arr, val) => (
   setOwnProp(arr, arr.length, val)
 );

+ 3 - 3
src/injected/web/index.js

@@ -43,7 +43,7 @@ export default function initialize(
     global.chrome = undefined;
     global.browser = undefined;
     bridge.addHandlers({
-      RunAt,
+      RunAt: doRunAt,
     });
   } else {
     bridge.mode = INJECT_PAGE;
@@ -133,7 +133,7 @@ async function onCodeSet(item, fn) {
   }
 }
 
-async function RunAt(name) {
+async function doRunAt(name) {
   if (name) {
     safePush(runningQueues, waitingQueues[name]);
     if (runningQueues.length > 1) return;
@@ -145,7 +145,7 @@ async function RunAt(name) {
         if (fn) {
           queue[j] = null;
           if (fn === 1) {
-            queueMacrotask(RunAt);
+            queueMacrotask(doRunAt);
             return;
           }
           await 0;