Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid eval in async wrappers; fixes #1403 #1404

Merged
merged 1 commit into from Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 2 additions & 14 deletions 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';
}
Expand All @@ -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 };
13 changes: 12 additions & 1 deletion 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);
Expand Down