Skip to content

Commit 9379ecd

Browse files
committed
[Robustness] use call-bound, safe-regex-test
1 parent fc46390 commit 9379ecd

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
'use strict';
22

3-
var toStr = Object.prototype.toString;
4-
var fnToStr = Function.prototype.toString;
5-
var isFnRegex = /^\s*async(?:\s+function(?:\s+|\()|\s*\()/;
3+
var callBound = require('call-bound');
4+
var safeRegexTest = require('safe-regex-test');
5+
6+
var toStr = callBound('Object.prototype.toString');
7+
var fnToStr = callBound('Function.prototype.toString');
8+
var isFnRegex = safeRegexTest(/^\s*async(?:\s+function(?:\s+|\()|\s*\()/);
9+
610
var hasToStringTag = require('has-tostringtag/shams')();
711
var getProto = require('get-proto');
12+
813
var getAsyncFunc = function () { // eslint-disable-line consistent-return
914
if (!hasToStringTag) {
1015
return false;
@@ -20,11 +25,11 @@ module.exports = function isAsyncFunction(fn) {
2025
if (typeof fn !== 'function') {
2126
return false;
2227
}
23-
if (isFnRegex.test(fnToStr.call(fn))) {
28+
if (isFnRegex(fnToStr(fn))) {
2429
return true;
2530
}
2631
if (!hasToStringTag) {
27-
var str = toStr.call(fn);
32+
var str = toStr(fn);
2833
return str === '[object AsyncFunction]';
2934
}
3035
if (!getProto) {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
"url": "https://github.com/inspect-js/is-async-function/issues"
4141
},
4242
"dependencies": {
43+
"call-bound": "^1.0.3",
4344
"get-proto": "^1.0.1",
44-
"has-tostringtag": "^1.0.2"
45+
"has-tostringtag": "^1.0.2",
46+
"safe-regex-test": "^1.1.0"
4547
},
4648
"devDependencies": {
4749
"@ljharb/eslint-config": "^21.1.1",

0 commit comments

Comments
 (0)