@opencode/codemode 0.0.0-dev-1180 → 0.0.0-dev-1216
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/README.md +6 -12
- package/dist/codemode.d.ts +7 -21
- package/dist/codemode.js +17 -38
- package/dist/extension.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/scan.js +2 -2
- package/dist/tool-runtime.d.ts +8 -11
- package/dist/tool-runtime.js +13 -11
- package/dist/tool.d.ts +18 -9
- package/dist/tool.js +15 -23
- package/dist/vm/data.d.ts +1 -1
- package/dist/vm/runtime/execute.d.ts +16 -6
- package/dist/vm/runtime/execute.js +10 -7
- package/dist/vm/snapshot/codec.d.ts +3 -2
- package/dist/vm/snapshot/codec.js +3 -2
- package/dist/vm/snapshot/snapshot.d.ts +6 -3
- package/dist/vm/snapshot/snapshot.js +13 -2
- package/dist/vm/vm.d.ts +2 -2
- package/package.json +3 -5
- package/dist/data.d.ts +0 -21
- package/dist/data.js +0 -93
- package/dist/interpreter/callback.d.ts +0 -35
- package/dist/interpreter/callback.js +0 -98
- package/dist/interpreter/errors.d.ts +0 -23
- package/dist/interpreter/errors.js +0 -173
- package/dist/interpreter/execute.d.ts +0 -14
- package/dist/interpreter/execute.js +0 -207
- package/dist/interpreter/extensions.d.ts +0 -9
- package/dist/interpreter/extensions.js +0 -248
- package/dist/interpreter/generators.d.ts +0 -3
- package/dist/interpreter/generators.js +0 -168
- package/dist/interpreter/globals.d.ts +0 -6
- package/dist/interpreter/globals.js +0 -144
- package/dist/interpreter/interpreter.d.ts +0 -48
- package/dist/interpreter/interpreter.js +0 -2253
- package/dist/interpreter/intrinsics.d.ts +0 -15
- package/dist/interpreter/intrinsics.js +0 -105
- package/dist/interpreter/limits.d.ts +0 -10
- package/dist/interpreter/limits.js +0 -19
- package/dist/interpreter/model.d.ts +0 -68
- package/dist/interpreter/model.js +0 -54
- package/dist/interpreter/modules.d.ts +0 -4
- package/dist/interpreter/modules.js +0 -33
- package/dist/interpreter/native.d.ts +0 -17
- package/dist/interpreter/native.js +0 -35
- package/dist/interpreter/objects.d.ts +0 -301
- package/dist/interpreter/objects.js +0 -592
- package/dist/interpreter/promises.d.ts +0 -18
- package/dist/interpreter/promises.js +0 -292
- package/dist/interpreter/references.d.ts +0 -8
- package/dist/interpreter/references.js +0 -51
- package/dist/interpreter/runner.d.ts +0 -178
- package/dist/interpreter/runner.js +0 -480
- package/dist/interpreter/scope.d.ts +0 -16
- package/dist/interpreter/scope.js +0 -79
- package/dist/stdlib/array.d.ts +0 -11
- package/dist/stdlib/array.js +0 -498
- package/dist/stdlib/bytes.d.ts +0 -10
- package/dist/stdlib/bytes.js +0 -253
- package/dist/stdlib/collections.d.ts +0 -7
- package/dist/stdlib/collections.js +0 -497
- package/dist/stdlib/console.d.ts +0 -6
- package/dist/stdlib/console.js +0 -93
- package/dist/stdlib/date.d.ts +0 -2
- package/dist/stdlib/date.js +0 -132
- package/dist/stdlib/headers.d.ts +0 -2
- package/dist/stdlib/headers.js +0 -110
- package/dist/stdlib/iterator.d.ts +0 -2
- package/dist/stdlib/iterator.js +0 -322
- package/dist/stdlib/json.d.ts +0 -3
- package/dist/stdlib/json.js +0 -58
- package/dist/stdlib/math.d.ts +0 -8
- package/dist/stdlib/math.js +0 -97
- package/dist/stdlib/number.d.ts +0 -3
- package/dist/stdlib/number.js +0 -72
- package/dist/stdlib/object.d.ts +0 -6
- package/dist/stdlib/object.js +0 -219
- package/dist/stdlib/regexp.d.ts +0 -7
- package/dist/stdlib/regexp.js +0 -114
- package/dist/stdlib/string.d.ts +0 -2
- package/dist/stdlib/string.js +0 -272
- package/dist/stdlib/url.d.ts +0 -13
- package/dist/stdlib/url.js +0 -255
- package/dist/stdlib/value.d.ts +0 -7
- package/dist/stdlib/value.js +0 -33
- package/dist/stdlib/web.d.ts +0 -5
- package/dist/stdlib/web.js +0 -97
- package/dist/suspend-error.d.ts +0 -24
- package/dist/suspend-error.js +0 -25
- package/dist/vm/index.d.ts +0 -6
- package/dist/vm/index.js +0 -6
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ErrorObj, Obj, type Value } from "./objects.js";
|
|
2
|
-
export declare const errorTypes: readonly ["Error", "TypeError", "RangeError", "SyntaxError", "ReferenceError", "EvalError", "URIError", "AggregateError"];
|
|
3
|
-
export type ErrorType = (typeof errorTypes)[number];
|
|
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", "WeakMap", "WeakSet", "URL", "URLSearchParams", "Headers", "Uint8Array", "TextEncoder", "TextDecoder", "Promise", "Iterator", "IteratorHelper", "AsyncIterator", "Generator", "AsyncGenerator"];
|
|
6
|
-
/**
|
|
7
|
-
* The built-in prototype objects of one runtime, allocated empty in dependency order. The globals populate them
|
|
8
|
-
* and attach their constructors when the runtime is built.
|
|
9
|
-
*/
|
|
10
|
-
export type Builtins = Readonly<Record<(typeof builtins)[number] | ErrorType, Obj>>;
|
|
11
|
-
export declare const createErrorValue: (prototype: Obj, message: string | undefined) => ErrorObj;
|
|
12
|
-
/** The prototype a primitive reads its methods from without being boxed; none for null, undefined, and symbols. */
|
|
13
|
-
export declare const primitivePrototype: (builtins: Builtins, value: Value) => Obj | undefined;
|
|
14
|
-
export declare const createBuiltins: () => Builtins;
|
|
15
|
-
export {};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { define, hidden, Native, Arr, ErrorObj, Obj } from "./objects.js";
|
|
2
|
-
export const errorTypes = [
|
|
3
|
-
"Error",
|
|
4
|
-
"TypeError",
|
|
5
|
-
"RangeError",
|
|
6
|
-
"SyntaxError",
|
|
7
|
-
"ReferenceError",
|
|
8
|
-
"EvalError",
|
|
9
|
-
"URIError",
|
|
10
|
-
"AggregateError",
|
|
11
|
-
];
|
|
12
|
-
export const isErrorType = (name) => errorTypes.includes(name);
|
|
13
|
-
const builtins = [
|
|
14
|
-
"Object",
|
|
15
|
-
"Function",
|
|
16
|
-
"Array",
|
|
17
|
-
"String",
|
|
18
|
-
"Number",
|
|
19
|
-
"Boolean",
|
|
20
|
-
"Date",
|
|
21
|
-
"RegExp",
|
|
22
|
-
"Map",
|
|
23
|
-
"Set",
|
|
24
|
-
"WeakMap",
|
|
25
|
-
"WeakSet",
|
|
26
|
-
"URL",
|
|
27
|
-
"URLSearchParams",
|
|
28
|
-
"Headers",
|
|
29
|
-
"Uint8Array",
|
|
30
|
-
"TextEncoder",
|
|
31
|
-
"TextDecoder",
|
|
32
|
-
"Promise",
|
|
33
|
-
"Iterator",
|
|
34
|
-
"IteratorHelper",
|
|
35
|
-
"AsyncIterator",
|
|
36
|
-
"Generator",
|
|
37
|
-
"AsyncGenerator",
|
|
38
|
-
];
|
|
39
|
-
export const createErrorValue = (prototype, message) => {
|
|
40
|
-
const value = new ErrorObj(prototype);
|
|
41
|
-
if (message !== undefined)
|
|
42
|
-
define(value, "message", message, hidden);
|
|
43
|
-
return value;
|
|
44
|
-
};
|
|
45
|
-
/** The prototype a primitive reads its methods from without being boxed; none for null, undefined, and symbols. */
|
|
46
|
-
export const primitivePrototype = (builtins, value) => {
|
|
47
|
-
if (typeof value === "string")
|
|
48
|
-
return builtins.String;
|
|
49
|
-
if (typeof value === "number")
|
|
50
|
-
return builtins.Number;
|
|
51
|
-
if (typeof value === "boolean")
|
|
52
|
-
return builtins.Boolean;
|
|
53
|
-
return undefined;
|
|
54
|
-
};
|
|
55
|
-
export const createBuiltins = () => {
|
|
56
|
-
const object = new Obj(null);
|
|
57
|
-
// Function.prototype is itself callable and returns undefined.
|
|
58
|
-
const fn = new Native(object, { name: "", call: () => undefined });
|
|
59
|
-
const plain = () => new Obj(object);
|
|
60
|
-
const error = plain();
|
|
61
|
-
define(error, "name", "Error", hidden);
|
|
62
|
-
define(error, "message", "", hidden);
|
|
63
|
-
const derived = (type) => {
|
|
64
|
-
const proto = new Obj(error);
|
|
65
|
-
define(proto, "name", type, hidden);
|
|
66
|
-
define(proto, "message", "", hidden);
|
|
67
|
-
return proto;
|
|
68
|
-
};
|
|
69
|
-
const iterator = plain();
|
|
70
|
-
const asyncIterator = plain();
|
|
71
|
-
return {
|
|
72
|
-
Object: object,
|
|
73
|
-
Function: fn,
|
|
74
|
-
Array: new Arr(object),
|
|
75
|
-
String: plain(),
|
|
76
|
-
Number: plain(),
|
|
77
|
-
Boolean: plain(),
|
|
78
|
-
Date: plain(),
|
|
79
|
-
RegExp: plain(),
|
|
80
|
-
Map: plain(),
|
|
81
|
-
Set: plain(),
|
|
82
|
-
WeakMap: plain(),
|
|
83
|
-
WeakSet: plain(),
|
|
84
|
-
URL: plain(),
|
|
85
|
-
URLSearchParams: plain(),
|
|
86
|
-
Headers: plain(),
|
|
87
|
-
Uint8Array: plain(),
|
|
88
|
-
TextEncoder: plain(),
|
|
89
|
-
TextDecoder: plain(),
|
|
90
|
-
Promise: plain(),
|
|
91
|
-
Iterator: iterator,
|
|
92
|
-
IteratorHelper: new Obj(iterator),
|
|
93
|
-
AsyncIterator: asyncIterator,
|
|
94
|
-
Generator: new Obj(iterator),
|
|
95
|
-
AsyncGenerator: new Obj(asyncIterator),
|
|
96
|
-
Error: error,
|
|
97
|
-
TypeError: derived("TypeError"),
|
|
98
|
-
RangeError: derived("RangeError"),
|
|
99
|
-
SyntaxError: derived("SyntaxError"),
|
|
100
|
-
ReferenceError: derived("ReferenceError"),
|
|
101
|
-
EvalError: derived("EvalError"),
|
|
102
|
-
URIError: derived("URIError"),
|
|
103
|
-
AggregateError: derived("AggregateError"),
|
|
104
|
-
};
|
|
105
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** Longest string a built-in or operator may produce. */
|
|
2
|
-
export declare const MAX_STRING_LENGTH: number;
|
|
3
|
-
/** Longest array a built-in may create or grow to. */
|
|
4
|
-
export declare const MAX_ARRAY_LENGTH = 10000000;
|
|
5
|
-
/** Most promises that may be pending at once. */
|
|
6
|
-
export declare const MAX_PENDING_PROMISES = 10000;
|
|
7
|
-
/** Deepest nesting a value may have when it crosses to or from the host. */
|
|
8
|
-
export declare const MAX_VALUE_DEPTH = 32;
|
|
9
|
-
export declare const checkStringLength: (length: number) => void;
|
|
10
|
-
export declare const checkArrayLength: (length: number) => void;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { rangeError } from "./model.js";
|
|
2
|
-
// The timeout only fires between interpreter steps, so a single built-in must not be able to materialize an
|
|
3
|
-
// unbounded value. These bound what one call may build; programs cannot reach such sizes any other way.
|
|
4
|
-
/** Longest string a built-in or operator may produce. */
|
|
5
|
-
export const MAX_STRING_LENGTH = 1 << 24;
|
|
6
|
-
/** Longest array a built-in may create or grow to. */
|
|
7
|
-
export const MAX_ARRAY_LENGTH = 10_000_000;
|
|
8
|
-
/** Most promises that may be pending at once. */
|
|
9
|
-
export const MAX_PENDING_PROMISES = 10_000;
|
|
10
|
-
/** Deepest nesting a value may have when it crosses to or from the host. */
|
|
11
|
-
export const MAX_VALUE_DEPTH = 32;
|
|
12
|
-
export const checkStringLength = (length) => {
|
|
13
|
-
if (length > MAX_STRING_LENGTH)
|
|
14
|
-
throw rangeError("Invalid string length");
|
|
15
|
-
};
|
|
16
|
-
export const checkArrayLength = (length) => {
|
|
17
|
-
if (length > MAX_ARRAY_LENGTH)
|
|
18
|
-
throw rangeError("Invalid array length");
|
|
19
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { Node } from "acorn";
|
|
2
|
-
import type { ErrorType } from "./intrinsics.js";
|
|
3
|
-
import type { DiagnosticKind } from "../codemode.js";
|
|
4
|
-
import type { ErrorObj, Value } from "./objects.js";
|
|
5
|
-
/** Any parsed node; the interpreter narrows on `type` and reads `loc` for diagnostics. */
|
|
6
|
-
export type AstNode = Node;
|
|
7
|
-
export type Binding = {
|
|
8
|
-
mutable: boolean;
|
|
9
|
-
value: Value;
|
|
10
|
-
initialized?: boolean;
|
|
11
|
-
};
|
|
12
|
-
export type StatementResult = {
|
|
13
|
-
kind: "none";
|
|
14
|
-
} | {
|
|
15
|
-
kind: "return";
|
|
16
|
-
value: Value;
|
|
17
|
-
} | {
|
|
18
|
-
kind: "break";
|
|
19
|
-
label?: string;
|
|
20
|
-
} | {
|
|
21
|
-
kind: "continue";
|
|
22
|
-
label?: string;
|
|
23
|
-
};
|
|
24
|
-
export type GeneratorRequestKind = "next" | "return" | "throw";
|
|
25
|
-
export declare const AsyncIteratorSymbol: unique symbol;
|
|
26
|
-
export declare const IteratorSymbol: unique symbol;
|
|
27
|
-
export declare const IteratorSymbols: readonly [typeof AsyncIteratorSymbol, typeof IteratorSymbol];
|
|
28
|
-
export declare class Throw {
|
|
29
|
-
readonly value: Value;
|
|
30
|
-
constructor(value: Value);
|
|
31
|
-
}
|
|
32
|
-
export declare class GeneratorReturn {
|
|
33
|
-
readonly value: Value;
|
|
34
|
-
constructor(value: Value);
|
|
35
|
-
}
|
|
36
|
-
export declare const OptionalShortCircuit: unique symbol;
|
|
37
|
-
/**
|
|
38
|
-
* A failure raised by the interpreter or a built-in. It travels as a defect and becomes one program Error object
|
|
39
|
-
* the first time a handler observes it, so every observer of the same failure sees the same value.
|
|
40
|
-
*/
|
|
41
|
-
export declare class PendingThrow {
|
|
42
|
-
/** The JS error class a program sees when it catches this failure. */
|
|
43
|
-
readonly type: ErrorType;
|
|
44
|
-
readonly message: string;
|
|
45
|
-
readonly kind: DiagnosticKind;
|
|
46
|
-
readonly suggestions?: ReadonlyArray<string> | undefined;
|
|
47
|
-
node?: AstNode;
|
|
48
|
-
value?: ErrorObj;
|
|
49
|
-
constructor(
|
|
50
|
-
/** The JS error class a program sees when it catches this failure. */
|
|
51
|
-
type: ErrorType, message: string, node?: AstNode, kind?: DiagnosticKind, suggestions?: ReadonlyArray<string> | undefined);
|
|
52
|
-
}
|
|
53
|
-
export declare const typeError: (message: string, node?: AstNode) => PendingThrow;
|
|
54
|
-
export declare const invalidData: (message: string, node?: AstNode) => PendingThrow;
|
|
55
|
-
export declare const rangeError: (message: string, node?: AstNode) => PendingThrow;
|
|
56
|
-
export declare const referenceError: (message: string, node?: AstNode) => PendingThrow;
|
|
57
|
-
export declare const syntaxError: (message: string, node?: AstNode) => PendingThrow;
|
|
58
|
-
export declare const uriError: (message: string, node?: AstNode) => PendingThrow;
|
|
59
|
-
export declare const supportedSyntaxMessage = "This is a restricted JavaScript-like language. Supported: plain and async functions, data literals, destructuring, standard control flow, await and Promise, and built-ins such as Array, Object, Math, JSON, Date, RegExp, Map, Set, and URL. Unsupported: classes, getters/setters, BigInt, and custom Symbols. Use plain functions and data objects instead.";
|
|
60
|
-
export declare const unsupportedSyntax: (kind: string, node: AstNode) => PendingThrow;
|
|
61
|
-
export declare const sourceLocation: (node: AstNode) => {
|
|
62
|
-
readonly line: number;
|
|
63
|
-
readonly column: number;
|
|
64
|
-
};
|
|
65
|
-
export declare const formatLocation: (location?: {
|
|
66
|
-
readonly line: number;
|
|
67
|
-
readonly column: number;
|
|
68
|
-
}) => string;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export const AsyncIteratorSymbol = Symbol("codemode.async-iterator");
|
|
2
|
-
export const IteratorSymbol = Symbol("codemode.iterator");
|
|
3
|
-
export const IteratorSymbols = [AsyncIteratorSymbol, IteratorSymbol];
|
|
4
|
-
export class Throw {
|
|
5
|
-
value;
|
|
6
|
-
constructor(value) {
|
|
7
|
-
this.value = value;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export class GeneratorReturn {
|
|
11
|
-
value;
|
|
12
|
-
constructor(value) {
|
|
13
|
-
this.value = value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export const OptionalShortCircuit = Symbol("codemode.optional-short-circuit");
|
|
17
|
-
/**
|
|
18
|
-
* A failure raised by the interpreter or a built-in. It travels as a defect and becomes one program Error object
|
|
19
|
-
* the first time a handler observes it, so every observer of the same failure sees the same value.
|
|
20
|
-
*/
|
|
21
|
-
export class PendingThrow {
|
|
22
|
-
type;
|
|
23
|
-
message;
|
|
24
|
-
kind;
|
|
25
|
-
suggestions;
|
|
26
|
-
node;
|
|
27
|
-
value;
|
|
28
|
-
constructor(
|
|
29
|
-
/** The JS error class a program sees when it catches this failure. */
|
|
30
|
-
type, message, node, kind = "ExecutionFailure", suggestions) {
|
|
31
|
-
this.type = type;
|
|
32
|
-
this.message = message;
|
|
33
|
-
this.kind = kind;
|
|
34
|
-
this.suggestions = suggestions;
|
|
35
|
-
if (node)
|
|
36
|
-
this.node = node;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const failure = (type, kind) => (message, node) => new PendingThrow(type, message, node, kind);
|
|
40
|
-
export const typeError = failure("TypeError");
|
|
41
|
-
export const invalidData = failure("TypeError", "InvalidDataValue");
|
|
42
|
-
export const rangeError = failure("RangeError");
|
|
43
|
-
export const referenceError = failure("ReferenceError");
|
|
44
|
-
export const syntaxError = failure("SyntaxError");
|
|
45
|
-
export const uriError = failure("URIError");
|
|
46
|
-
// Orient the agent rather than enumerate JavaScript; interpreter-support.md is the full matrix.
|
|
47
|
-
export const supportedSyntaxMessage = "This is a restricted JavaScript-like language. Supported: plain and async functions, data literals, destructuring, standard control flow, await and Promise, and built-ins such as Array, Object, Math, JSON, Date, RegExp, Map, Set, and URL. Unsupported: classes, getters/setters, BigInt, and custom Symbols. Use plain functions and data objects instead.";
|
|
48
|
-
export const unsupportedSyntax = (kind, node) => new PendingThrow("SyntaxError", `Syntax '${kind}' is not supported. ${supportedSyntaxMessage}`, node, "UnsupportedSyntax", [supportedSyntaxMessage]);
|
|
49
|
-
// Acorn lines are 1-based and its columns are 0-based. Diagnostics use 1-based columns of the submitted source.
|
|
50
|
-
export const sourceLocation = (node) => ({
|
|
51
|
-
line: node.loc?.start.line ?? 1,
|
|
52
|
-
column: (node.loc?.start.column ?? 0) + 1,
|
|
53
|
-
});
|
|
54
|
-
export const formatLocation = (location) => location ? ` (line ${location.line}, col ${location.column})` : "";
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { define, get, Obj } from "./objects.js";
|
|
2
|
-
/**
|
|
3
|
-
* What `import` and `require` load: a global, by the Node module name that provides it. `fs` loads the `fs` global
|
|
4
|
-
* and `crypto` the `crypto` global; the names below come from globals with different names. A module that would be
|
|
5
|
-
* empty isn't available.
|
|
6
|
-
*/
|
|
7
|
-
const aliases = {
|
|
8
|
-
"fs/promises": (global) => {
|
|
9
|
-
const fs = global("fs");
|
|
10
|
-
return fs instanceof Obj ? get(fs, "promises") : undefined;
|
|
11
|
-
},
|
|
12
|
-
url: (global) => pick(global, ["URL", "URLSearchParams"]),
|
|
13
|
-
util: (global) => pick(global, ["TextEncoder", "TextDecoder"]),
|
|
14
|
-
buffer: (global) => pick(global, ["Buffer", "atob", "btoa"]),
|
|
15
|
-
};
|
|
16
|
-
/** `node:fs` names the same module as `fs`. */
|
|
17
|
-
export const moduleName = (specifier) => (specifier.startsWith("node:") ? specifier.slice(5) : specifier);
|
|
18
|
-
export const resolveModule = (specifier, global) => {
|
|
19
|
-
const name = moduleName(specifier);
|
|
20
|
-
return global(name) ?? aliases[name]?.(global);
|
|
21
|
-
};
|
|
22
|
-
function pick(global, names) {
|
|
23
|
-
const found = names.flatMap((name) => {
|
|
24
|
-
const value = global(name);
|
|
25
|
-
return value === undefined ? [] : [[name, value]];
|
|
26
|
-
});
|
|
27
|
-
if (found.length === 0)
|
|
28
|
-
return undefined;
|
|
29
|
-
const module = new Obj(null);
|
|
30
|
-
for (const [name, value] of found)
|
|
31
|
-
define(module, name, value);
|
|
32
|
-
return module;
|
|
33
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Builtins } from "./intrinsics.js";
|
|
2
|
-
import { type Callable, Native, type NativeCall, type NativeOptions, Obj, type Value } from "./objects.js";
|
|
3
|
-
/** A native function body: a value, a thrown `PendingThrow`, or interpreter work producing a value. */
|
|
4
|
-
export type Impl = NativeCall;
|
|
5
|
-
export declare const native: (builtins: Builtins, options: NativeOptions) => Native;
|
|
6
|
-
export declare const fn: (builtins: Builtins, name: string, length: number, impl: Impl) => Native;
|
|
7
|
-
export type Method = readonly [name: string, length: number, impl: Impl];
|
|
8
|
-
export declare const methods: (builtins: Builtins, target: Obj, table: ReadonlyArray<Method>) => void;
|
|
9
|
-
export declare const constants: (target: Obj, table: Record<string, Value>) => void;
|
|
10
|
-
/** A constructor wired to its prototype: `C.prototype === proto` and `proto.constructor === C`. */
|
|
11
|
-
export declare const constructor: (builtins: Builtins, proto: Obj, options: NativeOptions) => Native;
|
|
12
|
-
/** The `call` of a constructor that JS requires to be invoked with `new`. */
|
|
13
|
-
export declare const requiresNew: (name: string) => () => never;
|
|
14
|
-
/** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
|
|
15
|
-
export declare const prototypeFrom: (newTarget: Callable, fallback: Obj) => Obj;
|
|
16
|
-
/** Narrows a method receiver to the built-in it belongs to, or throws the TypeError JS would. */
|
|
17
|
-
export declare const receiver: <T extends Obj>(cls: abstract new (...args: never) => T, thisValue: Value, method: string) => T;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { typeError } from "./model.js";
|
|
2
|
-
import { define, frozen, hidden, Native, Obj, } from "./objects.js";
|
|
3
|
-
import { describeValue } from "./references.js";
|
|
4
|
-
export const native = (builtins, options) => new Native(builtins.Function, options);
|
|
5
|
-
export const fn = (builtins, name, length, impl) => native(builtins, { name, length, call: impl });
|
|
6
|
-
export const methods = (builtins, target, table) => {
|
|
7
|
-
for (const [name, length, impl] of table)
|
|
8
|
-
define(target, name, fn(builtins, name, length, impl), hidden);
|
|
9
|
-
};
|
|
10
|
-
export const constants = (target, table) => {
|
|
11
|
-
for (const [name, value] of Object.entries(table))
|
|
12
|
-
define(target, name, value, frozen);
|
|
13
|
-
};
|
|
14
|
-
/** A constructor wired to its prototype: `C.prototype === proto` and `proto.constructor === C`. */
|
|
15
|
-
export const constructor = (builtins, proto, options) => {
|
|
16
|
-
const ctor = native(builtins, options);
|
|
17
|
-
define(ctor, "prototype", proto, frozen);
|
|
18
|
-
define(proto, "constructor", ctor, hidden);
|
|
19
|
-
return ctor;
|
|
20
|
-
};
|
|
21
|
-
/** The `call` of a constructor that JS requires to be invoked with `new`. */
|
|
22
|
-
export const requiresNew = (name) => () => {
|
|
23
|
-
throw typeError(`Constructor ${name} requires 'new'.`);
|
|
24
|
-
};
|
|
25
|
-
/** The instance prototype for `new` via `newTarget.prototype`, falling back to the built-in's own. */
|
|
26
|
-
export const prototypeFrom = (newTarget, fallback) => {
|
|
27
|
-
const proto = newTarget.props.get("prototype");
|
|
28
|
-
return proto !== undefined && "value" in proto && proto.value instanceof Obj ? proto.value : fallback;
|
|
29
|
-
};
|
|
30
|
-
/** Narrows a method receiver to the built-in it belongs to, or throws the TypeError JS would. */
|
|
31
|
-
export const receiver = (cls, thisValue, method) => {
|
|
32
|
-
if (thisValue instanceof cls)
|
|
33
|
-
return thisValue;
|
|
34
|
-
throw typeError(`${method} called on incompatible receiver ${describeValue(thisValue)}.`);
|
|
35
|
-
};
|