GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: use private field in AbortController · nodejs/node@73ba883

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • abort_controller.js
  • test/parallel
    • test-abortcontroller.js
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.