@volter/tabnode 0.5.3 → 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.
@@ -27130,6 +27130,10 @@ const stackOverrides = /* @__PURE__ */ new Map();
27130
27130
  const stackOverrideMap = {
27131
27131
  set(error, override) {
27132
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);
27133
27137
  return this;
27134
27138
  },
27135
27139
  get: (error) => stackOverrides.get(error),
@@ -75839,17 +75843,27 @@ function __substrateCallSiteFileNames() {
75839
75843
  }
75840
75844
  return namer;
75841
75845
  };
75842
- const overriding = (error, sites) => {
75843
- const override = error !== null && typeof error === "object" ? stackOverrides.get(error) : void 0;
75844
- if (override) {
75845
- stackOverrides.delete(error);
75846
- return override(error, sites.map(named));
75847
- }
75848
- if (typeof guestPrepare === "function") return namerFor(guestPrepare)(error, sites);
75849
- 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) => `
75850
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;
75851
75863
  };
75852
- 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;
75853
75867
  get2.__substrateNamesFrames = true;
75854
75868
  defineOnHost(Error, "prepareStackTrace", {
75855
75869
  get: get2,
package/dist/index.mjs CHANGED
@@ -17762,17 +17762,10 @@ var implementation$1 = function bind2(that) {
17762
17762
  var implementation = implementation$1;
17763
17763
  var functionBind = Function.prototype.bind || implementation;
17764
17764
  var functionCall = Function.prototype.call;
17765
- var functionApply;
17766
- var hasRequiredFunctionApply;
17767
- function requireFunctionApply() {
17768
- if (hasRequiredFunctionApply) return functionApply;
17769
- hasRequiredFunctionApply = 1;
17770
- functionApply = Function.prototype.apply;
17771
- return functionApply;
17772
- }
17765
+ var functionApply = Function.prototype.apply;
17773
17766
  var reflectApply = typeof Reflect !== "undefined" && Reflect && Reflect.apply;
17774
17767
  var bind$2 = functionBind;
17775
- var $apply$1 = requireFunctionApply();
17768
+ var $apply$1 = functionApply;
17776
17769
  var $call$2 = functionCall;
17777
17770
  var $reflectApply = reflectApply;
17778
17771
  var actualApply = $reflectApply || bind$2.call($call$2, $apply$1);
@@ -17892,7 +17885,7 @@ var hasSymbols = requireHasSymbols()();
17892
17885
  var getProto = requireGetProto();
17893
17886
  var $ObjectGPO = requireObject_getPrototypeOf();
17894
17887
  var $ReflectGPO = requireReflect_getPrototypeOf();
17895
- var $apply = requireFunctionApply();
17888
+ var $apply = functionApply;
17896
17889
  var $call = functionCall;
17897
17890
  var needsEval = {};
17898
17891
  var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array);
@@ -18533,7 +18526,7 @@ function requireApplyBind() {
18533
18526
  if (hasRequiredApplyBind) return applyBind;
18534
18527
  hasRequiredApplyBind = 1;
18535
18528
  var bind3 = functionBind;
18536
- var $apply2 = requireFunctionApply();
18529
+ var $apply2 = functionApply;
18537
18530
  var actualApply$1 = actualApply;
18538
18531
  applyBind = function applyBind2() {
18539
18532
  return actualApply$1(bind3, $apply2, arguments);
@@ -27297,6 +27290,10 @@ const stackOverrides = /* @__PURE__ */ new Map();
27297
27290
  const stackOverrideMap = {
27298
27291
  set(error, override) {
27299
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);
27300
27297
  return this;
27301
27298
  },
27302
27299
  get: (error) => stackOverrides.get(error),
@@ -35520,17 +35517,27 @@ function __substrateCallSiteFileNames() {
35520
35517
  }
35521
35518
  return namer;
35522
35519
  };
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 guestPrepare === "function") return namerFor(guestPrepare)(error, sites);
35530
- 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) => `
35531
35531
  at ${String(site)}`).join("")}`;
35532
- };
35533
- 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;
35534
35541
  get2.__substrateNamesFrames = true;
35535
35542
  defineOnHost(Error, "prepareStackTrace", {
35536
35543
  get: get2,
@@ -35555,7 +35562,7 @@ class WorkerRuntime {
35555
35562
  this.worker = new Worker(
35556
35563
  new URL(
35557
35564
  /* @vite-ignore */
35558
- "/assets/runtime-worker-CfmZOVKz.js",
35565
+ "/assets/runtime-worker-DBtzjAkn.js",
35559
35566
  import.meta.url
35560
35567
  ),
35561
35568
  { type: "module" }
@@ -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.3",
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', {
@@ -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),