GeezerVison is showing github.com — lib: add EventTarget-related browser globals · ide/node@eee522a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -287,6 +287,11 @@ module.exports = { | 287 | 287 | BigInt: 'readable', | 288 | 288 | BigInt64Array: 'readable', | 289 | 289 | BigUint64Array: 'readable', | | 290 | + Event: 'readable', | | 291 | + EventTarget: 'readable', | | 292 | + MessageChannel: 'readable', | | 293 | + MessageEvent: 'readable', | | 294 | + MessagePort: 'readable', | 290 | 295 | TextEncoder: 'readable', | 291 | 296 | TextDecoder: 'readable', | 292 | 297 | queueMicrotask: 'readable', | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/events.md +18-3Lines changed: 18 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1069,9 +1069,15 @@ const ac = new AbortController(); | 1069 | 1069 | process.nextTick(() => ac.abort()); | 1070 | 1070 | ``` | 1071 | 1071 |
| | 1072 | +<a id="event-target-and-event-api"></a> | 1072 | 1073 | ## `EventTarget` and `Event` API | 1073 | 1074 | <!-- YAML | 1074 | 1075 | added: v14.5.0 | | 1076 | +changes: | | 1077 | + - version: REPLACEME | | 1078 | + pr-url: https://github.com/nodejs/node/pull/35496 | | 1079 | + description: | | 1080 | + The `EventTarget` and `Event` classes are now available as globals. | 1075 | 1081 | --> | 1076 | 1082 |
| 1077 | 1083 | > Stability: 1 - Experimental | @@ -1082,7 +1088,7 @@ Neither the `EventTarget` nor `Event` classes are available for end | 1082 | 1088 | user code to create. | 1083 | 1089 |
| 1084 | 1090 | ```js | 1085 | | -const target = getEventTargetSomehow(); | | 1091 | +const target = new EventTarget(); | 1086 | 1092 |
| 1087 | 1093 | target.addEventListener('foo', (event) => { | 1088 | 1094 | console.log('foo event happened!'); | @@ -1168,7 +1174,7 @@ const handler4 = { | 1168 | 1174 | } | 1169 | 1175 | }; | 1170 | 1176 |
| 1171 | | -const target = getEventTargetSomehow(); | | 1177 | +const target = new EventTarget(); | 1172 | 1178 |
| 1173 | 1179 | target.addEventListener('foo', handler1); | 1174 | 1180 | target.addEventListener('foo', handler2); | @@ -1189,6 +1195,10 @@ The `EventTarget` does not implement any special default handling for | 1189 | 1195 | ### Class: `Event` | 1190 | 1196 | <!-- YAML | 1191 | 1197 | added: v14.5.0 | | 1198 | +changes: | | 1199 | + - version: REPLACEME | | 1200 | + pr-url: https://github.com/nodejs/node/pull/35496 | | 1201 | + description: The `Event` class is now available through the global object. | 1192 | 1202 | --> | 1193 | 1203 |
| 1194 | 1204 | The `Event` object is an adaptation of the [`Event` Web API][]. Instances | @@ -1341,6 +1351,11 @@ The event type identifier. | 1341 | 1351 | ### Class: `EventTarget` | 1342 | 1352 | <!-- YAML | 1343 | 1353 | added: v14.5.0 | | 1354 | +changes: | | 1355 | + - version: REPLACEME | | 1356 | + pr-url: https://github.com/nodejs/node/pull/35496 | | 1357 | + description: | | 1358 | + The `EventTarget` class is now available through the global object. | 1344 | 1359 | --> | 1345 | 1360 |
| 1346 | 1361 | #### `eventTarget.addEventListener(type, listener[, options])` | @@ -1374,7 +1389,7 @@ a `listener`. Any individual `listener` may be added once with | 1374 | 1389 | ```js | 1375 | 1390 | function handler(event) {} | 1376 | 1391 |
| 1377 | | -const target = getEventTargetSomehow(); | | 1392 | +const target = new EventTarget(); | 1378 | 1393 | target.addEventListener('foo', handler, { capture: true }); // first | 1379 | 1394 | target.addEventListener('foo', handler, { capture: false }); // second | 1380 | 1395 |
| |
Collapse file Copy file name to clipboardExpand all lines: doc/api/globals.md +55Lines changed: 55 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -169,6 +169,30 @@ added: v0.1.100 | 169 | 169 |
| 170 | 170 | Used to print to stdout and stderr. See the [`console`][] section. | 171 | 171 |
| | 172 | +## `Event` | | 173 | +<!-- YAML | | 174 | +added: REPLACEME | | 175 | +--> | | 176 | + | | 177 | +<!-- type=global --> | | 178 | + | | 179 | +> Stability: 1 - Experimental | | 180 | +
| | 181 | +A browser-compatible implementation of the `Event` class. See | | 182 | +[`EventTarget` and `Event` API][] for more details. | | 183 | + | | 184 | +## `EventTarget` | | 185 | +<!-- YAML | | 186 | +added: REPLACEME | | 187 | +--> | | 188 | + | | 189 | +<!-- type=global --> | | 190 | + | | 191 | +> Stability: 1 - Experimental | | 192 | +
| | 193 | +A browser-compatible implementation of the `EventTarget` class. See | | 194 | +[`EventTarget` and `Event` API][] for more details. | | 195 | + | 172 | 196 | ## `exports` | 173 | 197 |
| 174 | 198 | This variable may appear to be global but is not. See [`exports`][]. | @@ -187,6 +211,33 @@ within the browser `var something` will define a new global variable. In | 187 | 211 | Node.js this is different. The top-level scope is not the global scope; | 188 | 212 | `var something` inside a Node.js module will be local to that module. | 189 | 213 |
| | 214 | +## `MessageChannel` | | 215 | +<!-- YAML | | 216 | +added: REPLACEME | | 217 | +--> | | 218 | + | | 219 | +<!-- type=global --> | | 220 | + | | 221 | +The `MessageChannel` class. See [`MessageChannel`][] for more details. | | 222 | + | | 223 | +## `MessageEvent` | | 224 | +<!-- YAML | | 225 | +added: REPLACEME | | 226 | +--> | | 227 | + | | 228 | +<!-- type=global --> | | 229 | + | | 230 | +The `MessageEvent` class. See [`MessageEvent`][] for more details. | | 231 | + | | 232 | +## `MessagePort` | | 233 | +<!-- YAML | | 234 | +added: REPLACEME | | 235 | +--> | | 236 | + | | 237 | +<!-- type=global --> | | 238 | + | | 239 | +The `MessagePort` class. See [`MessagePort`][] for more details. | | 240 | + | 190 | 241 | ## `module` | 191 | 242 |
| 192 | 243 | This variable may appear to be global but is not. See [`module`][]. | @@ -322,6 +373,10 @@ The object that acts as the namespace for all W3C | 322 | 373 | [Mozilla Developer Network][webassembly-mdn] for usage and compatibility. | 323 | 374 |
| 324 | 375 | [`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController | | 376 | +[`EventTarget` and `Event` API]: events.md#event-target-and-event-api | | 377 | +[`MessageChannel`]: worker_threads.md#worker_threads_class_messagechannel | | 378 | +[`MessageEvent`]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/MessageEvent | | 379 | +[`MessagePort`]: worker_threads.md#worker_threads_class_messageport | 325 | 380 | [`TextDecoder`]: util.md#util_class_util_textdecoder | 326 | 381 | [`TextEncoder`]: util.md#util_class_util_textencoder | 327 | 382 | [`URLSearchParams`]: url.md#url_class_urlsearchparams | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -140,6 +140,21 @@ if (!config.noBrowserGlobals) { | 140 | 140 | exposeInterface(global, 'AbortController', AbortController); | 141 | 141 | exposeInterface(global, 'AbortSignal', AbortSignal); | 142 | 142 |
| | 143 | + const { | | 144 | + EventTarget, | | 145 | + Event, | | 146 | + } = require('internal/event_target'); | | 147 | + exposeInterface(global, 'EventTarget', EventTarget); | | 148 | + exposeInterface(global, 'Event', Event); | | 149 | + const { | | 150 | + MessageChannel, | | 151 | + MessagePort, | | 152 | + MessageEvent, | | 153 | + } = require('internal/worker/io'); | | 154 | + exposeInterface(global, 'MessageChannel', MessageChannel); | | 155 | + exposeInterface(global, 'MessagePort', MessagePort); | | 156 | + exposeInterface(global, 'MessageEvent', MessageEvent); | | 157 | + | 143 | 158 | // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope | 144 | 159 | const timers = require('timers'); | 145 | 160 | defineOperation(global, 'clearInterval', timers.clearInterval); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_external_reference.h +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -64,7 +64,8 @@ class ExternalReferenceRegistry { | 64 | 64 | V(string_decoder) \ | 65 | 65 | V(trace_events) \ | 66 | 66 | V(timers) \ | 67 | | - V(types) | | 67 | + V(types) \ | | 68 | + V(worker) | 68 | 69 |
| 69 | 70 | #if NODE_HAVE_I18N_SUPPORT | 70 | 71 | #define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu) | |
Collapse file Copy file name to clipboardExpand all lines: src/node_worker.cc +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | #include "debug_utils-inl.h" | 3 | 3 | #include "memory_tracker-inl.h" | 4 | 4 | #include "node_errors.h" | | 5 | +#include "node_external_reference.h" | 5 | 6 | #include "node_buffer.h" | 6 | 7 | #include "node_options-inl.h" | 7 | 8 | #include "node_perf.h" | @@ -860,9 +861,20 @@ void InitWorker(Local<Object> target, | 860 | 861 | NODE_DEFINE_CONSTANT(target, kTotalResourceLimitCount); | 861 | 862 | } | 862 | 863 |
| 863 | | -} // anonymous namespace | | 864 | +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | | 865 | + registry->Register(GetEnvMessagePort); | | 866 | + registry->Register(Worker::New); | | 867 | + registry->Register(Worker::StartThread); | | 868 | + registry->Register(Worker::StopThread); | | 869 | + registry->Register(Worker::Ref); | | 870 | + registry->Register(Worker::Unref); | | 871 | + registry->Register(Worker::GetResourceLimits); | | 872 | + registry->Register(Worker::TakeHeapSnapshot); | | 873 | +} | 864 | 874 |
| | 875 | +} // anonymous namespace | 865 | 876 | } // namespace worker | 866 | 877 | } // namespace node | 867 | 878 |
| 868 | 879 | NODE_MODULE_CONTEXT_AWARE_INTERNAL(worker, node::worker::InitWorker) | | 880 | +NODE_MODULE_EXTERNAL_REFERENCE(worker, node::worker::RegisterExternalReferences) |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-bootstrap-modules.js +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,6 +31,7 @@ const expectedModules = new Set([ | 31 | 31 | 'Internal Binding types', | 32 | 32 | 'Internal Binding url', | 33 | 33 | 'Internal Binding util', | | 34 | + 'Internal Binding worker', | 34 | 35 | 'NativeModule buffer', | 35 | 36 | 'NativeModule events', | 36 | 37 | 'NativeModule fs', | @@ -76,6 +77,17 @@ const expectedModules = new Set([ | 76 | 77 | 'NativeModule internal/process/warning', | 77 | 78 | 'NativeModule internal/querystring', | 78 | 79 | 'NativeModule internal/source_map/source_map_cache', | | 80 | + 'NativeModule internal/streams/buffer_list', | | 81 | + 'NativeModule internal/streams/destroy', | | 82 | + 'NativeModule internal/streams/duplex', | | 83 | + 'NativeModule internal/streams/end-of-stream', | | 84 | + 'NativeModule internal/streams/legacy', | | 85 | + 'NativeModule internal/streams/passthrough', | | 86 | + 'NativeModule internal/streams/pipeline', | | 87 | + 'NativeModule internal/streams/readable', | | 88 | + 'NativeModule internal/streams/state', | | 89 | + 'NativeModule internal/streams/transform', | | 90 | + 'NativeModule internal/streams/writable', | 79 | 91 | 'NativeModule internal/timers', | 80 | 92 | 'NativeModule internal/url', | 81 | 93 | 'NativeModule internal/util', | @@ -84,8 +96,10 @@ const expectedModules = new Set([ | 84 | 96 | 'NativeModule internal/util/types', | 85 | 97 | 'NativeModule internal/validators', | 86 | 98 | 'NativeModule internal/vm/module', | | 99 | + 'NativeModule internal/worker/io', | 87 | 100 | 'NativeModule internal/worker/js_transferable', | 88 | 101 | 'NativeModule path', | | 102 | + 'NativeModule stream', | 89 | 103 | 'NativeModule timers', | 90 | 104 | 'NativeModule url', | 91 | 105 | 'NativeModule util', | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-event-on-async-iterator.js +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,9 +5,7 @@ const common = require('../common'); | 5 | 5 | const assert = require('assert'); | 6 | 6 | const { on, EventEmitter } = require('events'); | 7 | 7 | const { | 8 | | - EventTarget, | 9 | | - NodeEventTarget, | 10 | | - Event | | 8 | + NodeEventTarget | 11 | 9 | } = require('internal/event_target'); | 12 | 10 |
| 13 | 11 | async function basic() { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-events-once.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | | -// Flags: --expose-internals --no-warnings | | 2 | +// Flags: --no-warnings | 3 | 3 |
| 4 | 4 | const common = require('../common'); | 5 | 5 | const { once, EventEmitter } = require('events'); | | 9 | 9 | fail, | 10 | 10 | rejects, | 11 | 11 | } = require('assert'); | 12 | | -const { EventTarget, Event } = require('internal/event_target'); | 13 | 12 |
| 14 | 13 | async function onceAnEvent() { | 15 | 14 | const ee = new EventEmitter(); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-eventtarget-whatwg-passive.js -6Lines changed: 0 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -// Flags: --expose-internals | 2 | 1 | 'use strict'; | 3 | 2 |
| 4 | 3 | const common = require('../common'); | 5 | 4 |
| 6 | | -const { | 7 | | - Event, | 8 | | - EventTarget, | 9 | | -} = require('internal/event_target'); | 10 | | - | 11 | 5 | const { | 12 | 6 | fail, | 13 | 7 | ok, | |
|