Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73ba883

Browse filesBrowse files
authored
lib: use private field in AbortController
Instead of validating the receiver ourselves, let V8 handle the validation using the semantics of private fields. PR-URL: #43820 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent e54ee80 commit 73ba883
Copy full SHA for 73ba883

File tree

Expand file treeCollapse file tree

2 files changed

+6
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-19
lines changed
Open diff view settings
Collapse file

‎lib/internal/abort_controller.js‎

Copy file name to clipboardExpand all lines: lib/internal/abort_controller.js
+3-16Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -292,34 +292,21 @@ function abortSignal(signal, reason) {
292292
signal.dispatchEvent(event);
293293
}
294294

295-
// TODO(joyeecheung): use private fields and we'll get invalid access
296-
// validation from V8 instead of throwing ERR_INVALID_THIS ourselves.
297-
const kSignal = Symbol('signal');
298-
299-
function validateAbortController(obj) {
300-
if (obj?.[kSignal] === undefined)
301-
throw new ERR_INVALID_THIS('AbortController');
302-
}
303-
304295
class AbortController {
305-
constructor() {
306-
this[kSignal] = createAbortSignal();
307-
}
296+
#signal = createAbortSignal();
308297

309298
/**
310299
* @type {AbortSignal}
311300
*/
312301
get signal() {
313-
validateAbortController(this);
314-
return this[kSignal];
302+
return this.#signal;
315303
}
316304

317305
/**
318306
* @param {any} reason
319307
*/
320308
abort(reason = new DOMException('This operation was aborted', 'AbortError')) {
321-
validateAbortController(this);
322-
abortSignal(this[kSignal], reason);
309+
abortSignal(this.#signal, reason);
323310
}
324311

325312
[customInspectSymbol](depth, options) {
Collapse file

‎test/parallel/test-abortcontroller.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-abortcontroller.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ const { setTimeout: sleep } = require('timers/promises');
108108
for (const badController of badAbortControllers) {
109109
throws(
110110
() => acSignalGet.call(badController),
111-
{ code: 'ERR_INVALID_THIS', name: 'TypeError' }
111+
{ name: 'TypeError' }
112112
);
113113
throws(
114114
() => acAbort.call(badController),
115-
{ code: 'ERR_INVALID_THIS', name: 'TypeError' }
115+
{ name: 'TypeError' }
116116
);
117117
}
118118
}
@@ -139,7 +139,7 @@ const { setTimeout: sleep } = require('timers/promises');
139139
for (const badSignal of badAbortSignals) {
140140
throws(
141141
() => signalAbortedGet.call(badSignal),
142-
{ code: 'ERR_INVALID_THIS', name: 'TypeError' }
142+
{ name: 'TypeError' }
143143
);
144144
}
145145
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.