@opencode/codemode 0.0.0-dev-1180 → 0.0.0-dev-1189
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
package/dist/stdlib/bytes.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { checkArrayLength, checkStringLength } from "../interpreter/limits.js";
|
|
2
|
-
import { constructor, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
3
|
-
import { IteratorSymbol, rangeError, syntaxError, typeError } from "../interpreter/model.js";
|
|
4
|
-
import { define, defineAccessor, get, hidden, Arr, Bytes, hostIterator, Obj, coerceToInteger, coerceToNumber, coerceToString, } from "../interpreter/objects.js";
|
|
5
|
-
import { describeValue } from "../interpreter/references.js";
|
|
6
|
-
import { applyCollectionCallback } from "../interpreter/callback.js";
|
|
7
|
-
import { callbackMethods, sortArray } from "./array.js";
|
|
8
|
-
/**
|
|
9
|
-
* The bytes a Uint8Array, array, or other iterable of numbers describes; the host array clamps each value. As in
|
|
10
|
-
* TypedArray.from, a mapper sees the original values, after the source is consumed in full.
|
|
11
|
-
*/
|
|
12
|
-
function* collectBytes(ctx, source, name, mapper, thisArg) {
|
|
13
|
-
const apply = mapper === undefined ? undefined : applyCollectionCallback(ctx, mapper, name);
|
|
14
|
-
if (source instanceof Bytes && apply === undefined)
|
|
15
|
-
return new Uint8Array(source.bytes);
|
|
16
|
-
const cursor = yield* ctx.iterate(source);
|
|
17
|
-
if (cursor === undefined) {
|
|
18
|
-
throw typeError(`${name} expects a Uint8Array, an array, or an iterable of numbers, received ${describeValue(source)}.`);
|
|
19
|
-
}
|
|
20
|
-
const values = [];
|
|
21
|
-
while (true) {
|
|
22
|
-
const step = yield* cursor.next();
|
|
23
|
-
if (step.done)
|
|
24
|
-
break;
|
|
25
|
-
values.push(step.value);
|
|
26
|
-
checkArrayLength(values.length);
|
|
27
|
-
}
|
|
28
|
-
if (apply === undefined)
|
|
29
|
-
return Uint8Array.from(values, coerceToNumber);
|
|
30
|
-
const mapped = [];
|
|
31
|
-
for (const [index, value] of values.entries())
|
|
32
|
-
mapped.push(yield* apply([value, index], thisArg));
|
|
33
|
-
return Uint8Array.from(mapped, coerceToNumber);
|
|
34
|
-
}
|
|
35
|
-
function* constructBytes(ctx, args, proto) {
|
|
36
|
-
const source = args[0];
|
|
37
|
-
if (source !== null && typeof source === "object") {
|
|
38
|
-
return new Bytes(proto, yield* collectBytes(ctx, source, "new Uint8Array(...)"));
|
|
39
|
-
}
|
|
40
|
-
const length = source === undefined ? 0 : coerceToNumber(source);
|
|
41
|
-
if (!Number.isInteger(length) || length < 0)
|
|
42
|
-
throw rangeError(`Invalid typed array length: ${coerceToString(source)}`);
|
|
43
|
-
checkArrayLength(length);
|
|
44
|
-
return new Bytes(proto, new Uint8Array(length));
|
|
45
|
-
}
|
|
46
|
-
export const uint8ArrayGlobal = (ctx) => {
|
|
47
|
-
const builtins = ctx.builtins;
|
|
48
|
-
const proto = builtins.Uint8Array;
|
|
49
|
-
const wrap = (bytes) => new Bytes(proto, bytes);
|
|
50
|
-
const uint8Array = constructor(builtins, proto, {
|
|
51
|
-
name: "Uint8Array",
|
|
52
|
-
length: 3,
|
|
53
|
-
call: requiresNew("Uint8Array"),
|
|
54
|
-
construct: (args, newTarget) => constructBytes(ctx, args, prototypeFrom(newTarget, proto)),
|
|
55
|
-
});
|
|
56
|
-
const decode = (name, args, from) => {
|
|
57
|
-
if (typeof args[0] !== "string")
|
|
58
|
-
throw typeError(`Uint8Array.${name} expects a string.`);
|
|
59
|
-
try {
|
|
60
|
-
return wrap(from(args[0]));
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
throw syntaxError(`Uint8Array.${name}: the string is not valid ${name === "fromHex" ? "hex" : "base64"}.`);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
methods(builtins, uint8Array, [
|
|
67
|
-
[
|
|
68
|
-
"from",
|
|
69
|
-
1,
|
|
70
|
-
function* (_, args) {
|
|
71
|
-
return wrap(yield* collectBytes(ctx, args[0], "Uint8Array.from", args[1], args[2]));
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
["of", 0, (_, args) => wrap(Uint8Array.from(args, coerceToNumber))],
|
|
75
|
-
["fromBase64", 1, (_, args) => decode("fromBase64", args, (text) => Uint8Array.fromBase64(text))],
|
|
76
|
-
["fromHex", 1, (_, args) => decode("fromHex", args, (text) => Uint8Array.fromHex(text))],
|
|
77
|
-
]);
|
|
78
|
-
const self = (thisValue, name) => receiver(Bytes, thisValue, `Uint8Array.prototype.${name}`);
|
|
79
|
-
const optNumber = (value) => (value === undefined ? undefined : coerceToInteger(value));
|
|
80
|
-
// Uint8Array cannot contain NaN, so non-number search values never match a byte.
|
|
81
|
-
const search = (value) => (typeof value === "number" ? value : NaN);
|
|
82
|
-
const wrapAll = (items) => new Arr(builtins.Array, items);
|
|
83
|
-
defineAccessor(proto, "length", (thisValue) => self(thisValue, "length").bytes.length);
|
|
84
|
-
methods(builtins, proto, [
|
|
85
|
-
["at", 1, (thisValue, args) => self(thisValue, "at").bytes.at(optNumber(args[0]) ?? 0)],
|
|
86
|
-
[
|
|
87
|
-
"slice",
|
|
88
|
-
2,
|
|
89
|
-
(thisValue, args) => wrap(self(thisValue, "slice").bytes.slice(optNumber(args[0]), optNumber(args[1]))),
|
|
90
|
-
],
|
|
91
|
-
// A view on the same bytes, as in JS: writes through one are visible through the other.
|
|
92
|
-
[
|
|
93
|
-
"subarray",
|
|
94
|
-
2,
|
|
95
|
-
(thisValue, args) => wrap(self(thisValue, "subarray").bytes.subarray(optNumber(args[0]), optNumber(args[1]))),
|
|
96
|
-
],
|
|
97
|
-
[
|
|
98
|
-
"set",
|
|
99
|
-
1,
|
|
100
|
-
function* (thisValue, args) {
|
|
101
|
-
const target = self(thisValue, "set");
|
|
102
|
-
const offset = optNumber(args[1]) ?? 0;
|
|
103
|
-
const source = yield* collectBytes(ctx, args[0], "Uint8Array.set");
|
|
104
|
-
if (!Number.isInteger(offset) || offset < 0 || source.length + offset > target.bytes.length) {
|
|
105
|
-
throw rangeError("Uint8Array.set: the source does not fit at that offset.");
|
|
106
|
-
}
|
|
107
|
-
target.bytes.set(source, offset);
|
|
108
|
-
return undefined;
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
[
|
|
112
|
-
"fill",
|
|
113
|
-
1,
|
|
114
|
-
(thisValue, args) => {
|
|
115
|
-
const target = self(thisValue, "fill");
|
|
116
|
-
target.bytes.fill(coerceToNumber(args[0]), optNumber(args[1]), optNumber(args[2]));
|
|
117
|
-
return target;
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
[
|
|
121
|
-
"reverse",
|
|
122
|
-
0,
|
|
123
|
-
(thisValue) => {
|
|
124
|
-
const target = self(thisValue, "reverse");
|
|
125
|
-
target.bytes.reverse();
|
|
126
|
-
return target;
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
[
|
|
130
|
-
"sort",
|
|
131
|
-
1,
|
|
132
|
-
function* (thisValue, args) {
|
|
133
|
-
const target = self(thisValue, "sort");
|
|
134
|
-
// Without a comparator, typed arrays sort numerically rather than by string.
|
|
135
|
-
if (args[0] === undefined) {
|
|
136
|
-
target.bytes.sort();
|
|
137
|
-
return target;
|
|
138
|
-
}
|
|
139
|
-
const sorted = yield* sortArray(ctx, [...target.bytes], args[0], "Uint8Array.sort");
|
|
140
|
-
target.bytes.set(Uint8Array.from(sorted, coerceToNumber));
|
|
141
|
-
return target;
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
["indexOf", 1, (thisValue, args) => self(thisValue, "indexOf").bytes.indexOf(search(args[0]), optNumber(args[1]))],
|
|
145
|
-
[
|
|
146
|
-
"lastIndexOf",
|
|
147
|
-
1,
|
|
148
|
-
(thisValue, args) => {
|
|
149
|
-
const target = self(thisValue, "lastIndexOf").bytes;
|
|
150
|
-
return args.length < 2
|
|
151
|
-
? target.lastIndexOf(search(args[0]))
|
|
152
|
-
: target.lastIndexOf(search(args[0]), optNumber(args[1]));
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
[
|
|
156
|
-
"includes",
|
|
157
|
-
1,
|
|
158
|
-
(thisValue, args) => self(thisValue, "includes").bytes.includes(search(args[0]), optNumber(args[1])),
|
|
159
|
-
],
|
|
160
|
-
[
|
|
161
|
-
"join",
|
|
162
|
-
1,
|
|
163
|
-
(thisValue, args) => {
|
|
164
|
-
const joined = self(thisValue, "join").bytes.join(args[0] === undefined ? "," : coerceToString(args[0]));
|
|
165
|
-
checkStringLength(joined.length);
|
|
166
|
-
return joined;
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
["toString", 0, (thisValue) => self(thisValue, "toString").bytes.join(",")],
|
|
170
|
-
["toBase64", 0, (thisValue) => self(thisValue, "toBase64").bytes.toBase64()],
|
|
171
|
-
["toHex", 0, (thisValue) => self(thisValue, "toHex").bytes.toHex()],
|
|
172
|
-
["keys", 0, (thisValue) => hostIterator(builtins, self(thisValue, "keys").bytes.keys())],
|
|
173
|
-
["values", 0, (thisValue) => hostIterator(builtins, self(thisValue, "values").bytes.values())],
|
|
174
|
-
[
|
|
175
|
-
"entries",
|
|
176
|
-
0,
|
|
177
|
-
(thisValue) => hostIterator(builtins, self(thisValue, "entries")
|
|
178
|
-
.bytes.entries()
|
|
179
|
-
.map(([index, byte]) => wrapAll([index, byte]))),
|
|
180
|
-
],
|
|
181
|
-
...callbackMethods(ctx, "Uint8Array", self, (target) => target.bytes, (values) => wrap(Uint8Array.from(values, coerceToNumber))),
|
|
182
|
-
]);
|
|
183
|
-
define(proto, IteratorSymbol, get(proto, "values"), hidden);
|
|
184
|
-
return uint8Array;
|
|
185
|
-
};
|
|
186
|
-
export const textEncoderGlobal = (ctx) => {
|
|
187
|
-
const builtins = ctx.builtins;
|
|
188
|
-
const proto = builtins.TextEncoder;
|
|
189
|
-
const encoder = new TextEncoder();
|
|
190
|
-
defineAccessor(proto, "encoding", () => "utf-8");
|
|
191
|
-
methods(builtins, proto, [
|
|
192
|
-
[
|
|
193
|
-
"encode",
|
|
194
|
-
0,
|
|
195
|
-
(_, args) => new Bytes(builtins.Uint8Array, encoder.encode(coerceToString(args[0] === undefined ? "" : args[0]))),
|
|
196
|
-
],
|
|
197
|
-
]);
|
|
198
|
-
return constructor(builtins, proto, {
|
|
199
|
-
name: "TextEncoder",
|
|
200
|
-
call: requiresNew("TextEncoder"),
|
|
201
|
-
construct: (_, newTarget) => new Obj(prototypeFrom(newTarget, proto)),
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
/** A `TextDecoder` holding the host decoder its label and options configured. */
|
|
205
|
-
export class TextDecoderObj extends Obj {
|
|
206
|
-
decoder;
|
|
207
|
-
constructor(proto, decoder) {
|
|
208
|
-
super(proto);
|
|
209
|
-
this.decoder = decoder;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// The WHATWG labels for UTF-8, the only encoding CodeMode decodes.
|
|
213
|
-
const utf8Labels = new Set(["unicode-1-1-utf-8", "unicode11utf8", "unicode20utf8", "utf-8", "utf8", "x-unicode20utf8"]);
|
|
214
|
-
export const textDecoderGlobal = (ctx) => {
|
|
215
|
-
const builtins = ctx.builtins;
|
|
216
|
-
const proto = builtins.TextDecoder;
|
|
217
|
-
const self = (thisValue, name) => receiver(TextDecoderObj, thisValue, `TextDecoder.prototype.${name}`);
|
|
218
|
-
defineAccessor(proto, "encoding", (thisValue) => self(thisValue, "encoding").decoder.encoding);
|
|
219
|
-
defineAccessor(proto, "fatal", (thisValue) => self(thisValue, "fatal").decoder.fatal);
|
|
220
|
-
defineAccessor(proto, "ignoreBOM", (thisValue) => self(thisValue, "ignoreBOM").decoder.ignoreBOM);
|
|
221
|
-
methods(builtins, proto, [
|
|
222
|
-
[
|
|
223
|
-
"decode",
|
|
224
|
-
0,
|
|
225
|
-
(thisValue, args) => {
|
|
226
|
-
const decoder = self(thisValue, "decode").decoder;
|
|
227
|
-
if (args[0] === undefined)
|
|
228
|
-
return "";
|
|
229
|
-
if (!(args[0] instanceof Bytes)) {
|
|
230
|
-
throw typeError(`TextDecoder.decode expects a Uint8Array, received ${describeValue(args[0])}.`);
|
|
231
|
-
}
|
|
232
|
-
try {
|
|
233
|
-
return decoder.decode(args[0].bytes);
|
|
234
|
-
}
|
|
235
|
-
catch {
|
|
236
|
-
throw typeError(`TextDecoder.decode: the input is not valid ${decoder.encoding}.`);
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
],
|
|
240
|
-
]);
|
|
241
|
-
return constructor(builtins, proto, {
|
|
242
|
-
name: "TextDecoder",
|
|
243
|
-
call: requiresNew("TextDecoder"),
|
|
244
|
-
construct: (args, newTarget) => {
|
|
245
|
-
const label = args[0] === undefined ? "utf-8" : coerceToString(args[0]).trim().toLowerCase();
|
|
246
|
-
if (!utf8Labels.has(label))
|
|
247
|
-
throw rangeError(`The "${label}" encoding is not supported; only UTF-8 is.`);
|
|
248
|
-
const options = args[1] instanceof Obj ? args[1] : undefined;
|
|
249
|
-
const flag = (name) => options !== undefined && Boolean(get(options, name));
|
|
250
|
-
return new TextDecoderObj(prototypeFrom(newTarget, proto), new TextDecoder("utf-8", { fatal: flag("fatal"), ignoreBOM: flag("ignoreBOM") }));
|
|
251
|
-
},
|
|
252
|
-
});
|
|
253
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
2
|
-
/** `Map.groupBy` and `Object.groupBy`: the same iteration, keyed into a Map or a data object. */
|
|
3
|
-
export declare const groupBy: <R>(ctx: Interpreter<R>, namespace: "Map" | "Object") => import("../interpreter/objects.js").Native;
|
|
4
|
-
export declare const mapGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
|
|
5
|
-
export declare const setGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
|
|
6
|
-
export declare const weakMapGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
|
|
7
|
-
export declare const weakSetGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
|