aboutsummaryrefslogtreecommitdiff
path: root/test/fixtures
diff options
context:
space:
mode:
authorRefael Ackermann <refack@gmail.com>2017-04-27 21:57:12 -0400
committerRefael Ackermann <refack@gmail.com>2017-06-10 22:49:28 -0400
commitaf3aa682ac534bb55765f5fef2755a88e5ff2580 (patch)
treed632fb6f8347f58c05731d16374b05706ef828ba /test/fixtures
parent780acc2208a3cdd3b01ae93aeaa478771fd3fd56 (diff)
downloadandroid-node-v8-af3aa682ac534bb55765f5fef2755a88e5ff2580.tar.gz
android-node-v8-af3aa682ac534bb55765f5fef2755a88e5ff2580.tar.bz2
android-node-v8-af3aa682ac534bb55765f5fef2755a88e5ff2580.zip
util: add callbackify
Add `util.callbackify(function)` for creating callback style functions from functions returning a `Thenable` PR-URL: https://github.com/nodejs/node/pull/12712 Fixes: https://github.com/nodejs/CTC/issues/109 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/fixtures')
-rw-r--r--test/fixtures/uncaught-exceptions/callbackify1.js15
-rw-r--r--test/fixtures/uncaught-exceptions/callbackify2.js22
2 files changed, 37 insertions, 0 deletions
diff --git a/test/fixtures/uncaught-exceptions/callbackify1.js b/test/fixtures/uncaught-exceptions/callbackify1.js
new file mode 100644
index 0000000000..1fbe7c8ebf
--- /dev/null
+++ b/test/fixtures/uncaught-exceptions/callbackify1.js
@@ -0,0 +1,15 @@
+'use strict';
+
+// Used to test that `uncaughtException` is emitted
+
+const { callbackify } = require('util');
+
+{
+ async function fn() { }
+
+ const cbFn = callbackify(fn);
+
+ cbFn((err, ret) => {
+ throw new Error(__filename);
+ });
+}
diff --git a/test/fixtures/uncaught-exceptions/callbackify2.js b/test/fixtures/uncaught-exceptions/callbackify2.js
new file mode 100644
index 0000000000..9080da234f
--- /dev/null
+++ b/test/fixtures/uncaught-exceptions/callbackify2.js
@@ -0,0 +1,22 @@
+'use strict';
+
+// Used to test the `uncaughtException` err object
+
+const assert = require('assert');
+const { callbackify } = require('util');
+
+{
+ const sentinel = new Error(__filename);
+ process.once('uncaughtException', (err) => {
+ assert.strictEqual(err, sentinel);
+ // Calling test will use `stdout` to assert value of `err.message`
+ console.log(err.message);
+ });
+
+ async function fn() {
+ return await Promise.reject(sentinel);
+ }
+
+ const cbFn = callbackify(fn);
+ cbFn((err, ret) => assert.ifError(err));
+}