@ccheever/exact-ibex-runtime 0.1.0

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 (161) hide show
  1. package/package.json +63 -0
  2. package/src/abort/AbortController.ts +23 -0
  3. package/src/abort/AbortSignal.ts +152 -0
  4. package/src/abort/index.ts +2 -0
  5. package/src/accessibility.ts +12 -0
  6. package/src/arraybuffer-detach.ts +109 -0
  7. package/src/base64/base64.ts +168 -0
  8. package/src/base64/index.ts +1 -0
  9. package/src/blob/Blob.ts +259 -0
  10. package/src/blob/File.ts +59 -0
  11. package/src/blob/FormData.ts +323 -0
  12. package/src/blob/index.ts +3 -0
  13. package/src/bootstrap.ts +1946 -0
  14. package/src/broadcast/BroadcastChannel.ts +280 -0
  15. package/src/broadcast/index.ts +5 -0
  16. package/src/cache/Cache.ts +349 -0
  17. package/src/cache/CacheStorage.ts +89 -0
  18. package/src/cache/index.ts +27 -0
  19. package/src/camera/index.ts +6202 -0
  20. package/src/camera/processor.worker.ts +194 -0
  21. package/src/camera/scene.ts +195 -0
  22. package/src/clipboard/Clipboard.ts +129 -0
  23. package/src/clipboard/ClipboardItem.ts +97 -0
  24. package/src/clipboard/index.ts +6 -0
  25. package/src/clone/index.ts +1 -0
  26. package/src/clone/structuredClone.ts +389 -0
  27. package/src/clone/transferableSymbols.ts +2 -0
  28. package/src/compression/CompressionStream.ts +146 -0
  29. package/src/compression/DecompressionStream.ts +342 -0
  30. package/src/compression/index.ts +4 -0
  31. package/src/console/Console.ts +341 -0
  32. package/src/console/index.ts +2 -0
  33. package/src/core/accessibility-state.ts +263 -0
  34. package/src/core/accessibility.ts +184 -0
  35. package/src/core/agent-state.ts +37 -0
  36. package/src/core/diagnostics-logs.ts +144 -0
  37. package/src/core/host-call-bridge.ts +16 -0
  38. package/src/core/i18n-helpers.ts +189 -0
  39. package/src/core/locale-state.ts +253 -0
  40. package/src/core/locale.ts +95 -0
  41. package/src/crypto/Crypto.ts +2743 -0
  42. package/src/crypto/index.ts +1 -0
  43. package/src/diagnostics/logs.ts +7 -0
  44. package/src/encoding/TextDecoder.ts +1181 -0
  45. package/src/encoding/TextDecoderStream.ts +58 -0
  46. package/src/encoding/TextEncoder.ts +180 -0
  47. package/src/encoding/TextEncoderStream.ts +39 -0
  48. package/src/encoding/index.ts +8 -0
  49. package/src/events/CloseEvent.ts +91 -0
  50. package/src/events/DOMException.ts +409 -0
  51. package/src/events/ErrorEvent.ts +39 -0
  52. package/src/events/Event.ts +151 -0
  53. package/src/events/EventTarget.ts +280 -0
  54. package/src/events/FocusEvent.ts +27 -0
  55. package/src/events/KeyboardEvent.ts +46 -0
  56. package/src/events/MessageEvent.ts +61 -0
  57. package/src/events/ProgressEvent.ts +33 -0
  58. package/src/events/PromiseRejectionEvent.ts +31 -0
  59. package/src/events/index.ts +52 -0
  60. package/src/eventsource/EventSource.ts +371 -0
  61. package/src/eventsource/index.ts +2 -0
  62. package/src/fetch/Headers.ts +642 -0
  63. package/src/fetch/Request.ts +760 -0
  64. package/src/fetch/Response.ts +543 -0
  65. package/src/fetch/body.ts +1256 -0
  66. package/src/fetch/cookie-jar.ts +566 -0
  67. package/src/fetch/demo.ts +207 -0
  68. package/src/fetch/errors.ts +101 -0
  69. package/src/fetch/fetch.ts +2610 -0
  70. package/src/fetch/index.ts +101 -0
  71. package/src/fetch/native-bridge.ts +65 -0
  72. package/src/fetch/types.ts +258 -0
  73. package/src/filereader/FileReader.ts +236 -0
  74. package/src/filereader/index.ts +1 -0
  75. package/src/fs/Dirent.ts +39 -0
  76. package/src/fs/ExactFile.ts +450 -0
  77. package/src/fs/Stats.ts +80 -0
  78. package/src/fs/index.ts +944 -0
  79. package/src/fs/promises.ts +386 -0
  80. package/src/fs/shared.ts +328 -0
  81. package/src/http-server/index.js +697 -0
  82. package/src/http-server/index.ts +27 -0
  83. package/src/identity.generated.ts +14 -0
  84. package/src/index.ts +283 -0
  85. package/src/indexeddb/IDBCursor.ts +188 -0
  86. package/src/indexeddb/IDBDatabase.ts +343 -0
  87. package/src/indexeddb/IDBFactory.ts +269 -0
  88. package/src/indexeddb/IDBIndex.ts +194 -0
  89. package/src/indexeddb/IDBKeyRange.ts +109 -0
  90. package/src/indexeddb/IDBObjectStore.ts +468 -0
  91. package/src/indexeddb/IDBRequest.ts +163 -0
  92. package/src/indexeddb/IDBTransaction.ts +207 -0
  93. package/src/indexeddb/index.ts +34 -0
  94. package/src/indexeddb/utils.ts +52 -0
  95. package/src/inspect/index.ts +1 -0
  96. package/src/inspect/inspect.ts +465 -0
  97. package/src/internal/detect.ts +104 -0
  98. package/src/locale.ts +10 -0
  99. package/src/location/index.ts +1059 -0
  100. package/src/locks/LockManager.ts +460 -0
  101. package/src/locks/index.ts +12 -0
  102. package/src/media/VideoFrame.ts +58 -0
  103. package/src/messaging/MessageChannel.ts +31 -0
  104. package/src/messaging/MessagePort.ts +180 -0
  105. package/src/messaging/index.ts +2 -0
  106. package/src/messaging.ts +247 -0
  107. package/src/native/NativeModules.ts +354 -0
  108. package/src/native/index.ts +1 -0
  109. package/src/navigator/Navigator.ts +351 -0
  110. package/src/navigator/index.ts +1 -0
  111. package/src/node/Buffer.ts +1786 -0
  112. package/src/node/index.ts +4 -0
  113. package/src/node/path.ts +495 -0
  114. package/src/node/process.ts +2528 -0
  115. package/src/performance/Performance.ts +532 -0
  116. package/src/performance/index.ts +21 -0
  117. package/src/polyfills/array.ts +236 -0
  118. package/src/polyfills/arraybuffer.ts +172 -0
  119. package/src/polyfills/groupby.ts +85 -0
  120. package/src/polyfills/index.ts +85 -0
  121. package/src/polyfills/intl.ts +1956 -0
  122. package/src/polyfills/iterator.ts +479 -0
  123. package/src/polyfills/promise.ts +37 -0
  124. package/src/polyfills/set.ts +245 -0
  125. package/src/polyfills/string.ts +85 -0
  126. package/src/polyfills/typedarray.ts +110 -0
  127. package/src/promise-rejection-tracking.ts +464 -0
  128. package/src/react-native/index.ts +388 -0
  129. package/src/runtime-entry.ts +55 -0
  130. package/src/scheduling/AnimationFrame.ts +105 -0
  131. package/src/scheduling/IdleCallback.ts +167 -0
  132. package/src/scheduling/index.ts +13 -0
  133. package/src/security/Capabilities.ts +1146 -0
  134. package/src/security/Permissions.ts +392 -0
  135. package/src/security/capability-bits.generated.ts +63 -0
  136. package/src/security/index.ts +16 -0
  137. package/src/sqlite/Database.ts +456 -0
  138. package/src/sqlite/Statement.ts +206 -0
  139. package/src/sqlite/constants.ts +79 -0
  140. package/src/sqlite/errors.ts +25 -0
  141. package/src/sqlite/index.ts +34 -0
  142. package/src/sqlite/module.js +438 -0
  143. package/src/storage/Storage.ts +291 -0
  144. package/src/storage/StorageManager.ts +91 -0
  145. package/src/storage/index.ts +3 -0
  146. package/src/stream-compat.ts +47 -0
  147. package/src/streams/ReadableStream.ts +4131 -0
  148. package/src/streams/TransformStream.ts +375 -0
  149. package/src/streams/WritableStream.ts +866 -0
  150. package/src/streams/index.ts +41 -0
  151. package/src/timers/Timers.ts +296 -0
  152. package/src/timers/index.ts +11 -0
  153. package/src/url/URL.ts +656 -0
  154. package/src/url/URLPattern.ts +850 -0
  155. package/src/url/URLSearchParams.ts +244 -0
  156. package/src/url/index.ts +9 -0
  157. package/src/websocket/WebSocket.ts +770 -0
  158. package/src/websocket/WebSocketError.ts +52 -0
  159. package/src/websocket/WebSocketStream.ts +628 -0
  160. package/src/websocket/index.ts +7 -0
  161. package/src/window/index.ts +872 -0
