@opencode/codemode 0.0.0-dev-19937 → 0.0.0-dev-19941

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.
Files changed (42) hide show
  1. package/dist/data.d.ts +5 -4
  2. package/dist/interpreter/callback.d.ts +8 -8
  3. package/dist/interpreter/callback.js +1 -2
  4. package/dist/interpreter/errors.d.ts +3 -3
  5. package/dist/interpreter/errors.js +1 -2
  6. package/dist/interpreter/execute.d.ts +2 -1
  7. package/dist/interpreter/extensions.d.ts +2 -1
  8. package/dist/interpreter/extensions.js +7 -35
  9. package/dist/interpreter/globals.d.ts +2 -1
  10. package/dist/interpreter/interpreter.d.ts +8 -14
  11. package/dist/interpreter/interpreter.js +25 -52
  12. package/dist/interpreter/intrinsics.d.ts +2 -2
  13. package/dist/interpreter/model.d.ts +7 -8
  14. package/dist/interpreter/model.js +0 -1
  15. package/dist/interpreter/native.d.ts +5 -5
  16. package/dist/interpreter/objects.d.ts +127 -42
  17. package/dist/interpreter/objects.js +207 -25
  18. package/dist/interpreter/promises.d.ts +7 -7
  19. package/dist/interpreter/references.d.ts +8 -7
  20. package/dist/interpreter/references.js +10 -46
  21. package/dist/interpreter/scope.d.ts +5 -4
  22. package/dist/stdlib/array.d.ts +2 -1
  23. package/dist/stdlib/array.js +1 -2
  24. package/dist/stdlib/bytes.js +1 -2
  25. package/dist/stdlib/collections.js +6 -13
  26. package/dist/stdlib/console.d.ts +2 -2
  27. package/dist/stdlib/console.js +6 -50
  28. package/dist/stdlib/date.js +1 -2
  29. package/dist/stdlib/headers.js +8 -11
  30. package/dist/stdlib/iterator.js +1 -1
  31. package/dist/stdlib/number.js +2 -1
  32. package/dist/stdlib/object.d.ts +3 -4
  33. package/dist/stdlib/object.js +4 -15
  34. package/dist/stdlib/regexp.d.ts +3 -3
  35. package/dist/stdlib/regexp.js +1 -2
  36. package/dist/stdlib/string.js +8 -13
  37. package/dist/stdlib/url.d.ts +2 -1
  38. package/dist/stdlib/url.js +2 -12
  39. package/dist/stdlib/value.d.ts +0 -3
  40. package/dist/stdlib/value.js +1 -68
  41. package/dist/stdlib/web.js +1 -2
  42. package/package.json +1 -1
package/dist/data.d.ts CHANGED
@@ -1,19 +1,20 @@
1
1
  export * as Data from "./data.js";
2
2
  import { Effect, type Schema } from "effect";
3
3
  import type { Interpreter } from "./interpreter/interpreter.js";
4
+ import { type Value } from "./interpreter/objects.js";
4
5
  export type Json = Schema.Json;
5
- type Replacer<R> = (args: Array<unknown>) => Effect.Effect<unknown, unknown, R>;
6
+ type Replacer<R> = (args: Array<Value>) => Effect.Effect<Value, unknown, R>;
6
7
  /**
7
8
  * What `JSON.stringify` would serialize for a program value, as host JSON: `toJSON` is honored, functions and
8
9
  * `undefined` vanish, non-finite numbers become null, and everything else is copied. Two departures from JS
9
10
  * so a mistake is not a silent `{}`: an Error serializes as `{ name, message, ...own }`, and a promise throws.
10
11
  */
11
- export declare const toJson: <R>(ctx: Interpreter<R>, value: unknown, replacer?: Replacer<R>) => Effect.Effect<Schema.Json | undefined, unknown, R>;
12
+ export declare const toJson: <R>(ctx: Interpreter<R>, value: Value, replacer?: Replacer<R>) => Effect.Effect<Schema.Json | undefined, unknown, R>;
12
13
  /**
13
14
  * The host boundary: `toJson`, plus what a program most likely meant when a value cannot be JSON. A promise is
14
15
  * awaited, a Set crosses as an array, a URLSearchParams as its query string, a Uint8Array asks to be encoded as
15
16
  * text first, and a `__proto__` key is dropped so host code can never receive one.
16
17
  */
