Skip to content

Commit

Permalink
Merge pull request #34 from defunctzombie/old-node
Browse files Browse the repository at this point in the history
Fix callbackify on old Node.js
  • Loading branch information
goto-bus-stop committed Apr 29, 2019
2 parents a5a2f84 + eb824c7 commit 9e5ac07
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
10 changes: 7 additions & 3 deletions .airtap.yml
@@ -1,10 +1,14 @@
browsers:
- name: chrome
version: 27..latest
version:
- 49 # last supported on XP (keep it so long as it's easy to support)
- -1..latest
- name: firefox
version: latest
version:
- 52 # extended support release
- -1..latest
- name: safari
version: latest
version: -1..latest
- name: ie
version: 9..latest
sauce_connect: true
Expand Down
9 changes: 7 additions & 2 deletions test/node/callbackify.js
Expand Up @@ -8,6 +8,11 @@ var assert = require('assert');
var callbackify = require('../../').callbackify;
var execFile = require('child_process').execFile;

if (typeof Promise === 'undefined') {
console.log('no global Promise found, skipping callbackify tests');
return;
}

var values = [
'hello world',
null,
Expand Down Expand Up @@ -72,7 +77,7 @@ if (typeof Symbol !== 'undefined') {
assert.strictEqual(err.message, 'Promise was rejected with a falsy value');
assert.strictEqual(err.reason, value);
} else {
assert.strictEqual(String(value).endsWith(err.message), true);
assert.strictEqual(String(value).slice(-err.message.length), err.message);
}
} else {
assert.strictEqual(err, value);
Expand All @@ -97,7 +102,7 @@ if (typeof Symbol !== 'undefined') {
assert.strictEqual(err.message, 'Promise was rejected with a falsy value');
assert.strictEqual(err.reason, value);
} else {
assert.strictEqual(String(value).endsWith(err.message), true);
assert.strictEqual(String(value).slice(-err.message.length), err.message);
}
} else {
assert.strictEqual(err, value);
Expand Down
4 changes: 2 additions & 2 deletions util.js
Expand Up @@ -691,8 +691,8 @@ function callbackify(original) {
// In true node style we process the callback on `nextTick` with all the
// implications (stack, `uncaughtException`, `async_hooks`)
original.apply(this, args)
.then(function(ret) { process.nextTick(cb, null, ret) },
function(rej) { process.nextTick(callbackifyOnRejected, rej, cb) });
.then(function(ret) { process.nextTick(cb.bind(null, null, ret)) },
function(rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
}

Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
Expand Down

0 comments on commit 9e5ac07

Please sign in to comment.