@volter/tabnode 0.5.2 → 0.5.4

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.
@@ -17595,10 +17595,17 @@ var implementation$1 = function bind2(that) {
17595
17595
  var implementation = implementation$1;
17596
17596
  var functionBind = Function.prototype.bind || implementation;
17597
17597
  var functionCall = Function.prototype.call;
17598
- var functionApply = Function.prototype.apply;
17598
+ var functionApply;
17599
+ var hasRequiredFunctionApply;
17600
+ function requireFunctionApply() {
17601
+ if (hasRequiredFunctionApply) return functionApply;
17602
+ hasRequiredFunctionApply = 1;
17603
+ functionApply = Function.prototype.apply;
17604
+ return functionApply;
17605
+ }
17599
17606
  var reflectApply = typeof Reflect !== "undefined" && Reflect && Reflect.apply;
17600
17607
  var bind$2 = functionBind;
17601
- var $apply$1 = functionApply;
17608
+ var $apply$1 = requireFunctionApply();
17602
17609
  var $call$2 = functionCall;
17603
17610
  var $reflectApply = reflectApply;
17604
17611
  var actualApply = $reflectApply || bind$2.call($call$2, $apply$1);
@@ -17718,7 +17725,7 @@ var hasSymbols = requireHasSymbols()();
17718
17725
  var getProto = requireGetProto();
17719
17726
  var $ObjectGPO = requireObject_getPrototypeOf();
17720
17727
  var $ReflectGPO = requireReflect_getPrototypeOf();
17721
- var $apply = functionApply;
17728
+ var $apply = requireFunctionApply();
17722
17729
  var $call = functionCall;
17723
17730
  var needsEval = {};
17724
17731
  var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array);
@@ -18359,7 +18366,7 @@ function requireApplyBind() {
18359
18366
  if (hasRequiredApplyBind) return applyBind;
18360
18367
  hasRequiredApplyBind = 1;
18361
18368
  var bind3 = functionBind;
18362
- var $apply2 = functionApply;
18369
+ var $apply2 = requireFunctionApply();
18363
18370
  var actualApply$1 = actualApply;
18364
18371
  applyBind = function applyBind2() {
18365
18372
  return actualApply$1(bind3, $apply2, arguments);
@@ -27123,6 +27130,10 @@ const stackOverrides = /* @__PURE__ */ new Map();
27123
27130
  const stackOverrideMap = {
27124
27131
  set(error, override) {
27125
27132
  stackOverrides.set(error, override);
27133
+ const nativeSetTimeout = globalThis.__browserRuntimeNativeSetTimeout ?? setTimeout;
27134
+ nativeSetTimeout.call(globalThis, () => {
27135
+ if (stackOverrides.get(error) === override) stackOverrides.delete(error);
27136
+ }, 0);
27126
27137
  return this;
27127
27138
  },
27128
27139
  get: (error) => stackOverrides.get(error),
@@ -75832,17 +75843,27 @@ function __substrateCallSiteFileNames() {
75832
75843
  }
75833
75844
  return namer;
75834
75845
  };
75835
- const overriding = (error, sites) => {
75836
- const override = error !== null && typeof error === "object" ? stackOverrides.get(error) : void 0;
75837
- if (override) {
75838
- stackOverrides.delete(error);
75839
- return override(error, sites.map(named));
75840
- }
75841
- if (typeof guestPrepare === "function") return namerFor(guestPrepare)(error, sites);
75842
- return `${Error.prototype.toString.call(error)}${sites.map((site) => `
75846
+ const overridingFor = (guest) => {
75847
+ const known = typeof guest === "function" ? overridings.get(guest) : overridingNone;
75848
+ if (known) return known;
75849
+ const overriding = (error, sites) => {
75850
+ const override = error !== null && typeof error === "object" ? stackOverrides.get(error) : void 0;
75851
+ if (override) {
75852
+ stackOverrides.delete(error);
75853
+ return override(error, sites.map(named));
75854
+ }
75855
+ if (typeof guest === "function") return namerFor(guest)(error, sites);
75856
+ return `${Error.prototype.toString.call(error)}${sites.map((site) => `
75843
75857
  at ${String(site)}`).join("")}`;
75858
+ };
75859
+ guests.set(overriding, guest);
75860
+ if (typeof guest === "function") overridings.set(guest, overriding);
75861
+ else overridingNone = overriding;
75862
+ return overriding;
75844
75863
  };
75845
- const get2 = () => stackOverrides.size > 0 ? overriding : typeof guestPrepare === "function" ? namerFor(guestPrepare) : guestPrepare;
75864
+ const overridings = /* @__PURE__ */ new WeakMap();
75865
+ let overridingNone;
75866
+ const get2 = () => stackOverrides.size > 0 ? overridingFor(guestPrepare) : typeof guestPrepare === "function" ? namerFor(guestPrepare) : guestPrepare;
75846
75867
  get2.__substrateNamesFrames = true;
75847
75868
  defineOnHost(Error, "prepareStackTrace", {
75848
75869
  get: get2,
package/dist/index.mjs CHANGED
@@ -27290,6 +27290,10 @@ const stackOverrides = /* @__PURE__ */ new Map();
27290
27290
  const stackOverrideMap = {
27291
27291
  set(error, override) {
27292
27292
  stackOverrides.set(error, override);
27293
+ const nativeSetTimeout = globalThis.__browserRuntimeNativeSetTimeout ?? setTimeout;
27294
+ nativeSetTimeout.call(globalThis, () => {
27295
+ if (stackOverrides.get(error) === override) stackOverrides.delete(error);
27296
+ }, 0);
27293
27297
  return this;
27294
27298
  },
27295
27299
  get: (error) => stackOverrides.get(error),
@@ -35513,17 +35517,27 @@ function __substrateCallSiteFileNames() {
35513
35517
  }
35514
35518
  return namer;
35515
35519
  };
35516
- const overriding = (error, sites) => {
35517
- const override = error !== null && typeof error === "object" ? stackOverrides.get(error) : void 0;
35518
- if (override) {
35519
- stackOverrides.delete(error);
35520
- return override(error, sites.map(named));
35521
- }
35522
- if (typeof guestPrepare === "function") return namerFor(guestPrepare)(error, sites);
35523
- return `${Error.prototype.toString.call(error)}${sites.map((site) => `
35520
+ const overridingFor = (guest) => {
35521
+ const known = typeof guest === "function" ? overridings.get(guest) : overridingNone;
35522
+ if (known) return known;
35523
+ const overriding = (error, sites) => {
35524
+ const override = error !== null && typeof error === "object" ? stackOverrides.get(error) : void 0;
35525
+ if (override) {
35526
+ stackOverrides.delete(error);
35527
+ return override(error, sites.map(named));
35528
+ }
35529
+ if (typeof guest === "function") return namerFor(guest)(error, sites);
35530
+ return `${Error.prototype.toString.call(error)}${sites.map((site) => `
35524
35531
  at ${String(site)}`).join("")}`;
35525
- };
35526
- const get2 = () => stackOverrides.size > 0 ? overriding : typeof guestPrepare === "function" ? namerFor(guestPrepare) : guestPrepare;
35532
+ };
35533
+ guests.set(overriding, guest);
35534
+ if (typeof guest === "function") overridings.set(guest, overriding);
35535
+ else overridingNone = overriding;
35536
+ return overriding;
35537
+ };
35538
+ const overridings = /* @__PURE__ */ new WeakMap();
35539
+ let overridingNone;
35540
+ const get2 = () => stackOverrides.size > 0 ? overridingFor(guestPrepare) : typeof guestPrepare === "function" ? namerFor(guestPrepare) : guestPrepare;
35527
35541
  get2.__substrateNamesFrames = true;
35528
35542
  defineOnHost(Error, "prepareStackTrace", {
35529
35543
  get: get2,
@@ -35548,7 +35562,7 @@ class WorkerRuntime {
35548
35562
  this.worker = new Worker(
35549
35563
  new URL(
35550
35564
  /* @vite-ignore */
35551
- "/assets/runtime-worker-CqG62h2U.js",
35565
+ "/assets/runtime-worker-DBtzjAkn.js",
35552
35566
  import.meta.url
35553
35567
  ),
35554
35568
  { type: "module" }
@@ -37408,11 +37422,15 @@ function __substrateListenForUpgrades(bridge) {
37408
37422
  const key = uint8ToBase64(crypto.getRandomValues(new Uint8Array(16)));
37409
37423
  const protocols = Array.isArray(data2.protocols) ? data2.protocols : [];
37410
37424
  void __upgradeOverLoopback(port, "GET", url2.pathname + url2.search, {
37411
- Host: url2.host,
37425
+ // Host is the authority the client addressed, as an HTTP request's is
37426
+ Host: typeof data2.host === "string" && /^(?:\[[0-9a-f:.]+\]|[a-z0-9.-]+)(?::[0-9]{1,5})?$/iu.test(data2.host) ? data2.host : url2.host,
37412
37427
  Upgrade: "websocket",
37413
37428
  "Sec-WebSocket-Version": "13",
37414
37429
  "Sec-WebSocket-Key": key,
37415
- ...protocols.length ? { "Sec-WebSocket-Protocol": protocols.join(", ") } : {}
37430
+ ...protocols.length ? { "Sec-WebSocket-Protocol": protocols.join(", ") } : {},
37431
+ // A browser sends Origin on every WebSocket handshake, and a server's
37432
+ // check of it is how it refuses sockets from pages it did not serve.
37433
+ ...typeof data2.origin === "string" && /^https?:\/\/[^/]+$/u.test(data2.origin) ? { Origin: data2.origin } : {}
37416
37434
  }).then((result) => {
37417
37435
  if (result.statusCode !== 101 || !result.socket) {
37418
37436
  channel.postMessage({ type: "close", targetClient: data2.clientId, code: 1006, reason: "upgrade refused" });
@@ -9,7 +9,7 @@
9
9
  * registration; `Error.prepareStackTrace` is the door it has. Every process's
10
10
  * `internal/errors` writes here, and the realm's hook reads here, so the
11
11
  * override reaches V8 whichever process set it. An entry is consumed by the
12
- * stack it formats, as Node's is.
12
+ * stack it formats, as Node's is, and lapses at the end of the task that set it.
13
13
  */
14
14
  export type StackOverride = (error: unknown, sites: unknown[]) => unknown;
15
15
  export declare const stackOverrides: Map<object, StackOverride>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/tabnode",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Node's own library, in a browser tab.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/runtime.ts CHANGED
@@ -2942,13 +2942,25 @@ function __substrateCallSiteFileNames(): void {
2942
2942
  // override and every other error what it would have had: the guest's
2943
2943
  // function, else V8's own text, which is the error and one `at` line
2944
2944
  // per call site. Otherwise V8 is handed exactly what the guest set.
2945
- const overriding: Prepare = (error, sites) => {
2946
- const override = error !== null && typeof error === 'object' ? stackOverrides.get(error) : undefined;
2947
- if (override) { stackOverrides.delete(error as object); return override(error, sites.map(named)); }
2948
- if (typeof guestPrepare === 'function') return namerFor(guestPrepare as Prepare)(error, sites);
2949
- return `${Error.prototype.toString.call(error)}${sites.map(site => `\n at ${String(site)}`).join('')}`;
2945
+ const overridingFor = (guest: unknown): Prepare => {
2946
+ const known = typeof guest === 'function' ? overridings.get(guest) : overridingNone;
2947
+ if (known) return known;
2948
+ const overriding: Prepare = (error, sites) => {
2949
+ const override = error !== null && typeof error === 'object' ? stackOverrides.get(error) : undefined;
2950
+ if (override) { stackOverrides.delete(error as object); return override(error, sites.map(named)); }
2951
+ if (typeof guest === 'function') return namerFor(guest as Prepare)(error, sites);
2952
+ return `${Error.prototype.toString.call(error)}${sites.map(site => `\n at ${String(site)}`).join('')}`;
2953
+ };
2954
+ // A guest that saves the hook and restores it later restores the function
2955
+ // it read; that stands for the guest's own, as a namer does.
2956
+ guests.set(overriding, guest);
2957
+ if (typeof guest === 'function') overridings.set(guest, overriding);
2958
+ else overridingNone = overriding;
2959
+ return overriding;
2950
2960
  };
2951
- const get = () => (stackOverrides.size > 0 ? overriding
2961
+ const overridings = new WeakMap<object, Prepare>();
2962
+ let overridingNone: Prepare | undefined;
2963
+ const get = () => (stackOverrides.size > 0 ? overridingFor(guestPrepare)
2952
2964
  : typeof guestPrepare === 'function' ? namerFor(guestPrepare as Prepare) : guestPrepare);
2953
2965
  (get as { __substrateNamesFrames?: boolean }).__substrateNamesFrames = true;
2954
2966
  defineOnHost(Error, 'prepareStackTrace', {
@@ -123,6 +123,10 @@ interface UpgradeSignal {
123
123
  protocols?: string[];
124
124
  /** `"none"` asks for a byte pipe; anything else, or nothing, is a WebSocket. */
125
125
  framing?: "websocket" | "none";
126
+ /** The origin of the page that opened the socket, which a browser sends on every handshake. */
127
+ origin?: string;
128
+ /** The authority the client addressed, its handshake's Host; the engine's own URL names the port. */
129
+ host?: string;
126
130
  payload?: string | ArrayBuffer;
127
131
  code?: number;
128
132
  reason?: string;
@@ -348,11 +352,15 @@ function __substrateListenForUpgrades(bridge: ServerBridge): BroadcastChannel |
348
352
  // with the socket, which is what the real `ws` takes over. What comes
349
353
  // back here is the client's end of that same connection.
350
354
  void __upgradeOverLoopback(port, "GET", url2.pathname + url2.search, {
351
- Host: url2.host,
355
+ // Host is the authority the client addressed, as an HTTP request's is
356
+ Host: typeof data2.host === "string" && /^(?:\[[0-9a-f:.]+\]|[a-z0-9.-]+)(?::[0-9]{1,5})?$/iu.test(data2.host) ? data2.host : url2.host,
352
357
  Upgrade: "websocket",
353
358
  "Sec-WebSocket-Version": "13",
354
359
  "Sec-WebSocket-Key": key,
355
360
  ...(protocols.length ? { "Sec-WebSocket-Protocol": protocols.join(", ") } : {}),
361
+ // A browser sends Origin on every WebSocket handshake, and a server's
362
+ // check of it is how it refuses sockets from pages it did not serve.
363
+ ...(typeof data2.origin === "string" && /^https?:\/\/[^/]+$/u.test(data2.origin) ? { Origin: data2.origin } : {}),
356
364
  }).then((result) => {
357
365
  if (result.statusCode !== 101 || !result.socket) {
358
366
  channel.postMessage({ type: "close", targetClient: data2.clientId, code: 1006, reason: "upgrade refused" });
@@ -9,7 +9,7 @@
9
9
  * registration; `Error.prepareStackTrace` is the door it has. Every process's
10
10
  * `internal/errors` writes here, and the realm's hook reads here, so the
11
11
  * override reaches V8 whichever process set it. An entry is consumed by the
12
- * stack it formats, as Node's is.
12
+ * stack it formats, as Node's is, and lapses at the end of the task that set it.
13
13
  */
14
14
  export type StackOverride = (error: unknown, sites: unknown[]) => unknown;
15
15
 
@@ -17,7 +17,16 @@ export const stackOverrides = new Map<object, StackOverride>();
17
17
 
18
18
  /** A WeakMap-shaped view of the table, which is what `internal/errors` holds. */
19
19
  export const stackOverrideMap = {
20
- set(this: object, error: object, override: StackOverride) { stackOverrides.set(error, override); return this; },
20
+ set(this: object, error: object, override: StackOverride) {
21
+ stackOverrides.set(error, override);
22
+ // Node's map is weak, so an override whose stack is never read costs nothing
23
+ // there. Here it would hold its error and keep every stack on the fallback
24
+ // formatter; Node's readers read in the same task, so it lapses after it.
25
+ // The realm's own timer: a guest's would count as that guest's work.
26
+ const nativeSetTimeout = (globalThis as { __browserRuntimeNativeSetTimeout?: typeof setTimeout }).__browserRuntimeNativeSetTimeout ?? setTimeout;
27
+ nativeSetTimeout.call(globalThis, () => { if (stackOverrides.get(error) === override) stackOverrides.delete(error); }, 0);
28
+ return this;
29
+ },
21
30
  get: (error: object) => stackOverrides.get(error),
22
31
  has: (error: object) => stackOverrides.has(error),
23
32
  delete: (error: object) => stackOverrides.delete(error),