@isoloop/runtime 0.0.0-next.69da74b → 0.0.0-next.d028bc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bootstrap.js CHANGED
@@ -20,11 +20,12 @@ var __exportAll = (all, no_symbols) => {
20
20
  // ../protocol/dist/index.js
21
21
  /**
22
22
  * True for a well-formed envelope this build can read: `v` is a supported
23
- * version, `t` is a string, `id`/`re` are absent or strings, and `p` is present.
23
+ * version, `t` is a string, `id`/`re`/`isolate` are absent or strings, and `p`
24
+ * is present.
24
25
  * Says nothing about whether `t` is known; see the per-port guards.
25
26
  */
26
27
  function isEnvelope(x) {
27
- return isRecord(x) && x["v"] === PROTOCOL.v && typeof x["t"] === "string" && "p" in x && isOptionalString(x["id"]) && isOptionalString(x["re"]);
28
+ return isRecord(x) && x["v"] === PROTOCOL.v && typeof x["t"] === "string" && "p" in x && isOptionalString(x["id"]) && isOptionalString(x["re"]) && isOptionalString(x["isolate"]);
28
29
  }
29
30
  /**
30
31
  * Builds a guard for one port's union from its message types. Each side drops
@@ -37,6 +38,69 @@ function envelopeGuard(types) {
37
38
  function isSystemTopic(topic) {
38
39
  return topic.startsWith(SYSTEM_TOPIC_PREFIX);
39
40
  }
41
+ function createCommitter(o) {
42
+ const intervalMs = o.intervalMs ?? 100;
43
+ const half = Math.max(1, Math.floor((o.credit ?? 1e3) / 2));
44
+ /** Highest settled offset per topic, not yet sent. */
45
+ const offsets = /* @__PURE__ */ new Map();
46
+ /** Records settled per topic since its last send: the early send at half the credit. */
47
+ const counts = /* @__PURE__ */ new Map();
48
+ let timer;
49
+ let queued = false;
50
+ const take = () => {
51
+ if (timer !== void 0) {
52
+ clearTimeout(timer);
53
+ timer = void 0;
54
+ }
55
+ queued = false;
56
+ if (offsets.size === 0) return void 0;
57
+ const out = [];
58
+ for (const [topic, offset] of offsets) out.push({
59
+ topic,
60
+ offset
61
+ });
62
+ offsets.clear();
63
+ counts.clear();
64
+ return out;
65
+ };
66
+ const flush = () => {
67
+ const out = take();
68
+ if (out) o.send(out);
69
+ };
70
+ const schedule = () => {
71
+ if (intervalMs === 0) {
72
+ if (queued) return;
73
+ queued = true;
74
+ queueMicrotask(() => {
75
+ if (queued) flush();
76
+ });
77
+ return;
78
+ }
79
+ timer ??= setTimeout(flush, intervalMs);
80
+ };
81
+ return {
82
+ settle(topic, offset, records = 1) {
83
+ const prev = offsets.get(topic);
84
+ if (prev === void 0 || offset > prev) offsets.set(topic, offset);
85
+ const n = (counts.get(topic) ?? 0) + records;
86
+ counts.set(topic, n);
87
+ if (n >= half) flush();
88
+ else schedule();
89
+ },
90
+ flush,
91
+ take,
92
+ drop(topic) {
93
+ offsets.delete(topic);
94
+ counts.delete(topic);
95
+ },
96
+ pending: () => offsets,
97
+ dispose() {
98
+ if (timer !== void 0) clearTimeout(timer);
99
+ timer = void 0;
100
+ queued = false;
101
+ }
102
+ };
103
+ }
40
104
  /** Wraps a hand-written check as a Standard Schema that passes valid values through unchanged. */
41
105
  function systemSchema(check) {
42
106
  return { "~standard": {
@@ -151,6 +215,117 @@ var init_dist = __esmMin((() => {
151
215
  retention: { kind: "compacted" }
152
216
  });
153
217
  }));
218
+ // src/freeze.ts
219
+ init_dist();
220
+ /** Constructors whose `prototype` and statics are frozen, if this engine has them. */
221
+ const NAMES = [
222
+ "Object",
223
+ "Function",
224
+ "Array",
225
+ "String",
226
+ "Number",
227
+ "Boolean",
228
+ "Symbol",
229
+ "BigInt",
230
+ "Date",
231
+ "RegExp",
232
+ "Error",
233
+ "EvalError",
234
+ "RangeError",
235
+ "ReferenceError",
236
+ "SyntaxError",
237
+ "TypeError",
238
+ "URIError",
239
+ "AggregateError",
240
+ "Promise",
241
+ "Map",
242
+ "Set",
243
+ "WeakMap",
244
+ "WeakSet",
245
+ "WeakRef",
246
+ "FinalizationRegistry",
247
+ "ArrayBuffer",
248
+ "DataView",
249
+ "Int8Array",
250
+ "Uint8Array",
251
+ "Uint8ClampedArray",
252
+ "Int16Array",
253
+ "Uint16Array",
254
+ "Int32Array",
255
+ "Uint32Array",
256
+ "Float32Array",
257
+ "Float64Array",
258
+ "BigInt64Array",
259
+ "BigUint64Array"
260
+ ];
261
+ /**
262
+ * Freezing a prototype makes its data properties read-only, and in strict
263
+ * code assigning a property of the same name on an instance then throws (the
264
+ * "override mistake": `this.name = 'MyError'`, `Foo.prototype.toString = …`).
265
+ * As Hardened JS does, each data property becomes an accessor whose setter
266
+ * defines the property on the instance instead, so overriding still works
267
+ * while the prototype itself can't change.
268
+ */
269
+ function tameOverrides(proto) {
270
+ for (const key of Reflect.ownKeys(proto)) {
271
+ const d = Object.getOwnPropertyDescriptor(proto, key);
272
+ if (!d || !("value" in d) || !d.configurable) continue;
273
+ const value = d.value;
274
+ Object.defineProperty(proto, key, {
275
+ get() {
276
+ return value;
277
+ },
278
+ set(v) {
279
+ if (this === proto) throw new TypeError(`Cannot assign to read only property '${String(key)}' of a frozen built-in`);
280
+ if (typeof this !== "object" && typeof this !== "function") return;
281
+ if (this === null) return;
282
+ Object.defineProperty(this, key, {
283
+ value: v,
284
+ writable: true,
285
+ enumerable: true,
286
+ configurable: true
287
+ });
288
+ },
289
+ enumerable: d.enumerable ?? false,
290
+ configurable: false
291
+ });
292
+ }
293
+ }
294
+ function hardenProto(proto) {
295
+ if (typeof proto !== "object" && typeof proto !== "function" || proto === null) return;
296
+ if (Object.isFrozen(proto)) return;
297
+ tameOverrides(proto);
298
+ Object.freeze(proto);
299
+ }
300
+ function freezeWithPrototype(c) {
301
+ if (typeof c !== "function") return;
302
+ hardenProto(Reflect.get(c, "prototype"));
303
+ if (c !== Error) Object.freeze(c);
304
+ }
305
+ /** Freezes the shared intrinsics. Call once, before any member module loads. */
306
+ function freezeBuiltins() {
307
+ const g = globalThis;
308
+ for (const name of NAMES) freezeWithPrototype(Reflect.get(g, name));
309
+ freezeWithPrototype(Object.getPrototypeOf(Int8Array));
310
+ const protos = [
311
+ Object.getPrototypeOf([][Symbol.iterator]()),
312
+ Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())),
313
+ Object.getPrototypeOf((/* @__PURE__ */ new Map())[Symbol.iterator]()),
314
+ Object.getPrototypeOf((/* @__PURE__ */ new Set())[Symbol.iterator]()),
315
+ Object.getPrototypeOf(""[Symbol.iterator]()),
316
+ Object.getPrototypeOf(function* () {}),
317
+ Object.getPrototypeOf(async function() {}),
318
+ Object.getPrototypeOf(async function* () {})
319
+ ];
320
+ for (const p of protos) {
321
+ if (typeof p !== "object" && typeof p !== "function" || p === null) continue;
322
+ hardenProto(Reflect.get(p, "prototype"));
323
+ hardenProto(p);
324
+ }
325
+ Object.freeze(Math);
326
+ Object.freeze(JSON);
327
+ Object.freeze(Reflect);
328
+ }
154
329
  // src/bus-client.ts
