Browse Source

fixup: add the missing "?.", remove spread polyfill

regressed in 2c0a2202
tophf 4 years ago
parent
commit
efd6a4d01a
3 changed files with 6 additions and 5 deletions
  1. 1 1
      .eslintrc.js
  2. 1 1
      src/background/utils/db.js
  3. 4 3
      src/common/util.js

+ 1 - 1
.eslintrc.js

@@ -57,7 +57,7 @@ module.exports = {
          Ideally, `eslint-plugin-compat` should be used but I couldn't make it work. */
       'no-restricted-syntax': ['error', {
         selector: 'ObjectExpression > ExperimentalSpreadProperty',
-        message: 'Object spread in an unsafe environment',
+        message: 'Object spread adds a polyfill in injected* even if unused by it',
       }, {
         selector: 'OptionalCallExpression',
         message: 'Optional call in an unsafe environment',

+ 1 - 1
src/background/utils/db.js

@@ -557,7 +557,7 @@ export async function fetchResources(script, resourceCache, reqOptions) {
     ...Object.values(meta.resources).map(url => snatch(url, 'cache')),
     isRemote(meta.icon) && snatch(meta.icon, 'cache', validateImage),
   ]);
-  if (!resourceCache.ignoreDepsErrors) {
+  if (!resourceCache?.ignoreDepsErrors) {
     const error = errors.map(formatHttpError)::trueJoin('\n');
     if (error) {
       const message = i18n('msgErrorFetchingResource');

+ 4 - 3
src/common/util.js

@@ -280,9 +280,10 @@ export async function request(url, options = {}) {
   const isBodyObj = body && body::({}).toString() === '[object Object]';
   const hostname = url.split('/', 3)[2];
   const accept = FORCED_ACCEPT[hostname];
-  const init = {
+  // Not using ...spread because Babel mistakenly adds its polyfill to injected-web
+  const init = Object.assign({
     cache: isRemote(url) ? undefined : 'no-cache',
-    ...options, /* Used in safe context */// eslint-disable-line no-restricted-syntax
+  }, options, {
     body: isBodyObj ? JSON.stringify(body) : body,
     headers: isBodyObj || accept
       ? Object.assign({},
@@ -290,7 +291,7 @@ export async function request(url, options = {}) {
         isBodyObj && { 'Content-Type': 'application/json' },
         accept && { accept })
       : headers,
-  };
+  });
   const result = { url, status: -1 };
   try {
     const resp = await fetch(url, init);