@opencode/codemode 0.0.0-dev-19631 → 0.0.0-dev-19634
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.
- package/dist/codemode.js +1 -1
- package/dist/data.d.ts +3 -3
- package/dist/data.js +37 -31
- package/dist/interpreter/callback.d.ts +20 -0
- package/dist/interpreter/{runner.js → callback.js} +10 -10
- package/dist/interpreter/errors.d.ts +5 -5
- package/dist/interpreter/errors.js +21 -22
- package/dist/interpreter/execute.d.ts +2 -2
- package/dist/interpreter/execute.js +11 -11
- package/dist/interpreter/extensions.d.ts +2 -2
- package/dist/interpreter/extensions.js +42 -36
- package/dist/interpreter/generators.d.ts +2 -3
- package/dist/interpreter/generators.js +8 -8
- package/dist/interpreter/globals.d.ts +2 -12
- package/dist/interpreter/globals.js +41 -37
- package/dist/interpreter/interpreter.d.ts +31 -0
- package/dist/interpreter/{runtime.js → interpreter.js} +118 -117
- package/dist/interpreter/intrinsics.d.ts +5 -5
- package/dist/interpreter/intrinsics.js +16 -10
- package/dist/interpreter/model.d.ts +3 -3
- package/dist/interpreter/model.js +1 -1
- package/dist/interpreter/native.d.ts +9 -9
- package/dist/interpreter/native.js +9 -9
- package/dist/interpreter/objects.d.ts +51 -46
- package/dist/interpreter/objects.js +57 -40
- package/dist/interpreter/promises.d.ts +13 -13
- package/dist/interpreter/promises.js +70 -70
- package/dist/interpreter/references.js +17 -15
- package/dist/openapi/types.d.ts +1 -1
- package/dist/stdlib/array.d.ts +3 -3
- package/dist/stdlib/array.js +31 -31
- package/dist/stdlib/bytes.d.ts +10 -0
- package/dist/stdlib/bytes.js +228 -0
- package/dist/stdlib/collections.d.ts +4 -4
- package/dist/stdlib/collections.js +55 -55
- package/dist/stdlib/console.d.ts +3 -3
- package/dist/stdlib/console.js +24 -22
- package/dist/stdlib/date.d.ts +2 -2
- package/dist/stdlib/date.js +19 -19
- package/dist/stdlib/json.d.ts +3 -3
- package/dist/stdlib/json.js +24 -24
- package/dist/stdlib/math.d.ts +3 -3
- package/dist/stdlib/math.js +7 -7
- package/dist/stdlib/number.d.ts +3 -3
- package/dist/stdlib/number.js +11 -11
- package/dist/stdlib/object.d.ts +5 -5
- package/dist/stdlib/object.js +41 -39
- package/dist/stdlib/regexp.d.ts +6 -6
- package/dist/stdlib/regexp.js +24 -24
- package/dist/stdlib/string.d.ts +2 -2
- package/dist/stdlib/string.js +24 -24
- package/dist/stdlib/url.d.ts +6 -6
- package/dist/stdlib/url.js +39 -39
- package/dist/stdlib/value.d.ts +3 -3
- package/dist/stdlib/value.js +18 -14
- package/dist/stdlib/web.d.ts +4 -4
- package/dist/stdlib/web.js +19 -5
- package/dist/tool-runtime.d.ts +2 -2
- package/dist/tool-runtime.js +2 -2
- package/package.json +1 -1
- package/dist/interpreter/runner.d.ts +0 -27
- package/dist/interpreter/runtime.d.ts +0 -19
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
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
|
|
11
|
-
export declare const createErrorValue: (prototype:
|
|
12
|
-
export declare const
|
|
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,
|
|
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
|
|
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
|
|
40
|
-
const object = new
|
|
42
|
+
export const createBuiltins = () => {
|
|
43
|
+
const object = new Obj(null);
|
|
41
44
|
// Function.prototype is itself callable and returns undefined.
|
|
42
|
-
const fn = new
|
|
43
|
-
const plain = () => new
|
|
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
|
|
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
|
|
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
|
|
72
|
-
AsyncGenerator: new
|
|
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 {
|
|
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
|
|
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?:
|
|
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
|
|
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 {
|
|
3
|
-
import { type Callable,
|
|
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>(
|
|
7
|
-
export declare const fn: <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: (
|
|
10
|
-
export declare const constants: (target:
|
|
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>(
|
|
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:
|
|
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
|
|
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,
|
|
3
|
+
import { define, frozen, hidden, Native, Obj } from "./objects.js";
|
|
4
4
|
import { describeValue } from "./references.js";
|
|
5
|
-
// The dispatch in `Frame.
|
|
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 = (
|
|
11
|
-
export const fn = (
|
|
12
|
-
export const methods = (
|
|
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(
|
|
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 = (
|
|
22
|
-
const ctor = native(
|
|
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
|
|
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
|
|
34
|
-
proto:
|
|
33
|
+
export declare class Obj {
|
|
34
|
+
proto: Obj | null;
|
|
35
35
|
readonly props: Map<string | symbol, Slot>;
|
|
36
|
-
constructor(proto:
|
|
36
|
+
constructor(proto: Obj | null);
|
|
37
37
|
}
|
|
38
|
-
export declare class
|
|
38
|
+
export declare class Arr extends Obj {
|
|
39
39
|
readonly items: Array<unknown>;
|
|
40
|
-
constructor(proto:
|
|
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
|
|
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
|
|
48
|
-
constructor(proto:
|
|
47
|
+
export declare abstract class Callable extends Obj {
|
|
48
|
+
constructor(proto: Obj, name: string, length: number);
|
|
49
49
|
}
|
|
50
|
-
export declare class
|
|
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:
|
|
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
|
|
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:
|
|
73
|
+
constructor(proto: Obj, options: NativeOptions<R>);
|
|
74
74
|
}
|
|
75
|
-
export declare class
|
|
75
|
+
export declare class PromiseObj extends Obj {
|
|
76
76
|
readonly fiber: Fiber.Fiber<unknown, unknown>;
|
|
77
|
-
constructor(proto:
|
|
77
|
+
constructor(proto: Obj, fiber: Fiber.Fiber<unknown, unknown>);
|
|
78
78
|
}
|
|
79
|
-
export declare class
|
|
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:
|
|
82
|
+
constructor(proto: Obj, asynchronous: boolean, request: (kind: GeneratorRequestKind, value: unknown) => Effect.Effect<unknown, unknown, unknown>);
|
|
83
83
|
}
|
|
84
|
-
export declare class
|
|
84
|
+
export declare class DateObj extends Obj {
|
|
85
85
|
time: number;
|
|
86
|
-
constructor(proto:
|
|
86
|
+
constructor(proto: Obj, time: number);
|
|
87
87
|
}
|
|
88
|
-
export declare class
|
|
88
|
+
export declare class RegExpObj extends Obj {
|
|
89
89
|
readonly regex: RegExp;
|
|
90
|
-
constructor(proto:
|
|
90
|
+
constructor(proto: Obj, pattern: string, flags: string);
|
|
91
91
|
}
|
|
92
|
-
export declare class
|
|
92
|
+
export declare class MapObj extends Obj {
|
|
93
93
|
readonly map: Map<unknown, unknown>;
|
|
94
94
|
}
|
|
95
|
-
export declare class
|
|
95
|
+
export declare class SetObj extends Obj {
|
|
96
96
|
readonly set: Set<unknown>;
|
|
97
97
|
}
|
|
98
|
-
export declare class
|
|
98
|
+
export declare class URLSearchParamsObj extends Obj {
|
|
99
99
|
readonly params: URLSearchParams;
|
|
100
|
-
constructor(proto:
|
|
100
|
+
constructor(proto: Obj, params: URLSearchParams);
|
|
101
101
|
}
|
|
102
|
-
export declare class
|
|
102
|
+
export declare class URLObj extends Obj {
|
|
103
103
|
readonly url: URL;
|
|
104
|
-
readonly searchParams:
|
|
105
|
-
constructor(proto:
|
|
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
|
|
113
|
+
export declare class Handle extends Obj {
|
|
109
114
|
readonly instance: object;
|
|
110
|
-
constructor(proto:
|
|
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
|
|
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:
|
|
117
|
-
export declare const hasOwn: (target:
|
|
118
|
-
export declare const getOwn: (target:
|
|
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:
|
|
121
|
-
export declare const has: (target:
|
|
122
|
-
export declare const hasPrototype: (value: unknown, proto:
|
|
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:
|
|
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:
|
|
127
|
-
export declare const defineAccessor: (target:
|
|
128
|
-
export declare const remove: (target:
|
|
129
|
-
export declare const ownKeys: (target:
|
|
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:
|
|
136
|
+
export declare const enumerableKeys: (target: Obj) => Array<string | symbol>;
|
|
132
137
|
/** Own enumerable string keys: `Object.keys`. */
|
|
133
|
-
export declare const keys: (target:
|
|
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:
|
|
136
|
-
export declare const record: (proto:
|
|
137
|
-
export declare const assign: (target:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
96
|
+
export class MapObj extends Obj {
|
|
97
97
|
map = new Map();
|
|
98
98
|
}
|
|
99
|
-
export class
|
|
99
|
+
export class SetObj extends Obj {
|
|
100
100
|
set = new Set();
|
|
101
101
|
}
|
|
102
|
-
export class
|
|
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
|
|
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
|
|
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
|
|
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
|
|
128
|
-
value instanceof
|
|
129
|
-
value instanceof
|
|
130
|
-
value instanceof
|
|
131
|
-
value instanceof
|
|
132
|
-
value instanceof
|
|
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
|
|
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
|
|
157
|
+
if (isIndexed(target)) {
|
|
147
158
|
const at = index(target, name);
|
|
148
159
|
if (at !== undefined) {
|
|
149
|
-
|
|
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
|
|
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
|
|
198
|
+
const writeElement = (target, name, value) => {
|
|
186
199
|
const at = index(target, name);
|
|
187
200
|
if (at !== undefined) {
|
|
188
|
-
target
|
|
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
|
|
218
|
-
const written =
|
|
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
|
|
226
|
-
const written =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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;
|