@opencode/codemode 0.0.0-dev-19878 → 0.0.0-dev-19882
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/interpreter/extensions.js +2 -1
- package/dist/interpreter/globals.js +2 -0
- package/dist/interpreter/interpreter.js +31 -24
- package/dist/interpreter/objects.d.ts +5 -0
- package/dist/interpreter/objects.js +8 -0
- package/dist/interpreter/references.js +4 -1
- package/dist/stdlib/array.js +8 -5
- package/dist/stdlib/bytes.js +8 -5
- package/dist/stdlib/collections.js +16 -8
- package/dist/stdlib/headers.js +15 -5
- package/dist/stdlib/iterator.d.ts +2 -0
- package/dist/stdlib/iterator.js +17 -0
- package/dist/stdlib/string.js +4 -3
- package/dist/stdlib/url.js +8 -5
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { createErrorValue, isErrorType } from "./intrinsics.js";
|
|
|
5
5
|
import { MAX_VALUE_DEPTH } from "./limits.js";
|
|
6
6
|
import { PendingThrow, Throw, typeError } from "./model.js";
|
|
7
7
|
import { fn } from "./native.js";
|
|
8
|
-
import { Callable, define, entries, get, has, hidden, keys, Arr, Bytes, DateObj, ErrorObj, GeneratorObj, MapObj, Obj, PromiseObj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, HeadersObj, } from "./objects.js";
|
|
8
|
+
import { Callable, define, entries, get, has, hidden, keys, Arr, Bytes, DateObj, ErrorObj, GeneratorObj, IteratorObj, MapObj, Obj, PromiseObj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, HeadersObj, } from "./objects.js";
|
|
9
9
|
import { describeValue } from "./references.js";
|
|
10
10
|
/**
|
|
11
11
|
* The global bindings of one run's extensions. Everything crossing the boundary is converted: plain data and
|
|
@@ -42,6 +42,7 @@ export const extensionGlobals = (ctx, extensions) => {
|
|
|
42
42
|
if (!(value instanceof Obj) ||
|
|
43
43
|
value instanceof Callable ||
|
|
44
44
|
value instanceof GeneratorObj ||
|
|
45
|
+
value instanceof IteratorObj ||
|
|
45
46
|
value instanceof PromiseObj) {
|
|
46
47
|
throw typeError(`${label} contains ${describeValue(value)}, which cannot be passed to an extension.`);
|
|
47
48
|
}
|
|
@@ -12,6 +12,7 @@ import { regexpGlobal } from "../stdlib/regexp.js";
|
|
|
12
12
|
import { stringGlobal } from "../stdlib/string.js";
|
|
13
13
|
import { uriGlobal, urlGlobal, urlSearchParamsGlobal } from "../stdlib/url.js";
|
|
14
14
|
import { headersGlobal } from "../stdlib/headers.js";
|
|
15
|
+
import { iteratorGlobals } from "../stdlib/iterator.js";
|
|
15
16
|
import { coercion } from "../stdlib/value.js";
|
|
16
17
|
import { base64Global, cryptoGlobal } from "../stdlib/web.js";
|
|
17
18
|
import { ToolReference } from "../tool-runtime.js";
|
|
@@ -90,5 +91,6 @@ export const globalNames = new Set(Object.keys(table));
|
|
|
90
91
|
/** The immutable global bindings of every program, in declaration order. */
|
|
91
92
|
export const globals = (ctx) => {
|
|
92
93
|
generatorGlobals(ctx);
|
|
94
|
+
iteratorGlobals(ctx);
|
|
93
95
|
return Object.entries(table).map(([name, factory]) => [name, factory(ctx)]);
|
|
94
96
|
};
|
|
@@ -5,7 +5,7 @@ import { AsyncIteratorSymbol, CallSite, GeneratorReturn, IteratorSymbol, Optiona
|
|
|
5
5
|
import { checkStringLength } from "./limits.js";
|
|
6
6
|
import { locate, materialize } from "./errors.js";
|
|
7
7
|
import { globals } from "./globals.js";
|
|
8
|
-
import { assign, Callable, define, get, has, hasPrototype, keys, Native, parseArrayIndex, Arr, Bytes, DateObj, Fn, GeneratorObj, MapObj, Obj, PromiseObj, SetObj, URLSearchParamsObj, HeadersObj, record, remove, set, } from "./objects.js";
|
|
8
|
+
import { assign, Callable, define, get, has, hasPrototype, keys, Native, parseArrayIndex, Arr, Bytes, DateObj, Fn, GeneratorObj, IteratorObj, MapObj, Obj, PromiseObj, SetObj, URLSearchParamsObj, HeadersObj, record, remove, set, } from "./objects.js";
|
|
9
9
|
import { preserveConsumerError } from "./callback.js";
|
|
10
10
|
import { Pending, resolvePromise, resolvePromiseValue } from "./promises.js";
|
|
11
11
|
import { containsOpaqueReference, describeValue, rejectCircularInsertion, typeofValue } from "./references.js";
|
|
@@ -477,8 +477,8 @@ class Frame {
|
|
|
477
477
|
if (declared?.lexical)
|
|
478
478
|
self.predeclarePattern(declared.pattern, declared.mutable, left);
|
|
479
479
|
const right = yield* self.evaluateExpression(node.right);
|
|
480
|
-
const
|
|
481
|
-
const
|
|
480
|
+
const cursor = self.hostCursor(right);
|
|
481
|
+
const iterator = cursor === undefined ? yield* self.customIterator(right, node, awaiting) : undefined;
|
|
482
482
|
if (iterator === undefined && cursor === undefined) {
|
|
483
483
|
throw invalidData(`${awaiting ? "for await...of" : "for...of"} requires an array, string, Map, Set, URLSearchParams, or Headers, or custom iterator value.`, node);
|
|
484
484
|
}
|
|
@@ -550,6 +550,18 @@ class Frame {
|
|
|
550
550
|
});
|
|
551
551
|
}
|
|
552
552
|
iterate(value, node) {
|
|
553
|
+
const cursor = this.hostCursor(value);
|
|
554
|
+
if (cursor !== undefined)
|
|
555
|
+
return Effect.succeed(cursor);
|
|
556
|
+
const self = this;
|
|
557
|
+
return Effect.map(this.customIterator(value, node, false), (iterator) => iterator === undefined
|
|
558
|
+
? undefined
|
|
559
|
+
: {
|
|
560
|
+
next: self.nextIteratorResult(iterator, node, false),
|
|
561
|
+
close: Effect.suspend(() => self.closeIterator(iterator, node, false)),
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
hostCursor(value) {
|
|
553
565
|
const iterator = value instanceof Arr
|
|
554
566
|
? value.items[Symbol.iterator]()
|
|
555
567
|
: typeof value === "string"
|
|
@@ -564,27 +576,22 @@ class Frame {
|
|
|
564
576
|
? value.headers.entries()
|
|
565
577
|
: value instanceof Bytes
|
|
566
578
|
? value.bytes.values()
|
|
567
|
-
:
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
? undefined
|
|
584
|
-
: {
|
|
585
|
-
next: self.nextIteratorResult(iterator, node, false),
|
|
586
|
-
close: Effect.suspend(() => self.closeIterator(iterator, node, false)),
|
|
587
|
-
});
|
|
579
|
+
: value instanceof IteratorObj
|
|
580
|
+
? value.iterator
|
|
581
|
+
: undefined;
|
|
582
|
+
if (iterator === undefined)
|
|
583
|
+
return undefined;
|
|
584
|
+
const proto = this.ctx.builtins.Array;
|
|
585
|
+
return {
|
|
586
|
+
next: Effect.sync(() => {
|
|
587
|
+
const step = iterator.next();
|
|
588
|
+
return {
|
|
589
|
+
done: Boolean(step.done),
|
|
590
|
+
value: Array.isArray(step.value) ? new Arr(proto, step.value) : step.value,
|
|
591
|
+
};
|
|
592
|
+
}),
|
|
593
|
+
close: Effect.void,
|
|
594
|
+
};
|
|
588
595
|
}
|
|
589
596
|
customIterator(value, node, allowAsync = true) {
|
|
590
597
|
if (!(value instanceof Obj))
|
|
@@ -81,6 +81,11 @@ export declare class GeneratorObj extends Obj {
|
|
|
81
81
|
readonly request: (kind: GeneratorRequestKind, value: unknown) => Effect.Effect<unknown, unknown, unknown>;
|
|
82
82
|
constructor(proto: Obj, asynchronous: boolean, request: (kind: GeneratorRequestKind, value: unknown) => Effect.Effect<unknown, unknown, unknown>);
|
|
83
83
|
}
|
|
84
|
+
/** A built-in collection iterator: live over the host collection, yielding program values. */
|
|
85
|
+
export declare class IteratorObj extends Obj {
|
|
86
|
+
readonly iterator: IteratorObject<unknown>;
|
|
87
|
+
constructor(proto: Obj, iterator: IteratorObject<unknown>);
|
|
88
|
+
}
|
|
84
89
|
export declare class DateObj extends Obj {
|
|
85
90
|
time: number;
|
|
86
91
|
constructor(proto: Obj, time: number);
|
|
@@ -78,6 +78,14 @@ export class GeneratorObj extends Obj {
|
|
|
78
78
|
this.request = request;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
/** A built-in collection iterator: live over the host collection, yielding program values. */
|
|
82
|
+
export class IteratorObj extends Obj {
|
|
83
|
+
iterator;
|
|
84
|
+
constructor(proto, iterator) {
|
|
85
|
+
super(proto);
|
|
86
|
+
this.iterator = iterator;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
81
89
|
export class DateObj extends Obj {
|
|
82
90
|
time;
|
|
83
91
|
constructor(proto, time) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ToolReference } from "../tool-runtime.js";
|
|
2
2
|
import { invalidData } from "./model.js";
|
|
3
|
-
import { Callable, getOwn, isWrapper, ownKeys, Arr, Bytes, DateObj, GeneratorObj, MapObj, Obj, PromiseObj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, HeadersObj, } from "./objects.js";
|
|
3
|
+
import { Callable, getOwn, isWrapper, ownKeys, Arr, Bytes, DateObj, GeneratorObj, IteratorObj, MapObj, Obj, PromiseObj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, HeadersObj, } from "./objects.js";
|
|
4
4
|
/** Values that cannot cross the data boundary. */
|
|
5
5
|
export const isRuntimeReference = (value) => value instanceof Callable ||
|
|
6
6
|
value instanceof GeneratorObj ||
|
|
7
|
+
value instanceof IteratorObj ||
|
|
7
8
|
value instanceof ToolReference ||
|
|
8
9
|
value instanceof PromiseObj ||
|
|
9
10
|
isWrapper(value);
|
|
@@ -69,6 +70,8 @@ export const describeValue = (value) => {
|
|
|
69
70
|
return "a Uint8Array";
|
|
70
71
|
if (value instanceof GeneratorObj)
|
|
71
72
|
return "a generator";
|
|
73
|
+
if (value instanceof IteratorObj)
|
|
74
|
+
return "an iterator";
|
|
72
75
|
if (isRuntimeReference(value))
|
|
73
76
|
return "a function";
|
|
74
77
|
if (typeof value === "object")
|
package/dist/stdlib/array.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, methods, prototypeFrom, receiver } from "../interpreter/native.js";
|
|
3
3
|
import { checkArrayLength, checkStringLength, MAX_ARRAY_LENGTH } from "../interpreter/limits.js";
|
|
4
|
-
import { invalidData, rangeError, typeError } from "../interpreter/model.js";
|
|
5
|
-
import { get, Arr, GeneratorObj, Obj } from "../interpreter/objects.js";
|
|
4
|
+
import { invalidData, IteratorSymbol, rangeError, typeError } from "../interpreter/model.js";
|
|
5
|
+
import { define, get, hidden, Arr, GeneratorObj, IteratorObj, Obj } from "../interpreter/objects.js";
|
|
6
6
|
import { describeValue, rejectCircularInsertion } from "../interpreter/references.js";
|
|
7
7
|
import { applyCollectionCallback, preserveConsumerError } from "../interpreter/callback.js";
|
|
8
8
|
import { compareText } from "../tool-runtime.js";
|
|
@@ -317,12 +317,14 @@ export const arrayGlobal = (ctx) => {
|
|
|
317
317
|
return target;
|
|
318
318
|
},
|
|
319
319
|
],
|
|
320
|
-
["keys", 0, (thisValue) =>
|
|
321
|
-
["values", 0, (thisValue) =>
|
|
320
|
+
["keys", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "keys").items.keys())],
|
|
321
|
+
["values", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "values").items.values())],
|
|
322
322
|
[
|
|
323
323
|
"entries",
|
|
324
324
|
0,
|
|
325
|
-
(thisValue) =>
|
|
325
|
+
(thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries")
|
|
326
|
+
.items.entries()
|
|
327
|
+
.map(([index, item]) => wrap([index, item]))),
|
|
326
328
|
],
|
|
327
329
|
iterate("map", 1, (target, receiver, apply) => Effect.gen(function* () {
|
|
328
330
|
const length = target.length;
|
|
@@ -461,5 +463,6 @@ export const arrayGlobal = (ctx) => {
|
|
|
461
463
|
return accumulator;
|
|
462
464
|
})),
|
|
463
465
|
]);
|
|
466
|
+
define(proto, IteratorSymbol, get(proto, "values"), hidden);
|
|
464
467
|
return array;
|
|
465
468
|
};
|
package/dist/stdlib/bytes.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { checkArrayLength, checkStringLength } from "../interpreter/limits.js";
|
|
3
3
|
import { constructor, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
4
|
-
import { rangeError, syntaxError, typeError } from "../interpreter/model.js";
|
|
5
|
-
import { defineAccessor, get, Arr, Bytes, Obj } from "../interpreter/objects.js";
|
|
4
|
+
import { IteratorSymbol, rangeError, syntaxError, typeError } from "../interpreter/model.js";
|
|
5
|
+
import { define, defineAccessor, get, hidden, Arr, Bytes, IteratorObj, Obj } from "../interpreter/objects.js";
|
|
6
6
|
import { describeValue } from "../interpreter/references.js";
|
|
7
7
|
import { coerceToNumber, coerceToString } from "./value.js";
|
|
8
8
|
/** The bytes a Uint8Array, array, or other iterable of numbers describes; the host array clamps each value. */
|
|
@@ -152,14 +152,17 @@ export const uint8ArrayGlobal = (ctx) => {
|
|
|
152
152
|
["toString", 0, (thisValue) => self(thisValue, "toString").bytes.join(",")],
|
|
153
153
|
["toBase64", 0, (thisValue) => self(thisValue, "toBase64").bytes.toBase64()],
|
|
154
154
|
["toHex", 0, (thisValue) => self(thisValue, "toHex").bytes.toHex()],
|
|
155
|
-
["keys", 0, (thisValue) =>
|
|
156
|
-
["values", 0, (thisValue) =>
|
|
155
|
+
["keys", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "keys").bytes.keys())],
|
|
156
|
+
["values", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "values").bytes.values())],
|
|
157
157
|
[
|
|
158
158
|
"entries",
|
|
159
159
|
0,
|
|
160
|
-
(thisValue) =>
|
|
160
|
+
(thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries")
|
|
161
|
+
.bytes.entries()
|
|
162
|
+
.map(([index, byte]) => wrapAll([index, byte]))),
|
|
161
163
|
],
|
|
162
164
|
]);
|
|
165
|
+
define(proto, IteratorSymbol, get(proto, "values"), hidden);
|
|
163
166
|
return uint8Array;
|
|
164
167
|
};
|
|
165
168
|
export const textEncoderGlobal = (ctx) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, fn, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
3
|
-
import { invalidData, typeError } from "../interpreter/model.js";
|
|
4
|
-
import { define, defineAccessor, get, getOwn, hidden, isWrapper, Arr, MapObj, Obj, PromiseObj, SetObj, } from "../interpreter/objects.js";
|
|
3
|
+
import { invalidData, IteratorSymbol, typeError } from "../interpreter/model.js";
|
|
4
|
+
import { define, defineAccessor, get, getOwn, hidden, isWrapper, Arr, IteratorObj, MapObj, Obj, PromiseObj, SetObj, } from "../interpreter/objects.js";
|
|
5
5
|
import { describeValue, isRuntimeReference } from "../interpreter/references.js";
|
|
6
6
|
import { applyCollectionCallback, isSupportedCallback, preserveConsumerError, toPrimitiveNumber, toPrimitiveString, } from "../interpreter/callback.js";
|
|
7
7
|
const coerceGroupByPropertyKey = (ctx, value) => {
|
|
@@ -132,12 +132,14 @@ export const mapGlobal = (ctx) => {
|
|
|
132
132
|
return undefined;
|
|
133
133
|
},
|
|
134
134
|
],
|
|
135
|
-
["keys", 0, (thisValue) =>
|
|
136
|
-
["values", 0, (thisValue) =>
|
|
135
|
+
["keys", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "keys").map.keys())],
|
|
136
|
+
["values", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "values").map.values())],
|
|
137
137
|
[
|
|
138
138
|
"entries",
|
|
139
139
|
0,
|
|
140
|
-
(thisValue) =>
|
|
140
|
+
(thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries")
|
|
141
|
+
.map.entries()
|
|
142
|
+
.map(([key, item]) => wrap([key, item]))),
|
|
141
143
|
],
|
|
142
144
|
[
|
|
143
145
|
"forEach",
|
|
@@ -153,6 +155,7 @@ export const mapGlobal = (ctx) => {
|
|
|
153
155
|
},
|
|
154
156
|
],
|
|
155
157
|
]);
|
|
158
|
+
define(proto, IteratorSymbol, get(proto, "entries"), hidden);
|
|
156
159
|
return map;
|
|
157
160
|
};
|
|
158
161
|
const loadSetRecord = (ctx, source, name) => {
|
|
@@ -187,6 +190,8 @@ const loadSetRecord = (ctx, source, name) => {
|
|
|
187
190
|
size: Math.max(Math.trunc(size), 0),
|
|
188
191
|
has: (item) => Effect.map(ctx.call(has, source, [item]), Boolean),
|
|
189
192
|
keys: () => Effect.flatMap(ctx.call(keys, source, []), (result) => {
|
|
193
|
+
if (result instanceof IteratorObj)
|
|
194
|
+
return Effect.succeed(result.iterator);
|
|
190
195
|
if (result instanceof Arr)
|
|
191
196
|
return Effect.succeed(result.items);
|
|
192
197
|
throw typeError(`Set.${name} expected 'keys' to return an iterator.`);
|
|
@@ -313,12 +318,14 @@ export const setGlobal = (ctx) => {
|
|
|
313
318
|
return undefined;
|
|
314
319
|
},
|
|
315
320
|
],
|
|
316
|
-
["keys", 0, (thisValue) =>
|
|
317
|
-
["values", 0, (thisValue) =>
|
|
321
|
+
["keys", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "keys").set.values())],
|
|
322
|
+
["values", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "values").set.values())],
|
|
318
323
|
[
|
|
319
324
|
"entries",
|
|
320
325
|
0,
|
|
321
|
-
(thisValue) =>
|
|
326
|
+
(thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries")
|
|
327
|
+
.set.values()
|
|
328
|
+
.map((item) => wrap([item, item]))),
|
|
322
329
|
],
|
|
323
330
|
[
|
|
324
331
|
"forEach",
|
|
@@ -341,5 +348,6 @@ export const setGlobal = (ctx) => {
|
|
|
341
348
|
operation("isSupersetOf"),
|
|
342
349
|
operation("isDisjointFrom"),
|
|
343
350
|
]);
|
|
351
|
+
define(proto, IteratorSymbol, get(proto, "values"), hidden);
|
|
344
352
|
return set;
|
|
345
353
|
};
|
package/dist/stdlib/headers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
3
|
-
import { typeError } from "../interpreter/model.js";
|
|
4
|
-
import { entries, Arr, HeadersObj, Obj } from "../interpreter/objects.js";
|
|
3
|
+
import { IteratorSymbol, typeError } from "../interpreter/model.js";
|
|
4
|
+
import { define, entries, get, hidden, Arr, HeadersObj, IteratorObj, Obj } from "../interpreter/objects.js";
|
|
5
5
|
import { applyCollectionCallback } from "../interpreter/callback.js";
|
|
6
6
|
import { isRuntimeReference } from "../interpreter/references.js";
|
|
7
7
|
import { coerceToString } from "./value.js";
|
|
@@ -91,12 +91,21 @@ export const headersGlobal = (ctx) => {
|
|
|
91
91
|
return attempt(() => target.set(arg(args, 0), arg(args, 1)));
|
|
92
92
|
},
|
|
93
93
|
],
|
|
94
|
-
|
|
95
|
-
[
|
|
94
|
+
// Iterator.from because Bun's Headers typings predate iterator helpers; the runtime iterators already have them.
|
|
95
|
+
[
|
|
96
|
+
"keys",
|
|
97
|
+
0,
|
|
98
|
+
(thisValue) => new IteratorObj(builtins.Iterator, Iterator.from(self(thisValue, "keys").headers.keys())),
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
"values",
|
|
102
|
+
0,
|
|
103
|
+
(thisValue) => new IteratorObj(builtins.Iterator, Iterator.from(self(thisValue, "values").headers.values())),
|
|
104
|
+
],
|
|
96
105
|
[
|
|
97
106
|
"entries",
|
|
98
107
|
0,
|
|
99
|
-
(thisValue) =>
|
|
108
|
+
(thisValue) => new IteratorObj(builtins.Iterator, Iterator.from(self(thisValue, "entries").headers.entries()).map(([key, value]) => wrap([key, value]))),
|
|
100
109
|
],
|
|
101
110
|
[
|
|
102
111
|
"forEach",
|
|
@@ -113,5 +122,6 @@ export const headersGlobal = (ctx) => {
|
|
|
113
122
|
},
|
|
114
123
|
],
|
|
115
124
|
]);
|
|
125
|
+
define(proto, IteratorSymbol, get(proto, "entries"), hidden);
|
|
116
126
|
return headers;
|
|
117
127
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { methods, receiver } from "../interpreter/native.js";
|
|
2
|
+
import { IteratorObj, record } from "../interpreter/objects.js";
|
|
3
|
+
// Every built-in collection iterator shares the Iterator prototype; JS gives each collection its own, which is only
|
|
4
|
+
// observable through getPrototypeOf.
|
|
5
|
+
export const iteratorGlobals = (ctx) => {
|
|
6
|
+
const builtins = ctx.builtins;
|
|
7
|
+
methods(builtins, builtins.Iterator, [
|
|
8
|
+
[
|
|
9
|
+
"next",
|
|
10
|
+
0,
|
|
11
|
+
(thisValue) => {
|
|
12
|
+
const step = receiver(IteratorObj, thisValue, "Iterator.prototype.next").iterator.next();
|
|
13
|
+
return record(builtins.Object, { value: step.value, done: Boolean(step.done) });
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
]);
|
|
17
|
+
};
|
package/dist/stdlib/string.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { constructor, methods } from "../interpreter/native.js";
|
|
2
|
+
import { constructor, fn, methods } from "../interpreter/native.js";
|
|
3
3
|
import { checkArrayLength, checkStringLength } from "../interpreter/limits.js";
|
|
4
|
-
import { invalidData, rangeError, typeError } from "../interpreter/model.js";
|
|
5
|
-
import { Arr, PromiseObj, RegExpObj, record } from "../interpreter/objects.js";
|
|
4
|
+
import { invalidData, IteratorSymbol, rangeError, typeError } from "../interpreter/model.js";
|
|
5
|
+
import { define, hidden, Arr, IteratorObj, PromiseObj, RegExpObj, record } from "../interpreter/objects.js";
|
|
6
6
|
import { containsOpaqueReference, typeofValue } from "../interpreter/references.js";
|
|
7
7
|
import { applyCollectionCallback, isSupportedCallback } from "../interpreter/callback.js";
|
|
8
8
|
import { matchToValue, toHostRegex } from "./regexp.js";
|
|
@@ -232,5 +232,6 @@ export const stringGlobal = (ctx) => {
|
|
|
232
232
|
return joined;
|
|
233
233
|
}),
|
|
234
234
|
]);
|
|
235
|
+
define(builtins.String, IteratorSymbol, fn(builtins, "[Symbol.iterator]", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "[Symbol.iterator]")[Symbol.iterator]())), hidden);
|
|
235
236
|
return string;
|
|
236
237
|
};
|
package/dist/stdlib/url.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, fn, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
3
|
-
import { PendingThrow, typeError, uriError } from "../interpreter/model.js";
|
|
4
|
-
import { defineAccessor, entries, isWrapper, Arr, Obj, URLObj, URLSearchParamsObj } from "../interpreter/objects.js";
|
|
3
|
+
import { IteratorSymbol, PendingThrow, typeError, uriError } from "../interpreter/model.js";
|
|
4
|
+
import { define, defineAccessor, entries, get, hidden, isWrapper, Arr, IteratorObj, Obj, URLObj, URLSearchParamsObj, } from "../interpreter/objects.js";
|
|
5
5
|
import { isRuntimeReference } from "../interpreter/references.js";
|
|
6
6
|
import { applyCollectionCallback, preserveConsumerError } from "../interpreter/callback.js";
|
|
7
7
|
import { coerceToString } from "./value.js";
|
|
@@ -237,12 +237,14 @@ export const urlSearchParamsGlobal = (ctx) => {
|
|
|
237
237
|
return undefined;
|
|
238
238
|
},
|
|
239
239
|
],
|
|
240
|
-
["keys", 0, (thisValue) =>
|
|
241
|
-
["values", 0, (thisValue) =>
|
|
240
|
+
["keys", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "keys").params.keys())],
|
|
241
|
+
["values", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "values").params.values())],
|
|
242
242
|
[
|
|
243
243
|
"entries",
|
|
244
244
|
0,
|
|
245
|
-
(thisValue) =>
|
|
245
|
+
(thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries")
|
|
246
|
+
.params.entries()
|
|
247
|
+
.map(([key, value]) => wrap([key, value]))),
|
|
246
248
|
],
|
|
247
249
|
["toString", 0, (thisValue) => self(thisValue, "toString").params.toString()],
|
|
248
250
|
[
|
|
@@ -260,5 +262,6 @@ export const urlSearchParamsGlobal = (ctx) => {
|
|
|
260
262
|
},
|
|
261
263
|
],
|
|
262
264
|
]);
|
|
265
|
+
define(proto, IteratorSymbol, get(proto, "entries"), hidden);
|
|
263
266
|
return searchParams;
|
|
264
267
|
};
|
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-dev-
|
|
4
|
+
"version": "0.0.0-dev-19882",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|