Skip to content

Commit 14cd6b9

Browse files
committed
feat(runtime): native MessagePort, MessageChannel, BroadcastChannel, and node:worker_threads
Ports are Node's three-way split without libuv: an isolate-free PortData (mutex-guarded queue, sibling-group entanglement) under a per-isolate NativeMessagePort whose wake is a coalesced EventLoop::PostInternal — producers never take a foreign isolate's Locker. Pairwise channels and named BroadcastChannel groups share one SiblingGroup mechanism; close sentinels are empty messages ordered behind queued traffic. Ports transfer through postMessage and structuredClone as host-object tag 2 on the DOMException wire format: index in-stream, PortData out-of-band, nothing detached until the whole graph has written, and received ports pre-constructed before ReadValue since no JS may run inside ReadHostObject. In passing this fixes claimed host objects suppressing V8's embedder-field detection (ObjC wrappers were written as plain objects once any DOMException existed) and a dangling handle in Deserialize's ports out-parameter. Worker and the worker global scope are now real EventTargets: delivery dispatches MessageEvents through defineEventHandler-backed onmessage attributes (position-fixed HTML handler semantics), replacing the direct property calls. Handler wrappers live on the target's own listener bag — a WeakMap keyed by ObjectManager-registered objects corrupts the heap when the finalizer resurrects them. node:worker_threads ships the real MessageChannel/MessagePort/ BroadcastChannel/receiveMessageOnPort/threadId/environment-data surface with documented shims for the rest (docs/worker-threads.md). New globals ride the lazy tier: MessagePort, MessageChannel, BroadcastChannel, MessageEvent. Suite: 1664/0 (+154 messaging specs in the shared submodule).
1 parent 0e243e6 commit 14cd6b9

28 files changed

Lines changed: 3100 additions & 156 deletions

‎NativeScript/runtime/LazyGlobals.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Base64.h"
44
#include "BuiltinLoader.h"
55
#include "Helpers.h"
6+
#include "Messaging.h"
67
#include "StructuredSerialization.h"
78
#include "TextEncoding.h"
89

@@ -39,6 +40,11 @@ constexpr LazyGlobalEntry kLazyGlobals[] = {
3940
// events.js is an eager builtin (Events::Init), so this row never runs a
4041
// file: the read hits the exports cache and only the placement is lazy.
4142
{"CustomEvent", "CustomEvent", BuiltinExports<BuiltinId::kEvents>},
43+
{"MessageEvent", "MessageEvent", BuiltinExports<BuiltinId::kMessageEvent>},
44+
{"MessagePort", "MessagePort", messaging::GetMessageChannelExports},
45+
{"MessageChannel", "MessageChannel", messaging::GetMessageChannelExports},
46+
{"BroadcastChannel", "BroadcastChannel",
47+
messaging::GetBroadcastChannelExports},
4248
};
4349

4450
void LazyGlobalGetter(Local<v8::Name> property,

0 commit comments

Comments
 (0)