summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2017-04-17 14:43:54 -0400
committerGitHub <noreply@github.com>2017-04-17 14:43:54 -0400
commit996abc22d981d685eee2c431ca098d39b277cfa7 (patch)
treeee8686b7fb9d5ef5a9e25eb9e244f490d597d97d
parent81d66dd219f62bb24fc3ca684236bdddc4cc4267 (diff)
parent6d19dd3013480aa0ed7a025ee179fc499c255fca (diff)
downloadasync-996abc22d981d685eee2c431ca098d39b277cfa7.tar.gz
Merge pull request #1404 from caolan/avoid-eval
Avoid eval in async wrappers; fixes #1403
-rw-r--r--lib/internal/wrapAsync.js16
-rw-r--r--mocha_test/asyncFunctions.js13
2 files changed, 14 insertions, 15 deletions
diff --git a/lib/internal/wrapAsync.js b/lib/internal/wrapAsync.js
index aee0275..c4d1ea8 100644
--- a/lib/internal/wrapAsync.js
+++ b/lib/internal/wrapAsync.js
@@ -1,19 +1,7 @@
-import identity from 'lodash/identity';
import asyncify from '../asyncify';
var supportsSymbol = typeof Symbol === 'function';
-function supportsAsync() {
- var supported;
- try {
- /* eslint no-eval: 0 */
- supported = isAsync(eval('(async function () {})'));
- } catch (e) {
- supported = false;
- }
- return supported;
-}
-
function isAsync(fn) {
return supportsSymbol && fn[Symbol.toStringTag] === 'AsyncFunction';
}
@@ -22,6 +10,6 @@ function wrapAsync(asyncFn) {
return isAsync(asyncFn) ? asyncify(asyncFn) : asyncFn;
}
-export default supportsAsync() ? wrapAsync : identity;
+export default wrapAsync;
-export { supportsAsync, isAsync };
+export { isAsync };
diff --git a/mocha_test/asyncFunctions.js b/mocha_test/asyncFunctions.js
index b756a90..3b759e1 100644
--- a/mocha_test/asyncFunctions.js
+++ b/mocha_test/asyncFunctions.js
@@ -1,4 +1,15 @@
-var supportsAsync = require('../lib/internal/wrapAsync').supportsAsync;
+var isAsync = require('../lib/internal/wrapAsync').isAsync;
+
+function supportsAsync() {
+ var supported;
+ try {
+ /* eslint no-eval: 0 */
+ supported = isAsync(eval('(async function () {})'));
+ } catch (e) {
+ supported = false;
+ }
+ return supported;
+}
describe('async function support', function () {
this.timeout(100);