@opencode/codemode 2.2.0 → 2.2.1

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.
Files changed (55) hide show
  1. package/README.md +33 -4
  2. package/dist/codemode.d.ts +9 -7
  3. package/dist/codemode.js +1 -1
  4. package/dist/data.d.ts +5 -4
  5. package/dist/data.js +7 -4
  6. package/dist/extension.d.ts +17 -4
  7. package/dist/extension.js +8 -0
  8. package/dist/interpreter/callback.d.ts +10 -10
  9. package/dist/interpreter/callback.js +43 -31
  10. package/dist/interpreter/errors.d.ts +1 -1
  11. package/dist/interpreter/errors.js +12 -15
  12. package/dist/interpreter/execute.js +59 -29
  13. package/dist/interpreter/extensions.d.ts +2 -2
  14. package/dist/interpreter/extensions.js +46 -18
  15. package/dist/interpreter/generators.js +162 -19
  16. package/dist/interpreter/globals.js +12 -9
  17. package/dist/interpreter/interpreter.d.ts +20 -13
  18. package/dist/interpreter/interpreter.js +1329 -1147
  19. package/dist/interpreter/intrinsics.js +1 -2
  20. package/dist/interpreter/model.d.ts +4 -7
  21. package/dist/interpreter/model.js +1 -11
  22. package/dist/interpreter/native.d.ts +7 -8
  23. package/dist/interpreter/native.js +4 -10
  24. package/dist/interpreter/objects.d.ts +47 -21
  25. package/dist/interpreter/objects.js +33 -12
  26. package/dist/interpreter/promises.d.ts +15 -53
  27. package/dist/interpreter/promises.js +226 -401
  28. package/dist/interpreter/runner.d.ts +188 -0
  29. package/dist/interpreter/runner.js +492 -0
  30. package/dist/stdlib/array.d.ts +3 -3
  31. package/dist/stdlib/array.js +106 -102
  32. package/dist/stdlib/bytes.d.ts +3 -3
  33. package/dist/stdlib/bytes.js +46 -41
  34. package/dist/stdlib/collections.d.ts +5 -5
  35. package/dist/stdlib/collections.js +160 -165
  36. package/dist/stdlib/date.d.ts +1 -1
  37. package/dist/stdlib/date.js +28 -20
  38. package/dist/stdlib/headers.d.ts +1 -1
  39. package/dist/stdlib/headers.js +14 -19
  40. package/dist/stdlib/iterator.d.ts +1 -1
  41. package/dist/stdlib/iterator.js +140 -122
  42. package/dist/stdlib/json.js +9 -12
  43. package/dist/stdlib/math.js +10 -10
  44. package/dist/stdlib/number.d.ts +2 -2
  45. package/dist/stdlib/object.d.ts +1 -1
  46. package/dist/stdlib/object.js +21 -22
  47. package/dist/stdlib/regexp.d.ts +1 -1
  48. package/dist/stdlib/regexp.js +2 -3
  49. package/dist/stdlib/string.d.ts +1 -1
  50. package/dist/stdlib/string.js +18 -20
  51. package/dist/stdlib/url.d.ts +5 -5
  52. package/dist/stdlib/url.js +32 -33
  53. package/dist/stdlib/value.d.ts +2 -2
  54. package/dist/stdlib/web.d.ts +2 -2
  55. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
- import { Cause, Effect, Exit } from "effect";
2
1
  import { applyCollectionCallback } from "../interpreter/callback.js";
3
2
  import { rangeError, typeError } from "../interpreter/model.js";
4
3
  import { constructor, fn, methods, receiver, requiresNew } from "../interpreter/native.js";
5
- import { Arr, coerceToNumber, define, hasPrototype, hidden, IteratorObj, Obj, record, } from "../interpreter/objects.js";
4
+ import { Arr, coerceToNumber, define, hasPrototype, hidden, iteratorResult, IteratorObj, Obj, } from "../interpreter/objects.js";
6
5
  import { describeValue } from "../interpreter/references.js";
6
+ import { Interruption } from "../interpreter/runner.js";
7
7
  const finished = { done: true, value: undefined };
8
8
  // Every built-in iterator and helper shares the Iterator prototype; JS gives each collection its own, which is only
