Commit Graph

22 Commits

Author SHA1 Message Date
flakey5
64ad66bc99 lib: refactor transferable AbortSignal
Co-authored-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/44048
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-08-04 08:40:50 -07:00
Joyee Cheung
73ba8830d5
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: https://github.com/nodejs/node/pull/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>
2022-07-16 07:07:53 +01:00
Antoine du Hamel
06d8606960
lib: use null-prototype objects for property descriptors
Refs: https://github.com/nodejs/node/pull/42921

PR-URL: https://github.com/nodejs/node/pull/43270
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
2022-06-03 09:23:58 +01:00
Joyee Cheung
eb7b89c829
lib: update class fields TODO in abort_controller.js
https://bugs.chromium.org/p/v8/issues/detail?id=10704 is already
fixed, but since AbortController currently throws ERR_INVALID_THIS
we'll revert to class fields in a subsequent patch. For now just
update the comments.

PR-URL: https://github.com/nodejs/node/pull/42361
Refs: b1c3909bd7
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2022-03-23 20:07:53 +08:00
Mestery
998e5acc69
lib: move kEnumerableProperty to internal/util
PR-URL: https://github.com/nodejs/node/pull/41877
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-02-11 17:30:47 +00:00
James M Snell
29a909ab22 lib: make AbortSignal cloneable/transferable
Allows for using `AbortSignal` across worker threads and contexts.

```js
const ac = new AbortController();
const mc = new MessageChannel();
mc.port1.onmessage = ({ data }) => {
  data.addEventListener('abort', () => {
    console.log('aborted!');
  });
};
mc.port2.postMessage(ac.signal, [ac.signal]);
```

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/41050
Refs: https://github.com/whatwg/dom/issues/948
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2021-12-10 19:22:05 -08:00
James M Snell
3f72c72bbb
lib: add abortSignal.throwIfAborted()
Refs: https://github.com/whatwg/dom/pull/1034
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/40951
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2021-12-10 07:51:41 -08:00
James M Snell
722f113e0d
lib: add AbortSignal.timeout
Refs: https://github.com/whatwg/dom/pull/1032
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/40899
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2021-12-01 16:26:24 -08:00
James M Snell
7633c86eeb
lib: add reason to AbortSignal
A new reason property was recently added to the AbortSignal spec.

```js
const ac = new AbortController();
ac.abort(new Error('boom!'));
console.loc(ac.signal.reason);  // Error('boom!');
```

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/40807
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2021-11-24 06:46:43 -08:00
Mestery
2913211ba8 lib: use ERR_ILLEGAL_CONSTRUCTOR
Use ERR_ILLEGAL_CONSTRUCTOR error instead of `illegal constructor` or
`Illegal constructor` TypeError.

PR-URL: https://github.com/nodejs/node/pull/39556
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2021-08-01 14:24:26 +00:00
James M Snell
fa0c6883a6
stream: implement WHATWG streams
Experimental implementation of the WHATWG streams standard.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/39062
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2021-06-30 12:54:41 -07:00
Mattias Buelens
feaeb76d12
lib: add brand checks to AbortController and AbortSignal
PR-URL: https://github.com/nodejs/node/pull/37720
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2021-03-19 12:30:56 -07:00
James M Snell
263bf4e2e7
lib: implement AbortSignal.abort()
Refs: https://github.com/whatwg/dom/pull/960

PR-URL: https://github.com/nodejs/node/pull/37693
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2021-03-15 08:20:25 -07:00
James M Snell
513764b580
events: graduate Event, EventTarget, AbortController
Graduate these from experimental status

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/35949
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2020-11-23 09:33:41 -08:00
Benjamin Gruenbaum
d7bfa58942 lib: set abort-controller toStringTag
PR-URL: https://github.com/nodejs/node/pull/36115
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-11-19 15:56:51 +00:00
raisinten
22293eab48 events: disabled manual construction AbortSignal
Fixes: https://github.com/nodejs/node/issues/36064

PR-URL: https://github.com/nodejs/node/pull/36094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-11-14 14:46:30 +00:00
Benjamin Gruenbaum
1c99cdebbc events: define abort on prototype
PR-URL: https://github.com/nodejs/node/pull/35931
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-11-07 18:12:28 +02:00
Daijiro Wachi
44571d18e5 lib: let abort_controller target be EventTarget
The AbortController abort event should have EventTarget as a target
property of the argument event.

PR-URL: https://github.com/nodejs/node/pull/35869
Refs: https://github.com/web-platform-tests/wpt/blob/master/dom/abort/event.any.js
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2020-11-01 10:16:54 +09:00
Benjamin Gruenbaum
f20a783a31 events: make abort_controller event trusted
The AbortController abort event is trusted, currently we fire all
events with isTrusted: false. Allow dispatching events
internally with `isTrusted: true` and add a test for it.

Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com>
Fixes: https://github.com/nodejs/node/issues/35748

PR-URL: https://github.com/nodejs/node/pull/35811
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-10-28 18:33:03 +00:00
Michaël Zasso
a8806535d9
lib: use Object static properties from primordials
PR-URL: https://github.com/nodejs/node/pull/35380
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
2020-09-30 17:52:35 +02:00
Joyee Cheung
b1c3909bd7
lib: initialize instance members in class constructors
Since V8 snapshot does not currently support instance member
initialization, initialize them in ordianry class constructors
for now so that these classes can be included in the snapshot.
This may be reverted once
https://bugs.chromium.org/p/v8/issues/detail?id=10704
is fixed and backported.

PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-07-18 11:23:20 +08:00
James M Snell
74ca960aac
lib: initial experimental AbortController implementation
AbortController impl based very closely on:
 https://github.com/mysticatea/abort-controller

Marked experimental.
Not currently used by any of the existing promise apis.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/33527
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-06-05 12:21:47 -07:00