@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.
Files changed (91) hide show
  1. package/README.md +6 -12
  2. package/dist/codemode.d.ts +7 -21
  3. package/dist/codemode.js +17 -38
  4. package/dist/extension.d.ts +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/scan.js +2 -2
  7. package/dist/tool-runtime.d.ts +8 -11
  8. package/dist/tool-runtime.js +13 -11
  9. package/dist/tool.d.ts +18 -9
  10. package/dist/tool.js +15 -23
  11. package/dist/vm/data.d.ts +1 -1
  12. package/dist/vm/runtime/execute.d.ts +16 -6
  13. package/dist/vm/runtime/execute.js +10 -7
  14. package/dist/vm/snapshot/codec.d.ts +3 -2
  15. package/dist/vm/snapshot/codec.js +3 -2
  16. package/dist/vm/snapshot/snapshot.d.ts +6 -3
  17. package/dist/vm/snapshot/snapshot.js +13 -2
  18. package/dist/vm/vm.d.ts +2 -2
  19. package/package.json +3 -5
  20. package/dist/data.d.ts +0 -21
  21. package/dist/data.js +0 -93
  22. package/dist/interpreter/callback.d.ts +0 -35
  23. package/dist/interpreter/callback.js +0 -98
  24. package/dist/interpreter/errors.d.ts +0 -23
  25. package/dist/interpreter/errors.js +0 -173
  26. package/dist/interpreter/execute.d.ts +0 -14
  27. package/dist/interpreter/execute.js +0 -207
  28. package/dist/interpreter/extensions.d.ts +0 -9
  29. package/dist/interpreter/extensions.js +0 -248
  30. package/dist/interpreter/generators.d.ts +0 -3
  31. package/dist/interpreter/generators.js +0 -168
  32. package/dist/interpreter/globals.d.ts +0 -6
  33. package/dist/interpreter/globals.js +0 -144
  34. package/dist/interpreter/interpreter.d.ts +0 -48
  35. package/dist/interpreter/interpreter.js +0 -2253
  36. package/dist/interpreter/intrinsics.d.ts +0 -15
  37. package/dist/interpreter/intrinsics.js +0 -105
  38. package/dist/interpreter/limits.d.ts +0 -10
  39. package/dist/interpreter/limits.js +0 -19
  40. package/dist/interpreter/model.d.ts +0 -68
  41. package/dist/interpreter/model.js +0 -54
  42. package/dist/interpreter/modules.d.ts +0 -4
  43. package/dist/interpreter/modules.js +0 -33
  44. package/dist/interpreter/native.d.ts +0 -17
  45. package/dist/interpreter/native.js +0 -35
  46. package/dist/interpreter/objects.d.ts +0 -301
  47. package/dist/interpreter/objects.js +0 -592
  48. package/dist/interpreter/promises.d.ts +0 -18
  49. package/dist/interpreter/promises.js +0 -292
  50. package/dist/interpreter/references.d.ts +0 -8
  51. package/dist/interpreter/references.js +0 -51
  52. package/dist/interpreter/runner.d.ts +0 -178
  53. package/dist/interpreter/runner.js +0 -480
  54. package/dist/interpreter/scope.d.ts +0 -16
  55. package/dist/interpreter/scope.js +0 -79
  56. package/dist/stdlib/array.d.ts +0 -11
  57. package/dist/stdlib/array.js +0 -498
  58. package/dist/stdlib/bytes.d.ts +0 -10
  59. package/dist/stdlib/bytes.js +0 -253
  60. package/dist/stdlib/collections.d.ts +0 -7
  61. package/dist/stdlib/collections.js +0 -497
  62. package/dist/stdlib/console.d.ts +0 -6
  63. package/dist/stdlib/console.js +0 -93
  64. package/dist/stdlib/date.d.ts +0 -2
  65. package/dist/stdlib/date.js +0 -132
  66. package/dist/stdlib/headers.d.ts +0 -2
  67. package/dist/stdlib/headers.js +0 -110
  68. package/dist/stdlib/iterator.d.ts +0 -2
  69. package/dist/stdlib/iterator.js +0 -322
  70. package/dist/stdlib/json.d.ts +0 -3
  71. package/dist/stdlib/json.js +0 -58
  72. package/dist/stdlib/math.d.ts +0 -8
  73. package/dist/stdlib/math.js +0 -97
  74. package/dist/stdlib/number.d.ts +0 -3
  75. package/dist/stdlib/number.js +0 -72
  76. package/dist/stdlib/object.d.ts +0 -6
  77. package/dist/stdlib/object.js +0 -219
  78. package/dist/stdlib/regexp.d.ts +0 -7
  79. package/dist/stdlib/regexp.js +0 -114
  80. package/dist/stdlib/string.d.ts +0 -2
  81. package/dist/stdlib/string.js +0 -272
  82. package/dist/stdlib/url.d.ts +0 -13
  83. package/dist/stdlib/url.js +0 -255
  84. package/dist/stdlib/value.d.ts +0 -7
  85. package/dist/stdlib/value.js +0 -33
  86. package/dist/stdlib/web.d.ts +0 -5
  87. package/dist/stdlib/web.js +0 -97
  88. package/dist/suspend-error.d.ts +0 -24
  89. package/dist/suspend-error.js +0 -25
  90. package/dist/vm/index.d.ts +0 -6
  91. package/dist/vm/index.js +0 -6