@@ -0,0 +1,479 @@
1
+ /**
2
+ * ES2025 Iterator Helpers polyfills for Hermes engine
3
+ *
4
+ * - Iterator.prototype.map()
5
+ * - Iterator.prototype.filter()
6
+ * - Iterator.prototype.take()
7
+ * - Iterator.prototype.drop()
8
+ * - Iterator.prototype.flatMap()
9
+ * - Iterator.prototype.reduce()
10
+ * - Iterator.prototype.toArray()
11
+ * - Iterator.prototype.forEach()
12
+ * - Iterator.prototype.some()
13
+ * - Iterator.prototype.every()
14
+ * - Iterator.prototype.find()
15
+ * - Iterator.from()
16
+ */
17
+
18
+ export function installIteratorPolyfills(): void {
19
+ const g = globalThis as any;
20
+
21
+ // We need the Iterator constructor. If it doesn't exist, create it.
22
+ // Per the spec, Iterator is a global constructor with a prototype that
23
+ // iterator helpers live on.
24
+ let IteratorConstructor: any = g.Iterator;
25
+
26
+ if (typeof IteratorConstructor !== 'function') {
27
+ // Create the Iterator constructor
28
+ IteratorConstructor = function Iterator(this: any) {
29
+ if (new.target === IteratorConstructor) {
30
+ throw new TypeError('Iterator is not directly constructible');
31
+ }
32
+ };
33
+
34
+ IteratorConstructor.prototype = Object.create(null);
35
+ Object.defineProperty(IteratorConstructor.prototype, Symbol.iterator, {
36
+ value: function() { return this; },
37
+ writable: true,
38
+ enumerable: false,
39
+ configurable: true,
40
+ });
41
+ Object.defineProperty(IteratorConstructor.prototype, 'constructor', {
42
+ value: IteratorConstructor,
43
+ writable: true,
44
+ enumerable: false,
45
+ configurable: true,
46
+ });
47
+ Object.defineProperty(IteratorConstructor.prototype, Symbol.toStringTag, {
48
+ value: 'Iterator',
49
+ writable: false,
50
+ enumerable: false,
51
+ configurable: true,
52
+ });
53
+
54
+ Object.defineProperty(g, 'Iterator', {
55
+ value: IteratorConstructor,
56
+ writable: true,
57
+ enumerable: false,
58
+ configurable: true,
59
+ });
60
+ }
61
+
62
+ const IteratorProto = IteratorConstructor.prototype;
63
+
64
+ /**
65
+ * Helper to create a wrapper iterator that inherits from Iterator.prototype.
66
+ */
67
+ function createIteratorHelper(
68
+ nextFn: () => IteratorResult<any>,
69
+ returnFn?: () => IteratorResult<any>,
70
+ ): any {
71
+ const iter = Object.create(IteratorProto);
72
+ Object.defineProperty(iter, 'next', {
73
+ value: nextFn,
74
+ writable: true,
75
+ enumerable: false,
76
+ configurable: true,
77
+ });
78
+ if (returnFn) {
79
+ Object.defineProperty(iter, 'return', {
80
+ value: returnFn,
81
+ writable: true,
82
+ enumerable: false,
83
+ configurable: true,
84
+ });
85
+ }
86
+ return iter;
87
+ }
88
+
89
+ // --------------------------------------------------------------------------
90
+ // Iterator.prototype.map
91
+ // --------------------------------------------------------------------------
92
+ if (typeof IteratorProto.map !== 'function') {
93
+ Object.defineProperty(IteratorProto, 'map', {
94
+ value: function map(this: any, mapper: (value: any, index: number) => any): any {
95
+ if (typeof mapper !== 'function') {
96
+ throw new TypeError('mapper must be a function');
97
+ }
98
+ const source = this;
99
+ let index = 0;
100
+ return createIteratorHelper(
101
+ function next() {
102
+ const result = source.next();
103
+ if (result.done) return result;
104
+ return { value: mapper(result.value, index++), done: false };
105
+ },
106
+ function returnFn() {
107
+ if (typeof source.return === 'function') return source.return();
108
+ return { value: undefined, done: true };
109
+ },
110
+ );
111
+ },
112
+ writable: true,
113
+ enumerable: false,
114
+ configurable: true,
115
+ });
116
+ }
117
+
118
+ // --------------------------------------------------------------------------
119
+ // Iterator.prototype.filter
120
+ // --------------------------------------------------------------------------
121
+ if (typeof IteratorProto.filter !== 'function') {
122
+ Object.defineProperty(IteratorProto, 'filter', {
123
+ value: function filter(this: any, predicate: (value: any, index: number) => boolean): any {
124
+ if (typeof predicate !== 'function') {
125
+ throw new TypeError('predicate must be a function');
126
+ }
127
+ const source = this;
128
+ let index = 0;
129
+ return createIteratorHelper(
130
+ function next(): IteratorResult<any> {
131
+ while (true) {
132
+ const result = source.next();
133
+ if (result.done) return result;
134
+ if (predicate(result.value, index++)) {
135
+ return { value: result.value, done: false };
136
+ }
137
+ }
138
+ },
139
+ function returnFn() {
140
+ if (typeof source.return === 'function') return source.return();
141
+ return { value: undefined, done: true };
142
+ },
143
+ );
144
+ },
145
+ writable: true,
146
+ enumerable: false,
147
+ configurable: true,
148
+ });
149
+ }
150
+
151
+ // --------------------------------------------------------------------------
152
+ // Iterator.prototype.take
153
+ // --------------------------------------------------------------------------
154
+ if (typeof IteratorProto.take !== 'function') {
155
+ Object.defineProperty(IteratorProto, 'take', {
156
+ value: function take(this: any, limit: number): any {
157
+ const n = Number(limit);
158
+ if (!Number.isInteger(n) || n < 0) {
159
+ throw new RangeError('take argument must be a non-negative integer');
160
+ }
161
+ const source = this;
162
+ let remaining = n;
163
+ return createIteratorHelper(
164
+ function next() {
165
+ if (remaining <= 0) {
166
+ return { value: undefined, done: true };
167
+ }
168
+ remaining--;
169
+ const result = source.next();
170
+ if (result.done) remaining = 0;
171
+ return result;
172
+ },
173
+ function returnFn() {
174
+ if (typeof source.return === 'function') return source.return();
175
+ return { value: undefined, done: true };
176
+ },
177
+ );
178
+ },
179
+ writable: true,
180
+ enumerable: false,
181
+ configurable: true,
182
+ });
183
+ }
184
+
185
+ // --------------------------------------------------------------------------
186
+ // Iterator.prototype.drop
187
+ // --------------------------------------------------------------------------
188
+ if (typeof IteratorProto.drop !== 'function') {
189
+ Object.defineProperty(IteratorProto, 'drop', {
190
+ value: function drop(this: any, count: number): any {
191
+ const n = Number(count);
192
+ if (!Number.isInteger(n) || n < 0) {
193
+ throw new RangeError('drop argument must be a non-negative integer');
194
+ }
195
+ const source = this;
196
+ let dropped = false;
197
+ return createIteratorHelper(
198
+ function next() {
199
+ if (!dropped) {
200
+ dropped = true;
201
+ for (let i = 0; i < n; i++) {
202
+ const result = source.next();
203
+ if (result.done) return result;
204
+ }
205
+ }
206
+ return source.next();
207
+ },
208
+ function returnFn() {
209
+ if (typeof source.return === 'function') return source.return();
210
+ return { value: undefined, done: true };
211
+ },
212
+ );
213
+ },
214
+ writable: true,
215
+ enumerable: false,
216
+ configurable: true,
217
+ });
218
+ }
219
+
220
+ // --------------------------------------------------------------------------
221
+ // Iterator.prototype.flatMap
222
+ // --------------------------------------------------------------------------
223
+ if (typeof IteratorProto.flatMap !== 'function') {
224
+ Object.defineProperty(IteratorProto, 'flatMap', {
225
+ value: function flatMap(this: any, mapper: (value: any, index: number) => any): any {
226
+ if (typeof mapper !== 'function') {
227
+ throw new TypeError('mapper must be a function');
228
+ }
229
+ const source = this;
230
+ let index = 0;
231
+ let innerIterator: any = null;
232
+ return createIteratorHelper(
233
+ function next(): IteratorResult<any> {
234
+ while (true) {
235
+ if (innerIterator !== null) {
236
+ const innerResult = innerIterator.next();
237
+ if (!innerResult.done) {
238
+ return { value: innerResult.value, done: false };
239
+ }
240
+ innerIterator = null;
241
+ }
242
+ const result = source.next();
243
+ if (result.done) return result;
244
+ const mapped = mapper(result.value, index++);
245
+ // Per TC39 spec, the result must be an object (GetIteratorFlattenable)
246
+ if (mapped == null || typeof mapped !== 'object') {
247
+ throw new TypeError(
248
+ 'GetIteratorFlattenable expects its first argument to be an object',
249
+ );
250
+ }
251
+ if (typeof mapped[Symbol.iterator] === 'function') {
252
+ innerIterator = mapped[Symbol.iterator]();
253
+ } else if (typeof mapped.next === 'function') {
254
+ innerIterator = mapped;
255
+ } else {
256
+ throw new TypeError(
257
+ 'GetIteratorFlattenable expects its first argument to be an object',
258
+ );
259
+ }
260
+ }
261
+ },
262
+ function returnFn() {
263
+ if (innerIterator && typeof innerIterator.return === 'function') {
264
+ innerIterator.return();
265
+ }
266
+ if (typeof source.return === 'function') return source.return();
267
+ return { value: undefined, done: true };
268
+ },
269
+ );
270
+ },
271
+ writable: true,
272
+ enumerable: false,
273
+ configurable: true,
274
+ });
275
+ }
276
+
277
+ // --------------------------------------------------------------------------
278
+ // Iterator.prototype.reduce
279
+ // --------------------------------------------------------------------------
280
+ if (typeof IteratorProto.reduce !== 'function') {
281
+ Object.defineProperty(IteratorProto, 'reduce', {
282
+ value: function reduce(
283
+ this: any,
284
+ reducer: (accumulator: any, value: any, index: number) => any,
285
+ ...args: any[]
286
+ ): any {
287
+ if (typeof reducer !== 'function') {
288
+ throw new TypeError('reducer must be a function');
289
+ }
290
+ const source = this;
291
+ let accumulator: any;
292
+ let index = 0;
293
+
294
+ if (args.length > 0) {
295
+ accumulator = args[0];
296
+ } else {
297
+ const first = source.next();
298
+ if (first.done) {
299
+ throw new TypeError('Reduce of empty iterator with no initial value');
300
+ }
301
+ accumulator = first.value;
302
+ index = 1;
303
+ }
304
+
305
+ while (true) {
306
+ const result = source.next();
307
+ if (result.done) break;
308
+ accumulator = reducer(accumulator, result.value, index++);
309
+ }
310
+
311
+ return accumulator;
312
+ },
313
+ writable: true,
314
+ enumerable: false,
315
+ configurable: true,
316
+ });
317
+ }
318
+
319
+ // --------------------------------------------------------------------------
320
+ // Iterator.prototype.toArray
321
+ // --------------------------------------------------------------------------
322
+ if (typeof IteratorProto.toArray !== 'function') {
323
+ Object.defineProperty(IteratorProto, 'toArray', {
324
+ value: function toArray(this: any): any[] {
325
+ const result: any[] = [];
326
+ while (true) {
327
+ const item = this.next();
328
+ if (item.done) break;
329
+ result.push(item.value);
330
+ }
331
+ return result;
332
+ },
333
+ writable: true,
334
+ enumerable: false,
335
+ configurable: true,
336
+ });
337
+ }
338
+
339
+ // --------------------------------------------------------------------------
340
+ // Iterator.prototype.forEach
341
+ // --------------------------------------------------------------------------
342
+ if (typeof IteratorProto.forEach !== 'function') {
343
+ Object.defineProperty(IteratorProto, 'forEach', {
344
+ value: function forEach(this: any, fn: (value: any, index: number) => void): void {
345
+ if (typeof fn !== 'function') {
346
+ throw new TypeError('fn must be a function');
347
+ }
348
+ let index = 0;
349
+ while (true) {
350
+ const result = this.next();
351
+ if (result.done) break;
352
+ fn(result.value, index++);
353
+ }
354
+ },
355
+ writable: true,
356
+ enumerable: false,
357
+ configurable: true,
358
+ });
359
+ }
360
+
361
+ // --------------------------------------------------------------------------
362
+ // Iterator.prototype.some
363
+ // --------------------------------------------------------------------------
364
+ if (typeof IteratorProto.some !== 'function') {
365
+ Object.defineProperty(IteratorProto, 'some', {
366
+ value: function some(this: any, predicate: (value: any, index: number) => boolean): boolean {
367
+ if (typeof predicate !== 'function') {
368
+ throw new TypeError('predicate must be a function');
369
+ }
370
+ let index = 0;
371
+ while (true) {
372
+ const result = this.next();
373
+ if (result.done) return false;
374
+ if (predicate(result.value, index++)) return true;
375
+ }
376
+ },
377
+ writable: true,
378
+ enumerable: false,
379
+ configurable: true,
380
+ });
381
+ }
382
+
383
+ // --------------------------------------------------------------------------
384
+ // Iterator.prototype.every
385
+ // --------------------------------------------------------------------------
386
+ if (typeof IteratorProto.every !== 'function') {
387
+ Object.defineProperty(IteratorProto, 'every', {
388
+ value: function every(this: any, predicate: (value: any, index: number) => boolean): boolean {
389
+ if (typeof predicate !== 'function') {
390
+ throw new TypeError('predicate must be a function');
391
+ }
392
+ let index = 0;
393
+ while (true) {
394
+ const result = this.next();
395
+ if (result.done) return true;
396
+ if (!predicate(result.value, index++)) return false;
397
+ }
398
+ },
399
+ writable: true,
400
+ enumerable: false,
401
+ configurable: true,
402
+ });
403
+ }
404
+
405
+ // --------------------------------------------------------------------------
406
+ // Iterator.prototype.find
407
+ // --------------------------------------------------------------------------
408
+ if (typeof IteratorProto.find !== 'function') {
409
+ Object.defineProperty(IteratorProto, 'find', {
410
+ value: function find(
411
+ this: any,
412
+ predicate: (value: any, index: number) => boolean,
413
+ ): any | undefined {
414
+ if (typeof predicate !== 'function') {
415
+ throw new TypeError('predicate must be a function');
416
+ }
417
+ let index = 0;
418
+ while (true) {
419
+ const result = this.next();
420
+ if (result.done) return undefined;
421
+ if (predicate(result.value, index++)) return result.value;
422
+ }
423
+ },
424
+ writable: true,
425
+ enumerable: false,
426
+ configurable: true,
427
+ });
428
+ }
429
+
430
+ // --------------------------------------------------------------------------
431
+ // Iterator.from (static)
432
+ // Wraps a value into an Iterator. Accepts iterables and iterator-like objects.
433
+ // --------------------------------------------------------------------------
434
+ if (typeof IteratorConstructor.from !== 'function') {
435
+ Object.defineProperty(IteratorConstructor, 'from', {
436
+ value: function from(value: any): any {
437
+ if (value == null) {
438
+ throw new TypeError('Iterator.from requires a non-null value');
439
+ }
440
+
441
+ // If it's already an Iterator instance, return as-is
442
+ if (value instanceof IteratorConstructor) {
443
+ return value;
444
+ }
445
+
446
+ let iterator: any;
447
+
448
+ // Try [Symbol.iterator]
449
+ if (typeof value[Symbol.iterator] === 'function') {
450
+ iterator = value[Symbol.iterator]();
451
+ } else if (typeof value.next === 'function') {
452
+ // It's already an iterator-like (has .next())
453
+ iterator = value;
454
+ } else {
455
+ throw new TypeError('Value is not iterable or iterator-like');
456
+ }
457
+
458
+ // If the iterator already inherits from Iterator.prototype, return it
459
+ if (iterator instanceof IteratorConstructor) {
460
+ return iterator;
461
+ }
462
+
463
+ // Wrap it in an Iterator.prototype-based object
464
+ return createIteratorHelper(
465
+ function next() {
466
+ return iterator.next();
467
+ },
468
+ function returnFn() {
469
+ if (typeof iterator.return === 'function') return iterator.return();
470
+ return { value: undefined, done: true };
471
+ },
472
+ );
473
+ },
474
+ writable: true,
475
+ enumerable: false,
476
+ configurable: true,
477
+ });
478
+ }
479
+ }
@@ -0,0 +1,37 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * ES2024 Promise.withResolvers polyfill for Hermes engine
4
+ *
5
+ * - Promise.withResolvers()
6
+ */
7
+
8
+ export function installPromisePolyfills(): void {
9
+ // --------------------------------------------------------------------------
10
+ // Promise.withResolvers (ES2024)
11
+ // Returns an object with { promise, resolve, reject }.
12
+ // Equivalent to:
13
+ // let resolve, reject;
14
+ // const promise = new Promise((res, rej) => { resolve = res; reject = rej; });
15
+ // return { promise, resolve, reject };
16
+ // --------------------------------------------------------------------------
17
+ if (typeof Promise.withResolvers !== 'function') {
18
+ Object.defineProperty(Promise, 'withResolvers', {
19
+ value: function withResolvers<T>(): {
20
+ promise: Promise<T>;
21
+ resolve: (value: T | PromiseLike<T>) => void;
22
+ reject: (reason?: any) => void;
23
+ } {
24
+ let resolve!: (value: T | PromiseLike<T>) => void;
25
+ let reject!: (reason?: any) => void;
26
+ const promise = new Promise<T>((res, rej) => {
27
+ resolve = res;
28
+ reject = rej;
29
+ });
30
+ return { promise, resolve, reject };
31
+ },
32
+ writable: true,
33
+ enumerable: false,
34
+ configurable: true,
35
+ });
36
+ }
37
+ }