Browse Source

fix: Reflect.has throws for non-objects

tophf 3 years ago
parent
commit
46385c1ac4
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/injected/safe-globals-injected.js

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

@@ -33,7 +33,10 @@ export const isString = val => typeof val === 'string';
 export const getOwnProp = (obj, key, defVal) => {
   // obj may be a Proxy that throws in has() or its getter throws
   try {
-    if (hasOwnProperty(obj, key)) defVal = obj[key];
+    // hasOwnProperty is Reflect.has which throws for non-objects
+    if (obj && typeof obj === 'object' && hasOwnProperty(obj, key)) {
+      defVal = obj[key];
+    }
   } catch (e) { /* NOP */ }
   return defVal;
 };