Browse Source

refactor: obj.prop?.() is safe, there's no .call

tophf 3 years ago
parent
commit
3500ece038
3 changed files with 3 additions and 10 deletions
  1. 0 4
      .eslintrc.js
  2. 2 4
      src/injected/web/notifications.js
  3. 1 2
      src/injected/web/tabs.js

+ 0 - 4
.eslintrc.js

@@ -41,10 +41,6 @@ const INJECTED_RULES = {
     'error', {
       selector: 'ObjectExpression > ExperimentalSpreadProperty',
       message: 'Object spread adds a polyfill in injected* even if unused by it',
-    }, {
-      selector: 'OptionalCallExpression > MemberExpression',
-      message: 'Optional call on property uses .call(), which may be spoofed/broken in an unsafe environment',
-      // TODO: write a Babel plugin to use safeCall for this.
     }, {
       selector: 'ArrayPattern',
       message: 'Destructuring via Symbol.iterator may be spoofed/broken in an unsafe environment',

+ 2 - 4
src/injected/web/notifications.js

@@ -5,15 +5,13 @@ const notifications = createNullObj();
 
 addHandlers({
   NotificationClicked(id) {
-    const fn = notifications[id]?.onclick;
-    if (fn) fn();
+    notifications[id]?.onclick?.();
   },
   NotificationClosed(id) {
     const options = notifications[id];
     if (options) {
       delete notifications[id];
-      const fn = options.ondone;
-      if (fn) fn();
+      options.ondone?.();
     }
   },
 });

+ 1 - 2
src/injected/web/tabs.js

@@ -9,8 +9,7 @@ addHandlers({
     if (item) {
       item.closed = true;
       delete tabs[key];
-      const fn = item.onclose;
-      if (fn) fn();
+      item.onclose?.();
     }
   },
 });