@opencode/codemode 0.0.0-dev-19566 → 0.0.0-dev-19568

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.
@@ -1,9 +1,16 @@
1
1
  import type { Diagnostic } from "../codemode.js";
2
+ import { type AstNode } from "./model.js";
2
3
  import { type ErrorType } from "./intrinsics.js";
3
4
  import { type NativeFunction, ProgramError, ProgramObject } from "./objects.js";
4
5
  import { type Runner } from "./runner.js";
5
6
  export declare const normalizeError: (error: unknown) => Diagnostic;
6
- export declare const caughtErrorValue: <R>(runner: Runner<R>, thrown: unknown) => unknown;
7
+ /**
8
+ * Gives a failure the source location of the expression that raised it, keeping the first one attached. Host errors
9
+ * that escape a built-in become the equivalent program error here.
10
+ */
11
+ export declare const locate: (error: unknown, node?: AstNode) => unknown;
12
+ /** The program value a handler receives for a failure; one failure always yields the same value. */
13
+ export declare const materialize: <R>(runner: Runner<R>, thrown: unknown) => unknown;
7
14
  export declare const createAggregateErrorValue: <R>(runner: Runner<R>, errors: Array<unknown>, message: string, proto?: ProgramObject) => ProgramError;
8
15
  /** An error constructor such as `Error` or `TypeError`; callable with or without `new`, like JS. */
9
16
  export declare const errorGlobal: <R>(type: ErrorType, runner: Runner<R>) => NativeFunction<R>;
@@ -1,7 +1,7 @@
1
1
  import { Effect } from "effect";
2
2
  import { ToolError } from "../tool-error.js";
3
3
  import { toData, ToolRuntimeError } from "../data.js";
4
- import { formatLocation, InterpreterRuntimeError, ProgramThrow, sourceLocation } from "./model.js";
4
+ import { formatLocation, PendingThrow, ProgramThrow, sourceLocation, typeError } from "./model.js";
5
5
  import { containsRuntimeReference } from "./references.js";
6
6
  import { createErrorValue, isErrorType } from "./intrinsics.js";
7
7
  import { constructor, methods, prototypeFrom, receiver } from "./native.js";
@@ -9,10 +9,10 @@ import { define, get, hidden, ProgramArray, ProgramError, ProgramObject, } from
9
9
  import {} from "./runner.js";
10
10
  import { coerceToString } from "../stdlib/value.js";
