summaryrefslogtreecommitdiff
path: root/lib/child_process.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-05-19 00:25:07 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-07-16 16:45:48 +0200
commitbd1f355fc5805c8307da85a16d1a385e5c48813a (patch)
tree91cf2d7334ab07d87579eaceff8f956d1a45642c /lib/child_process.js
parentb70367e8cf0f4eae8a4f0c92b1a8a1fa59fec288 (diff)
downloadandroid-node-v8-bd1f355fc5805c8307da85a16d1a385e5c48813a.tar.gz
android-node-v8-bd1f355fc5805c8307da85a16d1a385e5c48813a.tar.bz2
android-node-v8-bd1f355fc5805c8307da85a16d1a385e5c48813a.zip
lib,src: replace all C++ promises with JS promises
C++ promises can not be properly optimized by V8. They also behave a tiny bit different than "regular" promises. PR-URL: https://github.com/nodejs/node/pull/20830 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/child_process.js')
-rw-r--r--lib/child_process.js23
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index 5c315290c2..a790e85ee2 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -26,8 +26,6 @@ const {
deprecate, convertToValidSignal, getSystemErrorName
} = require('internal/util');
const { isUint8Array } = require('internal/util/types');
-const { createPromise,
- promiseResolve, promiseReject } = process.binding('util');
const debug = util.debuglog('child_process');
const { Buffer } = require('buffer');
const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap');
@@ -152,18 +150,17 @@ exports.exec = function exec(command /* , options, callback */) {
const customPromiseExecFunction = (orig) => {
return (...args) => {
- const promise = createPromise();
-
- orig(...args, (err, stdout, stderr) => {
- if (err !== null) {
- err.stdout = stdout;
- err.stderr = stderr;
- promiseReject(promise, err);
- } else {
- promiseResolve(promise, { stdout, stderr });
- }
+ return new Promise((resolve, reject) => {
+ orig(...args, (err, stdout, stderr) => {
+ if (err !== null) {
+ err.stdout = stdout;
+ err.stderr = stderr;
+ reject(err);
+ } else {
+ resolve({ stdout, stderr });
+ }
+ });
});
- return promise;
};
};