Skip to content

Commit 1eb55de

Browse files
committed
[Robustness] use call-bound
1 parent 5f8b992 commit 1eb55de

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use strict';
22

3-
var toStr = Object.prototype.toString;
4-
var fnToStr = Function.prototype.toString;
3+
var callBound = require('call-bound');
54
var safeRegexTest = require('safe-regex-test');
65
var isFnRegex = safeRegexTest(/^\s*(?:function)?\*/);
76
var hasToStringTag = require('has-tostringtag/shams')();
87
var getProto = require('get-proto');
98

9+
var toStr = callBound('Object.prototype.toString');
10+
var fnToStr = callBound('Function.prototype.toString');
11+
1012
var getGeneratorFunc = function () { // eslint-disable-line consistent-return
1113
if (!hasToStringTag) {
1214
return false;
@@ -22,11 +24,11 @@ module.exports = function isGeneratorFunction(fn) {
2224
if (typeof fn !== 'function') {
2325
return false;
2426
}
25-
if (isFnRegex(fnToStr.call(fn))) {
27+
if (isFnRegex(fnToStr(fn))) {
2628
return true;
2729
}
2830
if (!hasToStringTag) {
29-
var str = toStr.call(fn);
31+
var str = toStr(fn);
3032
return str === '[object GeneratorFunction]';
3133
}
3234
if (!getProto) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"url": "https://github.com/inspect-js/is-generator-function/issues"
4343
},
4444
"dependencies": {
45+
"call-bound": "^1.0.3",
4546
"get-proto": "^1.0.0",
4647
"has-tostringtag": "^1.0.2",
4748
"safe-regex-test": "^1.1.0"

0 commit comments

Comments
 (0)