@@ -1,498 +0,0 @@
1
- import { constructor, methods, prototypeFrom, receiver } from "../interpreter/native.js";
2
- import { checkArrayLength, checkStringLength, MAX_ARRAY_LENGTH } from "../interpreter/limits.js";
3
- import { invalidData, IteratorSymbol, rangeError, typeError } from "../interpreter/model.js";
4
- import { define, get, hidden, Arr, GeneratorObj, hostIterator, Obj, PromiseObj, coerceToInteger, coerceToNumber, coerceToString, rejectAddition, } from "../interpreter/objects.js";
5
- import { describeValue, rejectCircularInsertion } from "../interpreter/references.js";
6
- import { applyCollectionCallback, invoke, preserveConsumerError, withPrimitives } from "../interpreter/callback.js";
7
- import { compareText } from "../tool-runtime.js";
8
- const arrayLikeSource = (source) => {
9
- // JS would treat a promise as an empty array-like; that would hide a missing `await`.
10
- if (source instanceof Obj && !(source instanceof PromiseObj)) {
11
- const length = Math.max(0, coerceToInteger(get(source, "length")));
12
- checkArrayLength(length);
13
- return { length, source };
14
- }
15
- throw invalidData(`Array.from expects an iterable or array-like value, received ${describeValue(source)}.`);
16
- };
17
- function* arrayFrom(ctx, args) {
18
- const source = args[0];
19
- const proto = ctx.builtins.Array;
20
- const apply = args.length < 2 || args[1] === undefined ? undefined : applyCollectionCallback(ctx, args[1], "Array.from");
21
- const cursor = yield* ctx.iterate(source);
22
- if (cursor === undefined) {
23
- if (source instanceof GeneratorObj) {
24
- throw typeError(`Array.from expects a synchronous iterable or array-like value, received ${describeValue(source)}.`);
25
- }
26
- const arrayLike = arrayLikeSource(source);
27
- const values = [];
28
- for (let index = 0; index < arrayLike.length; index += 1) {
29
- const item = get(arrayLike.source, index);
30
- values.push(apply === undefined ? item : yield* apply([item, index], args[2]));
31
- }
32
- return new Arr(proto, values);
33
- }
34
- const values = [];
35
- let index = 0;
36
- while (true) {
37
- const step = yield* cursor.next();
38
- if (step.done)
39
- return new Arr(proto, values);
40
- values.push(apply === undefined
41
- ? step.value
42
- : yield* preserveConsumerError(cursor.close, apply([step.value, index], args[2])));
43
- index += 1;
44
- }
45
- }
46
- export function* sortArray(ctx, target, comparator, name) {
47
- if (comparator === undefined) {
48
- return [...target].sort((a, b) => compareText(coerceToString(a), coerceToString(b)));
49
- }
50
- const apply = applyCollectionCallback(ctx, comparator, name);
51
- const mergeSort = function* (items) {
52
- if (items.length <= 1)
53
- return items;
54
- const midpoint = Math.floor(items.length / 2);
55
- const left = yield* mergeSort(items.slice(0, midpoint));
56
- const right = yield* mergeSort(items.slice(midpoint));
57
- const merged = [];
58
- let leftIndex = 0;
59
- let rightIndex = 0;
60
- while (leftIndex < left.length && rightIndex < right.length) {
61
- // Treat a NaN comparator result as equal to preserve stable ordering.
62
- const order = coerceToNumber(yield* apply([left[leftIndex], right[rightIndex]]));
63
- if (Number.isNaN(order) || order <= 0)
64
- merged.push(left[leftIndex++]);
65
- else
66
- merged.push(right[rightIndex++]);
67
- }
68
- return [...merged, ...left.slice(leftIndex), ...right.slice(rightIndex)];
69
- };
70
- const defined = target.filter((item) => item !== undefined);
71
- const undefinedCount = target.length - defined.length;
72
- const sorted = yield* mergeSort(defined);
73
- return [...sorted, ...Array(undefinedCount).fill(undefined)];
74
- }
75
- // Array constructs identically with or without new, like JS.
76
- export const arrayGlobal = (ctx) => {
77
- const builtins = ctx.builtins;
78
- const proto = builtins.Array;
79
- const wrap = (items) => new Arr(proto, items);
80
- const construct = (args, into) => {
81
- if (args.length !== 1)
82
- return new Arr(into, [...args]);
83
- const first = args[0];
84
- if (typeof first !== "number")
85
- return new Arr(into, [first]);
86
- if (!Number.isInteger(first) || first < 0 || first > MAX_ARRAY_LENGTH)
87
- throw rangeError("Invalid array length.");
88
- // Sparse like JS: Array(3) has holes, and combinator loops already skip them.
89
- return new Arr(into, new Array(first));
90
- };
91
- const array = constructor(builtins, proto, {
92
- name: "Array",
93
- length: 1,
94
- call: (_, args) => construct(args, proto),
95
- construct: (args, newTarget) => construct(args, prototypeFrom(newTarget, proto)),
96
- });
97
- methods(builtins, array, [
98
- ["isArray", 1, (_, args) => args[0] instanceof Arr],
99
- ["of", 0, (_, args) => wrap([...args])],
100
- ["from", 1, (_, args) => arrayFrom(ctx, args)],
101
- ]);
102
- const self = (thisValue, name) => receiver(Arr, thisValue, `Array.prototype.${name}`);
103
- // A mutating method fails where its first element write, delete, or `length` write would on a frozen, sealed, or
104
- // non-extensible array. `growth` is given by the methods that always write `length`, even when it is 0; holes a
105
- // method would fill on a non-extensible array are not checked.
106
- const mutable = (target, growth) => {
107
- const length = target.items.length;
108
- if ((growth ?? 0) > 0)
109
- rejectAddition(target, length);
110
- if ((growth ?? 0) < 0 && length > 0 && !target.elements.configurable) {
111
- throw typeError(`Cannot delete property '${length - 1}'.`);
112
- }
113
- if (!target.elements.writable && (length > 0 || growth !== undefined)) {
114
- throw typeError(`Cannot assign to read only property '${length > 0 ? 0 : "length"}'.`);
115
- }
116
- return target;
117
- };
118
- const optNumber = (value) => (value === undefined ? undefined : coerceToInteger(value));
119
- methods(builtins, proto, [
120
- [
121
- "join",
122
- 1,
123
- (thisValue, args) => {
124
- // .map would keep holes, which the conversion would then hand to the body as undefined.
125
- const parts = Array.from(self(thisValue, "join").items, (item) => item ?? "");
126
- return withPrimitives(ctx, "string", [args[0] === undefined ? "," : args[0], ...parts], ([separator, ...items]) => {
127
- const joined = items.map(coerceToString).join(coerceToString(separator));
128
- checkStringLength(joined.length);
129
- return joined;
130
- });
131
- },
132
- ],
133
- [
134
- "toString",
135
- 0,
136
- (thisValue) => withPrimitives(ctx, "string", Array.from(self(thisValue, "toString").items, (item) => item ?? ""), (items) => items.map(coerceToString).join(",")),
137
- ],
138
- [
139
- "includes",
140
- 1,
141
- (thisValue, args) => {
142
- return self(thisValue, "includes").items.includes(args[0], optNumber(args[1]));
143
- },
144
- ],
145
- ["indexOf", 1, (thisValue, args) => self(thisValue, "indexOf").items.indexOf(args[0], optNumber(args[1]))],
146
- [
147
- "lastIndexOf",
148
- 1,
149
- (thisValue, args) => {
150
- const target = self(thisValue, "lastIndexOf").items;
151
- // An explicit undefined is a fromIndex of 0, unlike omitting it.
152
- return args.length < 2 ? target.lastIndexOf(args[0]) : target.lastIndexOf(args[0], optNumber(args[1]));
153
- },
154
- ],
155
- ["at", 1, (thisValue, args) => self(thisValue, "at").items.at(optNumber(args[0]) ?? 0)],
156
- [
157
- "slice",
158
- 2,
159
- (thisValue, args) => wrap(self(thisValue, "slice").items.slice(optNumber(args[0]), optNumber(args[1]))),
160
- ],
161
- [
162
- "concat",
163
- 1,
164
- (thisValue, args) => {
165
- const joined = self(thisValue, "concat").items.concat(...args.map((item) => (item instanceof Arr ? item.items : item)));
166
- checkArrayLength(joined.length);
167
- return wrap(joined);
168
- },
169
- ],
170
- [
171
- "flat",
172
- 0,
173
- (thisValue, args) => {
174
- const flatten = (items, depth) => items.flatMap((item) => (item instanceof Arr && depth > 0 ? flatten(item.items, depth - 1) : [item]));
175
- const flattened = flatten(self(thisValue, "flat").items, optNumber(args[0]) ?? 1);
176
- checkArrayLength(flattened.length);
177
- return wrap(flattened);
178
- },
179
- ],
180
- [
181
- "reverse",
182
- 0,
183
- (thisValue) => {
184
- const target = self(thisValue, "reverse");
185
- // Fewer than two elements means no writes at all, so a frozen one-element array reverses fine.
186
- if (target.items.length > 1)
187
- mutable(target);
188
- target.items.reverse();
189
- return target;
190
- },
191
- ],
192
- [
193
- "sort",
194
- 1,
195
- function* (thisValue, args) {
196
- const target = mutable(self(thisValue, "sort"));
197
- const items = target.items;
198
- const length = items.length;
199
- const holeCount = Array.from({ length }, (_, index) => Object.hasOwn(items, index)).filter((o) => !o).length;
200
- const itemCount = length - holeCount;
201
- const sorted = yield* sortArray(ctx, items, args[0], "Array.sort");
202
- sorted.slice(0, itemCount).forEach((item, index) => {
203
- items[index] = item;
204
- });
205
- Array.from({ length: holeCount }, (_, index) => itemCount + index).forEach((index) => {
206
- delete items[index];
207
- });
208
- return target;
209
- },
210
- ],
211
- [
212
- "toSorted",
213
- 1,
214
- function* (thisValue, args) {
215
- return wrap(yield* sortArray(ctx, self(thisValue, "toSorted").items, args[0], "Array.toSorted"));
216
- },
217
- ],
218
- ["toReversed", 0, (thisValue) => wrap([...self(thisValue, "toReversed").items].reverse())],
219
- [
220
- "with",
221
- 2,
222
- (thisValue, args) => {
223
- const target = self(thisValue, "with").items;
224
- const index = optNumber(args[0]) ?? 0;
225
- const resolved = index < 0 ? target.length + index : index;
226
- if (resolved < 0 || resolved >= target.length)
227
- throw rangeError("Array.with index is out of range.");
228
- const copied = [...target];
229
- copied[resolved] = args[1];
230
- return wrap(copied);
231
- },
232
- ],
233
- [
234
- "push",
235
- 1,
236
- (thisValue, args) => {
237
- const target = mutable(self(thisValue, "push"), args.length);
238
- // Validate all insertions before mutating to avoid partial cyclic updates.
239
- for (const item of args)
240
- rejectCircularInsertion(target, item, "Array.push result");
241
- return target.items.push(...args);
242
- },
243
- ],
244
- [
245
- "unshift",
246
- 1,
247
- (thisValue, args) => {
248
- const target = mutable(self(thisValue, "unshift"), args.length);
249
- for (const item of args)
250
- rejectCircularInsertion(target, item, "Array.unshift result");
251
- return target.items.unshift(...args);
252
- },
253
- ],
254
- ["pop", 0, (thisValue) => mutable(self(thisValue, "pop"), -1).items.pop()],
255
- ["shift", 0, (thisValue) => mutable(self(thisValue, "shift"), -1).items.shift()],
256
- [
257
- "splice",
258
- 2,
259
- (thisValue, args) => {
260
- const target = self(thisValue, "splice");
261
- const length = target.items.length;
262
- const start = optNumber(args[0]) ?? 0;
263
- const from = start < 0 ? Math.max(length + start, 0) : Math.min(start, length);
264
- const deleteCount = args.length === 1 ? length - from : Math.min(Math.max(optNumber(args[1]) ?? 0, 0), length - from);
265
- const inserted = args.slice(2);
266
- for (const item of inserted)
267
- rejectCircularInsertion(target, item, "Array.splice result");
268
- mutable(target, inserted.length - deleteCount);
269
- return wrap(target.items.splice(from, deleteCount, ...inserted));
270
- },
271
- ],
272
- [
273
- "toSpliced",
274
- 2,
275
- (thisValue, args) => {
276
- const copied = [...self(thisValue, "toSpliced").items];
277
- if (args.length === 0)
278
- return wrap(copied);
279
- const start = optNumber(args[0]) ?? 0;
280
- if (args.length === 1)
281
- copied.splice(start);
282
- else
283
- copied.splice(start, optNumber(args[1]) ?? 0, ...args.slice(2));
284
- return wrap(copied);
285
- },
286
- ],
287
- [
288
- "fill",
289
- 1,
290
- (thisValue, args) => {
291
- const target = mutable(self(thisValue, "fill"));
292
- rejectCircularInsertion(target, args[0], "Array.fill result");
293
- target.items.fill(args[0], optNumber(args[1]), optNumber(args[2]));
294
- return target;
295
- },
296
- ],
297
- [
298
- "copyWithin",
299
- 2,
300
- (thisValue, args) => {
301
- const target = mutable(self(thisValue, "copyWithin"));
302
- target.items.copyWithin(optNumber(args[0]) ?? 0, optNumber(args[1]) ?? 0, optNumber(args[2]));
303
- return target;
304
- },
305
- ],
306
- [
307
- "toLocaleString",
308
- 0,
309
- function* (thisValue) {
310
- const items = self(thisValue, "toLocaleString").items;
311
- const length = items.length;
312
- const parts = [];
313
- for (let index = 0; index < length; index += 1) {
314
- const item = items[index];
315
- parts.push(item === null || item === undefined
316
- ? ""
317
- : coerceToString(yield* invoke(ctx, item, "toLocaleString", "Array.prototype.toLocaleString")));
318
- }
319
- return parts.join(",");
320
- },
321
- ],
322
- ["keys", 0, (thisValue) => hostIterator(builtins, self(thisValue, "keys").items.keys())],
323
- ["values", 0, (thisValue) => hostIterator(builtins, self(thisValue, "values").items.values())],
324
- [
325
- "entries",
326
- 0,
327
- (thisValue) => hostIterator(builtins, self(thisValue, "entries")
328
- .items.entries()
329
- .map(([index, item]) => wrap([index, item]))),
330
- ],
331
- [
332
- "flatMap",
333
- 1,
334
- function* (thisValue, args) {
335
- const target = self(thisValue, "flatMap");
336
- const apply = applyCollectionCallback(ctx, args[0], "Array.flatMap");
337
- const length = target.items.length;
338
- const values = [];
339
- for (let index = 0; index < length; index += 1) {
340
- if (!(index in target.items))
341
- continue;
342
- const mapped = yield* apply([target.items[index], index, target], args[1]);
343
- if (mapped instanceof Arr) {
344
- // forEach skips holes, as flattening does; spreading would turn them into undefined.
345
- mapped.items.forEach((item) => values.push(item));
346
- continue;
347
- }
348
- values.push(mapped);
349
- }
350
- return wrap(values);
351
- },
352
- ],
353
- ...callbackMethods(ctx, "Array", self, (target) => target.items, wrap),
354
- ]);
355
- define(proto, IteratorSymbol, get(proto, "values"), hidden);
356
- return array;
357
- };
358
- /**
359
- * The callback methods Array and Uint8Array share. They fix the iteration length while reading existing elements
360
- * live; `wrap` builds the collection `map` and `filter` return.
361
- */
362
- export const callbackMethods = (ctx, label, self, elements, wrap) => {
363
- const iterate = (name, length, body) => [
364
- name,
365
- length,
366
- (thisValue, args) => {
367
- const target = self(thisValue, name);
368
- const call = applyCollectionCallback(ctx, args[0], `${label}.${name}`);
369
- // reduce and reduceRight take an initial value where the others take a thisArg.
370
- const thisArg = name.startsWith("reduce") ? undefined : args[1];
371
- return body(elements(target), target, (callbackArgs) => call(callbackArgs, thisArg), args);
372
- },
373
- ];
374
- return [
375
- iterate("map", 1, function* (target, receiver, apply) {
376
- const length = target.length;
377
- const values = [];
378
- values.length = length;
379
- for (let index = 0; index < length; index += 1) {
380
- if (!(index in target))
381
- continue;
382
- values[index] = yield* apply([target[index], index, receiver]);
383
- }
384
- return wrap(values);
385
- }),
386
- iterate("filter", 1, function* (target, receiver, apply) {
387
- const length = target.length;
388
- const values = [];
389
- for (let index = 0; index < length; index += 1) {
390
- if (!(index in target))
391
- continue;
392
- const item = target[index];
393
- if (yield* apply([item, index, receiver]))
394
- values.push(item);
395
- }
396
- return wrap(values);
397
- }),
398
- iterate("find", 1, function* (target, receiver, apply) {
399
- const length = target.length;
400
- for (let index = 0; index < length; index += 1) {
401
- const item = target[index];
402
- if (yield* apply([item, index, receiver]))
403
- return item;
404
- }
405
- return undefined;
406
- }),
407
- iterate("findIndex", 1, function* (target, receiver, apply) {
408
- const length = target.length;
409
- for (let index = 0; index < length; index += 1) {
410
- if (yield* apply([target[index], index, receiver]))
411
- return index;
412
- }
413
- return -1;
414
- }),
415
- iterate("findLast", 1, function* (target, receiver, apply) {
416
- for (let index = target.length - 1; index >= 0; index -= 1) {
417
- const item = target[index];
418
- if (yield* apply([item, index, receiver]))
419
- return item;
420
- }
421
- return undefined;
422
- }),
423
- iterate("findLastIndex", 1, function* (target, receiver, apply) {
424
- for (let index = target.length - 1; index >= 0; index -= 1) {
425
- if (yield* apply([target[index], index, receiver]))
426
- return index;
427
- }
428
- return -1;
429
- }),
430
- iterate("some", 1, function* (target, receiver, apply) {
431
- const length = target.length;
432
- for (let index = 0; index < length; index += 1) {
433
- if (!(index in target))
434
- continue;
435
- if (yield* apply([target[index], index, receiver]))
436
- return true;
437
- }
438
- return false;
439
- }),
440
- iterate("every", 1, function* (target, receiver, apply) {
441
- const length = target.length;
442
- for (let index = 0; index < length; index += 1) {
443
- if (!(index in target))
444
- continue;
445
- if (!(yield* apply([target[index], index, receiver])))
446
- return false;
447
- }
448
- return true;
449
- }),
450
- iterate("forEach", 1, function* (target, receiver, apply) {
451
- const length = target.length;
452
- for (let index = 0; index < length; index += 1) {
453
- if (index in target)
454
- yield* apply([target[index], index, receiver]);
455
- }
456
- return undefined;
457
- }),
458
- iterate("reduce", 1, function* (target, receiver, apply, args) {
459
- const length = target.length;
460
- let start = 0;
461
- let accumulator = args[1];
462
- if (args.length < 2) {
463
- while (start < length && !(start in target))
464
- start += 1;
465
- if (start === length) {
466
- throw typeError(`${label}.reduce of an empty array with no initial value.`);
467
- }
468
- accumulator = target[start];
469
- start += 1;
470
- }
471
- for (let index = start; index < length; index += 1) {
472
- if (!(index in target))
473
- continue;
474
- accumulator = yield* apply([accumulator, target[index], index, receiver]);
475
- }
476
- return accumulator;
477
- }),
478
- iterate("reduceRight", 1, function* (target, receiver, apply, args) {
479
- let start = target.length - 1;
480
- let accumulator = args[1];
481
- if (args.length < 2) {
482
- while (start >= 0 && !(start in target))
483
- start -= 1;
484
- if (start < 0) {
485
- throw typeError(`${label}.reduceRight of an empty array with no initial value.`);
486
- }
487
- accumulator = target[start];
488
- start -= 1;
489
- }
490
- for (let index = start; index >= 0; index -= 1) {
491
- if (!(index in target))
492
- continue;
493
- accumulator = yield* apply([accumulator, target[index], index, receiver]);
494
- }
495
- return accumulator;
496
- }),
497
- ];
498
- };
@@ -1,10 +0,0 @@
1
- import { Obj } from "../interpreter/objects.js";
2
- import type { Interpreter } from "../interpreter/interpreter.js";
3
- export declare const uint8ArrayGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
4
- export declare const textEncoderGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
5
- /** A `TextDecoder` holding the host decoder its label and options configured. */
6
- export declare class TextDecoderObj extends Obj {
7
- readonly decoder: TextDecoder;
8
- constructor(proto: Obj, decoder: TextDecoder);
9
- }
10
- export declare const textDecoderGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;