| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 12023df commit e795547
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,10 +24,10 @@ const { | |||
| 24 | 24 | validateObject, | |
| 25 | 25 | } = require('internal/validators'); | |
| 26 | 26 | ||
| 27 | - function cancelListenerHandler(clear, reject) { | ||
| 27 | + function cancelListenerHandler(clear, reject, signal) { | ||
| 28 | 28 | if (!this._destroyed) { | |
| 29 | 29 | clear(this); | |
| 30 | - reject(new AbortError()); | ||
| 30 | + reject(new AbortError(undefined, { cause: signal?.reason })); | ||
| 31 | 31 | } | |
| 32 | 32 | } | |
| 33 | 33 | ||
@@ -57,7 +57,7 @@ function setTimeout(after, value, options = {}) { | |||
| 57 | 57 | // to 12.x, then this can be converted to use optional chaining to | |
| 58 | 58 | // simplify the check. | |
| 59 | 59 | if (signal && signal.aborted) { | |
| 60 | - return PromiseReject(new AbortError()); | ||
| 60 | + return PromiseReject(new AbortError(undefined, { cause: signal.reason })); | ||
| 61 | 61 | } | |
| 62 | 62 | let oncancel; | |
| 63 | 63 | const ret = new Promise((resolve, reject) => { | |
@@ -66,7 +66,7 @@ function setTimeout(after, value, options = {}) { | |||
| 66 | 66 | if (signal) { | |
| 67 | 67 | oncancel = FunctionPrototypeBind(cancelListenerHandler, | |
| 68 | 68 | // eslint-disable-next-line no-undef | |
| 69 | - timeout, clearTimeout, reject); | ||
| 69 | + timeout, clearTimeout, reject, signal); | ||
| 70 | 70 | signal.addEventListener('abort', oncancel); | |
| 71 | 71 | } | |
| 72 | 72 | }); | |
@@ -101,7 +101,7 @@ function setImmediate(value, options = {}) { | |||
| 101 | 101 | // to 12.x, then this can be converted to use optional chaining to | |
| 102 | 102 | // simplify the check. | |
| 103 | 103 | if (signal && signal.aborted) { | |
| 104 | - return PromiseReject(new AbortError()); | ||
| 104 | + return PromiseReject(new AbortError(undefined, { cause: signal.reason })); | ||
| 105 | 105 | } | |
| 106 | 106 | let oncancel; | |
| 107 | 107 | const ret = new Promise((resolve, reject) => { | |
@@ -110,7 +110,8 @@ function setImmediate(value, options = {}) { | |||
| 110 | 110 | if (signal) { | |
| 111 | 111 | oncancel = FunctionPrototypeBind(cancelListenerHandler, | |
| 112 | 112 | // eslint-disable-next-line no-undef | |
| 113 | - immediate, clearImmediate, reject); | ||
| 113 | + immediate, clearImmediate, reject, | ||
| 114 | + signal); | ||
| 114 | 115 | signal.addEventListener('abort', oncancel); | |
| 115 | 116 | } | |
| 116 | 117 | }); | |
@@ -127,7 +128,7 @@ async function* setInterval(after, value, options = {}) { | |||
| 127 | 128 | validateBoolean(ref, 'options.ref'); | |
| 128 | 129 | ||
| 129 | 130 | if (signal?.aborted) | |
| 130 | - throw new AbortError(); | ||
| 131 | + throw new AbortError(undefined, { cause: signal?.reason }); | ||
| 131 | 132 | ||
| 132 | 133 | let onCancel; | |
| 133 | 134 | let interval; | |
@@ -147,7 +148,9 @@ async function* setInterval(after, value, options = {}) { | |||
| 147 | 148 | // eslint-disable-next-line no-undef | |
| 148 | 149 | clearInterval(interval); | |
| 149 | 150 | if (callback) { | |
| 150 | - callback(PromiseReject(new AbortError())); | ||
| 151 | + callback( | ||
| 152 | + PromiseReject( | ||
| 153 | + new AbortError(undefined, { cause: signal.reason }))); | ||
| 151 | 154 | callback = undefined; | |
| 152 | 155 | } | |
| 153 | 156 | }; | |
@@ -162,7 +165,7 @@ async function* setInterval(after, value, options = {}) { | |||
| 162 | 165 | yield value; | |
| 163 | 166 | } | |
| 164 | 167 | } | |
| 165 | - throw new AbortError(); | ||
| 168 | + throw new AbortError(undefined, { cause: signal?.reason }); | ||
| 166 | 169 | } finally { | |
| 167 | 170 | // eslint-disable-next-line no-undef | |
| 168 | 171 | clearInterval(interval); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,3 +97,10 @@ process.on('multipleResolves', common.mustNotCall()); | |||
| 97 | 97 | assert.strictEqual(stderr, ''); | |
| 98 | 98 | })); | |
| 99 | 99 | } | |
| 100 | + | ||
| 101 | + (async () => { | ||
| 102 | + const signal = AbortSignal.abort('boom'); | ||
| 103 | + await assert.rejects(timerPromises.setImmediate(undefined, { signal }), { | ||
| 104 | + cause: 'boom', | ||
| 105 | + }); | ||
| 106 | + })().then(common.mustCall()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -246,3 +246,15 @@ process.on('multipleResolves', common.mustNotCall()); | |||
| 246 | 246 | setPromiseTimeout(time_unit * 3).then(() => post = true), | |
| 247 | 247 | ]).then(common.mustCall()); | |
| 248 | 248 | } | |
| 249 | + | ||
| 250 | + (async () => { | ||
| 251 | + const signal = AbortSignal.abort('boom'); | ||
| 252 | + try { | ||
| 253 | + const iterable = timerPromises.setInterval(2, undefined, { signal }); | ||
| 254 | + // eslint-disable-next-line no-unused-vars | ||
| 255 | + for await (const _ of iterable) {} | ||
| 256 | + assert.fail('should have failed'); | ||
| 257 | + } catch (err) { | ||
| 258 | + assert.strictEqual(err.cause, 'boom'); | ||
| 259 | + } | ||
| 260 | + })().then(common.mustCall()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,3 +97,10 @@ process.on('multipleResolves', common.mustNotCall()); | |||
| 97 | 97 | assert.strictEqual(stderr, ''); | |
| 98 | 98 | })); | |
| 99 | 99 | } | |
| 100 | + | ||
| 101 | + (async () => { | ||
| 102 | + const signal = AbortSignal.abort('boom'); | ||
| 103 | + await assert.rejects(timerPromises.setTimeout(1, undefined, { signal }), { | ||
| 104 | + cause: 'boom', | ||
| 105 | + }); | ||
| 106 | + })().then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments