@opencode/codemode 0.0.0-dev-19631 → 0.0.0-dev-19633

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 (62) hide show
  1. package/dist/codemode.js +1 -1
  2. package/dist/data.d.ts +3 -3
  3. package/dist/data.js +37 -31
  4. package/dist/interpreter/callback.d.ts +20 -0
  5. package/dist/interpreter/{runner.js → callback.js} +10 -10
  6. package/dist/interpreter/errors.d.ts +5 -5
  7. package/dist/interpreter/errors.js +21 -22
  8. package/dist/interpreter/execute.d.ts +2 -2
  9. package/dist/interpreter/execute.js +11 -11
  10. package/dist/interpreter/extensions.d.ts +2 -2
  11. package/dist/interpreter/extensions.js +42 -36
  12. package/dist/interpreter/generators.d.ts +2 -3
  13. package/dist/interpreter/generators.js +8 -8
  14. package/dist/interpreter/globals.d.ts +2 -12
  15. package/dist/interpreter/globals.js +41 -37
  16. package/dist/interpreter/interpreter.d.ts +31 -0
  17. package/dist/interpreter/{runtime.js → interpreter.js} +118 -117
  18. package/dist/interpreter/intrinsics.d.ts +5 -5
  19. package/dist/interpreter/intrinsics.js +16 -10
  20. package/dist/interpreter/model.d.ts +3 -3
  21. package/dist/interpreter/model.js +1 -1
  22. package/dist/interpreter/native.d.ts +9 -9
  23. package/dist/interpreter/native.js +9 -9
  24. package/dist/interpreter/objects.d.ts +51 -46
  25. package/dist/interpreter/objects.js +57 -40
  26. package/dist/interpreter/promises.d.ts +13 -13
  27. package/dist/interpreter/promises.js +70 -70
  28. package/dist/interpreter/references.js +17 -15
  29. package/dist/openapi/types.d.ts +1 -1
  30. package/dist/stdlib/array.d.ts +3 -3
  31. package/dist/stdlib/array.js +31 -31
  32. package/dist/stdlib/bytes.d.ts +10 -0
  33. package/dist/stdlib/bytes.js +228 -0
  34. package/dist/stdlib/collections.d.ts +4 -4
  35. package/dist/stdlib/collections.js +55 -55
  36. package/dist/stdlib/console.d.ts +3 -3
  37. package/dist/stdlib/console.js +24 -22
  38. package/dist/stdlib/date.d.ts +2 -2
  39. package/dist/stdlib/date.js +19 -19
  40. package/dist/stdlib/json.d.ts +3 -3
  41. package/dist/stdlib/json.js +24 -24
  42. package/dist/stdlib/math.d.ts +3 -3
  43. package/dist/stdlib/math.js +7 -7
  44. package/dist/stdlib/number.d.ts +3 -3
  45. package/dist/stdlib/number.js +11 -11
  46. package/dist/stdlib/object.d.ts +5 -5
  47. package/dist/stdlib/object.js +41 -39
  48. package/dist/stdlib/regexp.d.ts +6 -6
  49. package/dist/stdlib/regexp.js +24 -24
  50. package/dist/stdlib/string.d.ts +2 -2
  51. package/dist/stdlib/string.js +24 -24
  52. package/dist/stdlib/url.d.ts +6 -6
  53. package/dist/stdlib/url.js +39 -39
  54. package/dist/stdlib/value.d.ts +3 -3
  55. package/dist/stdlib/value.js +18 -14
  56. package/dist/stdlib/web.d.ts +4 -4
  57. package/dist/stdlib/web.js +19 -5
  58. package/dist/tool-runtime.d.ts +2 -2
  59. package/dist/tool-runtime.js +2 -2
  60. package/package.json +1 -1
  61. package/dist/interpreter/runner.d.ts +0 -27
  62. package/dist/interpreter/runtime.d.ts +0 -19
@@ -1,22 +1,22 @@
1
1
  import { Effect } from "effect";
2
2
  import { constructor, methods, prototypeFrom, receiver } from "../interpreter/native.js";
3
3
  import { rangeError } from "../interpreter/model.js";
4
- import { ProgramDate, ProgramObject } from "../interpreter/objects.js";
5
- import { toPrimitive, toPrimitiveNumber } from "../interpreter/runner.js";
4
+ import { DateObj, Obj } from "../interpreter/objects.js";
5
+ import { toPrimitive, toPrimitiveNumber } from "../interpreter/callback.js";
6
6
  import { coerceToNumber, coerceToString } from "./value.js";