155
330
  function createBusClient(first, o = {}) {
156
331
  const limit = o.inboxLimit ?? 1e3;
@@ -189,15 +364,19 @@ function createBusClient(first, o = {}) {
189
364
  send(withId);
190
365
  });
191
366
  };
367
+ const committer = createCommitter({
368
+ send: (offsets) => {
369
+ send({
370
+ v: 1,
371
+ t: "commits",
372
+ p: { offsets }
373
+ });
374
+ },
375
+ ...o.commitIntervalMs === void 0 ? {} : { intervalMs: o.commitIntervalMs },
376
+ ...o.credit === void 0 ? {} : { credit: o.credit }
377
+ });
192
378
  const commit = (topic, offset) => {
193
- send({
194
- v: 1,
195
- t: "commit",
196
- p: {
197
- topic,
198
- offset
199
- }
200
- });
379
+ committer.settle(topic, offset);
201
380
  };
202
381
  const drain = async (sub) => {
203
382
  if (sub.running) return;
@@ -207,7 +386,8 @@ function createBusClient(first, o = {}) {
207
386
  if (!r) break;
208
387
  topicOf.set(r, sub.topic);
209
388
  try {
210
- await sub.fn(r);
389
+ const done = sub.fn(r);
390
+ if (isThenable(done)) await done;
211
391
  } catch (err) {
212
392
  sub.stuck = true;
213
393
  o.onError?.(err);
@@ -258,6 +438,7 @@ function createBusClient(first, o = {}) {
258
438
  const sub = subs.get(msg.p.topic);
259
439
  if (!sub) return;
260
440
  sub.queue.length = 0;
441
+ committer.drop(msg.p.topic);
261
442
  try {
262
443
  sub.opts.onReset?.();
263
444
  } catch (err) {
@@ -306,6 +487,7 @@ function createBusClient(first, o = {}) {
306
487
  return () => {
307
488
  if (subs.get(topic.name) !== sub) return;
308
489
  subs.delete(topic.name);
490
+ committer.flush();
309
491
  send({
310
492
  v: 1,
311
493
  t: "unsubscribe",
@@ -381,17 +563,29 @@ function createBusClient(first, o = {}) {
381
563
  value: null
382
564
  });
383
565
  }
566
+ committer.take();
384
567
  for (const sub of subs.values()) {
385
568
  sub.queue.length = 0;
386
569
  sendSubscribe(sub);
387
570
  }
388
571
  for (const p of unanswered) if (p.msg.t !== "subscribe") send(p.msg);
572
+ },
573
+ async close() {
574
+ const offsets = committer.take();
575
+ committer.dispose();
576
+ if (offsets) await call({
577
+ v: 1,
578
+ t: "commits",
579
+ p: { offsets }
580
+ });
389
581
  }
390
582
  };
391
583
  }
584
+ function isThenable(x) {
585
+ return (typeof x === "object" || typeof x === "function") && x !== null && typeof x.then === "function";
586
+ }
392
587
  var randomEpoch, check, REQUEST_TIMEOUT_MS;
393
588
  var init_bus_client = __esmMin((() => {
394
- init_dist();
395
589
  randomEpoch = () => crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] ?? 0;
396
590
  check = (r) => {
397
591
  if (!r.ok) throw new BusError(r.error);
@@ -516,7 +710,7 @@ var ISOLOOP_DOM_FMT;
516
710
  var init_records_wVZrPpqr = __esmMin((() => {
517
711
  ISOLOOP_DOM_FMT = "isoloop-dom@1";
518
712
  }));
519
- // ../dom/dist/dom-9S5T0UVQ.js
713
+ // ../dom/dist/dom-yLsf0Z4e.js
520
714
  function createStyle(el) {
521
715
  const decls = /* @__PURE__ */ new Map();
522
716
  const write = () => {
@@ -643,78 +837,131 @@ function serialize(n) {
643
837
  children: n.childNodes.map(serialize)
644
838
  };
645
839
  }
646
- function learn(n, core) {
840
+ /** Whether `n` or anything under it was rendered under a root other than `owner`. */
841
+ function ownedElsewhere(n, owner) {
842
+ if (n.isoOwner && n.isoOwner !== owner) return true;
843
+ return !n.isoKnown && n.childNodes.some((c) => ownedElsewhere(c, owner));
844
+ }
845
+ function learn(n, core, owner) {
647
846
  n.isoKnown = true;
847
+ n.isoOwner = owner;
648
848
  core.known.set(n.isoId, n);
649
- for (const c of n.childNodes) learn(c, core);
849
+ for (const c of n.childNodes) learn(c, core, owner);
650
850
  }
651
851
  function forget(n, core) {
652
852
  n.isoKnown = false;
653
853
  core.known.delete(n.isoId);
654
854
  for (const c of n.childNodes) forget(c, core);
655
855
  }
656
- function createDom(opts) {
657
- const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
856
+ function setValueOf(node, value, o) {
857
+ if (!isControl(node)) throw new TypeError("setValue: not an input, textarea or select");
858
+ if (!o.force) {
859
+ node.value = value;
860
+ return;
861
+ }
862
+ node.isoSetProp("value", value, false);
863
+ if (node.isoKnown) emit(node, [
864
+ "prop",
865
+ node.isoWire,
866
+ "value",
867
+ value,
868
+ true
869
+ ]);
870
+ }
871
+ function deliverTo(node, event) {
872
+ if (!node) return;
873
+ if (isControl(node) && event.value !== void 0) node.isoSetProp("value", event.value, false);
874
+ if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
875
+ if (event.type === "scroll" && node instanceof WElement) node.isoScroll = {
876
+ top: event.scrollTop ?? 0,
877
+ left: event.scrollLeft ?? 0
878
+ };
879
+ node.dispatchEvent(toEvent(event));
880
+ }
881
+ /** A root's recorder: records batched per microtask (or `schedule`) into `onBatch`. */
882
+ function recorder(root, onBatch, schedule) {
658
883
  let pending = [];
659
884
  let scheduled = false;
885
+ let live = true;
660
886
  const flush = () => {
661
887
  scheduled = false;
662
888
  if (pending.length === 0) return;
663
889
  const batch = pending;
664
890
  pending = [];
665
- opts.onBatch(batch);
891
+ if (live) onBatch(batch);
892
+ };
893
+ return {
894
+ owner: {
895
+ root,
896
+ push(r) {
897
+ if (!live) return;
898
+ pending.push(r);
899
+ if (!scheduled) {
900
+ scheduled = true;
901
+ schedule(flush);
902
+ }
903
+ }
904
+ },
905
+ flush,
906
+ stop: () => {
907
+ live = false;
908
+ pending = [];
909
+ }
666
910
  };
911
+ }
912
+ function createDom(opts) {
913
+ const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
667
914
  const core = {
668
- root: null,
915
+ roots: /* @__PURE__ */ new Set(),
669
916
  nextId: 1,
670
917
  known: /* @__PURE__ */ new Map(),
671
- onHead: opts.onHead ?? (() => {}),
672
- record(r) {
673
- pending.push(r);
674
- if (!scheduled) {
675
- scheduled = true;
676
- schedule(flush);
677
- }
678
- }
918
+ onHead: opts.onHead ?? (() => {})
679
919
  };
680
920
  const document = new WDocument(core);
681
- const root = new WHTMLElement(document, 0, "iso-root", "html");
682
- root.isoKnown = true;
683
- core.known.set(0, root);
684
- core.root = root;
921
+ const makeRoot = (id) => {
922
+ const root = new WHTMLElement(document, id, "iso-root", "html");
923
+ root.isoKnown = true;
924
+ core.known.set(id, root);
925
+ core.roots.add(root);
926
+ return root;
927
+ };
928
+ const root = makeRoot(0);
929
+ const main = recorder(root, (b) => opts.onBatch(b), schedule);
930
+ root.isoOwner = main.owner;
685
931
  return {
686
932
  document,
687
933
  root,
688
- flush,
934
+ flush: main.flush,
689
935
  idOf: (node) => node.isoId,
690
- setValue(node, value, o = {}) {
691
- if (!(node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement)) throw new TypeError("setValue: not an input, textarea or select");
692
- if (!o.force) {
693
- node.value = value;
694
- return;
695
- }
696
- node.isoSetProp("value", value, false);
697
- if (node.isoKnown) core.record([
698
- "prop",
699
- node.isoId,
700
- "value",
701
- value,
702
- true
703
- ]);
704
- },
705
- deliver(event) {
706
- const node = core.known.get(event.target);
707
- if (!node) return;
708
- if ((node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement) && event.value !== void 0) node.isoSetProp("value", event.value, false);
709
- if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
710
- node.dispatchEvent(toEvent(event));
936
+ setValue: (node, value, o = {}) => setValueOf(node, value, o),
937
+ deliver: (event) => deliverTo(core.known.get(event.target), event),
938
+ addRoot(o) {
939
+ const member = makeRoot(core.nextId++);
940
+ const rec = recorder(member, (b) => o.onBatch(b), o.schedule ?? schedule);
941
+ member.isoOwner = rec.owner;
942
+ const mine = (node) => node?.isoKnown && node.isoOwner === rec.owner ? node : void 0;
943
+ return {
944
+ root: member,
945
+ flush: rec.flush,
946
+ idOf: (node) => mine(node) ? node.isoWire : void 0,
947
+ setValue(node, value, so = {}) {
948
+ if (node.isoOwner && node.isoOwner !== rec.owner) throw new TypeError("setValue: not a node of this member's root");
949
+ setValueOf(node, value, so);
950
+ },
951
+ deliver: (event) => deliverTo(mine(event.target === 0 ? member : core.known.get(event.target)), event),
952
+ dispose() {
953
+ rec.stop();
954
+ core.roots.delete(member);
955
+ forget(member, core);
956
+ }
957
+ };
711
958
  }
712
959
  };
713
960
  }
714
961
  /** A real `Event` with the fields frameworks read from mouse and keyboard events. */
715
962
  function toEvent(e) {
716
963
  const ev = new Event(e.type, {
717
- bubbles: true,
964
+ bubbles: e.type !== "scroll",
718
965
  cancelable: true
719
966
  });
720
967
  const mods = {
@@ -739,8 +986,8 @@ function toEvent(e) {
739
986
  });
740
987
  return ev;
741
988
  }
742
- var HTML_NS, SVG_NS, str, domError, WEventTarget, WNode, WCharacterData, WText, WComment, kebab, WDOMTokenList, dataAttr, dataKey, WParentNode, WDocumentFragment, WElement, HANDLER_EVENTS, WHTMLElement, WSVGElement, WHTMLIFrameElement, WHTMLInputElement, WHTMLTextAreaElement, WHTMLSelectElement, WHTMLOptionElement, HTML_CLASSES, WDocument;
743
- var init_dom_9S5T0UVQ = __esmMin((() => {
989
+ var HTML_NS, SVG_NS, str, domError, emit, WEventTarget, WNode, WCharacterData, WText, WComment, kebab, WDOMTokenList, dataAttr, dataKey, WParentNode, WDocumentFragment, WElement, HANDLER_EVENTS, WHTMLElement, WSVGElement, WHTMLIFrameElement, WHTMLInputElement, WHTMLTextAreaElement, WHTMLSelectElement, WHTMLOptionElement, HTML_CLASSES, WDocument, isControl;
990
+ var init_dom_yLsf0Z4e = __esmMin((() => {
744
991
  HTML_NS = "http://www.w3.org/1999/xhtml";
745
992
  SVG_NS = "http://www.w3.org/2000/svg";
746
993
  str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
@@ -749,6 +996,9 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
749
996
  e.name = name;
750
997
  return e;
751
998
  };
999
+ emit = (n, r) => {
1000
+ n.isoOwner?.push(r);
1001
+ };
752
1002
  WEventTarget = class {
753
1003
  /** @internal */ isoListeners = /* @__PURE__ */ new Map();
754
1004
  /** @internal */ isoParentTarget() {
@@ -891,6 +1141,12 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
891
1141
  /** @internal */ isoNext = null;
892
1142
  /** @internal Whether the host knows this node (it's in the tree under the root). */
893
1143
  isoKnown = false;
1144
+ /**
1145
+ * @internal The root this node was rendered under, once it has been. Kept
1146
+ * after the node leaves the tree, so it can't move to another member's root
1147
+ * in a pool (ADR 0015, decision 3).
1148
+ */
1149
+ isoOwner = null;
894
1150
  constructor(doc, id) {
895
1151
  super();
896
1152
  this.ownerDocument = doc;
@@ -899,10 +1155,17 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
899
1155
  /** @internal */ isoParentTarget() {
900
1156
  return this.isoParent;
901
1157
  }
1158
+ /**
1159
+ * @internal The id the host knows this node by: a render root is always
1160
+ * `ROOT_ID` to its own surface, whatever its id in the document.
1161
+ */
1162
+ get isoWire() {
1163
+ return this.isoOwner?.root === this ? 0 : this.isoId;
1164
+ }
902
1165
  /** @internal */ isoListenChanged(type, on) {
903
- if (this.isoKnown) this.ownerDocument.isoCore.record([
1166
+ if (this.isoKnown) emit(this, [
904
1167
  "listen",
905
- this.isoId,
1168
+ this.isoWire,
906
1169
  type,
907
1170
  on
908
1171
  ]);
@@ -955,9 +1218,9 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
955
1218
  const data = str(v);
956
1219
  if (data === this.isoData) return;
957
1220
  this.isoData = data;
958
- if (this.isoKnown) this.ownerDocument.isoCore.record([
1221
+ if (this.isoKnown) emit(this, [
959
1222
  "text",
960
- this.isoId,
1223
+ this.isoWire,
961
1224
  data
962
1225
  ]);
963
1226
  }
@@ -1092,27 +1355,28 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1092
1355
  return child;
1093
1356
  }
1094
1357
  if (this.ownerDocument.head === this && child instanceof WElement) this.ownerDocument.isoCore.onHead(child.localName);
1358
+ if (this.isoKnown && ownedElsewhere(child, this.isoOwner)) throw domError("HierarchyRequestError", "insertBefore: a node can't move to another member's root in a pool");
1095
1359
  const wasKnown = child.isoKnown;
1096
1360
  child.isoParent?.isoUnlink(child);
1097
1361
  this.isoLink(child, ref);
1098
1362
  const core = this.ownerDocument.isoCore;
1099
- if (wasKnown && this.isoKnown) core.record([
1363
+ if (wasKnown && this.isoKnown) emit(this, [
1100
1364
  "move",
1101
- this.isoId,
1365
+ this.isoWire,
1102
1366
  child.isoId,
1103
1367
  ref?.isoId ?? null
1104
1368
  ]);
1105
1369
  else if (wasKnown) {
1106
- core.record(["remove", child.isoId]);
1370
+ emit(child, ["remove", child.isoId]);
1107
1371
  forget(child, core);
1108
1372
  } else if (this.isoKnown) {
1109
- core.record([
1373
+ emit(this, [
1110
1374
  "insert",
1111
- this.isoId,
1375
+ this.isoWire,
1112
1376
  serialize(child),
1113
1377
  ref?.isoId ?? null
1114
1378
  ]);
1115
- learn(child, core);
1379
+ learn(child, core, this.isoOwner);
1116
1380
  }
1117
1381
  return child;
1118
1382
  }
@@ -1120,9 +1384,8 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1120
1384
  if (child.isoParent !== this) throw domError("NotFoundError", "removeChild: not a child");
1121
1385
  this.isoUnlink(child);
1122
1386
  if (child.isoKnown) {
1123
- const core = this.ownerDocument.isoCore;
1124
- core.record(["remove", child.isoId]);
1125
- forget(child, core);
1387
+ emit(child, ["remove", child.isoId]);
1388
+ forget(child, this.ownerDocument.isoCore);
1126
1389
  }
1127
1390
  return child;
1128
1391
  }
@@ -1172,6 +1435,11 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1172
1435
  /** @internal */ isoStyle = null;
1173
1436
  /** @internal */ isoClassList = null;
1174
1437
  /** @internal */ isoDataset = null;
1438
+ /** @internal The offsets the last `scroll` event brought (design §4.6). */
1439
+ isoScroll = {
1440
+ top: 0,
1441
+ left: 0
1442
+ };
1175
1443
  constructor(doc, id, localName, ns) {
1176
1444
  super(doc, id);
1177
1445
  this.localName = localName;
@@ -1205,9 +1473,9 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1205
1473
  const v = str(value);
1206
1474
  if (this.isoAttrs.get(n) === v) return;
1207
1475
  this.isoAttrs.set(n, v);
1208
- if (this.isoKnown) this.ownerDocument.isoCore.record([
1476
+ if (this.isoKnown) emit(this, [
1209
1477
  "attr",
1210
- this.isoId,
1478
+ this.isoWire,
1211
1479
  n,
1212
1480
  v
1213
1481
  ]);
@@ -1215,9 +1483,9 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1215
1483
  removeAttribute(name) {
1216
1484
  const n = this.isoAttrName(name);
1217
1485
  if (!this.isoAttrs.delete(n)) return;
1218
- if (this.isoKnown) this.ownerDocument.isoCore.record([
1486
+ if (this.isoKnown) emit(this, [
1219
1487
  "attr",
1220
- this.isoId,
1488
+ this.isoWire,
1221
1489
  n,
1222
1490
  null
1223
1491
  ]);
@@ -1238,6 +1506,16 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1238
1506
  this.isoDataset ??= createDataset(this);
1239
1507
  return this.isoDataset;
1240
1508
  }
1509
+ /**
1510
+ * Read only, and as of the last `scroll` event the element got: the host
1511
+ * owns scrolling. 0 until the element is scrolled and listens for `scroll`.
1512
+ */
1513
+ get scrollTop() {
1514
+ return this.isoScroll.top;
1515
+ }
1516
+ get scrollLeft() {
1517
+ return this.isoScroll.left;
1518
+ }
1241
1519
  get id() {
1242
1520
  return this.getAttribute("id") ?? "";
1243
1521
  }
@@ -1247,9 +1525,9 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1247
1525
  /** @internal */ isoSetProp(name, value, record) {
1248
1526
  if (this.isoProps.get(name) === value) return;
1249
1527
  this.isoProps.set(name, value);
1250
- if (record && this.isoKnown) this.ownerDocument.isoCore.record([
1528
+ if (record && this.isoKnown) emit(this, [
1251
1529
  "prop",
1252
- this.isoId,
1530
+ this.isoWire,
1253
1531
  name,
1254
1532
  value
1255
1533
  ]);
@@ -1506,8 +1784,11 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1506
1784
  }
1507
1785
  return null;
1508
1786
  };
1509
- const root = this.isoCore.root;
1510
- return (root ? walk(root) : null) ?? walk(this.head);
1787
+ for (const root of this.isoCore.roots) {
1788
+ const hit = walk(root);
1789
+ if (hit) return hit;
1790
+ }
1791
+ return walk(this.head);
1511
1792
  }
1512
1793
  /**
1513
1794
  * Type selectors only, alone or as a `head > title` child chain: what React
@@ -1542,8 +1823,9 @@ var init_dom_9S5T0UVQ = __esmMin((() => {
1542
1823
  }
1543
1824
  };
1544
1825
  defineHandlers(WDocument.prototype);
1826
+ isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
1545
1827
  }));
1546
- // ../dom/dist/install-DBKGtAel.js
1828
+ // ../dom/dist/install-D7m7By8i.js
1547
1829
  /**
1548
1830
  * Exposes `dom` as the worker's `document`, `window` and DOM classes, so
1549
1831
  * frameworks find them where they look. Only for isolates with a surface; a
@@ -1563,8 +1845,8 @@ function install(dom, scope) {
1563
1845
  dom.document.defaultView = scope;
1564
1846
  }
1565
1847
  var DOM_GLOBALS;
1566
- var init_install_DBKGtAel = __esmMin((() => {
1567
- init_dom_9S5T0UVQ();
1848
+ var init_install_D7m7By8i = __esmMin((() => {
1849
+ init_dom_yLsf0Z4e();
1568
1850
  DOM_GLOBALS = {
1569
1851
  Node: WNode,
1570
1852
  Element: WElement,
@@ -1584,15 +1866,29 @@ var init_install_DBKGtAel = __esmMin((() => {
1584
1866
  // ../dom/dist/worker.js
1585
1867
  var init_worker = __esmMin((() => {
1586
1868
  init_records_wVZrPpqr();
1587
- init_dom_9S5T0UVQ();
1588
- init_install_DBKGtAel();
1869
+ init_dom_yLsf0Z4e();
1870
+ init_install_D7m7By8i();
1589
1871
  }));
1590
1872
  // src/render/index.ts
1873
+ function sharedDom(scope) {
1874
+ if (!shared) {
1875
+ shared = createDom({
1876
+ onBatch: () => {},
1877
+ onHead: (tag) => {
1878
+ for (const fn of headListeners) fn(tag);
1879
+ }
1880
+ });
1881
+ if (scope) install(shared, scope);
1882
+ }
1883
+ return shared;
1884
+ }
1591
1885
  /**
1592
1886
  * Builds the DOM subset and posts its batches. With `scope`, also installs it
1593
- * as that global's `document` and DOM classes, which frameworks need.
1887
+ * as that global's `document` and DOM classes, which frameworks need. With
1888
+ * `pooled`, the isolate gets its own root in the worker's shared document
1889
+ * instead (ADR 0015).
1594
1890
  */
1595
- function createRender(post, scope) {
1891
+ function createRender(post, scope, pooled = false) {
1596
1892
  let pendingStyles = [];
1597
1893
  let pendingHead = [];
1598
1894
  /** Head tags already reported: each goes to the host once. */
@@ -1620,47 +1916,77 @@ function createRender(post, scope) {
1620
1916
  extrasScheduled = true;
1621
1917
  queueMicrotask(() => {
1622
1918
  extrasScheduled = false;
1623
- dom.flush();
1919
+ target.flush();
1624
1920
  if (pendingStyles.length > 0 || pendingHead.length > 0) postPatch([]);
1625
1921
  });
1626
1922
  };
1627
- const dom = createDom({
1628
- onBatch: postPatch,
1629
- schedule: (flush) => queueMicrotask(flush),
1630
- onHead(tag) {
1631
- if (headSeen.has(tag)) return;
1632
- headSeen.add(tag);
1633
- pendingHead.push(tag);
1634
- scheduleExtras();
1635
- }
1636
- });
1637
- if (scope) install(dom, scope);
1923
+ const onHead = (tag) => {
1924
+ if (headSeen.has(tag)) return;
1925
+ headSeen.add(tag);
1926
+ pendingHead.push(tag);
1927
+ scheduleExtras();
1928
+ };
1929
+ let target;
1930
+ if (pooled) {
1931
+ const member = sharedDom(scope).addRoot({ onBatch: postPatch });
1932
+ headListeners.add(onHead);
1933
+ target = {
1934
+ ...member,
1935
+ dispose() {
1936
+ headListeners.delete(onHead);
1937
+ member.dispose();
1938
+ }
1939
+ };
1940
+ } else {
1941
+ const dom = createDom({
1942
+ onBatch: postPatch,
1943
+ schedule: (flush) => queueMicrotask(flush),
1944
+ onHead
1945
+ });
1946
+ if (scope) install(dom, scope);
1947
+ target = {
1948
+ root: dom.root,
1949
+ flush: () => dom.flush(),
1950
+ deliver: (event) => dom.deliver(event),
1951
+ idOf: (node) => node.isConnected ? dom.idOf(node) : void 0,
1952
+ setValue: (node, value, o) => dom.setValue(node, value, o),
1953
+ dispose: () => {}
1954
+ };
1955
+ }
1638
1956
  return {
1639
1957
  fmt: ISOLOOP_DOM_FMT,
1640
- root: dom.root,
1641
- dom,
1958
+ root: target.root,
1959
+ flush: () => target.flush(),
1960
+ setValue: (node, value, o) => target.setValue(node, value, o),
1961
+ dispose: () => target.dispose(),
1642
1962
  styles(css) {
1643
1963
  pendingStyles.push(...typeof css === "string" ? [css] : css);
1644
1964
  scheduleExtras();
1645
1965
  },
1646
- idOf: (node) => node instanceof WNode && node.isConnected ? String(dom.idOf(node)) : void 0,
1966
+ idOf(node) {
1967
+ if (!(node instanceof WNode)) return void 0;
1968
+ const id = target.idOf(node);
1969
+ return id === void 0 ? void 0 : String(id);
1970
+ },
1647
1971
  receive(e) {
1648
- const target = nodeId(e.target);
1649
- if (target === void 0) return;
1972
+ const t = nodeId(e.target);
1973
+ if (t === void 0) return;
1650
1974
  const currentTargets = e.currentTargets.map(nodeId).filter((n) => n !== void 0);
1651
1975
  const { target: _t, currentTargets: _c, ...rest } = e;
1652
- dom.deliver({
1976
+ target.deliver({
1653
1977
  ...rest,
1654
- target,
1978
+ target: t,
1655
1979
  currentTargets
1656
1980
  });
1657
1981
  }
1658
1982
  };
1659
1983
  }
1660
- var nodeId;
1984
+ var nodeId, shared, headListeners;
1661
1985
  var init_render = __esmMin((() => {
1662
1986
  init_worker();
1663
1987
  nodeId = (s) => /^\d+$/.test(s) ? Number(s) : void 0;
1988
+ shared = null;
1989
+ headListeners = /* @__PURE__ */ new Set();
1664
1990
  }));
1665
1991
  // package.json
1666
1992
  var version = "0.0.0";
@@ -1681,11 +2007,11 @@ function defineIsolate(def) {
1681
2007
  };
1682
2008
  }
1683
2009
  /** Builds the context for `start(ctx)`. `scope` is the worker global the DOM subset installs on. */
1684
- function createVanillaIsolate(init, post, scope) {
1685
- const render = init.renderFmt === "none" ? null : createRender(post, scope);
2010
+ function createVanillaIsolate(init, post, scope, pooled = false) {
2011
+ const render = init.renderFmt === "none" ? null : createRender(post, scope, pooled);
1686
2012
  const calls = createHostCalls({
1687
2013
  post,
1688
- beforeCall: () => render?.dom.flush(),
2014
+ beforeCall: () => render?.flush(),
1689
2015
  idOf: (node) => render ? render.idOf(node) : void 0,
1690
2016
  surface: render !== null,
1691
2017
  navigate: init.grants.navigate === true
@@ -1693,6 +2019,7 @@ function createVanillaIsolate(init, post, scope) {
1693
2019
  const awake = createKeepAwake();
1694
2020
  const bus = createBusClient(init.busPort, {
1695
2021
  ...init.wake ? { wake: true } : {},
2022
+ ...init.commitIntervalMs === void 0 ? {} : { commitIntervalMs: init.commitIntervalMs },
1696
2023
  onError: (err) => {
1697
2024
  post({
1698
2025
  v: 1,
@@ -1709,24 +2036,58 @@ function createVanillaIsolate(init, post, scope) {
1709
2036
  }
1710
2037
  });
1711
2038
  const onShutdown = [];
1712
- return {
1713
- ctx: {
1714
- id: init.isolateId,
1715
- config: init.config,
1716
- root: render?.root,
1717
- host: calls.api,
1718
- bus: bus.client,
1719
- styles: (css) => render?.styles(css),
1720
- setValue(node, value, o) {
1721
- if (!render) return;
1722
- if (!(node instanceof WNode)) throw new TypeError("setValue: not a node of this isolate");
1723
- render.dom.setValue(node, value, o);
1724
- },
1725
- onShutdown: (fn) => {
1726
- onShutdown.push(fn);
1727
- },
1728
- keepAwake: () => awake.hold()
2039
+ let portal;
2040
+ const ctx = {
2041
+ id: init.isolateId,
2042
+ config: init.config,
2043
+ root: render?.root,
2044
+ portalRoot: void 0,
2045
+ reportError(error, o = {}) {
2046
+ const fatal = o.fatal ?? true;
2047
+ post({
2048
+ v: 1,
2049
+ t: "error",
2050
+ p: error instanceof Error ? {
2051
+ message: error.message,
2052
+ ...error.stack === void 0 ? {} : { stack: error.stack },
2053
+ fatal
2054
+ } : {
2055
+ message: String(error),
2056
+ fatal
2057
+ }
2058
+ });
2059
+ },
2060
+ host: calls.api,
2061
+ bus: bus.client,
2062
+ styles: (css) => render?.styles(css),
2063
+ setValue(node, value, o) {
2064
+ if (!render) return;
2065
+ if (!(node instanceof WNode)) throw new TypeError("setValue: not a node of this isolate");
2066
+ render.setValue(node, value, o);
1729
2067
  },
2068
+ onShutdown: (fn) => {
2069
+ onShutdown.push(fn);
2070
+ },
2071
+ keepAwake: () => awake.hold()
2072
+ };
2073
+ Object.defineProperty(ctx, "portalRoot", {
2074
+ enumerable: false,
2075
+ get() {
2076
+ if (!render) return void 0;
2077
+ if (!portal) {
2078
+ const { root } = render;
2079
+ const div = root.ownerDocument.createElement("div");
2080
+ div.setAttribute("data-isoloop-portal", "");
2081
+ queueMicrotask(() => {
2082
+ if (div.parentNode !== root) root.appendChild(div);
2083
+ });
2084
+ portal = div;
2085
+ }
2086
+ return portal;
2087
+ }
2088
+ });
2089
+ return {
2090
+ ctx,
1730
2091
  renderFmt: render ? render.fmt : "none",
1731
2092
  receive(msg) {
1732
2093
  if (isHostToIsolate(msg)) {
@@ -1745,7 +2106,9 @@ function createVanillaIsolate(init, post, scope) {
1745
2106
  },
1746
2107
  async shutdown(reason) {
1747
2108
  await Promise.allSettled(onShutdown.map(async (fn) => fn(reason)));
1748
- render?.dom.flush();
2109
+ await bus.close();
2110
+ render?.flush();
2111
+ render?.dispose();
1749
2112
  }
1750
2113
  };
1751
2114
  }
@@ -1761,11 +2124,19 @@ var init_vanilla = __esmMin((() => {
1761
2124
  }));
1762
2125
  // src/bootstrap.ts
1763
2126
  init_dist();
1764
- const post = (msg) => {
2127
+ let mode = null;
2128
+ const members = /* @__PURE__ */ new Map();
2129
+ const postWorker = (msg) => {
1765
2130
  self.postMessage(msg);
1766
2131
  };
1767
- const fatal = (message, code) => {
1768
- post({
2132
+ const memberPost = (name) => (msg) => {
2133
+ self.postMessage(name === void 0 ? msg : {
2134
+ ...msg,
2135
+ isolate: name
2136
+ });
2137
+ };
2138
+ const fatal = (m, message, code) => {
2139
+ m.post({
1769
2140
  v: 1,
1770
2141
  t: "error",
1771
2142
  p: code ? {
@@ -1778,46 +2149,70 @@ const fatal = (message, code) => {
1778
2149
  }
1779
2150
  });
1780
2151
  };
1781
- /** Set once the isolate has started: what the beat reports for suspension (ADR 0001). */
1782
- let idleReport = null;
2152
+ let beating = false;
2153
+ /** Once per worker, after the first isolate's protocol check. */
1783
2154
  function startHeartbeat(everyMs) {
2155
+ if (beating) return;
2156
+ beating = true;
1784
2157
  let last = performance.now();
1785
2158
  setInterval(() => {
1786
2159
  const now = performance.now();
1787
2160
  const lagMs = Math.max(0, now - last - everyMs);
1788
- post({
1789
- v: 1,
1790
- t: "beat",
1791
- p: idleReport ? {
1792
- lagMs,
1793
- idle: idleReport()
1794
- } : { lagMs }
1795
- });
2161
+ if (mode === "pool") {
2162
+ const reports = {};
2163
+ for (const m of members.values()) if (m.name !== void 0 && m.idleReport) reports[m.name] = m.idleReport();
2164
+ postWorker({
2165
+ v: 1,
2166
+ t: "beat",
2167
+ p: {
2168
+ lagMs,
2169
+ members: reports
2170
+ }
2171
+ });
2172
+ } else {
2173
+ const idle = members.get(void 0)?.idleReport?.();
2174
+ postWorker({
2175
+ v: 1,
2176
+ t: "beat",
2177
+ p: idle ? {
2178
+ lagMs,
2179
+ idle
2180
+ } : { lagMs }
2181
+ });
2182
+ }
1796
2183
  last = now;
1797
2184
  }, everyMs);
1798
2185
  }
1799
- async function boot(init) {
2186
+ /** `shutdown` for a member: `bye` once its handlers settle or the grace runs out. */
2187
+ function shutdownMember(m, graceMs, reason) {
2188
+ if (members.get(m.name) === m) members.delete(m.name);
2189
+ m.receive = null;
2190
+ const done = m.shutdownHook?.(reason) ?? Promise.resolve();
2191
+ const grace = new Promise((r) => setTimeout(r, Math.max(0, graceMs - 50)));
2192
+ Promise.race([done, grace]).finally(() => {
2193
+ m.post({
2194
+ v: 1,
2195
+ t: "bye",
2196
+ p: {}
2197
+ });
2198
+ if (members.size === 0) self.close();
2199
+ });
2200
+ }
2201
+ /** Routes one message from the host to the member it is for. */
2202
+ function route(msg) {
2203
+ const m = members.get(mode === "pool" ? msg.isolate : void 0);
2204
+ if (!m) return;
2205
+ if (msg.t === "shutdown") shutdownMember(m, msg.p.graceMs, msg.p.reason);
2206
+ else m.receive?.(msg);
2207
+ }
2208
+ async function boot(m, init) {
1800
2209
  if (init.protocol.min > PROTOCOL.v || init.protocol.max < PROTOCOL.min) {
1801
- fatal(`Host speaks protocol ${init.protocol.min}–${init.protocol.max}, this runtime ${PROTOCOL.min}–${PROTOCOL.v}`, "protocol_mismatch");
2210
+ fatal(m, `Host speaks protocol ${init.protocol.min}–${init.protocol.max}, this runtime ${PROTOCOL.min}–${PROTOCOL.v}`, "protocol_mismatch");
1802
2211
  return;
1803
2212
  }
1804
- self.addEventListener("message", (e) => {
1805
- const msg = e.data;
1806
- if (!isHostToIsolate(msg) || msg.t !== "shutdown") return;
1807
- const done = shutdownHook?.(msg.p.reason) ?? Promise.resolve();
1808
- const grace = new Promise((r) => setTimeout(r, Math.max(0, msg.p.graceMs - 50)));
1809
- Promise.race([done, grace]).finally(() => {
1810
- post({
1811
- v: 1,
1812
- t: "bye",
1813
- p: {}
1814
- });
1815
- self.close();
1816
- });
1817
- });
1818
2213
  startHeartbeat(init.heartbeatMs);
1819
2214
  const { createVanillaIsolate } = await Promise.resolve().then(() => (init_vanilla(), vanilla_exports));
1820
- const runtime = createVanillaIsolate(init, post, self);
2215
+ const runtime = createVanillaIsolate(init, m.post, self, mode === "pool");
1821
2216
  let mod;
1822
2217
  try {
1823
2218
  mod = await import(
@@ -1827,7 +2222,7 @@ async function boot(init) {
1827
2222
  } catch (err) {
1828
2223
  const why = err instanceof Error ? err.message : String(err);
1829
2224
  const cross = new URL(init.src).origin !== self.location.origin;
1830
- fatal(`Could not import ${init.src}: ${why}${cross ? " (a cross-origin isolate needs CORS headers; see docs/guide/hosting.md)" : ""}`);
2225
+ fatal(m, `Could not import ${init.src}: ${why}${cross ? " (a cross-origin isolate needs CORS headers; see docs/guide/hosting.md)" : ""}`);
1831
2226
  return;
1832
2227
  }
1833
2228
  const main = typeof mod === "object" && mod !== null && "default" in mod ? mod.default : void 0;
@@ -1835,21 +2230,19 @@ async function boot(init) {
1835
2230
  const start = main.start;
1836
2231
  if (typeof start === "function") {
1837
2232
  const requires = "requires" in main ? main.requires : void 0;
1838
- await startIsolate(runtime, (ctx) => Reflect.apply(start, main, [ctx]), typeof requires === "string" ? requires : void 0);
2233
+ await startIsolate(m, runtime, (ctx) => Reflect.apply(start, main, [ctx]), typeof requires === "string" ? requires : void 0);
1839
2234
  return;
1840
2235
  }
1841
2236
  }
1842
- fatal(`${init.src} has no default export with start(ctx)`);
2237
+ fatal(m, `${init.src} has no default export with start(ctx)`);
1843
2238
  }
1844
- /** Set by a `{ start(ctx) }` isolate: runs its onShutdown handlers. */
1845
- let shutdownHook = null;
1846
- async function startIsolate(runtime, start, requires) {
1847
- self.addEventListener("message", (e) => {
1848
- runtime.receive(e.data);
1849
- });
1850
- shutdownHook = (reason) => runtime.shutdown(reason);
1851
- idleReport = () => runtime.idle();
1852
- post({
2239
+ async function startIsolate(m, runtime, start, requires) {
2240
+ m.receive = (msg) => {
2241
+ runtime.receive(msg);
2242
+ };
2243
+ m.shutdownHook = (reason) => runtime.shutdown(reason);
2244
+ m.idleReport = () => runtime.idle();
2245
+ m.post({
1853
2246
  v: 1,
1854
2247
  t: "ready",
1855
2248
  p: {
@@ -1862,15 +2255,44 @@ async function startIsolate(runtime, start, requires) {
1862
2255
  try {
1863
2256
  await start(runtime.ctx);
1864
2257
  } catch (err) {
1865
- fatal(`start() threw: ${err instanceof Error ? err.message : String(err)}`);
2258
+ fatal(m, `start() threw: ${err instanceof Error ? err.message : String(err)}`);
1866
2259
  }
1867
2260
  }
1868
- const onInit = (e) => {
2261
+ /** Handles one message from the host: `init` boots a member, the rest is routed. */
2262
+ function onMessage(e) {
1869
2263
  const msg = e.data;
1870
- if (!isHostToIsolate(msg) || msg.t !== "init") return;
1871
- self.removeEventListener("message", onInit);
1872
- boot(msg.p).catch((err) => {
1873
- fatal(err instanceof Error ? err.message : String(err));
2264
+ if (!isHostToIsolate(msg)) return;
2265
+ if (msg.t !== "init") {
2266
+ route(msg);
2267
+ return;
2268
+ }
2269
+ const name = msg.isolate;
2270
+ const wants = name === void 0 ? "own" : "pool";
2271
+ if (mode === "own" || mode === "pool" && wants === "own") return;
2272
+ if (mode === null) {
2273
+ mode = wants;
2274
+ if (mode === "pool") freezeBuiltins();
2275
+ }
2276
+ if (members.has(name)) return;
2277
+ const m = {
2278
+ name,
2279
+ post: memberPost(name),
2280
+ shutdownHook: null,
2281
+ idleReport: null,
2282
+ receive: null
2283
+ };
2284
+ members.set(name, m);
2285
+ boot(m, msg.p).catch((err) => {
2286
+ fatal(m, err instanceof Error ? err.message : String(err));
1874
2287
  });
1875
- };
1876
- self.addEventListener("message", onInit);
2288
+ }
2289
+ const STARTED = Symbol.for("isoloop.bootstrap");
2290
+ function startOnce() {
2291
+ self.addEventListener("message", onMessage);
2292
+ }
2293
+ if (Reflect.get(self, STARTED) === true) {
2294
+ if (import.meta.env?.DEV === true) console.warn("isoloop: worker entry evaluated twice; ignoring");
2295
+ } else {
2296
+ Reflect.set(self, STARTED, true);
2297
+ startOnce();
2298
+ }