Skip to content

Commit

Permalink
Fix: fallback to typeof when toString is applied to incompatible obje…
Browse files Browse the repository at this point in the history
…ct (#16017)
  • Loading branch information
JLHwung committed Oct 10, 2023
1 parent 0c9032d commit d25f265
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/babel-helpers/src/helpers.ts
Expand Up @@ -314,7 +314,12 @@ helpers.construct = helper("7.0.0-beta.0")`
helpers.isNativeFunction = helper("7.0.0-beta.0")`
export default function _isNativeFunction(fn) {
// Note: This function returns "true" for core-js functions.
return Function.toString.call(fn).indexOf("[native code]") !== -1;
try {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
} catch (e) {
// Firefox 31 throws when "toString" is applied to an HTMLElement
return typeof fn === "function";
}
}
`;

Expand Down

0 comments on commit d25f265

Please sign in to comment.