7
- const constructDate = (runner, args, proto) => {
7
+ const constructDate = (ctx, args, proto) => {
8
8
  if (args.length === 0)
9
- return Effect.succeed(new ProgramDate(proto, Date.now()));
9
+ return Effect.succeed(new DateObj(proto, Date.now()));
10
10
  if (args.length === 1) {
11
11
  const arg = args[0];
12
- if (arg instanceof ProgramDate)
13
- return Effect.succeed(new ProgramDate(proto, arg.time));
14
- return Effect.map(toPrimitive(runner, arg, "default"), (value) => typeof value === "string"
15
- ? new ProgramDate(proto, Date.parse(value))
16
- : new ProgramDate(proto, new Date(coerceToNumber(value)).getTime()));
12
+ if (arg instanceof DateObj)
13
+ return Effect.succeed(new DateObj(proto, arg.time));
14
+ return Effect.map(toPrimitive(ctx, arg, "default"), (value) => typeof value === "string"
15
+ ? new DateObj(proto, Date.parse(value))
16
+ : new DateObj(proto, new Date(coerceToNumber(value)).getTime()));
17
17
  }
18
18
  const parts = args.map((arg) => coerceToNumber(arg));
19
- return Effect.succeed(new ProgramDate(proto, new Date(...parts).getTime()));
19
+ return Effect.succeed(new DateObj(proto, new Date(...parts).getTime()));
20
20
  };
21
21
  const getters = [
22
22
  "getFullYear",
@@ -54,28 +54,28 @@ const setters = [
54
54
  ["setFullYear", 3],
55
55
  ["setUTCFullYear", 3],
56
56
  ];
57
- export const dateGlobal = (runner) => {
58
- const protos = runner.prototypes;
59
- const proto = protos.Date;
60
- const date = constructor(protos, proto, {
57
+ export const dateGlobal = (ctx) => {
58
+ const builtins = ctx.builtins;
59
+ const proto = builtins.Date;
60
+ const date = constructor(builtins, proto, {
61
61
  name: "Date",
62
62
  length: 7,
63
63
  // ISO instead of the host's locale string: date strings are deterministic and must not leak the host timezone.
64
64
  call: () => Effect.sync(() => new Date().toISOString()),
65
- construct: (args, newTarget) => constructDate(runner, args, prototypeFrom(newTarget, proto)),
65
+ construct: (args, newTarget) => constructDate(ctx, args, prototypeFrom(newTarget, proto)),
66
66
  });
67
- methods(protos, date, [
67
+ methods(builtins, date, [
68
68
  ["now", 0, () => Date.now()],
69
69
  ["parse", 1, (_, args) => Date.parse(coerceToString(args[0]))],
70
70
  ["UTC", 7, (_, args) => Date.UTC(...args.map((arg) => coerceToNumber(arg)))],
71
71
  ]);
72
- const self = (thisValue, name) => receiver(ProgramDate, thisValue, `Date.prototype.${name}`);
72
+ const self = (thisValue, name) => receiver(DateObj, thisValue, `Date.prototype.${name}`);
73
73
  const iso = (value) => {
74
74
  if (!Number.isFinite(value.time))
75
75
  throw rangeError("Invalid time value.");
76
76
  return new Date(value.time).toISOString();
77
77
  };
78
- methods(protos, proto, [
78
+ methods(builtins, proto, [
79
79
  ["getTime", 0, (thisValue) => self(thisValue, "getTime").time],
80
80
  ["valueOf", 0, (thisValue) => self(thisValue, "valueOf").time],
81
81
  ["toISOString", 0, (thisValue) => iso(self(thisValue, "toISOString"))],
@@ -100,7 +100,7 @@ export const dateGlobal = (runner) => {
100
100
  const target = self(thisValue, name);
101
101
  // Native setters read the current time before argument coercion, whose callbacks may mutate the Date.
102
102
  const hosted = new Date(target.time);
103
- return Effect.map(Effect.forEach(args.slice(0, length), (arg) => toPrimitiveNumber(runner, arg), {
103
+ return Effect.map(Effect.forEach(args.slice(0, length), (arg) => toPrimitiveNumber(ctx, arg), {
104
104
  concurrency: 1,
105
105
  }), (values) => {
106
106
  target.time = hosted[name](...values);
@@ -1,3 +1,3 @@
1
- import { type Runner } from "../interpreter/runner.js";
2
- import { ProgramObject } from "../interpreter/objects.js";
3
- export declare const jsonGlobal: <R>(runner: Runner<R>) => ProgramObject;
1
+ import type { Interpreter } from "../interpreter/interpreter.js";
2
+ import { Obj } from "../interpreter/objects.js";
3
+ export declare const jsonGlobal: <R>(ctx: Interpreter<R>) => Obj;
@@ -1,26 +1,26 @@
1
1
  import { Effect } from "effect";
2
2
  import { methods } from "../interpreter/native.js";
3
- import { applyCollectionCallback } from "../interpreter/runner.js";
3
+ import { applyCollectionCallback } from "../interpreter/callback.js";
4
4
  import { checkStringLength } from "../interpreter/limits.js";
5
5
  import { syntaxError, typeError } from "../interpreter/model.js";
6
6
  import { typeofValue } from "../interpreter/references.js";
7
7
  import { fromData, toData, toProgram } from "../data.js";
8
- import { Callable, get, keys, ProgramArray, ProgramObject, record, remove, set } from "../interpreter/objects.js";
9
- export const jsonGlobal = (runner) => {
10
- const json = new ProgramObject(runner.prototypes.Object);
11
- methods(runner.prototypes, json, [
12
- ["parse", 2, (_, args) => parse(runner, args)],
13
- ["stringify", 3, (_, args) => stringify(runner, args)],
8
+ import { Callable, get, keys, Arr, Obj, record, remove, set } from "../interpreter/objects.js";
9
+ export const jsonGlobal = (ctx) => {
10
+ const json = new Obj(ctx.builtins.Object);
11
+ methods(ctx.builtins, json, [
12
+ ["parse", 2, (_, args) => parse(ctx, args)],
13
+ ["stringify", 3, (_, args) => stringify(ctx, args)],
14
14
  ]);
15
15
  return json;
16
16
  };
17
- const parse = (runner, args) => {
17
+ const parse = (ctx, args) => {
18
18
  const text = args[0];
19
19
  if (typeof text !== "string")
20
20
  throw typeError("JSON.parse expects a string.");
21
21
  const parsed = (() => {
22
22
  try {
23
- return fromData(runner.prototypes, JSON.parse(text), "JSON.parse result");
23
+ return fromData(ctx.builtins, JSON.parse(text), "JSON.parse result");
24
24
  }
25
25
  catch (error) {
26
26
  throw syntaxError(`JSON.parse received invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
@@ -28,10 +28,10 @@ const parse = (runner, args) => {
28
28
  })();
29
29
  if (typeofValue(args[1]) !== "function")
30
30
  return Effect.succeed(parsed);
31
- const apply = applyCollectionCallback(runner, args[1], "JSON.parse");
31
+ const apply = applyCollectionCallback(ctx, args[1], "JSON.parse");
32
32
  const visit = (holder, key) => Effect.gen(function* () {
33
33
  const value = get(holder, key);
34
- if (value instanceof ProgramObject) {
34
+ if (value instanceof Obj) {
35
35
  for (const name of keys(value)) {
36
36
  const revived = yield* visit(value, name);
37
37
  if (revived === undefined)
@@ -42,14 +42,14 @@ const parse = (runner, args) => {
42
42
  }
43
43
  return yield* apply([key, value]);
44
44
  });
45
- return visit(record(runner.prototypes.Object, { "": parsed }), "");
45
+ return visit(record(ctx.builtins.Object, { "": parsed }), "");
46
46
  };
47
- const stringify = (runner, args) => {
47
+ const stringify = (ctx, args) => {
48
48
  const space = args[2];
49
49
  const indent = typeof space === "number" || typeof space === "string" ? space : undefined;
50
50
  const replacer = args[1];
51
51
  if (typeofValue(replacer) !== "function") {
52
- const properties = replacer instanceof ProgramArray
52
+ const properties = replacer instanceof Arr
53
53
  ? replacer.items
54
54
  .filter((item) => typeof item === "string" || typeof item === "number")
55
55
  .map(String)
@@ -61,24 +61,24 @@ const stringify = (runner, args) => {
61
61
  return Effect.succeed(text);
62
62
  }
63
63
  // Validate up front; the replacer walk below reads the original value.
64
- toProgram(runner.prototypes, args[0], "JSON.stringify value");
65
- const apply = applyCollectionCallback(runner, replacer, "JSON.stringify");
64
+ toProgram(ctx.builtins, args[0], "JSON.stringify value");
65
+ const apply = applyCollectionCallback(ctx, replacer, "JSON.stringify");
66
66
  const stack = new Set();
67
67
  const visit = (holder, key) => Effect.gen(function* () {
68
- const value = yield* apply([key, yield* toJSONValue(runner, get(holder, key), key)]);
68
+ const value = yield* apply([key, yield* toJSONValue(ctx, get(holder, key), key)]);
69
69
  if (value === undefined || typeofValue(value) === "function")
70
70
  return undefined;
71
- toProgram(runner.prototypes, value, "JSON.stringify replacer result");
71
+ toProgram(ctx.builtins, value, "JSON.stringify replacer result");
72
72
  if (typeof value === "number")
73
73
  return Number.isFinite(value) ? value : null;
74
74
  if (value === null || typeof value === "string" || typeof value === "boolean")
75
75
  return value;
76
- if (!(value instanceof ProgramObject))
76
+ if (!(value instanceof Obj))
77
77
  return {};
78
78
  if (stack.has(value))
79
79
  throw typeError("Converting circular structure to JSON.");
80
80
  stack.add(value);
81
- if (value instanceof ProgramArray) {
81
+ if (value instanceof Arr) {
82
82
  const result = [];
83
83
  for (let index = 0; index < value.items.length; index += 1) {
84
84
  result.push((yield* visit(value, String(index))) ?? null);
@@ -95,12 +95,12 @@ const stringify = (runner, args) => {
95
95
  stack.delete(value);
96
96
  return result;
97
97
  });
98
- return Effect.map(visit(record(runner.prototypes.Object, { "": args[0] }), ""), (value) => JSON.stringify(value, null, indent));
98
+ return Effect.map(visit(record(ctx.builtins.Object, { "": args[0] }), ""), (value) => JSON.stringify(value, null, indent));
99
99
  };
100
100
  // SerializeJSONProperty step 2: a callable `toJSON` decides the value, as Date and URL define.
101
- const toJSONValue = (runner, value, key) => {
102
- if (!(value instanceof ProgramObject))
101
+ const toJSONValue = (ctx, value, key) => {
102
+ if (!(value instanceof Obj))
103
103
  return Effect.succeed(value);
104
104
  const toJSON = get(value, "toJSON");
105
- return toJSON instanceof Callable ? runner.invokeCallable(toJSON, value, [key]) : Effect.succeed(value);
105
+ return toJSON instanceof Callable ? ctx.call(toJSON, value, [key]) : Effect.succeed(value);
106
106
  };
@@ -1,8 +1,8 @@
1
- import { ProgramObject } from "../interpreter/objects.js";
2
- import { type Runner } from "../interpreter/runner.js";
1
+ import { Obj } from "../interpreter/objects.js";
2
+ import type { Interpreter } from "../interpreter/interpreter.js";
3
3
  declare global {
4
4
  interface Math {
5
5
  sumPrecise(values: Iterable<number>): number;
6
6
  }
7
7
  }
8
- export declare const mathGlobal: <R>(runner: Runner<R>) => ProgramObject;
8
+ export declare const mathGlobal: <R>(ctx: Interpreter<R>) => Obj;
@@ -1,8 +1,8 @@
1
1
  import { Effect } from "effect";
2
2
  import { constants, methods } from "../interpreter/native.js";
3
3
  import { typeError } from "../interpreter/model.js";
4
- import { ProgramObject } from "../interpreter/objects.js";
5
- import { preserveConsumerError } from "../interpreter/runner.js";
4
+ import { Obj } from "../interpreter/objects.js";
5
+ import { preserveConsumerError } from "../interpreter/callback.js";
6
6
  // Validate only the arguments a method consumes; like JS, extras are ignored
7
7
  // (so built-ins work as callbacks receiving (element, index, array)).
8
8
  const number = (name, args, index) => {
@@ -28,9 +28,9 @@ const variadic = (name, op) => [
28
28
  return arg;
29
29
  })),
30
30
  ];
31
- export const mathGlobal = (runner) => {
32
- const protos = runner.prototypes;
33
- const math = new ProgramObject(protos.Object);
31
+ export const mathGlobal = (ctx) => {
32
+ const builtins = ctx.builtins;
33
+ const math = new Obj(builtins.Object);
34
34
  constants(math, {
35
35
  PI: Math.PI,
36
36
  E: Math.E,
@@ -41,7 +41,7 @@ export const mathGlobal = (runner) => {
41
41
  SQRT2: Math.SQRT2,
42
42
  SQRT1_2: Math.SQRT1_2,
43
43
  });
44
- methods(protos, math, [
44
+ methods(builtins, math, [
45
45
  ["random", 0, () => Math.random()],
46
46
  variadic("max", Math.max),
47
47
  variadic("min", Math.min),
@@ -82,7 +82,7 @@ export const mathGlobal = (runner) => {
82
82
  "sumPrecise",
83
83
  1,
84
84
  (_, args) => Effect.gen(function* () {
85
- const cursor = yield* runner.syncIterator(args[0]);
85
+ const cursor = yield* ctx.iterate(args[0]);
86
86
  if (cursor === undefined) {
87
87
  throw typeError("Math.sumPrecise expects a synchronous iterable.");
88
88
  }
@@ -1,3 +1,3 @@
1
- import type { Runner } from "../interpreter/runner.js";
2
- export declare const numberGlobal: <R>(runner: Runner<R>) => import("../interpreter/objects.js").NativeFunction<R>;
3
- export declare const booleanGlobal: <R>(runner: Runner<R>) => import("../interpreter/objects.js").NativeFunction<R>;
1
+ import type { Interpreter } from "../interpreter/interpreter.js";
2
+ export declare const numberGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
3
+ export declare const booleanGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
@@ -1,12 +1,12 @@
1
1
  import { constructor, constants, methods } from "../interpreter/native.js";
2
2
  import { rangeError, typeError } from "../interpreter/model.js";
3
3
  import { coercion, coerceToString } from "./value.js";
4
- export const numberGlobal = (runner) => {
5
- const protos = runner.prototypes;
6
- const number = constructor(protos, protos.Number, {
4
+ export const numberGlobal = (ctx) => {
5
+ const builtins = ctx.builtins;
6
+ const number = constructor(builtins, builtins.Number, {
7
7
  name: "Number",
8
8
  length: 1,
9
- call: coercion(runner, "Number").call,
9
+ call: coercion(ctx, "Number").call,
10
10
  });
11
11
  constants(number, {
12
12
  MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER,
@@ -18,7 +18,7 @@ export const numberGlobal = (runner) => {
18
18
  POSITIVE_INFINITY: Number.POSITIVE_INFINITY,
19
19
  NEGATIVE_INFINITY: Number.NEGATIVE_INFINITY,
20
20
  });
21
- methods(protos, number, [
21
+ methods(builtins, number, [
22
22
  ["isInteger", 1, (_, args) => Number.isInteger(args[0])],
23
23
  ["isFinite", 1, (_, args) => Number.isFinite(args[0])],
24
24
  ["isNaN", 1, (_, args) => Number.isNaN(args[0])],
@@ -48,7 +48,7 @@ export const numberGlobal = (runner) => {
48
48
  throw typeError(`Number.${name} expects a number argument.`);
49
49
  return arg;
50
50
  };
51
- methods(protos, protos.Number, [
51
+ methods(builtins, builtins.Number, [
52
52
  ["toFixed", 1, (thisValue, args) => self(thisValue, "toFixed").toFixed(optNum("toFixed", args[0]))],
53
53
  [
54
54
  "toExponential",
@@ -80,19 +80,19 @@ export const numberGlobal = (runner) => {
80
80
  ]);
81
81
  return number;
82
82
  };
83
- export const booleanGlobal = (runner) => {
84
- const protos = runner.prototypes;
85
- const boolean = constructor(protos, protos.Boolean, {
83
+ export const booleanGlobal = (ctx) => {
84
+ const builtins = ctx.builtins;
85
+ const boolean = constructor(builtins, builtins.Boolean, {
86
86
  name: "Boolean",
87
87
  length: 1,
88
- call: coercion(runner, "Boolean").call,
88
+ call: coercion(ctx, "Boolean").call,
89
89
  });
90
90
  const self = (thisValue, name) => {
91
91
  if (typeof thisValue === "boolean")
92
92
  return thisValue;
93
93
  throw typeError(`Boolean.prototype.${name} requires that 'this' be a Boolean.`);
94
94
  };
95
- methods(protos, protos.Boolean, [
95
+ methods(builtins, builtins.Boolean, [
96
96
  ["toString", 0, (thisValue) => String(self(thisValue, "toString"))],
97
97
  ["valueOf", 0, (thisValue) => self(thisValue, "valueOf")],
98
98
  ]);
@@ -1,7 +1,7 @@
1
1
  import { type AstNode } from "../interpreter/model.js";
2
- import { ProgramObject } from "../interpreter/objects.js";
3
- import { type Runner } from "../interpreter/runner.js";
4
- export declare const enumerableSource: <R>(runner: Runner<R>, label: string, value: unknown, node?: AstNode) => ProgramObject;
5
- export declare const objectAssign: <R>(runner: Runner<R>, args: Array<unknown>) => unknown;
2
+ import { Obj } from "../interpreter/objects.js";
3
+ import type { Interpreter } from "../interpreter/interpreter.js";
4
+ export declare const enumerableSource: <R>(ctx: Interpreter<R>, label: string, value: unknown, node?: AstNode) => Obj;
5
+ export declare const objectAssign: <R>(ctx: Interpreter<R>, args: Array<unknown>) => unknown;
6
6
  export declare const classTag: (value: unknown) => string;
7
- export declare const objectGlobal: <R>(runner: Runner<R>, toolKeys: (path: ReadonlyArray<string>) => ReadonlyArray<string>) => import("../interpreter/objects.js").NativeFunction<R>;
7
+ export declare const objectGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
@@ -2,44 +2,44 @@ import { Effect } from "effect";
2
2
  import { toProgram } from "../data.js";
3
3
  import { constructor, methods, receiver } from "../interpreter/native.js";
4
4
  import { AsyncIteratorSymbol, invalidData, IteratorSymbol, rangeError, typeError, } from "../interpreter/model.js";
5
- import { Callable, define, entries, enumerableKeys, getOwn, hasOwn, hasPrototype, hidden, keys, own, ProgramArray, ProgramDate, ProgramError, ProgramObject, ProgramPromise, ProgramRegExp, set, } from "../interpreter/objects.js";
5
+ import { Callable, define, entries, enumerableKeys, getOwn, hasOwn, hasPrototype, hidden, keys, own, Arr, Bytes, DateObj, ErrorObj, Obj, PromiseObj, RegExpObj, set, } from "../interpreter/objects.js";
6
6
  import { containsOpaqueReference, describeValue, rejectCircularInsertion } from "../interpreter/references.js";
7
- import { preserveConsumerError } from "../interpreter/runner.js";
7
+ import { preserveConsumerError } from "../interpreter/callback.js";
8
8
  import { ToolReference } from "../tool-runtime.js";
9
9
  import { groupBy } from "./collections.js";
10
10
  import { coerceToString } from "./value.js";
11
11
  // ToObject for enumeration.
12
- export const enumerableSource = (runner, label, value, node) => {
12
+ export const enumerableSource = (ctx, label, value, node) => {
13
13
  if (value === null || value === undefined) {
14
14
  throw typeError(`${label} cannot convert ${describeValue(value)} to an object.`, node);
15
15
  }
16
- if (value instanceof ProgramPromise) {
16
+ if (value instanceof PromiseObj) {
17
17
  throw invalidData(`${label} received an un-awaited Promise; await it before inspecting the result.`, node);
18
18
  }
19
19
  if (value instanceof ToolReference) {
20
20
  throw invalidData(`${label} cannot read tool references: they are not plain data. Use Object.keys(tools) for names, or search({ query }) for signatures.`, node);
21
21
  }
22
22
  if (typeof value === "string")
23
- return new ProgramArray(runner.prototypes.Array, [...value]);
24
- if (value instanceof ProgramObject)
23
+ return new Arr(ctx.builtins.Array, [...value]);
24
+ if (value instanceof Obj)
25
25
  return value;
26
- return new ProgramObject(runner.prototypes.Object);
26
+ return new Obj(ctx.builtins.Object);
27
27
  };
28
- export const objectAssign = (runner, args) => {
28
+ export const objectAssign = (ctx, args) => {
29
29
  const target = args[0];
30
30
  // JS would box a primitive target; wrappers and primitives cannot hold fields here.
31
- if (!(target instanceof ProgramObject)) {
31
+ if (!(target instanceof Obj)) {
32
32
  throw typeError(`Object.assign expects a data object or array target, received ${describeValue(target)}.`);
33
33
  }
34
34
  const seen = new Set();
35
35
  for (const source of args.slice(1)) {
36
36
  if (source === null || source === undefined)
37
37
  continue;
38
- const from = enumerableSource(runner, "Object.assign(...)", source);
38
+ const from = enumerableSource(ctx, "Object.assign(...)", source);
39
39
  for (const key of enumerableKeys(from)) {
40
40
  rejectCircularInsertion(target, getOwn(from, key), "Object.assign result", seen);
41
41
  if (!set(target, key, getOwn(from, key))) {
42
- if (target instanceof ProgramArray && key === "length")
42
+ if (target instanceof Arr && key === "length")
43
43
  throw rangeError("Invalid array length");
44
44
  throw typeError(`Cannot assign to read only property '${String(key)}'.`);
45
45
  }
@@ -47,10 +47,10 @@ export const objectAssign = (runner, args) => {
47
47
  }
48
48
  return target;
49
49
  };
50
- const objectFromEntries = (runner, source) => {
51
- const out = new ProgramObject(runner.prototypes.Object);
50
+ const objectFromEntries = (ctx, source) => {
51
+ const out = new Obj(ctx.builtins.Object);
52
52
  return Effect.gen(function* () {
53
- const cursor = yield* runner.syncIterator(source);
53
+ const cursor = yield* ctx.iterate(source);
54
54
  if (cursor === undefined) {
55
55
  throw typeError("Object.fromEntries expects a synchronous iterable of entries.");
56
56
  }
@@ -59,7 +59,7 @@ const objectFromEntries = (runner, source) => {
59
59
  if (step.done)
60
60
  return out;
61
61
  yield* preserveConsumerError(cursor, Effect.sync(() => {
62
- if (!(step.value instanceof ProgramObject) || containsOpaqueReference(step.value)) {
62
+ if (!(step.value instanceof Obj) || containsOpaqueReference(step.value)) {
63
63
  throw typeError("Object.fromEntries expects [key, value] entry objects.");
64
64
  }
65
65
  define(out, coerceToString(getOwn(step.value, 0)), getOwn(step.value, 1));
@@ -72,16 +72,18 @@ export const classTag = (value) => {
72
72
  return "Null";
73
73
  if (value === undefined)
74
74
  return "Undefined";
75
- if (value instanceof ProgramArray)
75
+ if (value instanceof Arr)
76
76
  return "Array";
77
77
  if (value instanceof Callable)
78
78
  return "Function";
79
- if (value instanceof ProgramError)
79
+ if (value instanceof ErrorObj)
80
80
  return "Error";
81
- if (value instanceof ProgramDate)
81
+ if (value instanceof DateObj)
82
82
  return "Date";
83
- if (value instanceof ProgramRegExp)
83
+ if (value instanceof RegExpObj)
84
84
  return "RegExp";
85
+ if (value instanceof Bytes)
86
+ return "Uint8Array";
85
87
  if (typeof value === "string")
86
88
  return "String";
87
89
  if (typeof value === "number")
@@ -93,41 +95,41 @@ export const classTag = (value) => {
93
95
  const propertyKey = (value) => value === AsyncIteratorSymbol || value === IteratorSymbol ? value : coerceToString(value);
94
96
  // Object constructs identically with or without new, like JS. Only `keys` copies its result into the
95
97
  // program; `values`, `entries`, `assign`, and `fromEntries` hand back the program's own values.
96
- export const objectGlobal = (runner, toolKeys) => {
97
- const protos = runner.prototypes;
98
+ export const objectGlobal = (ctx) => {
99
+ const builtins = ctx.builtins;
98
100
  const construct = (args) => {
99
101
  const first = args[0];
100
102
  if (first === null || first === undefined)
101
- return new ProgramObject(protos.Object);
102
- if (first instanceof ProgramObject)
103
+ return new Obj(builtins.Object);
104
+ if (first instanceof Obj)
103
105
  return first;
104
106
  throw typeError(`Object(${typeof first}) wrapper objects are not supported; use the primitive value directly.`);
105
107
  };
106
- const object = constructor(protos, protos.Object, {
108
+ const object = constructor(builtins, builtins.Object, {
107
109
  name: "Object",
108
110
  length: 1,
109
111
  call: (_, args) => Effect.sync(() => construct(args)),
110
112
  construct: (args) => Effect.sync(() => construct(args)),
111
113
  });
112
- methods(protos, object, [
114
+ methods(builtins, object, [
113
115
  [
114
116
  "keys",
115
117
  1,
116
- (_, args) => toProgram(protos, args[0] instanceof ToolReference
117
- ? [...toolKeys(args[0].path)]
118
- : keys(enumerableSource(runner, "Object.keys(...)", args[0])), "Object.keys result"),
118
+ (_, args) => toProgram(builtins, args[0] instanceof ToolReference
119
+ ? [...ctx.tools.keys(args[0].path)]
120
+ : keys(enumerableSource(ctx, "Object.keys(...)", args[0])), "Object.keys result"),
119
121
  ],
120
122
  [
121
123
  "values",
122
124
  1,
123
- (_, args) => new ProgramArray(protos.Array, entries(enumerableSource(runner, "Object.values(...)", args[0])).map((entry) => entry[1])),
125
+ (_, args) => new Arr(builtins.Array, entries(enumerableSource(ctx, "Object.values(...)", args[0])).map((entry) => entry[1])),
124
126
  ],
125
127
  [
126
128
  "entries",
127
129
  1,
128
- (_, args) => new ProgramArray(protos.Array, entries(enumerableSource(runner, "Object.entries(...)", args[0])).map((entry) => new ProgramArray(protos.Array, entry))),
130
+ (_, args) => new Arr(builtins.Array, entries(enumerableSource(ctx, "Object.entries(...)", args[0])).map((entry) => new Arr(builtins.Array, entry))),
129
131
  ],
130
- ["hasOwn", 2, (_, args) => hasOwn(enumerableSource(runner, "Object.hasOwn(...)", args[0]), propertyKey(args[1]))],
132
+ ["hasOwn", 2, (_, args) => hasOwn(enumerableSource(ctx, "Object.hasOwn(...)", args[0]), propertyKey(args[1]))],
131
133
  [
132
134
  "is",
133
135
  2,
@@ -138,26 +140,26 @@ export const objectGlobal = (runner, toolKeys) => {
138
140
  return Object.is(args[0], args[1]);
139
141
  },
140
142
  ],
141
- ["assign", 2, (_, args) => objectAssign(runner, args)],
142
- ["fromEntries", 1, (_, args) => objectFromEntries(runner, args[0])],
143
+ ["assign", 2, (_, args) => objectAssign(ctx, args)],
144
+ ["fromEntries", 1, (_, args) => objectFromEntries(ctx, args[0])],
143
145
  ]);
144
- define(object, "groupBy", groupBy(runner, "Object"), hidden);
145
- methods(protos, protos.Object, [
146
+ define(object, "groupBy", groupBy(ctx, "Object"), hidden);
147
+ methods(builtins, builtins.Object, [
146
148
  [
147
149
  "hasOwnProperty",
148
150
  1,
149
- (thisValue, args) => hasOwn(receiver(ProgramObject, thisValue, "Object.prototype.hasOwnProperty"), propertyKey(args[0])),
151
+ (thisValue, args) => hasOwn(receiver(Obj, thisValue, "Object.prototype.hasOwnProperty"), propertyKey(args[0])),
150
152
  ],
151
153
  [
152
154
  "isPrototypeOf",
153
155
  1,
154
- (thisValue, args) => hasPrototype(args[0], receiver(ProgramObject, thisValue, "Object.prototype.isPrototypeOf")),
156
+ (thisValue, args) => hasPrototype(args[0], receiver(Obj, thisValue, "Object.prototype.isPrototypeOf")),
155
157
  ],
156
158
  [
157
159
  "propertyIsEnumerable",
158
160
  1,
159
- (thisValue, args) => own(receiver(ProgramObject, thisValue, "Object.prototype.propertyIsEnumerable"), propertyKey(args[0]))
160
- ?.enumerable === true,
161
+ (thisValue, args) => own(receiver(Obj, thisValue, "Object.prototype.propertyIsEnumerable"), propertyKey(args[0]))?.enumerable ===
162
+ true,
161
163
  ],
162
164
  ["toString", 0, (thisValue) => `[object ${classTag(thisValue)}]`],
163
165
  ["toLocaleString", 0, (thisValue) => `[object ${classTag(thisValue)}]`],
@@ -1,7 +1,7 @@
1
- import type { Prototypes } from "../interpreter/intrinsics.js";
2
- import { ProgramArray, ProgramObject, ProgramRegExp } from "../interpreter/objects.js";
3
- import type { Runner } from "../interpreter/runner.js";
1
+ import type { Builtins } from "../interpreter/intrinsics.js";
2
+ import { Arr, Obj, RegExpObj } from "../interpreter/objects.js";
3
+ import type { Interpreter } from "../interpreter/interpreter.js";
4
4
  export declare const toHostRegex: (arg: unknown, method: string, extraFlags?: string) => RegExp;
5
- export declare const matchToValue: (protos: Prototypes, match: RegExpMatchArray) => ProgramArray;
6
- export declare const constructRegExp: (protos: Prototypes, args: Array<unknown>, proto?: ProgramObject) => ProgramRegExp;
7
- export declare const regexpGlobal: <R>(runner: Runner<R>) => import("../interpreter/objects.js").NativeFunction<R>;
5
+ export declare const matchToValue: (builtins: Builtins, match: RegExpMatchArray) => Arr;
6
+ export declare const constructRegExp: (builtins: Builtins, args: Array<unknown>, proto?: Obj) => RegExpObj;
7
+ export declare const regexpGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;