11
11
  export const normalizeError = (error) => {
12
- if (error instanceof InterpreterRuntimeError) {
12
+ if (error instanceof PendingThrow) {
13
13
  return {
14
14
  kind: error.kind,
15
- message: `${error.message}${formatLocation(error.node)}`,
15
+ message: `${error.type}: ${error.message}${formatLocation(error.node)}`,
16
16
  ...(error.node?.loc ? { location: sourceLocation(error.node) } : {}),
17
17
  ...(error.suggestions ? { suggestions: error.suggestions } : {}),
18
18
  };
@@ -29,6 +29,9 @@ export const normalizeError = (error) => {
29
29
  }
30
30
  if (error instanceof ProgramThrow) {
31
31
  const value = error.value;
32
+ if (value instanceof ProgramError) {
33
+ return value.host ? normalizeError(value.host) : { kind: "ExecutionFailure", message: errorToString(value) };
34
+ }
32
35
  let message;
33
36
  if (containsRuntimeReference(value)) {
34
37
  // Never expose runtime reference internals through thrown values.
@@ -37,9 +40,6 @@ export const normalizeError = (error) => {
37
40
  else if (typeof value === "string") {
38
41
  message = value;
39
42
  }
40
- else if (value instanceof ProgramObject && typeof get(value, "message") === "string") {
41
- message = get(value, "message");
42
- }
43
43
  else {
44
44
  try {
45
45
  message = JSON.stringify(toData(value, "Thrown value")) ?? String(value);
@@ -67,25 +67,57 @@ export const normalizeError = (error) => {
67
67
  message: String(error),
68
68
  };
69
69
  };
70
- export const caughtErrorValue = (runner, thrown) => {
70
+ /**
71
+ * Gives a failure the source location of the expression that raised it, keeping the first one attached. Host errors
72
+ * that escape a built-in become the equivalent program error here.
73
+ */
74
+ export const locate = (error, node) => {
75
+ if (error instanceof PendingThrow) {
76
+ if (error.node === undefined && node)
77
+ error.node = node;
78
+ return error;
79
+ }
80
+ if (error instanceof Error && !(error instanceof ToolError) && !(error instanceof ToolRuntimeError)) {
81
+ return new PendingThrow(isErrorType(error.name) ? error.name : "Error", error.message, node);
82
+ }
83
+ return error;
84
+ };
85
+ /** The program value a handler receives for a failure; one failure always yields the same value. */
86
+ export const materialize = (runner, thrown) => {
71
87
  if (thrown instanceof ProgramThrow)
72
88
  return thrown.value;
73
89
  const prototypes = runner.prototypes;
74
- if (thrown instanceof InterpreterRuntimeError)
75
- return createErrorValue(prototypes[thrown.type], thrown.message);
90
+ if (thrown instanceof PendingThrow) {
91
+ if (thrown.value === undefined) {
92
+ thrown.value = createErrorValue(prototypes[thrown.type], thrown.message);
93
+ thrown.value.host = thrown;
94
+ }
95
+ return thrown.value;
96
+ }
76
97
  const type = thrown instanceof Error && isErrorType(thrown.name) ? thrown.name : "Error";
77
98
  return createErrorValue(prototypes[type], normalizeError(thrown).message);
78
99
  };
100
+ /** Error.prototype.toString: `name: message`, omitting whichever side is empty. */
101
+ const errorToString = (self) => {
102
+ const name = get(self, "name");
103
+ const message = get(self, "message");
104
+ const shownName = name === undefined ? "Error" : coerceToString(name);
105
+ const shownMessage = message === undefined ? "" : coerceToString(message);
106
+ if (shownMessage === "")
107
+ return shownName;
108
+ if (shownName === "")
109
+ return shownMessage;
110
+ return `${shownName}: ${shownMessage}`;
111
+ };
79
112
  export const createAggregateErrorValue = (runner, errors, message, proto = runner.prototypes.AggregateError) => {
80
113
  const value = createErrorValue(proto, message);
81
114
  define(value, "errors", new ProgramArray(runner.prototypes.Array, errors), { ...hidden });
82
115
  return value;
83
116
  };
84
- const constructAggregateErrorValue = (runner, args, proto, node) => Effect.gen(function* () {
85
- const cursor = yield* runner.syncIterator(args[0], node);
86
- if (cursor === undefined) {
87
- throw new InterpreterRuntimeError("new AggregateError(...) expects a synchronous iterable of errors.", node);
88
- }
117
+ const constructAggregateErrorValue = (runner, args, proto) => Effect.gen(function* () {
118
+ const cursor = yield* runner.syncIterator(args[0]);
119
+ if (cursor === undefined)
120
+ throw typeError("new AggregateError(...) expects a synchronous iterable of errors.");
89
121
  const errors = [];
90
122
  while (true) {
91
123
  const step = yield* cursor.next;
@@ -99,36 +131,21 @@ const constructAggregateErrorValue = (runner, args, proto, node) => Effect.gen(f
99
131
  export const errorGlobal = (type, runner) => {
100
132
  const protos = runner.prototypes;
101
133
  const prototype = protos[type];
102
- const construct = (args, newTarget, node) => {
134
+ const construct = (args, newTarget) => {
103
135
  const proto = prototypeFrom(newTarget, prototype);
104
136
  return type === "AggregateError"
105
- ? constructAggregateErrorValue(runner, args, proto, node)
137
+ ? constructAggregateErrorValue(runner, args, proto)
106
138
  : Effect.sync(() => createErrorValue(proto, args[0] === undefined ? undefined : coerceToString(args[0])));
107
139
  };
108
140
  const ctor = constructor(protos, prototype, {
109
141
  name: type,
110
142
  length: type === "AggregateError" ? 2 : 1,
111
- call: (_, args, node) => construct(args, ctor, node),
143
+ call: (_, args) => construct(args, ctor),
112
144
  construct,
113
145
  });
114
146
  if (type === "Error") {
115
147
  methods(protos, prototype, [
116
- [
117
- "toString",
118
- 0,
119
- (thisValue, _, node) => {
120
- const self = receiver(ProgramObject, thisValue, "Error.prototype.toString", node);
121
- const name = get(self, "name");
122
- const message = get(self, "message");
123
- const shownName = name === undefined ? "Error" : coerceToString(name);
124
- const shownMessage = message === undefined ? "" : coerceToString(message);
125
- if (shownMessage === "")
126
- return shownName;
127
- if (shownName === "")
128
- return shownMessage;
129
- return `${shownName}: ${shownMessage}`;
130
- },
131
- ],
148
+ ["toString", 0, (thisValue) => errorToString(receiver(ProgramObject, thisValue, "Error.prototype.toString"))],
132
149
  ]);
133
150
  }
134
151
  return ctor;
@@ -7,7 +7,7 @@ import { toData } from "../data.js";
7
7
  import { ToolRuntime } from "../tool-runtime.js";
8
8
  import { normalizeError } from "./errors.js";
9
9
  import { createPrototypes } from "./intrinsics.js";
10
- import { InterpreterRuntimeError } from "./model.js";
10
+ import { PendingThrow } from "./model.js";
11
11
  import { PromiseRuntime } from "./promises.js";
12
12
  import { Runtime } from "./runtime.js";
13
13
  export const executeProgram = (code, prepared, limits, hooks, extraGlobals) => {
@@ -84,7 +84,7 @@ export const executeProgram = (code, prepared, limits, hooks, extraGlobals) => {
84
84
  const parseProgram = (code) => {
85
85
  const transpiled = transpile(`async function __codemode__() {\n${code}\n}`);
86
86
  if (transpiled.error !== undefined) {
87
- throw new InterpreterRuntimeError(`Failed to parse TypeScript: ${transpiled.error}`, undefined, "ParseError");
87
+ throw new PendingThrow("SyntaxError", `Failed to parse TypeScript: ${transpiled.error}`, undefined, "ParseError");
88
88
  }
89
89
  const bodyStart = transpiled.outputText.indexOf("{") + 1;
90
90
  const bodyEnd = transpiled.outputText.lastIndexOf("}");
@@ -11,9 +11,9 @@ export const generatorGlobals = (runner, promises) => {
11
11
  const request = (kind) => [
12
12
  kind,
13
13
  1,
14
- (thisValue, args, node) => {
15
- const generator = receiver(ProgramGenerator, thisValue, `${label}.prototype.${kind}`, node);
16
- const requested = generator.request(kind, args[0], node);
14
+ (thisValue, args) => {
15
+ const generator = receiver(ProgramGenerator, thisValue, `${label}.prototype.${kind}`);
16
+ const requested = generator.request(kind, args[0]);
17
17
  return generator.asynchronous ? promises.create(requested) : requested;
18
18
  },
19
19
  ];
@@ -16,26 +16,26 @@ import { ToolReference } from "../tool-runtime.js";
16
16
  import { errorGlobal } from "./errors.js";
17
17
  import { errorTypes } from "./intrinsics.js";
18
18
  import { constants, constructor, native } from "./native.js";
19
- import { AsyncIteratorSymbol, InterpreterRuntimeError, IteratorSymbol } from "./model.js";
19
+ import { AsyncIteratorSymbol, IteratorSymbol, typeError } from "./model.js";
20
20
  import { generatorGlobals } from "./generators.js";
21
21
  import { promiseGlobal } from "./promises.js";
22
22
  // Function.prototype.constructor exists so `fn.constructor === Function` holds; dynamic code is unsupported.
23
23
  const functionGlobal = (runner) => {
24
- const reject = (_, __, node) => Effect.sync(() => {
25
- throw new InterpreterRuntimeError("The Function constructor is not supported; write the function inline.", node);
24
+ const reject = () => Effect.sync(() => {
25
+ throw typeError("The Function constructor is not supported; write the function inline.");
26
26
  });
27
27
  return constructor(runner.prototypes, runner.prototypes.Function, {
28
28
  name: "Function",
29
29
  length: 1,
30
30
  call: reject,
31
- construct: (args, _, node) => reject(undefined, args, node),
31
+ construct: reject,
32
32
  });
33
33
  };
34
34
  const symbolGlobal = (runner) => {
35
35
  const symbol = native(runner.prototypes, {
36
36
  name: "Symbol",
37
- call: (_, __, node) => Effect.sync(() => {
38
- throw new InterpreterRuntimeError("Symbol is not callable; only Symbol.asyncIterator and Symbol.iterator are available.", node);
37
+ call: () => Effect.sync(() => {
38
+ throw typeError("Symbol is not callable; only Symbol.asyncIterator and Symbol.iterator are available.");
39
39
  }),
40
40
  callback: false,
41
41
  });
@@ -1,8 +1,11 @@
1
1
  import type { Node } from "acorn";
2
+ import { Context } from "effect";
2
3
  import type { ErrorType } from "./intrinsics.js";
3
4
  import type { DiagnosticKind } from "../codemode.js";
5
+ import type { ProgramError } from "./objects.js";
4
6
  /** Any parsed node; the interpreter narrows on `type` and reads `loc` for diagnostics. */
5
7
  export type AstNode = Node;
8
+ export declare const CallSite: Context.Reference<Node | undefined>;
6
9
  export type Binding = {
7
10
  mutable: boolean;
8
11
  value: unknown;
@@ -33,24 +36,30 @@ export declare class GeneratorReturn {
33
36
  constructor(value: unknown);
34
37
  }
35
38
  export declare const OptionalShortCircuit: unique symbol;
36
- export declare class InterpreterRuntimeError extends Error {
37
- readonly kind: DiagnosticKind;
38
- readonly suggestions?: ReadonlyArray<string> | undefined;
39
+ /**
40
+ * A failure raised by the interpreter or a built-in. It travels as a defect and becomes one program Error object
41
+ * the first time a handler observes it, so every observer of the same failure sees the same value.
42
+ */
43
+ export declare class PendingThrow {
39
44
  /** The JS error class a program sees when it catches this failure. */
40
45
  readonly type: ErrorType;
41
- readonly node?: AstNode;
42
- constructor(message: string, node?: AstNode, kind?: DiagnosticKind, suggestions?: ReadonlyArray<string> | undefined,
46
+ readonly message: string;
47
+ readonly kind: DiagnosticKind;
48
+ readonly suggestions?: ReadonlyArray<string> | undefined;
49
+ node?: AstNode;
50
+ value?: ProgramError;
51
+ constructor(
43
52
  /** The JS error class a program sees when it catches this failure. */
44
- type?: ErrorType);
53
+ type: ErrorType, message: string, node?: AstNode, kind?: DiagnosticKind, suggestions?: ReadonlyArray<string> | undefined);
45
54
  }
46
- /** Attaches a source location to a failure raised where none was known, such as inside a property accessor. */
47
- export declare const locate: (error: unknown, node: AstNode) => unknown;
48
- export declare const rangeError: (message: string, node?: AstNode) => InterpreterRuntimeError;
49
- export declare const referenceError: (message: string, node?: AstNode) => InterpreterRuntimeError;
50
- export declare const syntaxError: (message: string, node?: AstNode) => InterpreterRuntimeError;
51
- export declare const uriError: (message: string, node?: AstNode) => InterpreterRuntimeError;
55
+ export declare const typeError: (message: string, node?: AstNode) => PendingThrow;
56
+ export declare const invalidData: (message: string, node?: AstNode) => PendingThrow;
57
+ export declare const rangeError: (message: string, node?: AstNode) => PendingThrow;
58
+ export declare const referenceError: (message: string, node?: AstNode) => PendingThrow;
59
+ export declare const syntaxError: (message: string, node?: AstNode) => PendingThrow;
60
+ export declare const uriError: (message: string, node?: AstNode) => PendingThrow;
52
61
  export declare const supportedSyntaxMessage = "This is a restricted JavaScript-like language. Supported: plain and async functions, data literals, destructuring, standard control flow, await and Promise, and built-ins such as Array, Object, Math, JSON, Date, RegExp, Map, Set, and URL. Unsupported: classes, this, getters/setters, tagged templates, BigInt, and custom Symbols. Use plain functions and data objects instead.";
53
- export declare const unsupportedSyntax: (kind: string, node: AstNode) => InterpreterRuntimeError;
62
+ export declare const unsupportedSyntax: (kind: string, node: AstNode) => PendingThrow;
54
63
  export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
55
64
  export declare const sourceLocation: (node: AstNode) => {
56
65
  readonly line: number;
@@ -1,3 +1,5 @@
1
+ import { Context } from "effect";
2
+ export const CallSite = Context.Reference("codemode/CallSite", { defaultValue: () => undefined });
1
3
  export const AsyncIteratorSymbol = Symbol("codemode.async-iterator");
2
4
  export const IteratorSymbol = Symbol("codemode.iterator");
3
5
  export const IteratorSymbols = [AsyncIteratorSymbol, IteratorSymbol];
@@ -14,35 +16,38 @@ export class GeneratorReturn {
14
16
  }
15
17
  }
16
18
  export const OptionalShortCircuit = Symbol("codemode.optional-short-circuit");
17
- export class InterpreterRuntimeError extends Error {
19
+ /**
20
+ * A failure raised by the interpreter or a built-in. It travels as a defect and becomes one program Error object
21
+ * the first time a handler observes it, so every observer of the same failure sees the same value.
22
+ */
23
+ export class PendingThrow {
24
+ type;
25
+ message;
18
26
  kind;
19
27
  suggestions;
20
- type;
21
28
  node;
22
- constructor(message, node, kind = "ExecutionFailure", suggestions,
29
+ value;
30
+ constructor(
23
31
  /** The JS error class a program sees when it catches this failure. */
24
- type = "TypeError") {
25
- super(message);
32
+ type, message, node, kind = "ExecutionFailure", suggestions) {
33
+ this.type = type;
34
+ this.message = message;
26
35
  this.kind = kind;
27
36
  this.suggestions = suggestions;
28
- this.type = type;
29
- this.name = "InterpreterRuntimeError";
30
37
  if (node)
31
38
  this.node = node;
32
39
  }
33
40
  }
34
- /** Attaches a source location to a failure raised where none was known, such as inside a property accessor. */
35
- export const locate = (error, node) => error instanceof InterpreterRuntimeError && error.node === undefined
36
- ? new InterpreterRuntimeError(error.message, node, error.kind, error.suggestions, error.type)
37
- : error;
38
- const failure = (type) => (message, node) => new InterpreterRuntimeError(message, node, "ExecutionFailure", undefined, type);
41
+ const failure = (type, kind) => (message, node) => new PendingThrow(type, message, node, kind);
42
+ export const typeError = failure("TypeError");
43
+ export const invalidData = failure("TypeError", "InvalidDataValue");
39
44
  export const rangeError = failure("RangeError");
40
45
  export const referenceError = failure("ReferenceError");
41
46
  export const syntaxError = failure("SyntaxError");
42
47
  export const uriError = failure("URIError");
43
48
  // Orient the agent rather than enumerate JavaScript; interpreter-support.md is the full matrix.
44
49
  export const supportedSyntaxMessage = "This is a restricted JavaScript-like language. Supported: plain and async functions, data literals, destructuring, standard control flow, await and Promise, and built-ins such as Array, Object, Math, JSON, Date, RegExp, Map, Set, and URL. Unsupported: classes, this, getters/setters, tagged templates, BigInt, and custom Symbols. Use plain functions and data objects instead.";
45
- export const unsupportedSyntax = (kind, node) => new InterpreterRuntimeError(`Syntax '${kind}' is not supported. ${supportedSyntaxMessage}`, node, "UnsupportedSyntax", [supportedSyntaxMessage], "SyntaxError");
50
+ export const unsupportedSyntax = (kind, node) => new PendingThrow("SyntaxError", `Syntax '${kind}' is not supported. ${supportedSyntaxMessage}`, node, "UnsupportedSyntax", [supportedSyntaxMessage]);
46
51
  export const isRecord = (value) => typeof value === "object" && value !== null;
47
52
  export const sourceLocation = (node) => ({
48
53
  line: Math.max(1, (node.loc?.start.line ?? 2) - 1),
@@ -1,9 +1,8 @@
1
1
  import { Effect } from "effect";
2
2
  import type { Prototypes } from "./intrinsics.js";
3
- import { type AstNode } from "./model.js";
4
3
  import { type Callable, NativeFunction, type NativeOptions, ProgramObject } from "./objects.js";
5
- /** A native function body: a plain value, a thrown `InterpreterRuntimeError`, or an Effect. */
6
- export type Impl = (thisValue: unknown, args: Array<unknown>, node: AstNode) => unknown;
4
+ /** A native function body: a plain value, a thrown `PendingThrow`, or an Effect. */
5
+ export type Impl = (thisValue: unknown, args: Array<unknown>) => unknown;
7
6
  export declare const native: <R>(protos: Prototypes, options: NativeOptions<R>) => NativeFunction<R>;
8
7
  export declare const fn: <R>(protos: Prototypes, name: string, length: number, impl: Impl) => NativeFunction<R>;
9
8
  export type Method = readonly [name: string, length: number, impl: Impl];
@@ -12,8 +11,8 @@ export declare const constants: (target: ProgramObject, table: Record<string, un
12
11
  /** A constructor wired to its prototype: `C.prototype === proto` and `proto.constructor === C`. */
13
12
  export declare const constructor: <R>(protos: Prototypes, proto: ProgramObject, options: NativeOptions<R>) => NativeFunction<R>;
14
13
  /** The `call` of a constructor that JS requires to be invoked with `new`. */
15
- export declare const requiresNew: (name: string) => (_: unknown, __: Array<unknown>, node: AstNode) => Effect.Effect<never, unknown, never>;
14
+ export declare const requiresNew: (name: string) => () => Effect.Effect<never, unknown, never>;
16
15
  /** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
17
16
  export declare const prototypeFrom: (newTarget: Callable, fallback: ProgramObject) => ProgramObject;
18
17
  /** Narrows a method receiver to the built-in it belongs to, or throws the TypeError JS would. */
19
- export declare const receiver: <T extends ProgramObject>(cls: abstract new (...args: never) => T, thisValue: unknown, method: string, node?: AstNode) => T;
18
+ export declare const receiver: <T extends ProgramObject>(cls: abstract new (...args: never) => T, thisValue: unknown, method: string) => T;
@@ -1,11 +1,12 @@
1
1
  import { Effect } from "effect";
2
- import { InterpreterRuntimeError } from "./model.js";
2
+ import { typeError } from "./model.js";
3
3
  import { define, frozen, hidden, NativeFunction, ProgramObject } from "./objects.js";
4
4
  import { describeValue } from "./references.js";
5
- const lift = (impl) => (thisValue, args, node) => Effect.suspend(() => {
6
- const result = impl(thisValue, args, node);
5
+ // The dispatch in `Frame.invokeCallable` suspends every native call, so a synchronous throw here is a defect.
6
+ const lift = (impl) => (thisValue, args) => {
7
+ const result = impl(thisValue, args);
7
8
  return Effect.isEffect(result) ? result : Effect.succeed(result);
8
- });
9
+ };
9
10
  export const native = (protos, options) => new NativeFunction(protos.Function, options);
10
11
  export const fn = (protos, name, length, impl) => native(protos, { name, length, call: lift(impl) });
11
12
  export const methods = (protos, target, table) => {
@@ -24,8 +25,8 @@ export const constructor = (protos, proto, options) => {
24
25
  return ctor;
25
26
  };
26
27
  /** The `call` of a constructor that JS requires to be invoked with `new`. */
27
- export const requiresNew = (name) => (_, __, node) => Effect.sync(() => {
28
- throw new InterpreterRuntimeError(`Constructor ${name} requires 'new'.`, node);
28
+ export const requiresNew = (name) => () => Effect.sync(() => {
29
+ throw typeError(`Constructor ${name} requires 'new'.`);
29
30
  });
30
31
  /** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
31
32
  export const prototypeFrom = (newTarget, fallback) => {
@@ -33,8 +34,8 @@ export const prototypeFrom = (newTarget, fallback) => {
33
34
  return proto !== undefined && "value" in proto && proto.value instanceof ProgramObject ? proto.value : fallback;
34
35
  };
35
36
  /** Narrows a method receiver to the built-in it belongs to, or throws the TypeError JS would. */
36
- export const receiver = (cls, thisValue, method, node) => {
37
+ export const receiver = (cls, thisValue, method) => {
37
38
  if (thisValue instanceof cls)
38
39
  return thisValue;
39
- throw new InterpreterRuntimeError(`${method} called on incompatible receiver ${describeValue(thisValue)}.`, node);
40
+ throw typeError(`${method} called on incompatible receiver ${describeValue(thisValue)}.`);
40
41
  };
@@ -1,6 +1,6 @@
1
1
  import type { BlockStatement, Expression, Pattern } from "acorn";
2
2
  import type { Effect, Fiber } from "effect";
3
- import { type AstNode, type Binding, type GeneratorRequestKind } from "./model.js";
3
+ import { type Binding, type GeneratorRequestKind, type PendingThrow } from "./model.js";
4
4
  /** Property attributes, as in a JS property descriptor. */
5
5
  export type Attributes = {
6
6
  readonly writable: boolean;
@@ -41,6 +41,8 @@ export declare class ProgramArray extends ProgramObject {
41
41
  }
42
42
  /** An object with the [[ErrorData]] slot: what `Error.prototype.toString` and the host boundary recognize as an error. */
43
43
  export declare class ProgramError extends ProgramObject {
44
+ /** The interpreter failure this error materialized from, so rethrowing it keeps the diagnostic kind and location. */
45
+ host?: PendingThrow;
44
46
  }
45
47
  export declare abstract class Callable extends ProgramObject {
46
48
  constructor(proto: ProgramObject, name: string, length: number);
@@ -53,8 +55,8 @@ export declare class ProgramFunction extends Callable {
53
55
  readonly generator: boolean;
54
56
  constructor(proto: ProgramObject, name: string, parameters: ReadonlyArray<Pattern>, body: BlockStatement | Expression, capturedScopes: ReadonlyArray<Map<string, Binding>>, async: boolean, generator: boolean);
55
57
  }
56
- export type NativeCall<R> = (thisValue: unknown, args: Array<unknown>, node: AstNode) => Effect.Effect<unknown, unknown, R>;
57
- export type NativeConstruct<R> = (args: Array<unknown>, newTarget: Callable, node: AstNode) => Effect.Effect<unknown, unknown, R>;
58
+ export type NativeCall<R> = (thisValue: unknown, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>;
59
+ export type NativeConstruct<R> = (args: Array<unknown>, newTarget: Callable) => Effect.Effect<unknown, unknown, R>;
58
60
  export type NativeOptions<R> = {
59
61
  readonly name: string;
60
62
  readonly length?: number;
@@ -76,8 +78,8 @@ export declare class ProgramPromise extends ProgramObject {
76
78
  }
77
79
  export declare class ProgramGenerator extends ProgramObject {
78
80
  readonly asynchronous: boolean;
79
- readonly request: (kind: GeneratorRequestKind, value: unknown, node: AstNode) => Effect.Effect<unknown, unknown, unknown>;
80
- constructor(proto: ProgramObject, asynchronous: boolean, request: (kind: GeneratorRequestKind, value: unknown, node: AstNode) => Effect.Effect<unknown, unknown, unknown>);
81
+ readonly request: (kind: GeneratorRequestKind, value: unknown) => Effect.Effect<unknown, unknown, unknown>;
82
+ constructor(proto: ProgramObject, asynchronous: boolean, request: (kind: GeneratorRequestKind, value: unknown) => Effect.Effect<unknown, unknown, unknown>);
81
83
  }
82
84
  export declare class ProgramDate extends ProgramObject {
83
85
  time: number;
@@ -1,4 +1,4 @@
1
- import { AsyncIteratorSymbol, IteratorSymbol } from "./model.js";
1
+ import { AsyncIteratorSymbol, IteratorSymbol, } from "./model.js";
2
2
  /** Ordinary assignment: writable, enumerable, configurable. */
3
3
  export const data = { writable: true, enumerable: true, configurable: true };
4
4
  /** Built-in methods and `constructor`: writable and configurable but hidden from enumeration. */
@@ -24,6 +24,8 @@ export class ProgramArray extends ProgramObject {
24
24
  }
25
25
  /** An object with the [[ErrorData]] slot: what `Error.prototype.toString` and the host boundary recognize as an error. */
26
26
  export class ProgramError extends ProgramObject {
27
+ /** The interpreter failure this error materialized from, so rethrowing it keeps the diagnostic kind and location. */
28
+ host;
27
29
  }
28
30
  export class Callable extends ProgramObject {
29
31
  constructor(proto, name, length) {
@@ -1,6 +1,5 @@
1
1
  import { Effect, Exit, Scope } from "effect";
2
2
  import type { Diagnostic } from "../codemode.js";
3
- import { type AstNode, InterpreterRuntimeError } from "./model.js";
4
3
  import { ProgramObject, ProgramPromise } from "./objects.js";
5
4
  import { type Runner } from "./runner.js";
6
5
  export declare class PromiseRuntime<R> {
@@ -22,9 +21,8 @@ export declare class PromiseRuntime<R> {
22
21
  diagnostics(): Array<Diagnostic>;
23
22
  interrupt(): Effect.Effect<Array<Diagnostic>>;
24
23
  }
25
- export declare const selfResolutionError: (node?: AstNode) => InterpreterRuntimeError;
26
- export declare const resolvePromiseValue: <R>(runner: Runner<R>, value: unknown, node: AstNode, own?: {
24
+ export declare const resolvePromiseValue: <R>(runner: Runner<R>, value: unknown, own?: {
27
25
  promise?: ProgramPromise;
28
26
  }) => Effect.Effect<unknown, unknown, R>;
29
- export declare const resolvePromise: <R>(runner: Runner<R>, promises: PromiseRuntime<R>, value: unknown, node: AstNode) => Effect.Effect<ProgramPromise, never, R>;
27
+ export declare const resolvePromise: <R>(runner: Runner<R>, promises: PromiseRuntime<R>, value: unknown) => Effect.Effect<ProgramPromise, never, R>;
30
28
  export declare const promiseGlobal: <R>(runner: Runner<R>, promises: PromiseRuntime<R>) => import("./objects.js").NativeFunction<R>;