9
9
  // observable through getPrototypeOf.
@@ -12,13 +12,22 @@ export const iteratorGlobals = (ctx) => {
12
12
  const proto = builtins.Iterator;
13
13
  const method = (name) => `Iterator.prototype.${name}`;
14
14
  // A step that runs program code: when it throws, close the source first, as IteratorClose does.
15
- const guarded = (source, body) => Effect.flatMap(Effect.exit(body), (exit) => {
16
- if (Exit.isSuccess(exit))
17
- return Effect.succeed(exit.value);
18
- if (Cause.hasInterruptsOnly(exit.cause))
19
- return Effect.failCause(exit.cause);
20
- return Effect.andThen(Effect.exit(source.close), Effect.failCause(exit.cause));
21
- });
15
+ const guarded = function* (source, body) {
16
+ try {
17
+ return yield* body;
18
+ }
19
+ catch (error) {
20
+ if (error instanceof Interruption)
21
+ throw error;
22
+ try {
23
+ yield* source.close();
24
+ }
25
+ catch {
26
+ // The step's failure wins over a failing close.
27
+ }
28
+ throw error;
29
+ }
30
+ };
22
31
  // A lazy helper: `pull` advances it once. Once it reports done, throws, or is closed, it stays done. A callback
23
32
  // that re-enters its own helper is a TypeError, as for a running generator.
24
33
  const helper = (source, pull, close = source.close) => {
@@ -30,34 +39,44 @@ export const iteratorGlobals = (ctx) => {
30
39
  running = true;
31
40
  };
32
41
  return new IteratorObj(builtins.IteratorHelper, {
33
- next: Effect.suspend(() => {
42
+ next: function* () {
34
43
  if (done)
35
- return Effect.succeed(finished);
44
+ return finished;
36
45
  enter();
37
- return Effect.flatMap(Effect.exit(pull), (exit) => {
46
+ try {
47
+ const step = yield* pull();
48
+ done = step.done;
49
+ return step;
50
+ }
51
+ catch (error) {
52
+ done = true;
53
+ throw error;
54
+ }
55
+ finally {
38
56
  running = false;
39
- done = Exit.isSuccess(exit) ? exit.value.done : true;
40
- return exit;
41
- });
42
- }),
43
- close: Effect.suspend(() => {
57
+ }
58
+ },
59
+ close: function* () {
44
60
  if (done)
45
- return Effect.void;
61
+ return;
46
62
  enter();
47
63
  done = true;
48
- return Effect.ensuring(close, Effect.sync(() => {
64
+ try {
65
+ yield* close();
66
+ }
67
+ finally {
49
68
  running = false;
50
- }));
51
- }),
69
+ }
70
+ },
52
71
  });
53
72
  };
54
73
  // GetIteratorFlattenable: an iterable by `[Symbol.iterator]`, otherwise the object itself as an iterator.
55
- const flattenable = (value, name, strings) => Effect.gen(function* () {
74
+ const flattenable = function* (value, name, strings) {
56
75
  if (typeof value === "string" ? !strings : !(value instanceof Obj)) {
57
76
  throw typeError(`${name} expects an iterable or iterator, received ${describeValue(value)}.`);
58
77
  }
59
78
  return (yield* ctx.iterate(value)) ?? ctx.iterateDirect(value);
60
- });
79
+ };
61
80
  const limit = (value, name) => {
62
81
  const count = Math.trunc(coerceToNumber(value));
63
82
  if (Number.isNaN(count) || count < 0) {
@@ -69,7 +88,10 @@ export const iteratorGlobals = (ctx) => {
69
88
  [
70
89
  "next",
71
90
  0,
72
- (thisValue) => Effect.map(receiver(IteratorObj, thisValue, method("next")).cursor.next, (step) => record(builtins.Object, { value: step.value, done: step.done })),
91
+ function* (thisValue) {
92
+ const step = yield* receiver(IteratorObj, thisValue, method("next")).cursor.next();
93
+ return iteratorResult(builtins.Object, step.value, step.done);
94
+ },
73
95
  ],
74
96
  [
75
97
  "map",
@@ -78,12 +100,12 @@ export const iteratorGlobals = (ctx) => {
78
100
  const source = ctx.iterateDirect(thisValue);
79
101
  const apply = applyCollectionCallback(ctx, args[0], method("map"));
80
102
  let counter = 0;
81
- return helper(source, Effect.gen(function* () {
82
- const step = yield* source.next;
103
+ return helper(source, function* () {
104
+ const step = yield* source.next();
83
105
  if (step.done)
84
106
  return finished;
85
107
  return { done: false, value: yield* guarded(source, apply([step.value, counter++])) };
86
- }));
108
+ });
87
109
  },
88
110
  ],
89
111
  [
@@ -93,15 +115,15 @@ export const iteratorGlobals = (ctx) => {
93
115
  const source = ctx.iterateDirect(thisValue);
94
116
  const apply = applyCollectionCallback(ctx, args[0], method("filter"));
95
117
  let counter = 0;
96
- return helper(source, Effect.gen(function* () {
118
+ return helper(source, function* () {
97
119
  while (true) {
98
- const step = yield* source.next;
120
+ const step = yield* source.next();
99
121
  if (step.done)
100
122
  return finished;
101
123
  if (yield* guarded(source, apply([step.value, counter++])))
102
124
  return step;
103
125
  }
104
- }));
126
+ });
105
127
  },
106
128
  ],
107
129
  [
@@ -110,14 +132,14 @@ export const iteratorGlobals = (ctx) => {
110
132
  (thisValue, args) => {
111
133
  const source = ctx.iterateDirect(thisValue);
112
134
  let remaining = limit(args[0], "take");
113
- return helper(source, Effect.gen(function* () {
135
+ return helper(source, function* () {
114
136
  if (remaining === 0) {
115
- yield* source.close;
137
+ yield* source.close();
116
138
  return finished;
117
139
  }
118
140
  remaining -= 1;
119
- return yield* source.next;
120
- }));
141
+ return yield* source.next();
142
+ });
121
143
  },
122
144
  ],
123
145
  [
@@ -126,15 +148,15 @@ export const iteratorGlobals = (ctx) => {
126
148
  (thisValue, args) => {
127
149
  const source = ctx.iterateDirect(thisValue);
128
150
  let remaining = limit(args[0], "drop");
129
- return helper(source, Effect.gen(function* () {
151
+ return helper(source, function* () {
130
152
  while (remaining > 0) {
131
153
  remaining -= 1;
132
- const step = yield* source.next;
154
+ const step = yield* source.next();
133
155
  if (step.done)
134
156
  return finished;
135
157
  }
136
- return yield* source.next;
137
- }));
158
+ return yield* source.next();
159
+ });
138
160
  },
139
161
  ],
140
162
  [
@@ -145,138 +167,131 @@ export const iteratorGlobals = (ctx) => {
145
167
  const apply = applyCollectionCallback(ctx, args[0], method("flatMap"));
146
168
  let counter = 0;
147
169
  let inner;
148
- return helper(source, Effect.gen(function* () {
170
+ return helper(source, function* () {
149
171
  while (true) {
150
172
  if (inner !== undefined) {
151
- const step = yield* guarded(source, inner.next);
173
+ const step = yield* guarded(source, inner.next());
152
174
  if (!step.done)
153
175
  return step;
154
176
  inner = undefined;
155
177
  }
156
- const step = yield* source.next;
178
+ const step = yield* source.next();
157
179
  if (step.done)
158
180
  return finished;
159
- inner = yield* guarded(source, Effect.flatMap(apply([step.value, counter++]), (mapped) => flattenable(mapped, method("flatMap"), false)));
181
+ const mapped = yield* guarded(source, apply([step.value, counter++]));
182
+ inner = yield* guarded(source, flattenable(mapped, method("flatMap"), false));
160
183
  }
161
- }), Effect.suspend(() => (inner === undefined ? source.close : Effect.andThen(inner.close, source.close))));
184
+ }, function* () {
185
+ if (inner !== undefined)
186
+ yield* inner.close();
187
+ yield* source.close();
188
+ });
162
189
  },
163
190
  ],
164
191
  [
165
192
  "reduce",
166
193
  1,
167
- (thisValue, args) => {
194
+ function* (thisValue, args) {
168
195
  const source = ctx.iterateDirect(thisValue);
169
196
  const apply = applyCollectionCallback(ctx, args[0], method("reduce"));
170
- return Effect.gen(function* () {
171
- let counter = 0;
172
- let accumulator = args[1];
173
- if (args.length < 2) {
174
- const first = yield* source.next;
175
- if (first.done)
176
- throw typeError("Iterator.prototype.reduce of an empty iterator with no initial value.");
177
- accumulator = first.value;
178
- counter = 1;
179
- }
180
- while (true) {
181
- const step = yield* source.next;
182
- if (step.done)
183
- return accumulator;
184
- accumulator = yield* guarded(source, apply([accumulator, step.value, counter++]));
185
- }
186
- });
197
+ let counter = 0;
198
+ let accumulator = args[1];
199
+ if (args.length < 2) {
200
+ const first = yield* source.next();
201
+ if (first.done)
202
+ throw typeError("Iterator.prototype.reduce of an empty iterator with no initial value.");
203
+ accumulator = first.value;
204
+ counter = 1;
205
+ }
206
+ while (true) {
207
+ const step = yield* source.next();
208
+ if (step.done)
209
+ return accumulator;
210
+ accumulator = yield* guarded(source, apply([accumulator, step.value, counter++]));
211
+ }
187
212
  },
188
213
  ],
189
214
  [
190
215
  "toArray",
191
216
  0,
192
- (thisValue) => {
217
+ function* (thisValue) {
193
218
  const source = ctx.iterateDirect(thisValue);
194
- return Effect.gen(function* () {
195
- const items = [];
196
- while (true) {
197
- const step = yield* source.next;
198
- if (step.done)
199
- return new Arr(builtins.Array, items);
200
- items.push(step.value);
201
- }
202
- });
219
+ const items = [];
220
+ while (true) {
221
+ const step = yield* source.next();
222
+ if (step.done)
223
+ return new Arr(builtins.Array, items);
224
+ items.push(step.value);
225
+ }
203
226
  },
204
227
  ],
205
228
  [
206
229
  "forEach",
207
230
  1,
208
- (thisValue, args) => {
231
+ function* (thisValue, args) {
209
232
  const source = ctx.iterateDirect(thisValue);
210
233
  const apply = applyCollectionCallback(ctx, args[0], method("forEach"));
211
- return Effect.gen(function* () {
212
- let counter = 0;
213
- while (true) {
214
- const step = yield* source.next;
215
- if (step.done)
216
- return undefined;
217
- yield* guarded(source, apply([step.value, counter++]));
218
- }
219
- });
234
+ let counter = 0;
235
+ while (true) {
236
+ const step = yield* source.next();
237
+ if (step.done)
238
+ return undefined;
239
+ yield* guarded(source, apply([step.value, counter++]));
240
+ }
220
241
  },
221
242
  ],
222
243
  [
223
244
  "some",
224
245
  1,
225
- (thisValue, args) => {
246
+ function* (thisValue, args) {
226
247
  const source = ctx.iterateDirect(thisValue);
227
248
  const apply = applyCollectionCallback(ctx, args[0], method("some"));
228
- return Effect.gen(function* () {
229
- let counter = 0;
230
- while (true) {
231
- const step = yield* source.next;
232
- if (step.done)
233
- return false;
234
- if (yield* guarded(source, apply([step.value, counter++]))) {
235
- yield* source.close;
236
- return true;
237
- }
249
+ let counter = 0;
250
+ while (true) {
251
+ const step = yield* source.next();
252
+ if (step.done)
253
+ return false;
254
+ if (yield* guarded(source, apply([step.value, counter++]))) {
255
+ yield* source.close();
256
+ return true;
238
257
  }
239
- });
258
+ }
240
259
  },
241
260
  ],
242
261
  [
243
262
  "every",
244
263
  1,
245
- (thisValue, args) => {
264
+ function* (thisValue, args) {
246
265
  const source = ctx.iterateDirect(thisValue);
247
266
  const apply = applyCollectionCallback(ctx, args[0], method("every"));
248
- return Effect.gen(function* () {
249
- let counter = 0;
250
- while (true) {
251
- const step = yield* source.next;
252
- if (step.done)
253
- return true;
254
- if (!(yield* guarded(source, apply([step.value, counter++])))) {
255
- yield* source.close;
256
- return false;
257
- }
267
+ let counter = 0;
268
+ while (true) {
269
+ const step = yield* source.next();
270
+ if (step.done)
271
+ return true;
272
+ if (!(yield* guarded(source, apply([step.value, counter++])))) {
273
+ yield* source.close();
274
+ return false;
258
275
  }
259
- });
276
+ }
260
277
  },
261
278
  ],
262
279
  [
263
280
  "find",
264
281
  1,
265
- (thisValue, args) => {
282
+ function* (thisValue, args) {
266
283
  const source = ctx.iterateDirect(thisValue);
267
284
  const apply = applyCollectionCallback(ctx, args[0], method("find"));
268
- return Effect.gen(function* () {
269
- let counter = 0;
270
- while (true) {
271
- const step = yield* source.next;
272
- if (step.done)
273
- return undefined;
274
- if (yield* guarded(source, apply([step.value, counter++]))) {
275
- yield* source.close;
276
- return step.value;
277
- }
285
+ let counter = 0;
286
+ while (true) {
287
+ const step = yield* source.next();
288
+ if (step.done)
289
+ return undefined;
290
+ if (yield* guarded(source, apply([step.value, counter++]))) {
291
+ yield* source.close();
292
+ return step.value;
278
293
  }
279
- });
294
+ }
280
295
  },
281
296
  ],
282
297
  ]);
@@ -285,21 +300,24 @@ export const iteratorGlobals = (ctx) => {
285
300
  [
286
301
  "return",
287
302
  0,
288
- (thisValue) => Effect.map(receiver(IteratorObj, thisValue, "Iterator.prototype.return").cursor.close, () => record(builtins.Object, { value: undefined, done: true })),
303
+ function* (thisValue) {
304
+ yield* receiver(IteratorObj, thisValue, "Iterator.prototype.return").cursor.close();
305
+ return iteratorResult(builtins.Object, undefined, true);
306
+ },
289
307
  ],
290
308
  ]);
291
309
  const iterator = constructor(builtins, proto, {
292
310
  name: "Iterator",
293
311
  length: 0,
294
312
  call: requiresNew("Iterator"),
295
- construct: () => Effect.sync(() => {
313
+ construct: () => {
296
314
  throw typeError("Iterator is abstract; use Iterator.from(...) or a built-in iterator.");
297
- }),
315
+ },
298
316
  });
299
- define(iterator, "from", fn(builtins, "from", 1, (_, args) => Effect.gen(function* () {
317
+ define(iterator, "from", fn(builtins, "from", 1, function* (_, args) {
300
318
  if (args[0] instanceof Obj && hasPrototype(args[0], proto))
301
319
  return args[0];
302
320
  return new IteratorObj(builtins.IteratorHelper, yield* flattenable(args[0], "Iterator.from", true));
303
- })), hidden);
321
+ }), hidden);
304
322
  return iterator;
305
323
  };
@@ -1,4 +1,3 @@
1
- import { Effect } from "effect";
2
1
  import { methods } from "../interpreter/native.js";
3
2
  import { applyCollectionCallback } from "../interpreter/callback.js";
4
3
  import { checkStringLength } from "../interpreter/limits.js";
@@ -25,9 +24,9 @@ const parse = (ctx, args) => {
25
24
  }
26
25
  })();
27
26
  if (typeofValue(args[1]) !== "function")
28
- return Effect.succeed(parsed);
27
+ return parsed;
29
28
  const apply = applyCollectionCallback(ctx, args[1], "JSON.parse");
30
- const visit = (holder, key) => Effect.gen(function* () {
29
+ const visit = function* (holder, key) {
31
30
  const value = get(holder, key);
32
31
  if (value instanceof Obj) {
33
32
  for (const name of keys(value)) {
@@ -39,10 +38,10 @@ const parse = (ctx, args) => {
39
38
  }
40
39
  }
41
40
  return yield* apply([key, value], holder);
42
- });
41
+ };
43
42
  return visit(record(ctx.builtins.Object, { "": parsed }), "");
44
43
  };
45
- const stringify = (ctx, args) => {
44
+ function* stringify(ctx, args) {
46
45
  const space = args[2];
47
46
  const indent = typeof space === "number" || typeof space === "string" ? space : undefined;
48
47
  const replacer = args[1];
@@ -52,10 +51,8 @@ const stringify = (ctx, args) => {
52
51
  .map(String)
53
52
  : null;
54
53
  const callback = typeofValue(replacer) === "function" ? applyCollectionCallback(ctx, replacer, "JSON.stringify") : undefined;
55
- return Effect.map(toJson(ctx, args[0], callback), (value) => {
56
- const text = JSON.stringify(value, properties, indent);
57
- if (text !== undefined)
58
- checkStringLength(text.length);
59
- return text;
60
- });
61
- };
54
+ const text = JSON.stringify(yield* toJson(ctx, args[0], callback), properties, indent);
55
+ if (text !== undefined)
56
+ checkStringLength(text.length);
57
+ return text;
58
+ }
@@ -1,4 +1,3 @@
1
- import { Effect } from "effect";
2
1
  import { constants, methods } from "../interpreter/native.js";
3
2
  import { typeError } from "../interpreter/model.js";
4
3
  import { Obj, coerceToNumber } from "../interpreter/objects.js";
@@ -73,25 +72,26 @@ export const mathGlobal = (ctx) => {
73
72
  [
74
73
  "sumPrecise",
75
74
  1,
76
- (_, args) => Effect.gen(function* () {
75
+ function* (_, args) {
77
76
  const cursor = yield* ctx.iterate(args[0]);
78
77
  if (cursor === undefined) {
79
78
  throw typeError("Math.sumPrecise expects a synchronous iterable.");
80
79
  }
81
80
  const numbers = [];
82
81
  while (true) {
83
- const step = yield* cursor.next;
82
+ const step = yield* cursor.next();
84
83
  if (step.done)
85
84
  return Math.sumPrecise(numbers);
86
- yield* preserveConsumerError(cursor.close, Effect.sync(() => {
87
- if (typeof step.value !== "number") {
88
- throw typeError("Math.sumPrecise expects an iterable of numbers.");
89
- }
90
- numbers.push(step.value);
91
- }));
85
+ if (typeof step.value !== "number") {
86
+ yield* preserveConsumerError(cursor.close, rejectNonNumber());
87
+ }
88
+ numbers.push(step.value);
92
89
  }
93
- }),
90
+ },
94
91
  ],
95
92
  ]);
96
93
  return math;
97
94
  };
95
+ function* rejectNonNumber() {
96
+ throw typeError("Math.sumPrecise expects an iterable of numbers.");
97
+ }
@@ -1,3 +1,3 @@
1
1
  import type { Interpreter } from "../interpreter/interpreter.js";
2
- export declare const numberGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
3
- export declare const booleanGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
2
+ export declare const numberGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
3
+ export declare const booleanGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
@@ -3,4 +3,4 @@ import { Obj, type Value } from "../interpreter/objects.js";
3
3
  import type { Interpreter } from "../interpreter/interpreter.js";
4
4
  export declare const enumerableSource: <R>(ctx: Interpreter<R>, label: string, value: Value, node?: AstNode) => Obj;
5
5
  export declare const objectAssign: <R>(ctx: Interpreter<R>, args: Array<Value>) => Value;
6
- export declare const objectGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
6
+ export declare const objectGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
@@ -1,4 +1,3 @@
1
- import { Effect } from "effect";
2
1
  import { constructor, methods, receiver } from "../interpreter/native.js";
3
2
  import { AsyncIteratorSymbol, invalidData, IteratorSymbol, typeError } from "../interpreter/model.js";
4
3
  import { define, entries, enumerableKeys, getOwn, hasOwn, hasPrototype, hidden, keys, own, ownKeys, Arr, Bytes, Obj, PromiseObj, set, coerceToString, } from "../interpreter/objects.js";
@@ -44,26 +43,26 @@ export const objectAssign = (ctx, args) => {
44
43
  }
45
44
  return target;
46
45
  };
47
- const objectFromEntries = (ctx, source) => {
46
+ function* objectFromEntries(ctx, source) {
48
47
  const out = new Obj(ctx.builtins.Object);
49
- return Effect.gen(function* () {
50
- const cursor = yield* ctx.iterate(source);
51
- if (cursor === undefined) {
52
- throw typeError("Object.fromEntries expects a synchronous iterable of entries.");
53
- }
54
- while (true) {
55
- const step = yield* cursor.next;
56
- if (step.done)
57
- return out;
58
- yield* preserveConsumerError(cursor.close, Effect.sync(() => {
59
- if (!(step.value instanceof Obj) || containsOpaqueReference(step.value)) {
60
- throw typeError("Object.fromEntries expects [key, value] entry objects.");
61
- }
62
- define(out, coerceToString(getOwn(step.value, 0)), getOwn(step.value, 1));
63
- }));
64
- }
65
- });
66
- };
48
+ const cursor = yield* ctx.iterate(source);
49
+ if (cursor === undefined) {
50
+ throw typeError("Object.fromEntries expects a synchronous iterable of entries.");
51
+ }
52
+ while (true) {
53
+ const step = yield* cursor.next();
54
+ if (step.done)
55
+ return out;
56
+ yield* preserveConsumerError(cursor.close, defineEntry(out, step.value));
57
+ }
58
+ }
59
+ // A step, so a rejected entry closes the source iterator.
60
+ function* defineEntry(out, entry) {
61
+ if (!(entry instanceof Obj) || containsOpaqueReference(entry)) {
62
+ throw typeError("Object.fromEntries expects [key, value] entry objects.");
63
+ }
64
+ define(out, coerceToString(getOwn(entry, 0)), getOwn(entry, 1));
65
+ }
67
66
  const classTag = (value) => {
68
67
  if (value === null)
69
68
  return "Null";
@@ -127,8 +126,8 @@ export const objectGlobal = (ctx) => {
127
126
  const object = constructor(builtins, builtins.Object, {
128
127
  name: "Object",
129
128
  length: 1,
130
- call: (_, args) => Effect.sync(() => construct(args)),
131
- construct: (args) => Effect.sync(() => construct(args)),
129
+ call: (_, args) => construct(args),
130
+ construct: (args) => construct(args),
132
131
  });
133
132
  methods(builtins, object, [
134
133
  [
@@ -4,4 +4,4 @@ import type { Interpreter } from "../interpreter/interpreter.js";
4
4
  export declare const toHostRegex: (arg: Value, method: string, extraFlags?: string) => RegExp;
5
5
  export declare const matchToValue: (builtins: Builtins, match: RegExpMatchArray) => Arr;
6
6
  export declare const constructRegExp: (builtins: Builtins, args: Array<Value>, proto?: Obj) => RegExpObj;
7
- export declare const regexpGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
7
+ export declare const regexpGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
@@ -1,4 +1,3 @@
1
- import { Effect } from "effect";
2
1
  import { constructor, methods, prototypeFrom, receiver } from "../interpreter/native.js";
3
2
  import { syntaxError, typeError } from "../interpreter/model.js";
4
3
  import { define, defineAccessor, Arr, Obj, RegExpObj, record, coerceToNumber, coerceToString, } from "../interpreter/objects.js";
@@ -63,8 +62,8 @@ export const regexpGlobal = (ctx) => {
63
62
  const regexp = constructor(builtins, proto, {
64
63
  name: "RegExp",
65
64
  length: 2,
66
- call: (_, args) => Effect.sync(() => constructRegExp(builtins, args)),
67
- construct: (args, newTarget) => Effect.sync(() => constructRegExp(builtins, args, prototypeFrom(newTarget, proto))),
65
+ call: (_, args) => constructRegExp(builtins, args),
66
+ construct: (args, newTarget) => constructRegExp(builtins, args, prototypeFrom(newTarget, proto)),
68
67
  });
69
68
  methods(builtins, regexp, [
70
69
  [
@@ -1,2 +1,2 @@
1
1
  import type { Interpreter } from "../interpreter/interpreter.js";
2
- export declare const stringGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
2
+ export declare const stringGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;