| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b98bf82 commit 9817e40
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,8 +26,6 @@ const { | |||
| 26 | 26 | deprecate, convertToValidSignal, getSystemErrorName | |
| 27 | 27 | } = require('internal/util'); | |
| 28 | 28 | const { isUint8Array } = require('internal/util/types'); | |
| 29 | - const { createPromise, | ||
| 30 | - promiseResolve, promiseReject } = process.binding('util'); | ||
| 31 | 29 | const debug = util.debuglog('child_process'); | |
| 32 | 30 | const { Buffer } = require('buffer'); | |
| 33 | 31 | const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap'); | |
@@ -152,18 +150,17 @@ exports.exec = function exec(command /* , options, callback */) { | |||
| 152 | 150 | ||
| 153 | 151 | const customPromiseExecFunction = (orig) => { | |
| 154 | 152 | return (...args) => { | |
| 155 | - const promise = createPromise(); | ||
| 156 | - | ||
| 157 | - orig(...args, (err, stdout, stderr) => { | ||
| 158 | - if (err !== null) { | ||
| 159 | - err.stdout = stdout; | ||
| 160 | - err.stderr = stderr; | ||
| 161 | - promiseReject(promise, err); | ||
| 162 | - } else { | ||
| 163 | - promiseResolve(promise, { stdout, stderr }); | ||
| 164 | - } | ||
| 153 | + return new Promise((resolve, reject) => { | ||
| 154 | + orig(...args, (err, stdout, stderr) => { | ||
| 155 | + if (err !== null) { | ||
| 156 | + err.stdout = stdout; | ||
| 157 | + err.stderr = stderr; | ||
| 158 | + reject(err); | ||
| 159 | + } else { | ||
| 160 | + resolve({ stdout, stderr }); | ||
| 161 | + } | ||
| 162 | + }); | ||
| 165 | 163 | }); | |
| 166 | - return promise; | ||
| 167 | 164 | }; | |
| 168 | 165 | }; | |
| 169 | 166 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,10 +207,7 @@ function exists(path, callback) { | |||
| 207 | 207 | ||
| 208 | 208 | Object.defineProperty(exists, internalUtil.promisify.custom, { | |
| 209 | 209 | value: (path) => { | |
| 210 | - const { createPromise, promiseResolve } = process.binding('util'); | ||
| 211 | - const promise = createPromise(); | ||
| 212 | - fs.exists(path, (exists) => promiseResolve(promise, exists)); | ||
| 213 | - return promise; | ||
| 210 | + return new Promise((resolve) => fs.exists(path, resolve)); | ||
| 214 | 211 | } | |
| 215 | 212 | }); | |
| 216 | 213 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -113,7 +113,6 @@ const { isArrayBufferView } = require('internal/util/types'); | |||
| 113 | 113 | const { FileHandle } = process.binding('fs'); | |
| 114 | 114 | const binding = process.binding('http2'); | |
| 115 | 115 | const { ShutdownWrap } = process.binding('stream_wrap'); | |
| 116 | - const { createPromise, promiseResolve } = process.binding('util'); | ||
| 117 | 116 | const { UV_EOF } = process.binding('uv'); | |
| 118 | 117 | ||
| 119 | 118 | const { StreamPipe } = internalBinding('stream_pipe'); | |
@@ -2747,11 +2746,9 @@ function connect(authority, options, listener) { | |||
| 2747 | 2746 | // Support util.promisify | |
| 2748 | 2747 | Object.defineProperty(connect, promisify.custom, { | |
| 2749 | 2748 | value: (authority, options) => { | |
| 2750 | - const promise = createPromise(); | ||
| 2751 | - const server = connect(authority, | ||
| 2752 | - options, | ||
| 2753 | - () => promiseResolve(promise, server)); | ||
| 2754 | - return promise; | ||
| 2749 | + return new Promise((resolve) => { | ||
| 2750 | + const server = connect(authority, options, () => resolve(server)); | ||
| 2751 | + }); | ||
| 2755 | 2752 | } | |
| 2756 | 2753 | }); | |
| 2757 | 2754 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,10 +8,7 @@ const { | |||
| 8 | 8 | const { signals } = process.binding('constants').os; | |
| 9 | 9 | ||
| 10 | 10 | const { | |
| 11 | - createPromise, | ||
| 12 | 11 | getHiddenValue, | |
| 13 | - promiseResolve, | ||
| 14 | - promiseReject, | ||
| 15 | 12 | setHiddenValue, | |
| 16 | 13 | arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex, | |
| 17 | 14 | decorated_private_symbol: kDecoratedPrivateSymbolIndex | |
@@ -276,24 +273,21 @@ function promisify(original) { | |||
| 276 | 273 | const argumentNames = original[kCustomPromisifyArgsSymbol]; | |
| 277 | 274 | ||
| 278 | 275 | function fn(...args) { | |
| 279 | - const promise = createPromise(); | ||
| 280 | - try { | ||
| 276 | + return new Promise((resolve, reject) => { | ||
| 281 | 277 | original.call(this, ...args, (err, ...values) => { | |
| 282 | 278 | if (err) { | |
| 283 | - promiseReject(promise, err); | ||
| 284 | - } else if (argumentNames !== undefined && values.length > 1) { | ||
| 279 | + return reject(err); | ||
| 280 | + } | ||
| 281 | + if (argumentNames !== undefined && values.length > 1) { | ||
| 285 | 282 | const obj = {}; | |
| 286 | 283 | for (var i = 0; i < argumentNames.length; i++) | |
| 287 | 284 | obj[argumentNames[i]] = values[i]; | |
| 288 | - promiseResolve(promise, obj); | ||
| 285 | + resolve(obj); | ||
| 289 | 286 | } else { | |
| 290 | - promiseResolve(promise, values[0]); | ||
| 287 | + resolve(values[0]); | ||
| 291 | 288 | } | |
| 292 | 289 | }); | |
| 293 | - } catch (err) { | ||
| 294 | - promiseReject(promise, err); | ||
| 295 | - } | ||
| 296 | - return promise; | ||
| 290 | + }); | ||
| 297 | 291 | } | |
| 298 | 292 | ||
| 299 | 293 | Object.setPrototypeOf(fn, Object.getPrototypeOf(original)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,6 @@ const { | |||
| 34 | 34 | validateTimerDuration | |
| 35 | 35 | } = require('internal/timers'); | |
| 36 | 36 | const internalUtil = require('internal/util'); | |
| 37 | - const { createPromise, promiseResolve } = process.binding('util'); | ||
| 38 | 37 | const assert = require('assert'); | |
| 39 | 38 | const util = require('util'); | |
| 40 | 39 | const { ERR_INVALID_CALLBACK } = require('internal/errors').codes; | |
@@ -407,11 +406,9 @@ function setTimeout(callback, after, arg1, arg2, arg3) { | |||
| 407 | 406 | } | |
| 408 | 407 | ||
| 409 | 408 | setTimeout[internalUtil.promisify.custom] = function(after, value) { | |
| 410 | - const promise = createPromise(); | ||
| 411 | - const timeout = new Timeout(promise, after, [value], false, false); | ||
| 412 | - active(timeout); | ||
| 413 | - | ||
| 414 | - return promise; | ||
| 409 | + return new Promise((resolve) => { | ||
| 410 | + active(new Timeout(resolve, after, [value], false, false)); | ||
| 411 | + }); | ||
| 415 | 412 | }; | |
| 416 | 413 | ||
| 417 | 414 | exports.setTimeout = setTimeout; | |
@@ -420,7 +417,7 @@ exports.setTimeout = setTimeout; | |||
| 420 | 417 | function ontimeout(timer, start) { | |
| 421 | 418 | const args = timer._timerArgs; | |
| 422 | 419 | if (typeof timer._onTimeout !== 'function') | |
| 423 | - return promiseResolve(timer._onTimeout, args[0]); | ||
| 420 | + return Promise.resolve(timer._onTimeout, args[0]); | ||
| 424 | 421 | if (start === undefined && timer._repeat) | |
| 425 | 422 | start = TimerWrap.now(); | |
| 426 | 423 | if (!args) | |
@@ -691,7 +688,7 @@ function tryOnImmediate(immediate, oldTail, count, refCount) { | |||
| 691 | 688 | function runCallback(timer) { | |
| 692 | 689 | const argv = timer._argv; | |
| 693 | 690 | if (typeof timer._onImmediate !== 'function') | |
| 694 | - return promiseResolve(timer._onImmediate, argv[0]); | ||
| 691 | + return Promise.resolve(timer._onImmediate, argv[0]); | ||
| 695 | 692 | if (!argv) | |
| 696 | 693 | return timer._onImmediate(); | |
| 697 | 694 | Reflect.apply(timer._onImmediate, timer, argv); | |
@@ -766,9 +763,7 @@ function setImmediate(callback, arg1, arg2, arg3) { | |||
| 766 | 763 | } | |
| 767 | 764 | ||
| 768 | 765 | setImmediate[internalUtil.promisify.custom] = function(value) { | |
| 769 | - const promise = createPromise(); | ||
| 770 | - new Immediate(promise, [value]); | ||
| 771 | - return promise; | ||
| 766 | + return new Promise((resolve) => new Immediate(resolve, [value])); | ||
| 772 | 767 | }; | |
| 773 | 768 | ||
| 774 | 769 | exports.setImmediate = setImmediate; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,6 @@ using v8::Context; | |||
| 9 | 9 | using v8::FunctionCallbackInfo; | |
| 10 | 10 | using v8::Integer; | |
| 11 | 11 | using v8::Local; | |
| 12 | - using v8::Maybe; | ||
| 13 | 12 | using v8::Object; | |
| 14 | 13 | using v8::Private; | |
| 15 | 14 | using v8::Promise; | |
@@ -127,36 +126,6 @@ void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) { | |||
| 127 | 126 | args.GetReturnValue().Set(ret); | |
| 128 | 127 | } | |
| 129 | 128 | ||
| 130 | - | ||
| 131 | - void CreatePromise(const FunctionCallbackInfo<Value>& args) { | ||
| 132 | - Local<Context> context = args.GetIsolate()->GetCurrentContext(); | ||
| 133 | - auto maybe_resolver = Promise::Resolver::New(context); | ||
| 134 | - if (!maybe_resolver.IsEmpty()) | ||
| 135 | - args.GetReturnValue().Set(maybe_resolver.ToLocalChecked()); | ||
| 136 | - } | ||
| 137 | - | ||
| 138 | - | ||
| 139 | - void PromiseResolve(const FunctionCallbackInfo<Value>& args) { | ||
| 140 | - Local<Context> context = args.GetIsolate()->GetCurrentContext(); | ||
| 141 | - Local<Value> promise = args[0]; | ||
| 142 | - CHECK(promise->IsPromise()); | ||
| 143 | - if (promise.As<Promise>()->State() != Promise::kPending) return; | ||
| 144 | - Local<Promise::Resolver> resolver = promise.As<Promise::Resolver>(); // sic | ||
| 145 | - Maybe<bool> ret = resolver->Resolve(context, args[1]); | ||
| 146 | - args.GetReturnValue().Set(ret.FromMaybe(false)); | ||
| 147 | - } | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - void PromiseReject(const FunctionCallbackInfo<Value>& args) { | ||
| 151 | - Local<Context> context = args.GetIsolate()->GetCurrentContext(); | ||
| 152 | - Local<Value> promise = args[0]; | ||
| 153 | - CHECK(promise->IsPromise()); | ||
| 154 | - if (promise.As<Promise>()->State() != Promise::kPending) return; | ||
| 155 | - Local<Promise::Resolver> resolver = promise.As<Promise::Resolver>(); // sic | ||
| 156 | - Maybe<bool> ret = resolver->Reject(context, args[1]); | ||
| 157 | - args.GetReturnValue().Set(ret.FromMaybe(false)); | ||
| 158 | - } | ||
| 159 | - | ||
| 160 | 129 | void SafeGetenv(const FunctionCallbackInfo<Value>& args) { | |
| 161 | 130 | CHECK(args[0]->IsString()); | |
| 162 | 131 | Utf8Value strenvtag(args.GetIsolate(), args[0]); | |
@@ -211,10 +180,6 @@ void Initialize(Local<Object> target, | |||
| 211 | 180 | env->SetMethodNoSideEffect(target, "watchdogHasPendingSigint", | |
| 212 | 181 | WatchdogHasPendingSigint); | |
| 213 | 182 | ||
| 214 | - env->SetMethodNoSideEffect(target, "createPromise", CreatePromise); | ||
| 215 | - env->SetMethod(target, "promiseResolve", PromiseResolve); | ||
| 216 | - env->SetMethod(target, "promiseReject", PromiseReject); | ||
| 217 | - | ||
| 218 | 183 | env->SetMethod(target, "safeGetenv", SafeGetenv); | |
| 219 | 184 | } | |
| 220 | 185 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments