@opencode/codemode 2.2.4 → 2.2.6

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 (133) hide show
  1. package/README.md +70 -1
  2. package/dist/codemode.d.ts +55 -4
  3. package/dist/codemode.js +63 -8
  4. package/dist/extension.d.ts +14 -9
  5. package/dist/extension.js +2 -2
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/interpreter/execute.d.ts +1 -1
  9. package/dist/interpreter/execute.js +16 -4
  10. package/dist/interpreter/extensions.d.ts +3 -3
  11. package/dist/interpreter/extensions.js +17 -11
  12. package/dist/interpreter/globals.js +10 -0
  13. package/dist/interpreter/interpreter.d.ts +11 -1
  14. package/dist/interpreter/interpreter.js +86 -2
  15. package/dist/interpreter/modules.d.ts +4 -0
  16. package/dist/interpreter/modules.js +33 -0
  17. package/dist/suspend-error.d.ts +23 -0
  18. package/dist/suspend-error.js +25 -0
  19. package/dist/tool-runtime.d.ts +4 -1
  20. package/dist/vm/async.d.ts +78 -0
  21. package/dist/vm/async.js +335 -0
  22. package/dist/vm/code.d.ts +122 -0
  23. package/dist/vm/code.js +407 -0
  24. package/dist/vm/compiler/compile.d.ts +13 -0
  25. package/dist/vm/compiler/compile.js +1477 -0
  26. package/dist/vm/compiler/scope.d.ts +74 -0
  27. package/dist/vm/compiler/scope.js +515 -0
  28. package/dist/vm/data.d.ts +7 -0
  29. package/dist/vm/data.js +13 -0
  30. package/dist/vm/generators.d.ts +42 -0
  31. package/dist/vm/generators.js +413 -0
  32. package/dist/vm/host.d.ts +103 -0
  33. package/dist/vm/host.js +226 -0
  34. package/dist/vm/index.d.ts +6 -0
  35. package/dist/vm/index.js +6 -0
  36. package/dist/vm/internal-prelude.d.ts +45 -0
  37. package/dist/vm/internal-prelude.js +534 -0
  38. package/dist/vm/opcodes.d.ts +222 -0
  39. package/dist/vm/opcodes.js +235 -0
  40. package/dist/vm/prelude/bytecode.d.ts +18 -0
  41. package/dist/vm/prelude/bytecode.js +31 -0
  42. package/dist/vm/prelude/bytecode.json +1 -0
  43. package/dist/vm/prelude/helpers.d.ts +8 -0
  44. package/dist/vm/prelude/helpers.js +258 -0
  45. package/dist/vm/prelude/prelude.d.ts +21 -0
  46. package/dist/vm/prelude/prelude.js +53 -0
  47. package/dist/vm/prelude/source.d.ts +1 -0
  48. package/dist/vm/prelude/source.js +652 -0
  49. package/dist/vm/runtime/callback.d.ts +25 -0
  50. package/dist/vm/runtime/callback.js +51 -0
  51. package/dist/vm/runtime/driver.d.ts +58 -0
  52. package/dist/vm/runtime/driver.js +184 -0
  53. package/dist/vm/runtime/errors.d.ts +23 -0
  54. package/dist/vm/runtime/errors.js +169 -0
  55. package/dist/vm/runtime/execute.d.ts +80 -0
  56. package/dist/vm/runtime/execute.js +414 -0
  57. package/dist/vm/runtime/extensions.d.ts +16 -0
  58. package/dist/vm/runtime/extensions.js +270 -0
  59. package/dist/vm/runtime/generators.d.ts +6 -0
  60. package/dist/vm/runtime/generators.js +44 -0
  61. package/dist/vm/runtime/globals.d.ts +6 -0
  62. package/dist/vm/runtime/globals.js +137 -0
  63. package/dist/vm/runtime/interpreter.d.ts +50 -0
  64. package/dist/vm/runtime/interpreter.js +94 -0
  65. package/dist/vm/runtime/intrinsic-names.d.ts +56 -0
  66. package/dist/vm/runtime/intrinsic-names.js +166 -0
  67. package/dist/vm/runtime/intrinsics.d.ts +15 -0
  68. package/dist/vm/runtime/intrinsics.js +111 -0
  69. package/dist/vm/runtime/limits.d.ts +10 -0
  70. package/dist/vm/runtime/limits.js +19 -0
  71. package/dist/vm/runtime/model.d.ts +58 -0
  72. package/dist/vm/runtime/model.js +57 -0
  73. package/dist/vm/runtime/modules.d.ts +4 -0
  74. package/dist/vm/runtime/modules.js +33 -0
  75. package/dist/vm/runtime/native.d.ts +19 -0
  76. package/dist/vm/runtime/native.js +41 -0
  77. package/dist/vm/runtime/objects.d.ts +403 -0
  78. package/dist/vm/runtime/objects.js +784 -0
  79. package/dist/vm/runtime/operations.d.ts +49 -0
  80. package/dist/vm/runtime/operations.js +288 -0
  81. package/dist/vm/runtime/promises.d.ts +55 -0
  82. package/dist/vm/runtime/promises.js +232 -0
  83. package/dist/vm/runtime/references.d.ts +8 -0
  84. package/dist/vm/runtime/references.js +51 -0
  85. package/dist/vm/runtime/signals.d.ts +69 -0
  86. package/dist/vm/runtime/signals.js +68 -0
  87. package/dist/vm/runtime/source.d.ts +29 -0
  88. package/dist/vm/runtime/source.js +63 -0
  89. package/dist/vm/runtime/table.d.ts +43 -0
  90. package/dist/vm/runtime/table.js +132 -0
  91. package/dist/vm/scheduler.d.ts +178 -0
  92. package/dist/vm/scheduler.js +63 -0
  93. package/dist/vm/snapshot/codec.d.ts +87 -0
  94. package/dist/vm/snapshot/codec.js +751 -0
  95. package/dist/vm/snapshot/snapshot.d.ts +49 -0
  96. package/dist/vm/snapshot/snapshot.js +70 -0
  97. package/dist/vm/snapshot.d.ts +32 -0
  98. package/dist/vm/snapshot.js +306 -0
  99. package/dist/vm/stdlib/array.d.ts +16 -0
  100. package/dist/vm/stdlib/array.js +311 -0
  101. package/dist/vm/stdlib/bytes.d.ts +11 -0
  102. package/dist/vm/stdlib/bytes.js +222 -0
  103. package/dist/vm/stdlib/collections.d.ts +7 -0
  104. package/dist/vm/stdlib/collections.js +188 -0
  105. package/dist/vm/stdlib/console.d.ts +6 -0
  106. package/dist/vm/stdlib/console.js +93 -0
  107. package/dist/vm/stdlib/date.d.ts +2 -0
  108. package/dist/vm/stdlib/date.js +123 -0
  109. package/dist/vm/stdlib/headers.d.ts +2 -0
  110. package/dist/vm/stdlib/headers.js +92 -0
  111. package/dist/vm/stdlib/iterator.d.ts +2 -0
  112. package/dist/vm/stdlib/iterator.js +30 -0
  113. package/dist/vm/stdlib/json.d.ts +3 -0
  114. package/dist/vm/stdlib/json.js +42 -0
  115. package/dist/vm/stdlib/math.d.ts +3 -0
  116. package/dist/vm/stdlib/math.js +73 -0
  117. package/dist/vm/stdlib/number.d.ts +3 -0
  118. package/dist/vm/stdlib/number.js +72 -0
  119. package/dist/vm/stdlib/object.d.ts +6 -0
  120. package/dist/vm/stdlib/object.js +201 -0
  121. package/dist/vm/stdlib/regexp.d.ts +8 -0
  122. package/dist/vm/stdlib/regexp.js +119 -0
  123. package/dist/vm/stdlib/string.d.ts +2 -0
  124. package/dist/vm/stdlib/string.js +272 -0
  125. package/dist/vm/stdlib/url.d.ts +25 -0
  126. package/dist/vm/stdlib/url.js +255 -0
  127. package/dist/vm/stdlib/value.d.ts +6 -0
  128. package/dist/vm/stdlib/value.js +32 -0
  129. package/dist/vm/stdlib/web.d.ts +5 -0
  130. package/dist/vm/stdlib/web.js +97 -0
  131. package/dist/vm/vm.d.ts +225 -0
  132. package/dist/vm/vm.js +2931 -0
  133. package/package.json +6 -3
@@ -0,0 +1,403 @@
1
+ import { ToolReference } from "../../tool-runtime.js";
2
+ import type { Builtins } from "./intrinsics.js";
3
+ import { type AstNode, type PendingThrow } from "./model.js";
4
+ import { type Convert, type GeneratorRequest, Invoke, type Push, type Resume } from "./signals.js";
5
+ import type { Code } from "../code.js";
6
+ import { type Cell } from "../opcodes.js";
7
+ import type { Reaction, Resolving } from "../scheduler.js";
8
+ import type { Frame } from "../vm.js";
9
+ import { OrderedTable, type TableCursor } from "./table.js";
10
+ /** Property attributes, as in a JS property descriptor. */
11
+ export type Attributes = {
12
+ readonly writable: boolean;
13
+ readonly enumerable: boolean;
14
+ readonly configurable: boolean;
15
+ };
16
+ export type Getter = (receiver: Value) => Value;
17
+ export type Setter = (receiver: Value, value: Value) => void;
18
+ /** One own property: a data slot or a native accessor pair. */
19
+ export type Slot = {
20
+ value: Value;
21
+ writable: boolean;
22
+ enumerable: boolean;
23
+ configurable: boolean;
24
+ } | {
25
+ get: Getter | undefined;
26
+ set: Setter | undefined;
27
+ enumerable: boolean;
28
+ configurable: boolean;
29
+ };
30
+ /**
31
+ * Runs `make`, which makes a runtime's intrinsics, and returns every object made meanwhile, in creation order, after
32
+ * `first` (the built-in prototypes, made before). An object's index in the list is its static intrinsic id.
33
+ */
34
+ export declare const makingIntrinsics: <A>(first: ReadonlyArray<Obj>, make: () => A) => readonly [A, Array<Obj>];
35
+ /** Marks an intrinsic as changed by the program, so saving a run records it; any other object is left alone. */
36
+ export declare const changed: (target: Obj) => void;
37
+ /** Ordinary assignment: writable, enumerable, configurable. */
38
+ export declare const data: Attributes;
39
+ /** Built-in methods and `constructor`: writable and configurable but hidden from enumeration. */
40
+ export declare const hidden: Attributes;
41
+ /** Function `name` and `length`: read-only but deletable. */
42
+ export declare const readonly: Attributes;
43
+ /** Constants such as `Math.PI` and a constructor's `prototype`. */
44
+ export declare const frozen: Attributes;
45
+ /**
46
+ * An object owned by the program: own properties plus a prototype link. Subclasses answer, in one place, how a
47
+ * built-in kind of object prints, coerces, iterates, and crosses to the host.
48
+ */
49
+ export declare class Obj {
50
+ proto: Obj | null;
51
+ readonly props: Map<string | symbol, Slot>;
52
+ /** [[Extensible]]: cleared by `Object.preventExtensions`, `seal`, and `freeze`. */
53
+ extensible: boolean;
54
+ /**
55
+ * 0 for an object the program made. For an intrinsic, its id plus one while it is as the runtime made it, negated
56
+ * once it changes (see `changed` and `IntrinsicNames`).
57
+ */
58
+ intrinsic: number;
59
+ constructor(proto: Obj | null);
60
+ /** The class name `Object.prototype.toString` reports: `[object Map]`. */
61
+ readonly tag: string;
62
+ /** How diagnostics refer to a value of this kind. */
63
+ get describe(): string;
64
+ /** ToString without consulting program-defined methods. */
65
+ toString(): string;
66
+ /** ToPrimitive without consulting program-defined methods: only a Date answers a number hint differently. */
67
+ toPrimitive(hint: "default" | "number" | "string"): string | number;
68
+ /** ToNumber without consulting program-defined methods. */
69
+ toNumber(): number;
70
+ /** How `console.log` shows the value; `item` formats a child with cycle and depth tracking. */
71
+ inspect(item: (value: Value) => string): string;
72
+ /** A copy the host can hold; `item` converts a child. A `__proto__` key never reaches host code. */
73
+ toHost(item: (value: Value) => unknown): unknown;
74
+ /** The built-in iteration `for...of` and spread use, when this kind of object has one. */
75
+ iterator(builtins: Builtins): Cursor | undefined;
76
+ }
77
+ export declare class Arr extends Obj {
78
+ readonly items: Array<Value>;
79
+ readonly tag = "Array";
80
+ /** The attributes every live element shares; `seal` and `freeze` narrow them since elements have no slots. */
81
+ elements: Attributes;
82
+ constructor(proto: Obj, items?: Array<Value>);
83
+ get describe(): string;
84
+ toString(): string;
85
+ inspect(item: (value: Value) => string): string;
86
+ toHost(item: (value: Value) => unknown): unknown[];
87
+ iterator(builtins: Builtins): Position;
88
+ }
89
+ /** An object with the [[ErrorData]] slot: what `Error.prototype.toString` and the host boundary recognize as an error. */
90
+ export declare class ErrorObj extends Obj {
91
+ readonly tag = "Error";
92
+ /**
93
+ * The interpreter failure this error materialized from, so rethrowing it keeps the diagnostic kind and location. It
94
+ * is plain data (type, message, kind, suggestions, and the node it is located at), shared with the failure so a
95
+ * location attached later is seen here too.
96
+ */
97
+ failure?: PendingThrow;
98
+ /** Error.prototype.toString: "name: message", or just one when the other is empty. */
99
+ toString(): string;
100
+ inspect(): string;
101
+ }
102
+ /** Interpreter machinery a program can hold but never inspect, serialize, or hand to the host. */
103
+ export declare abstract class Opaque extends Obj {
104
+ inspect(): string;
105
+ }
106
+ export declare abstract class Callable extends Opaque {
107
+ readonly length: number;
108
+ readonly tag = "Function";
109
+ constructor(proto: Obj, name: string, length: number);
110
+ get describe(): string;
111
+ }
112
+ /** A program or prelude function: its bytecode, and the cells of the bindings it captured. */
113
+ export declare class Fn extends Callable {
114
+ readonly code: Code;
115
+ readonly cells: ReadonlyArray<Cell>;
116
+ constructor(proto: Obj, code: Code, cells: ReadonlyArray<Cell>, name?: string);
117
+ get generator(): boolean;
118
+ }
119
+ /** The strict `arguments` object: an ordinary object with indexed own properties and a hidden `length`. */
120
+ export declare class Arguments extends Obj {
121
+ readonly tag = "Arguments";
122
+ constructor(proto: Obj, args: Array<Value>);
123
+ iterator(builtins: Builtins): Position;
124
+ }
125
+ /**
126
+ * A native function body: a value, or what the VM carries out as the call: work it hands over by name (`Push`), a
127
+ * suspended generator to continue (`Resume`), a call it hands on (`Invoke`), or conversions to run before it runs again
128
+ * (`Convert`). A native never runs program code itself.
129
+ */
130
+ export type NativeResult = Value | Push | Resume | Invoke | Convert;
131
+ /** `site` is the call running the built-in, where a failure it reports later (a rejection) is located. */
132
+ export type NativeCall = (thisValue: Value, args: Array<Value>, site: AstNode | undefined) => NativeResult;
133
+ export type NativeConstruct = (args: Array<Value>, newTarget: Callable, site: AstNode | undefined) => NativeResult;
134
+ export type NativeOptions = {
135
+ /**
136
+ * Why this native may be made while the program runs, for the few kinds that still capture state in a host closure.
137
+ * Every other native is made with the intrinsics; see `nativeRule`.
138
+ */
139
+ readonly runtime?: RuntimeNative;
140
+ readonly name: string;
141
+ readonly length?: number;
142
+ readonly call: NativeCall;
143
+ /** `new name(...)`; without it the function is not a constructor. */
144
+ readonly construct?: NativeConstruct;
145
+ /** Whether callback sites (array methods, replacers, promise reactions) admit this function. Defaults to true. */
146
+ readonly callback?: boolean;
147
+ };
148
+ /** The natives still made at run time, each holding state in a host closure that cannot be saved yet. */
149
+ export type RuntimeNative = "extension";
150
+ /**
151
+ * Natives are made only with the intrinsics, so each one has an intrinsic name and run state never holds a host
152
+ * closure. When `check` is on (tests turn it on), making a native for a runtime whose intrinsics are `sealed` (keyed by
153
+ * its `Function.prototype`) throws, unless it declares one of the `RuntimeNative` exceptions.
154
+ */
155
+ export declare const nativeRule: {
156
+ check: boolean;
157
+ sealed: WeakSet<Obj>;
158
+ observe?: (native: Native) => void;
159
+ };
160
+ /**
161
+ * A built-in function: a `Native` made with the intrinsics, or a data kind such as `BoundFn` or `Resolver` whose state
162
+ * is plain fields and whose behaviour lives on its class.
163
+ */
164
+ export declare abstract class Builtin extends Callable {
165
+ /** `new name(...)`; without it the function is not a constructor. */
166
+ abstract readonly construct: NativeConstruct | undefined;
167
+ /** Whether callback sites (array methods, replacers, promise reactions) admit this function. */
168
+ abstract readonly callback: boolean;
169
+ abstract invoke(thisValue: Value, args: Array<Value>, site: AstNode | undefined): NativeResult;
170
+ }
171
+ export declare class Native extends Builtin {
172
+ readonly call: NativeCall;
173
+ readonly construct: NativeConstruct | undefined;
174
+ readonly callback: boolean;
175
+ constructor(proto: Obj, options: NativeOptions);
176
+ invoke(thisValue: Value, args: Array<Value>, site: AstNode | undefined): NativeResult;
177
+ }
178
+ /** `Function.prototype.bind`'s result: calls `target` with the bound receiver and leading arguments. */
179
+ export declare class BoundFn extends Builtin {
180
+ readonly target: Callable;
181
+ readonly boundThis: Value;
182
+ readonly boundArgs: ReadonlyArray<Value>;
183
+ readonly construct: undefined;
184
+ readonly callback = true;
185
+ constructor(proto: Obj, target: Callable, boundThis: Value, boundArgs: ReadonlyArray<Value>);
186
+ invoke(_: Value, args: Array<Value>, site: AstNode | undefined): NativeResult;
187
+ }
188
+ /** A `resolve` or `reject` function handed to an executor or thenable: settles its shared `Resolving` once. */
189
+ export declare class Resolver extends Builtin {
190
+ readonly resolving: Resolving;
191
+ readonly kind: "resolve" | "reject";
192
+ readonly construct: undefined;
193
+ readonly callback = true;
194
+ constructor(proto: Obj, name: string, resolving: Resolving, kind: "resolve" | "reject");
195
+ invoke(_: Value, args: Array<Value>): NativeResult;
196
+ }
197
+ export declare class PromiseObj extends Opaque {
198
+ /** Creation order, for reporting unhandled rejections in the order their promises were made. */
199
+ readonly id: number;
200
+ readonly tag = "Promise";
201
+ state: "pending" | "fulfilled" | "rejected";
202
+ /** The value, or the failure as thrown; a handler receives it materialized. */
203
+ result: unknown;
204
+ reactions: Array<Reaction>;
205
+ /** [[PromiseIsHandled]]: a reaction was attached, so a rejection is not reported as unhandled. */
206
+ handled: boolean;
207
+ constructor(proto: Obj,
208
+ /** Creation order, for reporting unhandled rejections in the order their promises were made. */
209
+ id: number);
210
+ get describe(): string;
211
+ inspect(): string;
212
+ }
213
+ export type GeneratorState = "suspendedStart" | "suspendedYield" | "executing" | "awaiting-return" | "draining" | "completed";
214
+ export declare class GeneratorObj extends Opaque {
215
+ readonly asynchronous: boolean;
216
+ readonly tag = "Generator";
217
+ state: GeneratorState;
218
+ /** The suspended body's frame, kept while it waits for the next request, which puts it back on the job stack. */
219
+ frame: Frame | undefined;
220
+ /** An async generator's requests, oldest first, each with what settles its promise. */
221
+ readonly queue: Array<{
222
+ readonly request: GeneratorRequest;
223
+ readonly resolving: Resolving;
224
+ }>;
225
+ constructor(proto: Obj, asynchronous: boolean);
226
+ get describe(): string;
227
+ }
228
+ /** One pull from an iterator, as `for...of` sees it. */
229
+ export type Step = {
230
+ readonly done: boolean;
231
+ readonly value: Value;
232
+ };
233
+ /**
234
+ * An iterator the interpreter drives, as data: a built-in cursor over a collection (`Position`), or a program
235
+ * iterator driven by its own `next` method (`CustomIterator`).
236
+ */
237
+ export type Cursor = Position | CustomIterator;
238
+ /** A program iterator record: the iterator, its `next` method, and whether its results are awaited. */
239
+ export type CustomIterator = {
240
+ readonly iterator: Obj;
241
+ readonly next: Value;
242
+ readonly asynchronous: boolean;
243
+ };
244
+ /** What a built-in iterator yields for each entry: `keys()`, `values()`, or `entries()`. */
245
+ export type IterationKind = "keys" | "values" | "entries";
246
+ /** What a built-in iterator walks: a collection, a string, or a fixed list of values. */
247
+ export type PositionSource = Arr | Bytes | MapObj | SetObj | HeadersObj | URLSearchParamsObj | string | ReadonlyArray<Value>;
248
+ /**
249
+ * A built-in iterator's place in its source, as data: what it walks, what it yields, and the next index. Iteration is
250
+ * live, as in JS: an array iterator reads the length on every step, and a Map or Set iterator is kept in place by its
251
+ * table. Once done it stays done. There is nothing to close.
252
+ */
253
+ export declare class Position implements TableCursor {
254
+ readonly source: PositionSource;
255
+ readonly kind: IterationKind;
256
+ /** The prototype of the `[key, value]` arrays `entries()` yields. */
257
+ readonly arrays: Obj;
258
+ index: number;
259
+ done: boolean;
260
+ constructor(source: PositionSource, kind: IterationKind,
261
+ /** The prototype of the `[key, value]` arrays `entries()` yields. */
262
+ arrays: Obj);
263
+ step(): Step;
264
+ private yield;
265
+ private finish;
266
+ }
267
+ /** A built-in iterator: a live cursor over a host collection or an iterator helper, yielding program values. */
268
+ export declare class IteratorObj extends Opaque {
269
+ readonly cursor: Cursor;
270
+ readonly tag = "Iterator";
271
+ constructor(proto: Obj, cursor: Cursor);
272
+ get describe(): string;
273
+ }
274
+ /** A built-in iterator over a collection, e.g. `array.values()`. */
275
+ export declare const positionIterator: (builtins: Builtins, source: PositionSource, kind: IterationKind) => IteratorObj;
276
+ /** A built-in object around a host value: data-like, so it prints as itself and crosses to extensions as a copy. */
277
+ export declare abstract class Wrapper extends Obj {
278
+ inspect(item: (value: Value) => string): string;
279
+ }
280
+ export declare class DateObj extends Wrapper {
281
+ time: number;
282
+ readonly tag = "Date";
283
+ constructor(proto: Obj, time: number);
284
+ toString(): string;
285
+ toPrimitive(hint: "default" | "number" | "string"): string | number;
286
+ toHost(): Date;
287
+ }
288
+ /** A RegExp as data: its source, flags, and `lastIndex`; the host regex is only a compiled cache of the first two. */
289
+ export declare class RegExpObj extends Wrapper {
290
+ readonly tag = "RegExp";
291
+ readonly source: string;
292
+ readonly flags: string;
293
+ /** Shared by `exec`/`test` and the String methods, as the host regex's own `lastIndex` would be. */
294
+ lastIndex: number;
295
+ private compiled;
296
+ constructor(proto: Obj, pattern: string, flags: string);
297
+ /** The compiled regex, for reading what it is; anything that matches goes through `use`. */
298
+ get regex(): RegExp;
299
+ /** Runs host regex work starting from this object's `lastIndex`, and keeps the `lastIndex` the work leaves. */
300
+ use<T>(work: (regex: RegExp) => T): T;
301
+ toString(): string;
302
+ toHost(): RegExp;
303
+ }
304
+ export declare class MapObj extends Wrapper {
305
+ readonly tag = "Map";
306
+ readonly map: OrderedTable;
307
+ inspect(item: (value: Value) => string): string;
308
+ toHost(item: (value: Value) => unknown): Map<unknown, unknown>;
309
+ iterator(builtins: Builtins): Position;
310
+ }
311
+ export declare class SetObj extends Wrapper {
312
+ readonly tag = "Set";
313
+ readonly set: OrderedTable;
314
+ inspect(item: (value: Value) => string): string;
315
+ toHost(item: (value: Value) => unknown): Set<unknown>;
316
+ iterator(builtins: Builtins): Position;
317
+ }
318
+ /**
319
+ * Keys are held strongly for the run, which is short-lived; garbage collection is not observable in Code Mode, and a
320
+ * plain table keeps the state as data.
321
+ */
322
+ export declare class WeakMapObj extends Wrapper {
323
+ readonly tag = "WeakMap";
324
+ readonly map: Map<Obj, Value>;
325
+ inspect(): string;
326
+ }
327
+ export declare class WeakSetObj extends Wrapper {
328
+ readonly tag = "WeakSet";
329
+ readonly set: Set<Obj>;
330
+ inspect(): string;
331
+ }
332
+ export declare class URLSearchParamsObj extends Wrapper {
333
+ readonly params: URLSearchParams;
334
+ readonly tag = "URLSearchParams";
335
+ constructor(proto: Obj, params: URLSearchParams);
336
+ toString(): string;
337
+ toHost(): URLSearchParams;
338
+ iterator(builtins: Builtins): Position;
339
+ }
340
+ export declare class HeadersObj extends Wrapper {
341
+ readonly headers: Headers;
342
+ readonly tag = "Headers";
343
+ constructor(proto: Obj, headers: Headers);
344
+ inspect(): string;
345
+ toHost(): Headers;
346
+ iterator(builtins: Builtins): Position;
347
+ }
348
+ export declare class URLObj extends Wrapper {
349
+ readonly url: URL;
350
+ readonly tag = "URL";
351
+ readonly searchParams: URLSearchParamsObj;
352
+ constructor(proto: Obj, searchParamsProto: Obj, url: URL);
353
+ toString(): string;
354
+ toHost(): URL;
355
+ }
356
+ /** A `Uint8Array`: the host array does the byte clamping and ignores out-of-range writes, as JS does. */
357
+ export declare class Bytes extends Wrapper {
358
+ readonly bytes: Uint8Array;
359
+ readonly tag = "Uint8Array";
360
+ constructor(proto: Obj, bytes: Uint8Array);
361
+ toString(): string;
362
+ inspect(): string;
363
+ toHost(): Uint8Array<ArrayBuffer>;
364
+ iterator(builtins: Builtins): Position;
365
+ }
366
+ /** Every value a program can hold. Host values never appear here; they are copied in at the boundaries. */
367
+ export type Value = string | number | boolean | null | undefined | symbol | Obj | ToolReference;
368
+ /** ToString without consulting program-defined methods. */
369
+ export declare const coerceToString: (value: Value) => string;
370
+ /** ToNumber without consulting program-defined methods; tool references are not numbers. */
371
+ export declare const coerceToNumber: (value: Value) => number;
372
+ /** ToIntegerOrInfinity: NaN is 0, fractions truncate. */
373
+ export declare const coerceToInteger: (value: Value) => number;
374
+ /** Values that cannot cross the data boundary: opaque machinery and host-backed wrappers. */
375
+ export declare const isRuntimeReference: (value: Value) => boolean;
376
+ export declare const parseArrayIndex: (key: string | number) => number | undefined;
377
+ /** The own property under `key`, including an array's live indexes and `length`. */
378
+ export declare const own: (target: Obj, key: PropertyKey) => Slot | undefined;
379
+ export declare const hasOwn: (target: Obj, key: PropertyKey) => boolean;
380
+ export declare const getOwn: (target: Obj, key: PropertyKey) => Value;
381
+ /** [[Get]]: walks the prototype chain; accessors see `receiver`, which is the primitive for wrapper prototypes. */
382
+ export declare const get: (target: Obj, key: PropertyKey, receiver?: Value) => Value;
383
+ export declare const has: (target: Obj, key: PropertyKey) => boolean;
384
+ export declare const hasPrototype: (value: Value, proto: Obj) => boolean;
385
+ /** [[Set]]: an inherited setter or read-only property decides before an own data property is created. */
386
+ export declare const set: (target: Obj, key: PropertyKey, value: Value) => boolean;
387
+ /** Creating a property on a non-extensible object is the one [[Set]] failure with its own message. */
388
+ export declare const rejectAddition: (target: Obj, key: string | symbol | number) => void;
389
+ /** [[DefineOwnProperty]] for a data property, ignoring the chain. */
390
+ export declare const define: (target: Obj, key: PropertyKey, value: Value, attrs?: Attributes) => void;
391
+ export declare const defineAccessor: (target: Obj, key: PropertyKey, get: Getter | undefined, set?: Setter) => void;
392
+ export declare const remove: (target: Obj, key: PropertyKey) => boolean;
393
+ export declare const ownKeys: (target: Obj) => Array<string | symbol>;
394
+ /** Own enumerable keys, including the iterator symbols; what spread and `Object.assign` copy. */
395
+ export declare const enumerableKeys: (target: Obj) => Array<string | symbol>;
396
+ /** Own enumerable string keys: `Object.keys`. */
397
+ export declare const keys: (target: Obj) => Array<string>;
398
+ /** Own enumerable string entries: `Object.entries` and serialization. */
399
+ export declare const entries: (target: Obj) => Array<[string, Value]>;
400
+ /** An iterator result `{ value, done }`, built directly since every iteration step makes one. */
401
+ export declare const iteratorResult: (proto: Obj, value: Value, done: boolean) => Obj;
402
+ export declare const record: (proto: Obj, fields: Record<string, Value>) => Obj;
403
+ export declare const assign: (target: Obj, source: Obj, skip?: ReadonlySet<PropertyKey>) => void;