17
- export declare const toBoundary: <R>(ctx: Interpreter<R>, value: unknown) => Effect.Effect<Schema.Json | undefined, unknown, R>;
18
+ export declare const toBoundary: <R>(ctx: Interpreter<R>, value: Value) => Effect.Effect<Schema.Json | undefined, unknown, R>;
18
19
  /** Host JSON as program values: objects and arrays are copied, primitives pass through. */
19
- export declare const fromJson: <R>(ctx: Interpreter<R>, value: unknown) => unknown;
20
+ export declare const fromJson: <R>(ctx: Interpreter<R>, value: Json | undefined) => Value;
@@ -1,10 +1,10 @@
1
1
  import { Effect } from "effect";
2
2
  import type { Interpreter } from "./interpreter.js";
3
- import { Callable } from "./objects.js";
3
+ import { Callable, type Value } from "./objects.js";
4
4
  export type IteratorCursor<R> = {
5
5
  readonly next: Effect.Effect<{
6
6
  readonly done: boolean;
7
- readonly value: unknown;
7
+ readonly value: Value;
8
8
  }, unknown, R>;
9
9
  readonly close: Effect.Effect<void, unknown, R>;
10
10
  };
@@ -13,10 +13,10 @@ export declare const preserveConsumerError: <A, R>(cursor: IteratorCursor<R>, ef
13
13
  * ToPrimitive: calls `valueOf`/`toString` in hint order and returns the first primitive result. Dates treat the
14
14
  * default hint as "string", like their `Symbol.toPrimitive`.
15
15
  */
16
- export declare const toPrimitive: <R>(ctx: Interpreter<R>, value: unknown, hint: "number" | "string" | "default") => Effect.Effect<unknown, unknown, R>;
16
+ export declare const toPrimitive: <R>(ctx: Interpreter<R>, value: Value, hint: "number" | "string" | "default") => Effect.Effect<Value, unknown, R>;
17
17
  /** Invoke(value, name): calls the method the value would find through its prototype. */
18
- export declare const invoke: <R>(ctx: Interpreter<R>, value: unknown, name: string, label: string) => Effect.Effect<unknown, unknown, R>;
19
- export declare const toPrimitiveString: <R>(ctx: Interpreter<R>, value: unknown) => Effect.Effect<string, unknown, R>;
20
- export declare const toPrimitiveNumber: <R>(ctx: Interpreter<R>, value: unknown) => Effect.Effect<number, unknown, R>;
21
- export declare const isSupportedCallback: (value: unknown) => value is Callable;
22
- export declare const applyCollectionCallback: <R>(ctx: Interpreter<R>, callback: unknown, name: string) => ((args: Array<unknown>) => Effect.Effect<unknown, unknown, R>);
18
+ export declare const invoke: <R>(ctx: Interpreter<R>, value: Value, name: string, label: string) => Effect.Effect<Value, unknown, R>;
19
+ export declare const toPrimitiveString: <R>(ctx: Interpreter<R>, value: Value) => Effect.Effect<string, unknown, R>;
20
+ export declare const toPrimitiveNumber: <R>(ctx: Interpreter<R>, value: Value) => Effect.Effect<number, unknown, R>;
21
+ export declare const isSupportedCallback: (value: Value) => value is Callable;
22
+ export declare const applyCollectionCallback: <R>(ctx: Interpreter<R>, callback: Value, name: string) => ((args: Array<Value>) => Effect.Effect<Value, unknown, R>);
@@ -1,8 +1,7 @@
1
1
  import { Effect, Exit } from "effect";
2
- import { coerceToNumber, coerceToString } from "../stdlib/value.js";
3
2
  import { primitivePrototype } from "./intrinsics.js";
4
3
  import { typeError } from "./model.js";
5
- import { Callable, get, Native, DateObj, Obj } from "./objects.js";
4
+ import { Callable, get, Native, DateObj, Obj, coerceToNumber, coerceToString } from "./objects.js";
6
5
  import { typeofValue } from "./references.js";
7
6
  export const preserveConsumerError = (cursor, effect) => Effect.flatMap(Effect.exit(effect), (exit) => Exit.isSuccess(exit)
8
7
  ? Effect.succeed(exit.value)
@@ -1,7 +1,7 @@
1
1
  import type { Diagnostic } from "../codemode.js";
2
2
  import { type AstNode } from "./model.js";
3
3
  import { type ErrorType } from "./intrinsics.js";
4
- import { type Native, ErrorObj, Obj } from "./objects.js";
4
+ import { type Native, ErrorObj, Obj, type Value } from "./objects.js";
5
5
  import type { Interpreter } from "./interpreter.js";
6
6
  export declare const normalizeError: (error: unknown) => Diagnostic;
7
7
  /**
@@ -10,7 +10,7 @@ export declare const normalizeError: (error: unknown) => Diagnostic;
10
10
  */
11
11
  export declare const locate: (error: unknown, node?: AstNode) => unknown;
12
12
  /** The program value a handler receives for a failure; one failure always yields the same value. */
13
- export declare const materialize: <R>(ctx: Interpreter<R>, thrown: unknown) => unknown;
14
- export declare const createAggregateErrorValue: <R>(ctx: Interpreter<R>, errors: Array<unknown>, message: string, proto?: Obj) => ErrorObj;
13
+ export declare const materialize: <R>(ctx: Interpreter<R>, thrown: unknown) => Value;
14
+ export declare const createAggregateErrorValue: <R>(ctx: Interpreter<R>, errors: Array<Value>, message: string, proto?: Obj) => ErrorObj;
15
15
  /** An error constructor such as `Error` or `TypeError`; callable with or without `new`, like JS. */
16
16
  export declare const errorGlobal: <R>(type: ErrorType, ctx: Interpreter<R>) => Native<R>;
@@ -5,9 +5,8 @@ import { formatLocation, PendingThrow, Throw, sourceLocation, typeError } from "
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";
8
- import { define, get, has, hidden, Arr, ErrorObj, Obj } from "./objects.js";
8
+ import { define, get, has, hidden, Arr, ErrorObj, Obj, coerceToString, } from "./objects.js";
9
9
  import { formatValue } from "../stdlib/console.js";
10
- import { coerceToString } from "../stdlib/value.js";
11
10
  export const normalizeError = (error) => {
12
11
  if (error instanceof PendingThrow) {
13
12
  return {
@@ -1,5 +1,6 @@
1
1
  import { Effect } from "effect";
2
2
  import type { ResolvedExecutionLimits, Result } from "../codemode.js";
3
3
  import { ToolRuntime } from "../tool-runtime.js";
4
+ import type { Value } from "./objects.js";
4
5
  import { Interpreter } from "./interpreter.js";
5
- export declare const executeProgram: <R>(code: string, prepared: ToolRuntime.Prepared<R>, limits: ResolvedExecutionLimits, hooks: ToolRuntime.Hooks<R>, globals?: (ctx: Interpreter<R>) => ReadonlyArray<readonly [string, unknown]>) => Effect.Effect<Result, never, R>;
6
+ export declare const executeProgram: <R>(code: string, prepared: ToolRuntime.Prepared<R>, limits: ResolvedExecutionLimits, hooks: ToolRuntime.Hooks<R>, globals?: (ctx: Interpreter<R>) => ReadonlyArray<readonly [string, Value]>) => Effect.Effect<Result, never, R>;
@@ -1,8 +1,9 @@
1
1
  import type { Extension } from "../extension.js";
2
2
  import type { Interpreter } from "./interpreter.js";
3
+ import { type Value } from "./objects.js";
3
4
  /**
4
5
  * The global bindings of one run's extensions. Everything crossing the boundary is converted: plain data and
5
6
  * built-in wrappers are copied, a host function becomes a program function whose calls cross the same way, and a
6
7
  * host Promise becomes a program promise.
7
8
  */
8
- export declare const extensionGlobals: <R>(ctx: Interpreter<R>, extensions: ReadonlyArray<Extension>) => ReadonlyArray<readonly [string, unknown]>;
9
+ export declare const extensionGlobals: <R>(ctx: Interpreter<R>, extensions: ReadonlyArray<Extension>) => ReadonlyArray<readonly [string, Value]>;
@@ -1,12 +1,11 @@
1
1
  import { Effect } from "effect";
2
- import { coerceToString } from "../stdlib/value.js";
3
2
  import { hooked } from "../tool-runtime.js";
4
3
  import { createErrorValue, isErrorType } from "./intrinsics.js";
5
4
  import { MAX_VALUE_DEPTH } from "./limits.js";
6
5
  import { PendingThrow, Throw, typeError } from "./model.js";
7
6
  import { fn } from "./native.js";
8
- import { Callable, define, entries, get, has, hidden, keys, Arr, Bytes, DateObj, ErrorObj, GeneratorObj, IteratorObj, MapObj, Obj, PromiseObj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, HeadersObj, } from "./objects.js";
9
- import { describeValue } from "./references.js";
7
+ import { define, get, has, hidden, keys, Arr, Bytes, DateObj, ErrorObj, HeadersObj, MapObj, Obj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, coerceToString, } from "./objects.js";
8
+ import { describeValue, isOpaque } from "./references.js";
10
9
  /**
11
10
  * The global bindings of one run's extensions. Everything crossing the boundary is converted: plain data and
12
11
  * built-in wrappers are copied, a host function becomes a program function whose calls cross the same way, and a
@@ -17,38 +16,15 @@ export const extensionGlobals = (ctx, extensions) => {
17
16
  const toHost = (value, label, depth = 0, seen = new Set()) => {
18
17
  if (depth > MAX_VALUE_DEPTH)
19
18
  throw typeError(`${label} exceeds the maximum value depth of ${MAX_VALUE_DEPTH}.`);
20
- if (value === null || typeof value !== "object") {
21
- if (isPrimitive(value))
22
- return value;
23
- throw typeError(`${label} contains ${describeValue(value)}, which cannot be passed to an extension.`);
24
- }
25
- if (value instanceof Bytes)
26
- return new Uint8Array(value.bytes);
27
- if (value instanceof DateObj)
28
- return new Date(value.time);
29
- if (value instanceof RegExpObj)
30
- return new RegExp(value.regex.source, value.regex.flags);
31
- if (value instanceof URLObj)
32
- return new URL(value.url.href);
33
- if (value instanceof URLSearchParamsObj)
34
- return new URLSearchParams(value.params);
35
- if (value instanceof HeadersObj)
36
- return new Headers(value.headers);
37
- const next = (item) => toHost(item, label, depth + 1, seen);
38
- if (value instanceof MapObj)
39
- return new Map([...value.map].map(([key, item]) => [next(key), next(item)]));
40
- if (value instanceof SetObj)
41
- return new Set([...value.set].map(next));
42
- if (!(value instanceof Obj) ||
43
- value instanceof Callable ||
44
- value instanceof GeneratorObj ||
45
- value instanceof IteratorObj ||
46
- value instanceof PromiseObj) {
19
+ if (isPrimitive(value))
20
+ return value;
21
+ if (!(value instanceof Obj) || isOpaque(value)) {
47
22
  throw typeError(`${label} contains ${describeValue(value)}, which cannot be passed to an extension.`);
48
23
  }
49
24
  if (seen.has(value))
50
25
  throw typeError(`${label} contains a circular value.`);
51
26
  seen.add(value);
27
+ const next = (item) => toHost(item, label, depth + 1, seen);
52
28
  if (value instanceof ErrorObj) {
53
29
  const name = coerceToString(get(value, "name"));
54
30
  const message = get(value, "message");
@@ -70,11 +46,7 @@ export const extensionGlobals = (ctx, extensions) => {
70
46
  seen.delete(value);
71
47
  return copied;
72
48
  }
73
- const copied = value instanceof Arr
74
- ? value.items.map(next)
75
- : Object.fromEntries(entries(value)
76
- .filter(([key]) => key !== "__proto__")
77
- .map(([key, item]) => [key, next(item)]));
49
+ const copied = value.toHost(next);
78
50
  seen.delete(value);
79
51
  return copied;
80
52
  };
@@ -1,5 +1,6 @@
1
+ import type { Value } from "./objects.js";
1
2
  import type { Interpreter } from "./interpreter.js";
2
3
  /** Names bound in every program before extensions apply. */
3
4
  export declare const globalNames: ReadonlySet<string>;
4
5
  /** The immutable global bindings of every program, in declaration order. */
5
- export declare const globals: <R>(ctx: Interpreter<R>) => ReadonlyArray<readonly [string, unknown]>;
6
+ export declare const globals: <R>(ctx: Interpreter<R>) => ReadonlyArray<readonly [string, Value]>;
@@ -3,7 +3,7 @@ import { Effect } from "effect";
3
3
  import { type Json } from "../data.js";
4
4
  import { type ToolRuntime } from "../tool-runtime.js";
5
5
  import { type Builtins } from "./intrinsics.js";
6
- import { PromiseObj } from "./objects.js";
6
+ import { PromiseObj, type Value } from "./objects.js";
7
7
  import { Pending } from "./promises.js";
8
8
  /** One program execution: the tool bridge, promise scheduler, captured logs, and the global scope built once. */
9
9
  export declare class Interpreter<R> {
@@ -17,24 +17,18 @@ export declare class Interpreter<R> {
17
17
  readonly pending: Pending<R>;
18
18
  readonly builtins: Builtins;
19
19
  readonly logs?: Array<string>;
20
- readonly globals?: (ctx: Interpreter<R>) => ReadonlyArray<readonly [string, unknown]>;
20
+ readonly globals?: (ctx: Interpreter<R>) => ReadonlyArray<readonly [string, Value]>;
21
21
  });
22
- run(program: Program): Effect.Effect<unknown, unknown, R>;
23
- call(callable: unknown, thisValue: unknown, args: Array<unknown>): Effect.Effect<unknown, unknown, R>;
24
- await(promise: PromiseObj): Effect.Effect<unknown, unknown, never>;
25
- iterate(value: unknown): Effect.Effect<{
22
+ run(program: Program): Effect.Effect<Value, unknown, R>;
23
+ call(callable: Value, thisValue: Value, args: Array<Value>): Effect.Effect<Value, unknown, R>;
24
+ await(promise: PromiseObj): Effect.Effect<Value, unknown, never>;
25
+ iterate(value: Value): Effect.Effect<{
26
26
  next: Effect.Effect<{
27
27
  done: boolean;
28
- value: any;
29
- }, never, never>;
30
- close: Effect.Effect<void, never, never>;
31
- }, never, never> | Effect.Effect<{
32
- next: Effect.Effect<{
33
- done: boolean;
34
- value: unknown;
28
+ value: Value;
35
29
  }, unknown, R>;
36
30
  close: Effect.Effect<void, unknown, R>;
37
31
  } | undefined, unknown, R>;
38
32
  /** Runs one host tool: arguments cross as JSON and the result comes back as program values. */
39
- tool(run: (args: Array<Json | undefined>) => Effect.Effect<Json | undefined, unknown, R>, args: Array<unknown>): Effect.Effect<unknown, unknown, R>;
33
+ tool(run: (args: Array<Json | undefined>) => Effect.Effect<Json | undefined, unknown, R>, args: Array<Value>): Effect.Effect<Value, unknown, R>;
40
34
  }
@@ -6,14 +6,14 @@ import { checkStringLength } from "./limits.js";
6
6
  import { locate, materialize } from "./errors.js";
7
7
  import { primitivePrototype } from "./intrinsics.js";
8
8
  import { globals } from "./globals.js";
9
- import { assign, Callable, define, get, has, hasPrototype, keys, Native, parseArrayIndex, Arr, Bytes, DateObj, Fn, GeneratorObj, IteratorObj, MapObj, Obj, PromiseObj, SetObj, URLSearchParamsObj, HeadersObj, record, remove, set, } from "./objects.js";
9
+ import { assign, Callable, define, get, has, hasPrototype, keys, Native, parseArrayIndex, Arr, Fn, GeneratorObj, Obj, PromiseObj, record, remove, set, coerceToNumber, coerceToString, } from "./objects.js";
10
10
  import { preserveConsumerError } from "./callback.js";
11
11
  import { Pending, resolvePromise, resolvePromiseValue } from "./promises.js";
12
12
  import { containsOpaqueReference, describeValue, rejectCircularInsertion, typeofValue } from "./references.js";
13
13
  import { ScopeStack } from "./scope.js";
14
14
  import { constructRegExp } from "../stdlib/regexp.js";
15
15
  import { enumerableSource } from "../stdlib/object.js";
16
- import { coerceToNumber, coerceToString, compoundOperators } from "../stdlib/value.js";
16
+ import { compoundOperators } from "../stdlib/value.js";
17
17
  // What a loop does with its body's result: exit with a StatementResult, or undefined to keep iterating.
18
18
  // Unlabelled break ends this loop; a label the loop does not carry propagates outward.
19
19
  const loopExit = (result, labels) => {
@@ -51,6 +51,14 @@ const calleeDescription = (node) => {
51
51
  return object === undefined ? undefined : `${object}.${key}`;
52
52
  };
53
53
  // OrdinaryHasInstance: walk the left operand's chain looking for the constructor's `prototype`.
54
+ // acorn types every literal as possibly a BigInt or RegExp; regex literals become RegExp objects before this is asked.
55
+ const literal = (node) => {
56
+ if (typeof node.value === "bigint")
57
+ throw typeError("BigInt literals are not supported.", node);
58
+ if (node.value instanceof RegExp)
59
+ throw unsupportedSyntax("RegExpLiteral", node);
60
+ return node.value;
61
+ };
54
62
  const instanceofValue = (lhs, rhs, node) => {
55
63
  if (!(rhs instanceof Callable)) {
56
64
  throw typeError("The right-hand side of 'instanceof' is not callable.", node);
@@ -487,7 +495,7 @@ class Frame {
487
495
  const cursor = self.hostCursor(right);
488
496
  const iterator = cursor === undefined ? yield* self.customIterator(right, node, awaiting) : undefined;
489
497
  if (iterator === undefined && cursor === undefined) {
490
- throw invalidData(`${awaiting ? "for await...of" : "for...of"} requires an array, string, Map, Set, URLSearchParams, or Headers, or custom iterator value.`, node);
498
+ throw invalidData(`${awaiting ? "for await...of" : "for...of"} requires an iterable value, received ${describeValue(right)}.`, node);
491
499
  }
492
500
  const close = () => iterator
493
501
  ? self.closeIterator(iterator, node, awaiting)
@@ -569,33 +577,17 @@ class Frame {
569
577
  });
570
578
  }
571
579
  hostCursor(value) {
572
- const iterator = value instanceof Arr
573
- ? value.items[Symbol.iterator]()
574
- : typeof value === "string"
575
- ? value[Symbol.iterator]()
576
- : value instanceof MapObj
577
- ? value.map.entries()
578
- : value instanceof SetObj
579
- ? value.set.values()
580
- : value instanceof URLSearchParamsObj
581
- ? value.params.entries()
582
- : value instanceof HeadersObj
583
- ? value.headers.entries()
584
- : value instanceof Bytes
585
- ? value.bytes.values()
586
- : value instanceof IteratorObj
587
- ? value.iterator
588
- : undefined;
580
+ const iterator = typeof value === "string"
581
+ ? value[Symbol.iterator]()
582
+ : value instanceof Obj
583
+ ? value.iterator(this.ctx.builtins)
584
+ : undefined;
589
585
  if (iterator === undefined)
590
586
  return undefined;
591
- const proto = this.ctx.builtins.Array;
592
587
  return {
593
588
  next: Effect.sync(() => {
594
589
  const step = iterator.next();
595
- return {
596
- done: Boolean(step.done),
597
- value: Array.isArray(step.value) ? new Arr(proto, step.value) : step.value,
598
- };
590
+ return { done: Boolean(step.done), value: step.value };
599
591
  }),
600
592
  close: Effect.void,
601
593
  };
@@ -967,9 +959,7 @@ class Frame {
967
959
  const regex = node.regex;
968
960
  if (regex)
969
961
  return Effect.sync(() => constructRegExp(this.ctx.builtins, [regex.pattern, regex.flags]));
970
- if (typeof node.value === "bigint")
971
- throw typeError("BigInt literals are not supported.", node);
972
- return Effect.succeed(node.value);
962
+ return Effect.succeed(literal(node));
973
963
  }
974
964
  case "Identifier":
975
965
  return Effect.sync(() => this.scopes.get(node.name, node));
@@ -1069,14 +1059,9 @@ class Frame {
1069
1059
  if (containsOpaqueReference(lhs) || containsOpaqueReference(rhs)) {
1070
1060
  throw invalidData("Binary operators require data values.", node);
1071
1061
  }
1072
- // Null-prototype data needs explicit primitive coercion; identity and `in` retain raw objects.
1073
- // Dates use their default string hint for addition and loose equality, and epoch time elsewhere.
1074
- const coerceOperand = (operand) => {
1075
- if (operand instanceof DateObj) {
1076
- return operator === "+" || operator === "==" || operator === "!=" ? coerceToString(operand) : operand.time;
1077
- }
1078
- return operand !== null && typeof operand === "object" ? coerceToString(operand) : operand;
1079
- };
1062
+ // Addition and loose equality use the default hint; every other operator asks for a number.
1063
+ const hint = operator === "+" || operator === "==" || operator === "!=" ? "default" : "number";
1064
+ const coerceOperand = (operand) => (operand instanceof Obj ? operand.toPrimitive(hint) : operand);
1080
1065
  const bothObjects = lhs !== null && typeof lhs === "object" && rhs !== null && typeof rhs === "object";
1081
1066
  const l = coerceOperand(lhs);
1082
1067
  const r = coerceOperand(rhs);
@@ -1161,11 +1146,7 @@ class Frame {
1161
1146
  if (containsOpaqueReference(value)) {
1162
1147
  throw invalidData("Unary operators require data values.", node);
1163
1148
  }
1164
- const operand = value instanceof DateObj
1165
- ? value.time
1166
- : value !== null && typeof value === "object"
1167
- ? coerceToString(value)
1168
- : value;
1149
+ const operand = value instanceof Obj ? value.toPrimitive("number") : value;
1169
1150
  let result;
1170
1151
  switch (operator) {
1171
1152
  case "+":
@@ -1524,16 +1505,8 @@ class Frame {
1524
1505
  delegateYield(value, node) {
1525
1506
  const self = this;
1526
1507
  return Effect.gen(function* () {
1527
- if (value instanceof Arr ||
1528
- typeof value === "string" ||
1529
- value instanceof MapObj ||
1530
- value instanceof SetObj ||
1531
- value instanceof URLSearchParamsObj ||
1532
- value instanceof HeadersObj ||
1533
- value instanceof Bytes) {
1534
- const cursor = yield* self.iterate(value, node);
1535
- if (!cursor)
1536
- throw typeError("Built-in iterator is unavailable.", node);
1508
+ const cursor = self.hostCursor(value);
1509
+ if (cursor !== undefined) {
1537
1510
  while (true) {
1538
1511
  const step = yield* cursor.next;
1539
1512
  if (step.done)
@@ -1616,7 +1589,7 @@ class Frame {
1616
1589
  key = keyNode.name;
1617
1590
  }
1618
1591
  else if (keyNode.type === "Literal") {
1619
- key = self.toPropertyKey(keyNode.value, keyNode);
1592
+ key = self.toPropertyKey(literal(keyNode), keyNode);
1620
1593
  }
1621
1594
  else {
1622
1595
  throw typeError("Unsupported object property key shape.", keyNode);
@@ -1,4 +1,4 @@
1
- import { ErrorObj, Obj } from "./objects.js";
1
+ import { ErrorObj, Obj, type Value } from "./objects.js";
2
2
  export declare const errorTypes: readonly ["Error", "TypeError", "RangeError", "SyntaxError", "ReferenceError", "EvalError", "URIError", "AggregateError"];
3
3
  export type ErrorType = (typeof errorTypes)[number];
4
4
  export declare const isErrorType: (name: string) => name is ErrorType;
@@ -10,6 +10,6 @@ declare const builtins: readonly ["Object", "Function", "Array", "String", "Numb
10
10
  export type Builtins = Readonly<Record<(typeof builtins)[number] | ErrorType, Obj>>;
11
11
  export declare const createErrorValue: (prototype: Obj, message: string | undefined) => ErrorObj;
12
12
  /** The prototype a primitive reads its methods from without being boxed; none for null, undefined, and symbols. */
13
- export declare const primitivePrototype: (builtins: Builtins, value: unknown) => Obj | undefined;
13
+ export declare const primitivePrototype: (builtins: Builtins, value: Value) => Obj | undefined;
14
14
  export declare const createBuiltins: () => Builtins;
15
15
  export {};
@@ -2,7 +2,7 @@ import type { Node } from "acorn";
2
2
  import { Context } from "effect";
3
3
  import type { ErrorType } from "./intrinsics.js";
4
4
  import type { DiagnosticKind } from "../codemode.js";
5
- import type { ErrorObj } from "./objects.js";
5
+ import type { ErrorObj, Value } from "./objects.js";
6
6
  /** Any parsed node; the interpreter narrows on `type` and reads `loc` for diagnostics. */
7
7
  export type AstNode = Node;
8
8
  /** The program call a built-in is running under: where to locate failures born inside it, and how deep the stack is there. */
@@ -12,14 +12,14 @@ export declare const CallSite: Context.Reference<{
12
12
  }>;
13
13
  export type Binding = {
14
14
  mutable: boolean;
15
- value: unknown;
15
+ value: Value;
16
16
  initialized?: boolean;
17
17
  };
18
18
  export type StatementResult = {
19
19
  kind: "none";
20
20
  } | {
21
21
  kind: "return";
22
- value: unknown;
22
+ value: Value;
23
23
  } | {
24
24
  kind: "break";
25
25
  label?: string;
@@ -32,12 +32,12 @@ export declare const AsyncIteratorSymbol: unique symbol;
32
32
  export declare const IteratorSymbol: unique symbol;
33
33
  export declare const IteratorSymbols: readonly [typeof AsyncIteratorSymbol, typeof IteratorSymbol];
34
34
  export declare class Throw {
35
- readonly value: unknown;
36
- constructor(value: unknown);
35
+ readonly value: Value;
36
+ constructor(value: Value);
37
37
  }
38
38
  export declare class GeneratorReturn {
39
- readonly value: unknown;
40
- constructor(value: unknown);
39
+ readonly value: Value;
40
+ constructor(value: Value);
41
41
  }
42
42
  export declare const OptionalShortCircuit: unique symbol;
43
43
  /**
@@ -64,7 +64,6 @@ export declare const syntaxError: (message: string, node?: AstNode) => PendingTh
64
64
  export declare const uriError: (message: string, node?: AstNode) => PendingThrow;
65
65
  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.";
66
66
  export declare const unsupportedSyntax: (kind: string, node: AstNode) => PendingThrow;
67
- export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
68
67
  export declare const sourceLocation: (node: AstNode) => {
69
68
  readonly line: number;
70
69
  readonly column: number;
@@ -51,7 +51,6 @@ export const uriError = failure("URIError");
51
51
  // Orient the agent rather than enumerate JavaScript; interpreter-support.md is the full matrix.
52
52
  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.";
53
53
  export const unsupportedSyntax = (kind, node) => new PendingThrow("SyntaxError", `Syntax '${kind}' is not supported. ${supportedSyntaxMessage}`, node, "UnsupportedSyntax", [supportedSyntaxMessage]);
54
- export const isRecord = (value) => typeof value === "object" && value !== null;
55
54
  // Acorn lines are 1-based and its columns are 0-based. Diagnostics use 1-based columns of the submitted source.
56
55
  export const sourceLocation = (node) => ({
57
56
  line: node.loc?.start.line ?? 1,
@@ -1,13 +1,13 @@
1
1
  import { Effect } from "effect";
2
2
  import type { Builtins } from "./intrinsics.js";
3
- import { type Callable, Native, type NativeOptions, Obj } from "./objects.js";
4
- /** A native function body: a plain value, a thrown `PendingThrow`, or an Effect. */
5
- export type Impl = (thisValue: unknown, args: Array<unknown>) => unknown;
3
+ import { type Callable, Native, type NativeOptions, Obj, type Value } from "./objects.js";
4
+ /** A native function body: a value, a thrown `PendingThrow`, or an Effect of a value. */
5
+ export type Impl = (thisValue: Value, args: Array<Value>) => Value | Effect.Effect<Value, unknown, unknown>;
6
6
  export declare const native: <R>(builtins: Builtins, options: NativeOptions<R>) => Native<R>;
7
7
  export declare const fn: <R>(builtins: Builtins, name: string, length: number, impl: Impl) => Native<R>;
8
8
  export type Method = readonly [name: string, length: number, impl: Impl];
9
9
  export declare const methods: (builtins: Builtins, target: Obj, table: ReadonlyArray<Method>) => void;
10
- export declare const constants: (target: Obj, table: Record<string, unknown>) => void;
10
+ export declare const constants: (target: Obj, table: Record<string, Value>) => void;
11
11
  /** A constructor wired to its prototype: `C.prototype === proto` and `proto.constructor === C`. */
12
12
  export declare const constructor: <R>(builtins: Builtins, proto: Obj, options: NativeOptions<R>) => Native<R>;
13
13
  /** The `call` of a constructor that JS requires to be invoked with `new`. */
@@ -15,4 +15,4 @@ export declare const requiresNew: (name: string) => () => Effect.Effect<never, u
15
15
  /** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
16
16
  export declare const prototypeFrom: (newTarget: Callable, fallback: Obj) => Obj;
17
17
  /** Narrows a method receiver to the built-in it belongs to, or throws the TypeError JS would. */
18
- export declare const receiver: <T extends Obj>(cls: abstract new (...args: never) => T, thisValue: unknown, method: string) => T;
18
+ export declare const receiver: <T extends Obj>(cls: abstract new (...args: never) => T, thisValue: Value, method: string) => T;