@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,13 +1,13 @@
1
- import { ProgramError, ProgramObject } from "./objects.js";
1
+ import { ErrorObj, Obj } 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;
5
- declare const builtins: readonly ["Object", "Function", "Array", "String", "Number", "Boolean", "Date", "RegExp", "Map", "Set", "URL", "URLSearchParams", "Promise", "Iterator", "AsyncIterator", "Generator", "AsyncGenerator"];
5
+ declare const builtins: readonly ["Object", "Function", "Array", "String", "Number", "Boolean", "Date", "RegExp", "Map", "Set", "URL", "URLSearchParams", "Uint8Array", "TextEncoder", "TextDecoder", "Promise", "Iterator", "AsyncIterator", "Generator", "AsyncGenerator"];
6
6
  /**
7
7
  * The built-in prototype objects of one runtime, allocated empty in dependency order. The globals populate them
8
8
  * and attach their constructors when the runtime is built.
9
9
  */
10
- export type Prototypes = Readonly<Record<(typeof builtins)[number] | ErrorType, ProgramObject>>;
11
- export declare const createErrorValue: (prototype: ProgramObject, message: string | undefined) => ProgramError;
12
- export declare const createPrototypes: () => Prototypes;
10
+ export type Builtins = Readonly<Record<(typeof builtins)[number] | ErrorType, Obj>>;
11
+ export declare const createErrorValue: (prototype: Obj, message: string | undefined) => ErrorObj;
12
+ export declare const createBuiltins: () => Builtins;
13
13
  export {};
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { define, hidden, NativeFunction, ProgramArray, ProgramError, ProgramObject } from "./objects.js";
2
+ import { define, hidden, Native, Arr, ErrorObj, Obj } from "./objects.js";
3
3
  export const errorTypes = [
4
4
  "Error",
5
5
  "TypeError",
@@ -24,6 +24,9 @@ const builtins = [
24
24
  "Set",
25
25
  "URL",
26
26
  "URLSearchParams",
27
+ "Uint8Array",
28
+ "TextEncoder",
29
+ "TextDecoder",
27
30
  "Promise",
28
31
  "Iterator",
29
32
  "AsyncIterator",
@@ -31,21 +34,21 @@ const builtins = [
31
34
  "AsyncGenerator",
32
35
  ];
33
36
  export const createErrorValue = (prototype, message) => {
34
- const value = new ProgramError(prototype);
37
+ const value = new ErrorObj(prototype);
35
38
  if (message !== undefined)
36
39
  define(value, "message", message, hidden);
37
40
  return value;
38
41
  };
39
- export const createPrototypes = () => {
40
- const object = new ProgramObject(null);
42
+ export const createBuiltins = () => {
43
+ const object = new Obj(null);
41
44
  // Function.prototype is itself callable and returns undefined.
42
- const fn = new NativeFunction(object, { name: "", call: () => Effect.undefined });
43
- const plain = () => new ProgramObject(object);
45
+ const fn = new Native(object, { name: "", call: () => Effect.undefined });
46
+ const plain = () => new Obj(object);
44
47
  const error = plain();
45
48
  define(error, "name", "Error", hidden);
46
49
  define(error, "message", "", hidden);
47
50
  const derived = (type) => {
48
- const proto = new ProgramObject(error);
51
+ const proto = new Obj(error);
49
52
  define(proto, "name", type, hidden);
50
53
  define(proto, "message", "", hidden);
51
54
  return proto;
@@ -55,7 +58,7 @@ export const createPrototypes = () => {
55
58
  return {
56
59
  Object: object,
57
60
  Function: fn,
58
- Array: new ProgramArray(object),
61
+ Array: new Arr(object),
59
62
  String: plain(),
60
63
  Number: plain(),
61
64
  Boolean: plain(),
@@ -65,11 +68,14 @@ export const createPrototypes = () => {
65
68
  Set: plain(),
66
69
  URL: plain(),
67
70
  URLSearchParams: plain(),
71
+ Uint8Array: plain(),
72
+ TextEncoder: plain(),
73
+ TextDecoder: plain(),
68
74
  Promise: plain(),
69
75
  Iterator: iterator,
70
76
  AsyncIterator: asyncIterator,
71
- Generator: new ProgramObject(iterator),
72
- AsyncGenerator: new ProgramObject(asyncIterator),
77
+ Generator: new Obj(iterator),
78
+ AsyncGenerator: new Obj(asyncIterator),
73
79
  Error: error,
74
80
  TypeError: derived("TypeError"),
75
81
  RangeError: derived("RangeError"),
@@ -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 { ProgramError } from "./objects.js";
5
+ import type { ErrorObj } 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. */
@@ -31,7 +31,7 @@ export type GeneratorRequestKind = "next" | "return" | "throw";
31
31
  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
- export declare class ProgramThrow {
34
+ export declare class Throw {
35
35
  readonly value: unknown;
36
36
  constructor(value: unknown);
37
37
  }
@@ -51,7 +51,7 @@ export declare class PendingThrow {
51
51
  readonly kind: DiagnosticKind;
52
52
  readonly suggestions?: ReadonlyArray<string> | undefined;
53
53
  node?: AstNode;
54
- value?: ProgramError;
54
+ value?: ErrorObj;
55
55
  constructor(
56
56
  /** The JS error class a program sees when it catches this failure. */
57
57
  type: ErrorType, message: string, node?: AstNode, kind?: DiagnosticKind, suggestions?: ReadonlyArray<string> | undefined);
@@ -6,7 +6,7 @@ export const CallSite = Context.Reference("codemode/CallSite", {
6
6
  export const AsyncIteratorSymbol = Symbol("codemode.async-iterator");
7
7
  export const IteratorSymbol = Symbol("codemode.iterator");
8
8
  export const IteratorSymbols = [AsyncIteratorSymbol, IteratorSymbol];
9
- export class ProgramThrow {
9
+ export class Throw {
10
10
  value;
11
11
  constructor(value) {
12
12
  this.value = value;
@@ -1,18 +1,18 @@
1
1
  import { Effect } from "effect";
2
- import type { Prototypes } from "./intrinsics.js";
3
- import { type Callable, NativeFunction, type NativeOptions, ProgramObject } from "./objects.js";
2
+ import type { Builtins } from "./intrinsics.js";
3
+ import { type Callable, Native, type NativeOptions, Obj } from "./objects.js";
4
4
  /** A native function body: a plain value, a thrown `PendingThrow`, or an Effect. */
5
5
  export type Impl = (thisValue: unknown, args: Array<unknown>) => unknown;
6
- export declare const native: <R>(protos: Prototypes, options: NativeOptions<R>) => NativeFunction<R>;
7
- export declare const fn: <R>(protos: Prototypes, name: string, length: number, impl: Impl) => NativeFunction<R>;
6
+ export declare const native: <R>(builtins: Builtins, options: NativeOptions<R>) => Native<R>;
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
- export declare const methods: (protos: Prototypes, target: ProgramObject, table: ReadonlyArray<Method>) => void;
10
- export declare const constants: (target: ProgramObject, table: Record<string, unknown>) => void;
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;
11
11
  /** A constructor wired to its prototype: `C.prototype === proto` and `proto.constructor === C`. */
12
- export declare const constructor: <R>(protos: Prototypes, proto: ProgramObject, options: NativeOptions<R>) => NativeFunction<R>;
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`. */
14
14
  export declare const requiresNew: (name: string) => () => Effect.Effect<never, unknown, never>;
15
15
  /** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
16
- export declare const prototypeFrom: (newTarget: Callable, fallback: ProgramObject) => ProgramObject;
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 ProgramObject>(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: unknown, method: string) => T;
@@ -1,25 +1,25 @@
1
1
  import { Effect } from "effect";
2
2
  import { typeError } from "./model.js";
3
- import { define, frozen, hidden, NativeFunction, ProgramObject } from "./objects.js";
3
+ import { define, frozen, hidden, Native, Obj } from "./objects.js";
4
4
  import { describeValue } from "./references.js";
5
- // The dispatch in `Frame.invokeCallable` suspends every native call, so a synchronous throw here is a defect.
5
+ // The dispatch in `Frame.call` suspends every native call, so a synchronous throw here is a defect.
6
6
  const lift = (impl) => (thisValue, args) => {
7
7
  const result = impl(thisValue, args);
8
8
  return Effect.isEffect(result) ? result : Effect.succeed(result);
9
9
  };
10
- export const native = (protos, options) => new NativeFunction(protos.Function, options);
11
- export const fn = (protos, name, length, impl) => native(protos, { name, length, call: lift(impl) });
12
- export const methods = (protos, target, table) => {
10
+ export const native = (builtins, options) => new Native(builtins.Function, options);
11
+ export const fn = (builtins, name, length, impl) => native(builtins, { name, length, call: lift(impl) });
12
+ export const methods = (builtins, target, table) => {
13
13
  for (const [name, length, impl] of table)
14
- define(target, name, fn(protos, name, length, impl), hidden);
14
+ define(target, name, fn(builtins, name, length, impl), hidden);
15
15
  };
16
16
  export const constants = (target, table) => {
17
17
  for (const [name, value] of Object.entries(table))
18
18
  define(target, name, value, frozen);
19
19
  };
20
20
  /** A constructor wired to its prototype: `C.prototype === proto` and `proto.constructor === C`. */
21
- export const constructor = (protos, proto, options) => {
22
- const ctor = native(protos, options);
21
+ export const constructor = (builtins, proto, options) => {
22
+ const ctor = native(builtins, options);
23
23
  define(ctor, "prototype", proto, frozen);
24
24
  define(proto, "constructor", ctor, hidden);
25
25
  return ctor;
@@ -31,7 +31,7 @@ export const requiresNew = (name) => () => Effect.sync(() => {
31
31
  /** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
32
32
  export const prototypeFrom = (newTarget, fallback) => {
33
33
  const proto = newTarget.props.get("prototype");
34
- return proto !== undefined && "value" in proto && proto.value instanceof ProgramObject ? proto.value : fallback;
34
+ return proto !== undefined && "value" in proto && proto.value instanceof Obj ? proto.value : fallback;
35
35
  };
36
36
  /** Narrows a method receiver to the built-in it belongs to, or throws the TypeError JS would. */
37
37
  export const receiver = (cls, thisValue, method) => {
@@ -30,30 +30,30 @@ export declare const readonly: Attributes;
30
30
  /** Constants such as `Math.PI` and a constructor's `prototype`. */
31
31
  export declare const frozen: Attributes;
32
32
  /** An object owned by the program: own properties plus a prototype link. */
33
- export declare class ProgramObject {
34
- proto: ProgramObject | null;
33
+ export declare class Obj {
34
+ proto: Obj | null;
35
35
  readonly props: Map<string | symbol, Slot>;
36
- constructor(proto: ProgramObject | null);
36
+ constructor(proto: Obj | null);
37
37
  }
38
- export declare class ProgramArray extends ProgramObject {
38
+ export declare class Arr extends Obj {
39
39
  readonly items: Array<unknown>;
40
- constructor(proto: ProgramObject, items?: Array<unknown>);
40
+ constructor(proto: Obj, items?: Array<unknown>);
41
41
  }
42
42
  /** An object with the [[ErrorData]] slot: what `Error.prototype.toString` and the host boundary recognize as an error. */
43
- export declare class ProgramError extends ProgramObject {
43
+ export declare class ErrorObj extends Obj {
44
44
  /** The interpreter failure this error materialized from, so rethrowing it keeps the diagnostic kind and location. */
45
45
  host?: PendingThrow;
46
46
  }
47
- export declare abstract class Callable extends ProgramObject {
48
- constructor(proto: ProgramObject, name: string, length: number);
47
+ export declare abstract class Callable extends Obj {
48
+ constructor(proto: Obj, name: string, length: number);
49
49
  }
50
- export declare class ProgramFunction extends Callable {
50
+ export declare class Fn extends Callable {
51
51
  readonly parameters: ReadonlyArray<Pattern>;
52
52
  readonly body: BlockStatement | Expression;
53
53
  readonly capturedScopes: ReadonlyArray<Map<string, Binding>>;
54
54
  readonly async: boolean;
55
55
  readonly generator: boolean;
56
- constructor(proto: ProgramObject, name: string, parameters: ReadonlyArray<Pattern>, body: BlockStatement | Expression, capturedScopes: ReadonlyArray<Map<string, Binding>>, async: boolean, generator: boolean);
56
+ constructor(proto: Obj, name: string, parameters: ReadonlyArray<Pattern>, body: BlockStatement | Expression, capturedScopes: ReadonlyArray<Map<string, Binding>>, async: boolean, generator: boolean);
57
57
  }
58
58
  export type NativeCall<R> = (thisValue: unknown, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>;
59
59
  export type NativeConstruct<R> = (args: Array<unknown>, newTarget: Callable) => Effect.Effect<unknown, unknown, R>;
@@ -66,72 +66,77 @@ export type NativeOptions<R> = {
66
66
  /** Whether callback sites (array methods, replacers, promise reactions) admit this function. Defaults to true. */
67
67
  readonly callback?: boolean;
68
68
  };
69
- export declare class NativeFunction<R = never> extends Callable {
69
+ export declare class Native<R = never> extends Callable {
70
70
  readonly call: NativeCall<R>;
71
71
  readonly construct: NativeConstruct<R> | undefined;
72
72
  readonly callback: boolean;
73
- constructor(proto: ProgramObject, options: NativeOptions<R>);
73
+ constructor(proto: Obj, options: NativeOptions<R>);
74
74
  }
75
- export declare class ProgramPromise extends ProgramObject {
75
+ export declare class PromiseObj extends Obj {
76
76
  readonly fiber: Fiber.Fiber<unknown, unknown>;
77
- constructor(proto: ProgramObject, fiber: Fiber.Fiber<unknown, unknown>);
77
+ constructor(proto: Obj, fiber: Fiber.Fiber<unknown, unknown>);
78
78
  }
79
- export declare class ProgramGenerator extends ProgramObject {
79
+ export declare class GeneratorObj extends Obj {
80
80
  readonly asynchronous: boolean;
81
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>);
82
+ constructor(proto: Obj, asynchronous: boolean, request: (kind: GeneratorRequestKind, value: unknown) => Effect.Effect<unknown, unknown, unknown>);
83
83
  }
84
- export declare class ProgramDate extends ProgramObject {
84
+ export declare class DateObj extends Obj {
85
85
  time: number;
86
- constructor(proto: ProgramObject, time: number);
86
+ constructor(proto: Obj, time: number);
87
87
  }
88
- export declare class ProgramRegExp extends ProgramObject {
88
+ export declare class RegExpObj extends Obj {
89
89
  readonly regex: RegExp;
90
- constructor(proto: ProgramObject, pattern: string, flags: string);
90
+ constructor(proto: Obj, pattern: string, flags: string);
91
91
  }
92
- export declare class ProgramMap extends ProgramObject {
92
+ export declare class MapObj extends Obj {
93
93
  readonly map: Map<unknown, unknown>;
94
94
  }
95
- export declare class ProgramSet extends ProgramObject {
95
+ export declare class SetObj extends Obj {
96
96
  readonly set: Set<unknown>;
97
97
  }
98
- export declare class ProgramURLSearchParams extends ProgramObject {
98
+ export declare class URLSearchParamsObj extends Obj {
99
99
  readonly params: URLSearchParams;
100
- constructor(proto: ProgramObject, params: URLSearchParams);
100
+ constructor(proto: Obj, params: URLSearchParams);
101
101
  }
102
- export declare class ProgramURL extends ProgramObject {
102
+ export declare class URLObj extends Obj {
103
103
  readonly url: URL;
104
- readonly searchParams: ProgramURLSearchParams;
105
- constructor(proto: ProgramObject, searchParamsProto: ProgramObject, url: URL);
104
+ readonly searchParams: URLSearchParamsObj;
105
+ constructor(proto: Obj, searchParamsProto: Obj, url: URL);
106
+ }
107
+ /** A `Uint8Array`: the host array does the byte clamping and ignores out-of-range writes, as JS does. */
108
+ export declare class Bytes extends Obj {
109
+ readonly bytes: Uint8Array;
110
+ constructor(proto: Obj, bytes: Uint8Array);
106
111
  }
107
112
  /** An instance of an extension class: the host object lives in a field no property path reaches. */
108
- export declare class ProgramHandle extends ProgramObject {
113
+ export declare class Handle extends Obj {
109
114
  readonly instance: object;
110
- constructor(proto: ProgramObject, instance: object);
115
+ constructor(proto: Obj, instance: object);
111
116
  }
112
117
  /** Built-in objects that wrap a host value; data-like, but never plain data. */
113
- export declare const isWrapper: (value: unknown) => value is ProgramDate | ProgramRegExp | ProgramMap | ProgramSet | ProgramURL | ProgramURLSearchParams;
118
+ export declare const isWrapper: (value: unknown) => value is DateObj | RegExpObj | MapObj | SetObj | URLObj | URLSearchParamsObj | Bytes;
114
119
  export declare const parseArrayIndex: (key: string | number) => number | undefined;
115
120
  /** The own property under `key`, including an array's live indexes and `length`. */
116
- export declare const own: (target: ProgramObject, key: PropertyKey) => Slot | undefined;
117
- export declare const hasOwn: (target: ProgramObject, key: PropertyKey) => boolean;
118
- export declare const getOwn: (target: ProgramObject, key: PropertyKey) => unknown;
121
+ export declare const own: (target: Obj, key: PropertyKey) => Slot | undefined;
122
+ export declare const hasOwn: (target: Obj, key: PropertyKey) => boolean;
123
+ export declare const getOwn: (target: Obj, key: PropertyKey) => unknown;
119
124
  /** [[Get]]: walks the prototype chain; accessors see `receiver`, which is the primitive for wrapper prototypes. */
120
- export declare const get: (target: ProgramObject, key: PropertyKey, receiver?: unknown) => unknown;
121
- export declare const has: (target: ProgramObject, key: PropertyKey) => boolean;
122
- export declare const hasPrototype: (value: unknown, proto: ProgramObject) => boolean;
125
+ export declare const get: (target: Obj, key: PropertyKey, receiver?: unknown) => unknown;
126
+ export declare const has: (target: Obj, key: PropertyKey) => boolean;
127
+ export declare const hasPrototype: (value: unknown, proto: Obj) => boolean;
123
128
  /** [[Set]]: an inherited setter or read-only property decides before an own data property is created. */
124
- export declare const set: (target: ProgramObject, key: PropertyKey, value: unknown) => boolean;
129
+ export declare const set: (target: Obj, key: PropertyKey, value: unknown) => boolean;
125
130
  /** [[DefineOwnProperty]] for a data property, ignoring the chain. */
126
- export declare const define: (target: ProgramObject, key: PropertyKey, value: unknown, attrs?: Attributes) => void;
127
- export declare const defineAccessor: (target: ProgramObject, key: PropertyKey, get: Getter | undefined, set?: Setter) => void;
128
- export declare const remove: (target: ProgramObject, key: PropertyKey) => boolean;
129
- export declare const ownKeys: (target: ProgramObject) => Array<string | symbol>;
131
+ export declare const define: (target: Obj, key: PropertyKey, value: unknown, attrs?: Attributes) => void;
132
+ export declare const defineAccessor: (target: Obj, key: PropertyKey, get: Getter | undefined, set?: Setter) => void;
133
+ export declare const remove: (target: Obj, key: PropertyKey) => boolean;
134
+ export declare const ownKeys: (target: Obj) => Array<string | symbol>;
130
135
  /** Own enumerable keys, including the iterator symbols; what spread and `Object.assign` copy. */
131
- export declare const enumerableKeys: (target: ProgramObject) => Array<string | symbol>;
136
+ export declare const enumerableKeys: (target: Obj) => Array<string | symbol>;
132
137
  /** Own enumerable string keys: `Object.keys`. */
133
- export declare const keys: (target: ProgramObject) => Array<string>;
138
+ export declare const keys: (target: Obj) => Array<string>;
134
139
  /** Own enumerable string entries: `Object.entries` and serialization. */
135
- export declare const entries: (target: ProgramObject) => Array<[string, unknown]>;
136
- export declare const record: (proto: ProgramObject, fields: Record<string, unknown>) => ProgramObject;
137
- export declare const assign: (target: ProgramObject, source: ProgramObject, skip?: ReadonlySet<PropertyKey>) => void;
140
+ export declare const entries: (target: Obj) => Array<[string, unknown]>;
141
+ export declare const record: (proto: Obj, fields: Record<string, unknown>) => Obj;
142
+ export declare const assign: (target: Obj, source: Obj, skip?: ReadonlySet<PropertyKey>) => void;
@@ -9,14 +9,14 @@ export const readonly = { writable: false, enumerable: false, configurable: true
9
9
  /** Constants such as `Math.PI` and a constructor's `prototype`. */
10
10
  export const frozen = { writable: false, enumerable: false, configurable: false };
11
11
  /** An object owned by the program: own properties plus a prototype link. */
12
- export class ProgramObject {
12
+ export class Obj {
13
13
  proto;
14
14
  props = new Map();
15
15
  constructor(proto) {
16
16
  this.proto = proto;
17
17
  }
18
18
  }
19
- export class ProgramArray extends ProgramObject {
19
+ export class Arr extends Obj {
20
20
  items;
21
21
  constructor(proto, items = []) {
22
22
  super(proto);
@@ -24,18 +24,18 @@ export class ProgramArray extends ProgramObject {
24
24
  }
25
25
  }
26
26
  /** An object with the [[ErrorData]] slot: what `Error.prototype.toString` and the host boundary recognize as an error. */
27
- export class ProgramError extends ProgramObject {
27
+ export class ErrorObj extends Obj {
28
28
  /** The interpreter failure this error materialized from, so rethrowing it keeps the diagnostic kind and location. */
29
29
  host;
30
30
  }
31
- export class Callable extends ProgramObject {
31
+ export class Callable extends Obj {
32
32
  constructor(proto, name, length) {
33
33
  super(proto);
34
34
  define(this, "length", length, readonly);
35
35
  define(this, "name", name, readonly);
36
36
  }
37
37
  }
38
- export class ProgramFunction extends Callable {
38
+ export class Fn extends Callable {
39
39
  parameters;
40
40
  body;
41
41
  capturedScopes;
@@ -51,7 +51,7 @@ export class ProgramFunction extends Callable {
51
51
  this.generator = generator;
52
52
  }
53
53
  }
54
- export class NativeFunction extends Callable {
54
+ export class Native extends Callable {
55
55
  call;
56
56
  construct;
57
57
  callback;
@@ -62,14 +62,14 @@ export class NativeFunction extends Callable {
62
62
  this.callback = options.callback ?? true;
63
63
  }
64
64
  }
65
- export class ProgramPromise extends ProgramObject {
65
+ export class PromiseObj extends Obj {
66
66
  fiber;
67
67
  constructor(proto, fiber) {
68
68
  super(proto);
69
69
  this.fiber = fiber;
70
70
  }
71
71
  }
72
- export class ProgramGenerator extends ProgramObject {
72
+ export class GeneratorObj extends Obj {
73
73
  asynchronous;
74
74
  request;
75
75
  constructor(proto, asynchronous, request) {
@@ -78,14 +78,14 @@ export class ProgramGenerator extends ProgramObject {
78
78
  this.request = request;
79
79
  }
80
80
  }
81
- export class ProgramDate extends ProgramObject {
81
+ export class DateObj extends Obj {
82
82
  time;
83
83
  constructor(proto, time) {
84
84
  super(proto);
85
85
  this.time = time;
86
86
  }
87
87
  }
88
- export class ProgramRegExp extends ProgramObject {
88
+ export class RegExpObj extends Obj {
89
89
  regex;
90
90
  constructor(proto, pattern, flags) {
91
91
  super(proto);
@@ -93,30 +93,38 @@ export class ProgramRegExp extends ProgramObject {
93
93
  define(this, "lastIndex", 0, { writable: true, enumerable: false, configurable: false });
94
94
  }
95
95
  }
96
- export class ProgramMap extends ProgramObject {
96
+ export class MapObj extends Obj {
97
97
  map = new Map();
98
98
  }
99
- export class ProgramSet extends ProgramObject {
99
+ export class SetObj extends Obj {
100
100
  set = new Set();
101
101
  }
102
- export class ProgramURLSearchParams extends ProgramObject {
102
+ export class URLSearchParamsObj extends Obj {
103
103
  params;
104
104
  constructor(proto, params) {
105
105
  super(proto);
106
106
  this.params = params;
107
107
  }
108
108
  }
109
- export class ProgramURL extends ProgramObject {
109
+ export class URLObj extends Obj {
110
110
  url;
111
111
  searchParams;
112
112
  constructor(proto, searchParamsProto, url) {
113
113
  super(proto);
114
114
  this.url = url;
115
- this.searchParams = new ProgramURLSearchParams(searchParamsProto, url.searchParams);
115
+ this.searchParams = new URLSearchParamsObj(searchParamsProto, url.searchParams);
116
+ }
117
+ }
118
+ /** A `Uint8Array`: the host array does the byte clamping and ignores out-of-range writes, as JS does. */
119
+ export class Bytes extends Obj {
120
+ bytes;
121
+ constructor(proto, bytes) {
122
+ super(proto);
123
+ this.bytes = bytes;
116
124
  }
117
125
  }
118
126
  /** An instance of an extension class: the host object lives in a field no property path reaches. */
119
- export class ProgramHandle extends ProgramObject {
127
+ export class Handle extends Obj {
120
128
  instance;
121
129
  constructor(proto, instance) {
122
130
  super(proto);
@@ -124,12 +132,13 @@ export class ProgramHandle extends ProgramObject {
124
132
  }
125
133
  }
126
134
  /** Built-in objects that wrap a host value; data-like, but never plain data. */
127
- export const isWrapper = (value) => value instanceof ProgramDate ||
128
- value instanceof ProgramRegExp ||
129
- value instanceof ProgramMap ||
130
- value instanceof ProgramSet ||
131
- value instanceof ProgramURL ||
132
- value instanceof ProgramURLSearchParams;
135
+ export const isWrapper = (value) => value instanceof DateObj ||
136
+ value instanceof RegExpObj ||
137
+ value instanceof MapObj ||
138
+ value instanceof SetObj ||
139
+ value instanceof URLObj ||
140
+ value instanceof URLSearchParamsObj ||
141
+ value instanceof Bytes;
133
142
  const MAX_ARRAY_INDEX = 4_294_967_295;
134
143
  export const parseArrayIndex = (key) => {
135
144
  const property = String(key);
@@ -139,17 +148,21 @@ export const parseArrayIndex = (key) => {
139
148
  return index < MAX_ARRAY_INDEX ? index : undefined;
140
149
  };
141
150
  const canonical = (key) => (typeof key === "symbol" ? key : String(key));
142
- const index = (target, key) => target instanceof ProgramArray && typeof key === "string" ? parseArrayIndex(key) : undefined;
151
+ const isIndexed = (target) => target instanceof Arr || target instanceof Bytes;
152
+ const elements = (target) => (target instanceof Arr ? target.items : target.bytes);
153
+ const index = (target, key) => isIndexed(target) && typeof key === "string" ? parseArrayIndex(key) : undefined;
143
154
  /** The own property under `key`, including an array's live indexes and `length`. */
144
155
  export const own = (target, key) => {
145
156
  const name = canonical(key);
146
- if (target instanceof ProgramArray) {
157
+ if (isIndexed(target)) {
147
158
  const at = index(target, name);
148
159
  if (at !== undefined) {
149
- return at in target.items ? { value: target.items[at], ...data } : undefined;
160
+ const items = elements(target);
161
+ return at in items ? { value: items[at], ...data } : undefined;
150
162
  }
151
- if (name === "length")
163
+ if (target instanceof Arr && name === "length") {
152
164
  return { value: target.items.length, writable: true, enumerable: false, configurable: false };
165
+ }
153
166
  }
154
167
  return target.props.get(name);
155
168
  };
@@ -176,19 +189,22 @@ export const has = (target, key) => {
176
189
  return false;
177
190
  };
178
191
  export const hasPrototype = (value, proto) => {
179
- for (let current = value instanceof ProgramObject ? value.proto : null; current !== null; current = current.proto) {
192
+ for (let current = value instanceof Obj ? value.proto : null; current !== null; current = current.proto) {
180
193
  if (current === proto)
181
194
  return true;
182
195
  }
183
196
  return false;
184
197
  };
185
- const writeArray = (target, name, value) => {
198
+ const writeElement = (target, name, value) => {
186
199
  const at = index(target, name);
187
200
  if (at !== undefined) {
188
- target.items[at] = value;
201
+ if (target instanceof Bytes)
202
+ target.bytes[at] = typeof value === "number" ? value : Number(value);
203
+ else
204
+ target.items[at] = value;
189
205
  return true;
190
206
  }
191
- if (name !== "length")
207
+ if (!(target instanceof Arr) || name !== "length")
192
208
  return undefined;
193
209
  const length = typeof value === "number" ? value : Number(value);
194
210
  if (!Number.isInteger(length) || length < 0)
@@ -214,16 +230,16 @@ export const set = (target, key, value) => {
214
230
  return false;
215
231
  if (current !== target)
216
232
  break;
217
- if (target instanceof ProgramArray) {
218
- const written = writeArray(target, name, value);
233
+ if (isIndexed(target)) {
234
+ const written = writeElement(target, name, value);
219
235
  if (written !== undefined)
220
236
  return written;
221
237
  }
222
238
  slot.value = value;
223
239
  return true;
224
240
  }
225
- if (target instanceof ProgramArray) {
226
- const written = writeArray(target, name, value);
241
+ if (isIndexed(target)) {
242
+ const written = writeElement(target, name, value);
227
243
  if (written !== undefined)
228
244
  return written;
229
245
  }
@@ -233,7 +249,7 @@ export const set = (target, key, value) => {
233
249
  /** [[DefineOwnProperty]] for a data property, ignoring the chain. */
234
250
  export const define = (target, key, value, attrs = data) => {
235
251
  const name = canonical(key);
236
- if (target instanceof ProgramArray && writeArray(target, name, value) !== undefined)
252
+ if (isIndexed(target) && writeElement(target, name, value) !== undefined)
237
253
  return;
238
254
  target.props.set(name, { value, ...attrs });
239
255
  };
@@ -242,11 +258,11 @@ export const defineAccessor = (target, key, get, set) => {
242
258
  };
243
259
  export const remove = (target, key) => {
244
260
  const name = canonical(key);
245
- if (target instanceof ProgramArray) {
261
+ if (isIndexed(target)) {
246
262
  const at = index(target, name);
247
263
  if (at !== undefined)
248
- return delete target.items[at];
249
- if (name === "length")
264
+ return target instanceof Bytes ? !(at in target.bytes) : delete target.items[at];
265
+ if (target instanceof Arr && name === "length")
250
266
  return false;
251
267
  }
252
268
  const slot = target.props.get(name);
@@ -262,7 +278,8 @@ export const ownKeys = (target) => {
262
278
  const strings = [...target.props.keys()].filter((key) => typeof key === "string");
263
279
  const symbols = [...target.props.keys()].filter((key) => typeof key === "symbol");
264
280
  return [
265
- ...(target instanceof ProgramArray ? [...Object.keys(target.items), "length"] : []),
281
+ ...(isIndexed(target) ? Object.keys(elements(target)) : []),
282
+ ...(target instanceof Arr ? ["length"] : []),
266
283
  ...strings.filter((key) => parseArrayIndex(key) !== undefined).sort((a, b) => Number(a) - Number(b)),
267
284
  ...strings.filter((key) => parseArrayIndex(key) === undefined),
268
285
  ...symbols,
@@ -276,7 +293,7 @@ export const keys = (target) => ownKeys(target).filter((key) => typeof key === "
276
293
  /** Own enumerable string entries: `Object.entries` and serialization. */
277
294
  export const entries = (target) => keys(target).map((key) => [key, getOwn(target, key)]);
278
295
  export const record = (proto, fields) => {
279
- const target = new ProgramObject(proto);
296
+ const target = new Obj(proto);
280
297
  for (const [key, value] of Object.entries(fields))
281
298
  define(target, key, value);
282
299
  return target;