@opencode/codemode 0.0.0-beta-19419 → 0.0.0-beta-19425
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.
|
@@ -10,6 +10,8 @@ export declare class Runtime<R> {
|
|
|
10
10
|
readonly promises: PromiseRuntime<R>;
|
|
11
11
|
readonly logs: Array<string>;
|
|
12
12
|
readonly runner: Runner<R>;
|
|
13
|
+
/** Built-in globals by name, unaffected by program shadowing. */
|
|
14
|
+
readonly builtins: ReadonlyMap<string, unknown>;
|
|
13
15
|
private readonly root;
|
|
14
16
|
constructor(executeTool: (path: ReadonlyArray<string>, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>, search: (args: Array<unknown>) => Effect.Effect<unknown, unknown, R>, toolKeys: (path: ReadonlyArray<string>) => ReadonlyArray<string>, promises: PromiseRuntime<R>, logs?: Array<string>);
|
|
15
17
|
run(program: Program): Effect.Effect<unknown, unknown, R>;
|
|
@@ -16,7 +16,7 @@ import { numberMethods } from "../stdlib/number.js";
|
|
|
16
16
|
import { constructRegExp, regexpMethods, regexpProperties } from "../stdlib/regexp.js";
|
|
17
17
|
import { stringMethods } from "../stdlib/string.js";
|
|
18
18
|
import { uriArgument, urlMethods, urlProperties, urlSearchParamsMethods, urlWritableProperties } from "../stdlib/url.js";
|
|
19
|
-
import { coerceToNumber, coerceToString, compoundOperators } from "../stdlib/value.js";
|
|
19
|
+
import { coerceToNumber, coerceToString, compoundOperators, errorBrandName } from "../stdlib/value.js";
|
|
20
20
|
import { Values } from "../values.js";
|
|
21
21
|
const MAX_ARRAY_LENGTH = 4_294_967_295;
|
|
22
22
|
const parseArrayIndex = (key) => {
|
|
@@ -42,6 +42,34 @@ const calleeDescription = (callee) => {
|
|
|
42
42
|
}
|
|
43
43
|
return "The called value";
|
|
44
44
|
};
|
|
45
|
+
const hasOwn = (value, key) => value !== null && typeof value === "object" && Object.hasOwn(value, key);
|
|
46
|
+
const constructorName = (value) => {
|
|
47
|
+
if (typeof value === "string")
|
|
48
|
+
return "String";
|
|
49
|
+
if (typeof value === "number")
|
|
50
|
+
return "Number";
|
|
51
|
+
if (typeof value === "boolean")
|
|
52
|
+
return "Boolean";
|
|
53
|
+
if (Array.isArray(value))
|
|
54
|
+
return "Array";
|
|
55
|
+
if (value instanceof Values.Date)
|
|
56
|
+
return "Date";
|
|
57
|
+
if (value instanceof Values.RegExp)
|
|
58
|
+
return "RegExp";
|
|
59
|
+
if (value instanceof Values.Map)
|
|
60
|
+
return "Map";
|
|
61
|
+
if (value instanceof Values.Set)
|
|
62
|
+
return "Set";
|
|
63
|
+
if (value instanceof Values.URL)
|
|
64
|
+
return "URL";
|
|
65
|
+
if (value instanceof Values.URLSearchParams)
|
|
66
|
+
return "URLSearchParams";
|
|
67
|
+
if (value instanceof Values.Promise)
|
|
68
|
+
return "Promise";
|
|
69
|
+
if (value === null || typeof value !== "object" || isRuntimeReference(value))
|
|
70
|
+
return undefined;
|
|
71
|
+
return errorBrandName(value) ?? "Object";
|
|
72
|
+
};
|
|
45
73
|
const instanceofValue = (lhs, rhs, node) => {
|
|
46
74
|
if (rhs instanceof HostFunction && rhs.instanceOf !== undefined)
|
|
47
75
|
return rhs.instanceOf(lhs);
|
|
@@ -105,6 +133,8 @@ export class Runtime {
|
|
|
105
133
|
promises;
|
|
106
134
|
logs;
|
|
107
135
|
runner;
|
|
136
|
+
/** Built-in globals by name, unaffected by program shadowing. */
|
|
137
|
+
builtins;
|
|
108
138
|
root;
|
|
109
139
|
constructor(executeTool, search, toolKeys, promises, logs = []) {
|
|
110
140
|
this.executeTool = executeTool;
|
|
@@ -121,7 +151,8 @@ export class Runtime {
|
|
|
121
151
|
settlePromise: (promise) => this.root.settlePromise(promise),
|
|
122
152
|
syncIterator: (value, node) => this.root.syncIterator(value, node),
|
|
123
153
|
};
|
|
124
|
-
|
|
154
|
+
this.builtins = new Map(globals(this));
|
|
155
|
+
for (const [name, value] of this.builtins)
|
|
125
156
|
globalScope.set(name, { mutable: false, value });
|
|
126
157
|
}
|
|
127
158
|
run(program) {
|
|
@@ -1686,6 +1717,12 @@ class Frame {
|
|
|
1686
1717
|
// Unknown static members read as undefined so feature detection works like native JS.
|
|
1687
1718
|
return new ComputedValue(objectValue.member(key, propertyNode));
|
|
1688
1719
|
}
|
|
1720
|
+
// Values have no prototype chain, so `.constructor` resolves to the owning built-in directly.
|
|
1721
|
+
if (operation === "read" && key === "constructor" && !hasOwn(objectValue, key)) {
|
|
1722
|
+
const name = constructorName(objectValue);
|
|
1723
|
+
if (name !== undefined)
|
|
1724
|
+
return new ComputedValue(self.runtime.builtins.get(name));
|
|
1725
|
+
}
|
|
1689
1726
|
if (typeof objectValue === "string") {
|
|
1690
1727
|
if (key === "length")
|
|
1691
1728
|
return new ComputedValue(objectValue.length);
|
|
@@ -1836,7 +1873,7 @@ class Frame {
|
|
|
1836
1873
|
modifyMember(node, compute) {
|
|
1837
1874
|
const self = this;
|
|
1838
1875
|
return Effect.gen(function* () {
|
|
1839
|
-
const reference = yield* self.getMemberReference(node);
|
|
1876
|
+
const reference = yield* self.getMemberReference(node, "write");
|
|
1840
1877
|
if (reference === OptionalShortCircuit ||
|
|
1841
1878
|
reference instanceof ComputedValue ||
|
|
1842
1879
|
reference === undefined ||
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/codemode",
|
|
4
|
-
"version": "0.0.0-beta-
|
|
4
|
+
"version": "0.0.0-beta-19425",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|