Skip to content

Commit

Permalink
[Fix] avoid calling Function until absolutely necessary
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
ljharb committed May 6, 2021
1 parent 5f6cc2a commit bce7ca6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ var getGeneratorFunc = function () { // eslint-disable-line consistent-return
} catch (e) {
}
};
var generatorFunc = getGeneratorFunc();
var GeneratorFunction = getProto && generatorFunc ? getProto(generatorFunc) : false;
var GeneratorFunction;

module.exports = function isGeneratorFunction(fn) {
if (typeof fn !== 'function') {
Expand All @@ -28,5 +27,12 @@ module.exports = function isGeneratorFunction(fn) {
var str = toStr.call(fn);
return str === '[object GeneratorFunction]';
}
return getProto && getProto(fn) === GeneratorFunction;
if (!getProto) {
return false;
}
if (typeof GeneratorFunction === 'undefined') {
var generatorFunc = getGeneratorFunc();
GeneratorFunction = generatorFunc ? getProto(generatorFunc) : false;
}
return getProto(fn) === GeneratorFunction;
};

0 comments on commit bce7ca6

Please sign in to comment.