@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.
- package/package.json +63 -0
- package/src/abort/AbortController.ts +23 -0
- package/src/abort/AbortSignal.ts +152 -0
- package/src/abort/index.ts +2 -0
- package/src/accessibility.ts +12 -0
- package/src/arraybuffer-detach.ts +109 -0
- package/src/base64/base64.ts +168 -0
- package/src/base64/index.ts +1 -0
- package/src/blob/Blob.ts +259 -0
- package/src/blob/File.ts +59 -0
- package/src/blob/FormData.ts +323 -0
- package/src/blob/index.ts +3 -0
- package/src/bootstrap.ts +1946 -0
- package/src/broadcast/BroadcastChannel.ts +280 -0
- package/src/broadcast/index.ts +5 -0
- package/src/cache/Cache.ts +349 -0
- package/src/cache/CacheStorage.ts +89 -0
- package/src/cache/index.ts +27 -0
- package/src/camera/index.ts +6202 -0
- package/src/camera/processor.worker.ts +194 -0
- package/src/camera/scene.ts +195 -0
- package/src/clipboard/Clipboard.ts +129 -0
- package/src/clipboard/ClipboardItem.ts +97 -0
- package/src/clipboard/index.ts +6 -0
- package/src/clone/index.ts +1 -0
- package/src/clone/structuredClone.ts +389 -0
- package/src/clone/transferableSymbols.ts +2 -0
- package/src/compression/CompressionStream.ts +146 -0
- package/src/compression/DecompressionStream.ts +342 -0
- package/src/compression/index.ts +4 -0
- package/src/console/Console.ts +341 -0
- package/src/console/index.ts +2 -0
- package/src/core/accessibility-state.ts +263 -0
- package/src/core/accessibility.ts +184 -0
- package/src/core/agent-state.ts +37 -0
- package/src/core/diagnostics-logs.ts +144 -0
- package/src/core/host-call-bridge.ts +16 -0
- package/src/core/i18n-helpers.ts +189 -0
- package/src/core/locale-state.ts +253 -0
- package/src/core/locale.ts +95 -0
- package/src/crypto/Crypto.ts +2743 -0
- package/src/crypto/index.ts +1 -0
- package/src/diagnostics/logs.ts +7 -0
- package/src/encoding/TextDecoder.ts +1181 -0
- package/src/encoding/TextDecoderStream.ts +58 -0
- package/src/encoding/TextEncoder.ts +180 -0
- package/src/encoding/TextEncoderStream.ts +39 -0
- package/src/encoding/index.ts +8 -0
- package/src/events/CloseEvent.ts +91 -0
- package/src/events/DOMException.ts +409 -0
- package/src/events/ErrorEvent.ts +39 -0
- package/src/events/Event.ts +151 -0
- package/src/events/EventTarget.ts +280 -0
- package/src/events/FocusEvent.ts +27 -0
- package/src/events/KeyboardEvent.ts +46 -0
- package/src/events/MessageEvent.ts +61 -0
- package/src/events/ProgressEvent.ts +33 -0
- package/src/events/PromiseRejectionEvent.ts +31 -0
- package/src/events/index.ts +52 -0
- package/src/eventsource/EventSource.ts +371 -0
- package/src/eventsource/index.ts +2 -0
- package/src/fetch/Headers.ts +642 -0
- package/src/fetch/Request.ts +760 -0
- package/src/fetch/Response.ts +543 -0
- package/src/fetch/body.ts +1256 -0
- package/src/fetch/cookie-jar.ts +566 -0
- package/src/fetch/demo.ts +207 -0
- package/src/fetch/errors.ts +101 -0
- package/src/fetch/fetch.ts +2610 -0
- package/src/fetch/index.ts +101 -0
- package/src/fetch/native-bridge.ts +65 -0
- package/src/fetch/types.ts +258 -0
- package/src/filereader/FileReader.ts +236 -0
- package/src/filereader/index.ts +1 -0
- package/src/fs/Dirent.ts +39 -0
- package/src/fs/ExactFile.ts +450 -0
- package/src/fs/Stats.ts +80 -0
- package/src/fs/index.ts +944 -0
- package/src/fs/promises.ts +386 -0
- package/src/fs/shared.ts +328 -0
- package/src/http-server/index.js +697 -0
- package/src/http-server/index.ts +27 -0
- package/src/identity.generated.ts +14 -0
- package/src/index.ts +283 -0
- package/src/indexeddb/IDBCursor.ts +188 -0
- package/src/indexeddb/IDBDatabase.ts +343 -0
- package/src/indexeddb/IDBFactory.ts +269 -0
- package/src/indexeddb/IDBIndex.ts +194 -0
- package/src/indexeddb/IDBKeyRange.ts +109 -0
- package/src/indexeddb/IDBObjectStore.ts +468 -0
- package/src/indexeddb/IDBRequest.ts +163 -0
- package/src/indexeddb/IDBTransaction.ts +207 -0
- package/src/indexeddb/index.ts +34 -0
- package/src/indexeddb/utils.ts +52 -0
- package/src/inspect/index.ts +1 -0
- package/src/inspect/inspect.ts +465 -0
- package/src/internal/detect.ts +104 -0
- package/src/locale.ts +10 -0
- package/src/location/index.ts +1059 -0
- package/src/locks/LockManager.ts +460 -0
- package/src/locks/index.ts +12 -0
- package/src/media/VideoFrame.ts +58 -0
- package/src/messaging/MessageChannel.ts +31 -0
- package/src/messaging/MessagePort.ts +180 -0
- package/src/messaging/index.ts +2 -0
- package/src/messaging.ts +247 -0
- package/src/native/NativeModules.ts +354 -0
- package/src/native/index.ts +1 -0
- package/src/navigator/Navigator.ts +351 -0
- package/src/navigator/index.ts +1 -0
- package/src/node/Buffer.ts +1786 -0
- package/src/node/index.ts +4 -0
- package/src/node/path.ts +495 -0
- package/src/node/process.ts +2528 -0
- package/src/performance/Performance.ts +532 -0
- package/src/performance/index.ts +21 -0
- package/src/polyfills/array.ts +236 -0
- package/src/polyfills/arraybuffer.ts +172 -0
- package/src/polyfills/groupby.ts +85 -0
- package/src/polyfills/index.ts +85 -0
- package/src/polyfills/intl.ts +1956 -0
- package/src/polyfills/iterator.ts +479 -0
- package/src/polyfills/promise.ts +37 -0
- package/src/polyfills/set.ts +245 -0
- package/src/polyfills/string.ts +85 -0
- package/src/polyfills/typedarray.ts +110 -0
- package/src/promise-rejection-tracking.ts +464 -0
- package/src/react-native/index.ts +388 -0
- package/src/runtime-entry.ts +55 -0
- package/src/scheduling/AnimationFrame.ts +105 -0
- package/src/scheduling/IdleCallback.ts +167 -0
- package/src/scheduling/index.ts +13 -0
- package/src/security/Capabilities.ts +1146 -0
- package/src/security/Permissions.ts +392 -0
- package/src/security/capability-bits.generated.ts +63 -0
- package/src/security/index.ts +16 -0
- package/src/sqlite/Database.ts +456 -0
- package/src/sqlite/Statement.ts +206 -0
- package/src/sqlite/constants.ts +79 -0
- package/src/sqlite/errors.ts +25 -0
- package/src/sqlite/index.ts +34 -0
- package/src/sqlite/module.js +438 -0
- package/src/storage/Storage.ts +291 -0
- package/src/storage/StorageManager.ts +91 -0
- package/src/storage/index.ts +3 -0
- package/src/stream-compat.ts +47 -0
- package/src/streams/ReadableStream.ts +4131 -0
- package/src/streams/TransformStream.ts +375 -0
- package/src/streams/WritableStream.ts +866 -0
- package/src/streams/index.ts +41 -0
- package/src/timers/Timers.ts +296 -0
- package/src/timers/index.ts +11 -0
- package/src/url/URL.ts +656 -0
- package/src/url/URLPattern.ts +850 -0
- package/src/url/URLSearchParams.ts +244 -0
- package/src/url/index.ts +9 -0
- package/src/websocket/WebSocket.ts +770 -0
- package/src/websocket/WebSocketError.ts +52 -0
- package/src/websocket/WebSocketStream.ts +628 -0
- package/src/websocket/index.ts +7 -0
- package/src/window/index.ts +872 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* ES2023+ Array polyfills for Hermes engine
|
|
4
|
+
*
|
|
5
|
+
* - Array.prototype.toSorted()
|
|
6
|
+
* - Array.prototype.toReversed()
|
|
7
|
+
* - Array.prototype.with()
|
|
8
|
+
* - Array.prototype.toSpliced()
|
|
9
|
+
* - Array.fromAsync()
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export function installArrayPolyfills(): void {
|
|
13
|
+
// --------------------------------------------------------------------------
|
|
14
|
+
// Array.prototype.toSorted (ES2023)
|
|
15
|
+
// Returns a new sorted array without mutating the original.
|
|
16
|
+
// --------------------------------------------------------------------------
|
|
17
|
+
if (typeof Array.prototype.toSorted !== 'function') {
|
|
18
|
+
Object.defineProperty(Array.prototype, 'toSorted', {
|
|
19
|
+
value: function toSorted(
|
|
20
|
+
this: any[],
|
|
21
|
+
compareFn?: (a: any, b: any) => number,
|
|
22
|
+
): any[] {
|
|
23
|
+
if (this == null) {
|
|
24
|
+
throw new TypeError('Array.prototype.toSorted called on null or undefined');
|
|
25
|
+
}
|
|
26
|
+
const o = Object(this);
|
|
27
|
+
const len = o.length >>> 0;
|
|
28
|
+
const copy = new Array(len);
|
|
29
|
+
for (let i = 0; i < len; i++) {
|
|
30
|
+
copy[i] = o[i];
|
|
31
|
+
}
|
|
32
|
+
copy.sort(compareFn);
|
|
33
|
+
return copy;
|
|
34
|
+
},
|
|
35
|
+
writable: true,
|
|
36
|
+
enumerable: false,
|
|
37
|
+
configurable: true,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// --------------------------------------------------------------------------
|
|
42
|
+
// Array.prototype.toReversed (ES2023)
|
|
43
|
+
// Returns a new reversed array without mutating the original.
|
|
44
|
+
// --------------------------------------------------------------------------
|
|
45
|
+
if (typeof Array.prototype.toReversed !== 'function') {
|
|
46
|
+
Object.defineProperty(Array.prototype, 'toReversed', {
|
|
47
|
+
value: function toReversed(this: any[]): any[] {
|
|
48
|
+
if (this == null) {
|
|
49
|
+
throw new TypeError('Array.prototype.toReversed called on null or undefined');
|
|
50
|
+
}
|
|
51
|
+
const o = Object(this);
|
|
52
|
+
const len = o.length >>> 0;
|
|
53
|
+
const result = new Array(len);
|
|
54
|
+
for (let i = 0; i < len; i++) {
|
|
55
|
+
result[i] = o[len - 1 - i];
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
},
|
|
59
|
+
writable: true,
|
|
60
|
+
enumerable: false,
|
|
61
|
+
configurable: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// --------------------------------------------------------------------------
|
|
66
|
+
// Array.prototype.with (ES2023)
|
|
67
|
+
// Returns a new array with the element at the given index replaced.
|
|
68
|
+
// --------------------------------------------------------------------------
|
|
69
|
+
if (typeof (Array.prototype as any).with !== 'function') {
|
|
70
|
+
Object.defineProperty(Array.prototype, 'with', {
|
|
71
|
+
value: function withMethod(this: any[], index: number, value: any): any[] {
|
|
72
|
+
if (this == null) {
|
|
73
|
+
throw new TypeError('Array.prototype.with called on null or undefined');
|
|
74
|
+
}
|
|
75
|
+
const o = Object(this);
|
|
76
|
+
const len = o.length >>> 0;
|
|
77
|
+
const relativeIndex = Number(index);
|
|
78
|
+
const actualIndex = relativeIndex < 0 ? len + relativeIndex : relativeIndex;
|
|
79
|
+
if (actualIndex < 0 || actualIndex >= len) {
|
|
80
|
+
throw new RangeError(`Invalid index : ${index}`);
|
|
81
|
+
}
|
|
82
|
+
const result = new Array(len);
|
|
83
|
+
for (let i = 0; i < len; i++) {
|
|
84
|
+
result[i] = i === actualIndex ? value : o[i];
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
},
|
|
88
|
+
writable: true,
|
|
89
|
+
enumerable: false,
|
|
90
|
+
configurable: true,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// --------------------------------------------------------------------------
|
|
95
|
+
// Array.prototype.toSpliced (ES2023)
|
|
96
|
+
// Returns a new array with elements added/removed at the given index.
|
|
97
|
+
// --------------------------------------------------------------------------
|
|
98
|
+
if (typeof Array.prototype.toSpliced !== 'function') {
|
|
99
|
+
Object.defineProperty(Array.prototype, 'toSpliced', {
|
|
100
|
+
value: function toSpliced(
|
|
101
|
+
this: any[],
|
|
102
|
+
start: number,
|
|
103
|
+
deleteCount?: number,
|
|
104
|
+
...items: any[]
|
|
105
|
+
): any[] {
|
|
106
|
+
if (this == null) {
|
|
107
|
+
throw new TypeError('Array.prototype.toSpliced called on null or undefined');
|
|
108
|
+
}
|
|
109
|
+
const o = Object(this);
|
|
110
|
+
const len = o.length >>> 0;
|
|
111
|
+
|
|
112
|
+
// Normalize start
|
|
113
|
+
const relativeStart = Number(start) || 0;
|
|
114
|
+
let actualStart: number;
|
|
115
|
+
if (relativeStart < 0) {
|
|
116
|
+
actualStart = Math.max(len + relativeStart, 0);
|
|
117
|
+
} else {
|
|
118
|
+
actualStart = Math.min(relativeStart, len);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Normalize deleteCount
|
|
122
|
+
let actualDeleteCount: number;
|
|
123
|
+
if (deleteCount === undefined && items.length === 0) {
|
|
124
|
+
// If called with only start, delete everything from start
|
|
125
|
+
actualDeleteCount = len - actualStart;
|
|
126
|
+
} else {
|
|
127
|
+
actualDeleteCount = Math.min(
|
|
128
|
+
Math.max(Number(deleteCount) || 0, 0),
|
|
129
|
+
len - actualStart,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const newLen = len - actualDeleteCount + items.length;
|
|
134
|
+
const result = new Array(newLen);
|
|
135
|
+
let r = 0;
|
|
136
|
+
|
|
137
|
+
// Copy elements before start
|
|
138
|
+
for (let i = 0; i < actualStart; i++) {
|
|
139
|
+
result[r++] = o[i];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Insert new items
|
|
143
|
+
for (let i = 0; i < items.length; i++) {
|
|
144
|
+
result[r++] = items[i];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Copy remaining elements after deleted section
|
|
148
|
+
for (let i = actualStart + actualDeleteCount; i < len; i++) {
|
|
149
|
+
result[r++] = o[i];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return result;
|
|
153
|
+
},
|
|
154
|
+
writable: true,
|
|
155
|
+
enumerable: false,
|
|
156
|
+
configurable: true,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// --------------------------------------------------------------------------
|
|
161
|
+
// Array.fromAsync (ES2024)
|
|
162
|
+
// Creates a new Array from an async iterable or iterable/array-like.
|
|
163
|
+
// --------------------------------------------------------------------------
|
|
164
|
+
if (typeof Array.fromAsync !== 'function') {
|
|
165
|
+
Object.defineProperty(Array, 'fromAsync', {
|
|
166
|
+
value: async function fromAsync(
|
|
167
|
+
arrayLike: any,
|
|
168
|
+
mapFn?: (value: any, index: number) => any,
|
|
169
|
+
thisArg?: any,
|
|
170
|
+
): Promise<any[]> {
|
|
171
|
+
if (mapFn !== undefined && typeof mapFn !== 'function') {
|
|
172
|
+
throw new TypeError('mapFn must be a function');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const result: any[] = [];
|
|
176
|
+
let index = 0;
|
|
177
|
+
|
|
178
|
+
// Try async iterator first
|
|
179
|
+
if (arrayLike != null && typeof arrayLike[Symbol.asyncIterator] === 'function') {
|
|
180
|
+
const iterator = arrayLike[Symbol.asyncIterator]();
|
|
181
|
+
let shouldCloseIterator = false;
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
while (true) {
|
|
185
|
+
const step = await iterator.next();
|
|
186
|
+
if (step.done) {
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Keep the iterator closable while mapping or pushing the current
|
|
191
|
+
// item so abrupt failures mirror for-await cleanup closely enough
|
|
192
|
+
// for our runtime.
|
|
193
|
+
shouldCloseIterator = true;
|
|
194
|
+
const value = mapFn ? await mapFn.call(thisArg, step.value, index) : step.value;
|
|
195
|
+
result.push(value);
|
|
196
|
+
index++;
|
|
197
|
+
shouldCloseIterator = false;
|
|
198
|
+
}
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (shouldCloseIterator && typeof iterator.return === 'function') {
|
|
201
|
+
try {
|
|
202
|
+
await iterator.return();
|
|
203
|
+
} catch {
|
|
204
|
+
// Preserve the original failure from the mapper or consumer.
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Try sync iterator
|
|
212
|
+
if (arrayLike != null && typeof arrayLike[Symbol.iterator] === 'function') {
|
|
213
|
+
for (const item of arrayLike) {
|
|
214
|
+
const awaited = await item;
|
|
215
|
+
const value = mapFn ? await mapFn.call(thisArg, awaited, index) : awaited;
|
|
216
|
+
result.push(value);
|
|
217
|
+
index++;
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Array-like object
|
|
223
|
+
const len = (arrayLike && arrayLike.length) >>> 0;
|
|
224
|
+
for (let i = 0; i < len; i++) {
|
|
225
|
+
const awaited = await arrayLike[i];
|
|
226
|
+
const value = mapFn ? await mapFn.call(thisArg, awaited, i) : awaited;
|
|
227
|
+
result.push(value);
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
},
|
|
231
|
+
writable: true,
|
|
232
|
+
enumerable: false,
|
|
233
|
+
configurable: true,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* ES2024 ArrayBuffer transfer polyfills for Hermes engine
|
|
4
|
+
*
|
|
5
|
+
* - ArrayBuffer.prototype.transfer()
|
|
6
|
+
* - ArrayBuffer.prototype.transferToFixedLength()
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { markDetachedArrayBuffer } from "../arraybuffer-detach";
|
|
10
|
+
|
|
11
|
+
export function installArrayBufferPolyfills(): void {
|
|
12
|
+
const NativeArrayBuffer = ArrayBuffer;
|
|
13
|
+
const resizableBuffers = new WeakSet<ArrayBuffer>();
|
|
14
|
+
const maxByteLengthByBuffer = new WeakMap<ArrayBuffer, number>();
|
|
15
|
+
|
|
16
|
+
if (!(NativeArrayBuffer as any).__exactResizableWrapped) {
|
|
17
|
+
const WrappedArrayBuffer = function ArrayBuffer(
|
|
18
|
+
this: ArrayBuffer,
|
|
19
|
+
length: number,
|
|
20
|
+
options?: { maxByteLength?: number },
|
|
21
|
+
): ArrayBuffer {
|
|
22
|
+
const buffer = new NativeArrayBuffer(length);
|
|
23
|
+
if (options && typeof options === 'object' && options.maxByteLength !== undefined) {
|
|
24
|
+
const maxByteLength = Number(options.maxByteLength);
|
|
25
|
+
if (!Number.isFinite(maxByteLength) || maxByteLength < buffer.byteLength) {
|
|
26
|
+
throw new RangeError('Invalid array buffer max length');
|
|
27
|
+
}
|
|
28
|
+
resizableBuffers.add(buffer);
|
|
29
|
+
maxByteLengthByBuffer.set(buffer, maxByteLength);
|
|
30
|
+
}
|
|
31
|
+
return buffer;
|
|
32
|
+
} as unknown as typeof ArrayBuffer;
|
|
33
|
+
|
|
34
|
+
WrappedArrayBuffer.prototype = NativeArrayBuffer.prototype;
|
|
35
|
+
Object.setPrototypeOf(WrappedArrayBuffer, NativeArrayBuffer);
|
|
36
|
+
Object.defineProperty(WrappedArrayBuffer, '__exactResizableWrapped', {
|
|
37
|
+
value: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
});
|
|
40
|
+
(globalThis as any).ArrayBuffer = WrappedArrayBuffer;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'resizable')) {
|
|
44
|
+
Object.defineProperty(ArrayBuffer.prototype, 'resizable', {
|
|
45
|
+
get: function resizable(this: ArrayBuffer): boolean {
|
|
46
|
+
if (!(this instanceof ArrayBuffer)) {
|
|
47
|
+
throw new TypeError('resizable called on non-ArrayBuffer');
|
|
48
|
+
}
|
|
49
|
+
return resizableBuffers.has(this);
|
|
50
|
+
},
|
|
51
|
+
enumerable: false,
|
|
52
|
+
configurable: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'maxByteLength')) {
|
|
57
|
+
Object.defineProperty(ArrayBuffer.prototype, 'maxByteLength', {
|
|
58
|
+
get: function maxByteLength(this: ArrayBuffer): number {
|
|
59
|
+
if (!(this instanceof ArrayBuffer)) {
|
|
60
|
+
throw new TypeError('maxByteLength called on non-ArrayBuffer');
|
|
61
|
+
}
|
|
62
|
+
return maxByteLengthByBuffer.get(this) ?? this.byteLength;
|
|
63
|
+
},
|
|
64
|
+
enumerable: false,
|
|
65
|
+
configurable: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof (ArrayBuffer.prototype as any).resize !== 'function') {
|
|
70
|
+
Object.defineProperty(ArrayBuffer.prototype, 'resize', {
|
|
71
|
+
value: function resize(this: ArrayBuffer, newLength: number): void {
|
|
72
|
+
if (!(this instanceof ArrayBuffer)) {
|
|
73
|
+
throw new TypeError('resize called on non-ArrayBuffer');
|
|
74
|
+
}
|
|
75
|
+
if (!resizableBuffers.has(this)) {
|
|
76
|
+
throw new TypeError('Cannot resize a fixed-length ArrayBuffer');
|
|
77
|
+
}
|
|
78
|
+
const targetLength = Number(newLength);
|
|
79
|
+
if (!Number.isFinite(targetLength) || targetLength < 0) {
|
|
80
|
+
throw new RangeError('Invalid array buffer length');
|
|
81
|
+
}
|
|
82
|
+
if (targetLength > (maxByteLengthByBuffer.get(this) ?? this.byteLength)) {
|
|
83
|
+
throw new RangeError('Invalid array buffer length');
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
writable: true,
|
|
87
|
+
enumerable: false,
|
|
88
|
+
configurable: true,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// --------------------------------------------------------------------------
|
|
93
|
+
// ArrayBuffer.prototype.transfer (ES2024)
|
|
94
|
+
// Creates a new ArrayBuffer with the same byte content, optionally resized,
|
|
95
|
+
// and detaches (neuters) the original. Since we cannot truly detach in pure
|
|
96
|
+
// JS, we zero the original buffer's bytes to simulate detachment.
|
|
97
|
+
// --------------------------------------------------------------------------
|
|
98
|
+
if (typeof ArrayBuffer.prototype.transfer !== 'function') {
|
|
99
|
+
Object.defineProperty(ArrayBuffer.prototype, 'transfer', {
|
|
100
|
+
value: function transfer(this: ArrayBuffer, newLength?: number): ArrayBuffer {
|
|
101
|
+
if (!(this instanceof ArrayBuffer)) {
|
|
102
|
+
throw new TypeError('transfer called on non-ArrayBuffer');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const oldLength = this.byteLength;
|
|
106
|
+
const targetLength = newLength !== undefined ? Number(newLength) : oldLength;
|
|
107
|
+
|
|
108
|
+
if (targetLength < 0 || !Number.isFinite(targetLength)) {
|
|
109
|
+
throw new RangeError('Invalid array buffer length');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const newBuffer = new ArrayBuffer(targetLength);
|
|
113
|
+
const copyLength = Math.min(oldLength, targetLength);
|
|
114
|
+
|
|
115
|
+
if (copyLength > 0) {
|
|
116
|
+
const source = new Uint8Array(this, 0, copyLength);
|
|
117
|
+
const target = new Uint8Array(newBuffer, 0, copyLength);
|
|
118
|
+
target.set(source);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
markDetachedArrayBuffer(this);
|
|
122
|
+
|
|
123
|
+
return newBuffer;
|
|
124
|
+
},
|
|
125
|
+
writable: true,
|
|
126
|
+
enumerable: false,
|
|
127
|
+
configurable: true,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// --------------------------------------------------------------------------
|
|
132
|
+
// ArrayBuffer.prototype.transferToFixedLength (ES2024)
|
|
133
|
+
// Same as transfer, but the result is always a non-resizable ArrayBuffer.
|
|
134
|
+
// In our polyfill, all ArrayBuffers are fixed-length, so this is identical
|
|
135
|
+
// to transfer.
|
|
136
|
+
// --------------------------------------------------------------------------
|
|
137
|
+
if (typeof ArrayBuffer.prototype.transferToFixedLength !== 'function') {
|
|
138
|
+
Object.defineProperty(ArrayBuffer.prototype, 'transferToFixedLength', {
|
|
139
|
+
value: function transferToFixedLength(
|
|
140
|
+
this: ArrayBuffer,
|
|
141
|
+
newLength?: number,
|
|
142
|
+
): ArrayBuffer {
|
|
143
|
+
if (!(this instanceof ArrayBuffer)) {
|
|
144
|
+
throw new TypeError('transferToFixedLength called on non-ArrayBuffer');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const oldLength = this.byteLength;
|
|
148
|
+
const targetLength = newLength !== undefined ? Number(newLength) : oldLength;
|
|
149
|
+
|
|
150
|
+
if (targetLength < 0 || !Number.isFinite(targetLength)) {
|
|
151
|
+
throw new RangeError('Invalid array buffer length');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const newBuffer = new ArrayBuffer(targetLength);
|
|
155
|
+
const copyLength = Math.min(oldLength, targetLength);
|
|
156
|
+
|
|
157
|
+
if (copyLength > 0) {
|
|
158
|
+
const source = new Uint8Array(this, 0, copyLength);
|
|
159
|
+
const target = new Uint8Array(newBuffer, 0, copyLength);
|
|
160
|
+
target.set(source);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
markDetachedArrayBuffer(this);
|
|
164
|
+
|
|
165
|
+
return newBuffer;
|
|
166
|
+
},
|
|
167
|
+
writable: true,
|
|
168
|
+
enumerable: false,
|
|
169
|
+
configurable: true,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* ES2024 Object.groupBy and Map.groupBy polyfills for Hermes engine
|
|
4
|
+
*
|
|
5
|
+
* - Object.groupBy()
|
|
6
|
+
* - Map.groupBy()
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export function installGroupByPolyfills(): void {
|
|
10
|
+
// --------------------------------------------------------------------------
|
|
11
|
+
// Object.groupBy (ES2024)
|
|
12
|
+
// Groups elements of an iterable by a callback's return value into a
|
|
13
|
+
// null-prototype object.
|
|
14
|
+
// --------------------------------------------------------------------------
|
|
15
|
+
if (typeof Object.groupBy !== 'function') {
|
|
16
|
+
Object.defineProperty(Object, 'groupBy', {
|
|
17
|
+
value: function groupBy<T>(
|
|
18
|
+
items: Iterable<T>,
|
|
19
|
+
callbackFn: (element: T, index: number) => PropertyKey,
|
|
20
|
+
): Record<PropertyKey, T[]> {
|
|
21
|
+
if (typeof callbackFn !== 'function') {
|
|
22
|
+
throw new TypeError('callbackFn must be a function');
|
|
23
|
+
}
|
|
24
|
+
if (items == null) {
|
|
25
|
+
throw new TypeError('items is null or undefined');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const result = Object.create(null) as Record<PropertyKey, T[]>;
|
|
29
|
+
let index = 0;
|
|
30
|
+
|
|
31
|
+
for (const item of items) {
|
|
32
|
+
const key = callbackFn(item, index++);
|
|
33
|
+
if (key in result) {
|
|
34
|
+
result[key].push(item);
|
|
35
|
+
} else {
|
|
36
|
+
result[key] = [item];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return result;
|
|
41
|
+
},
|
|
42
|
+
writable: true,
|
|
43
|
+
enumerable: false,
|
|
44
|
+
configurable: true,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// --------------------------------------------------------------------------
|
|
49
|
+
// Map.groupBy (ES2024)
|
|
50
|
+
// Groups elements of an iterable by a callback's return value into a Map.
|
|
51
|
+
// --------------------------------------------------------------------------
|
|
52
|
+
if (typeof Map.groupBy !== 'function') {
|
|
53
|
+
Object.defineProperty(Map, 'groupBy', {
|
|
54
|
+
value: function groupBy<T, K>(
|
|
55
|
+
items: Iterable<T>,
|
|
56
|
+
callbackFn: (element: T, index: number) => K,
|
|
57
|
+
): Map<K, T[]> {
|
|
58
|
+
if (typeof callbackFn !== 'function') {
|
|
59
|
+
throw new TypeError('callbackFn must be a function');
|
|
60
|
+
}
|
|
61
|
+
if (items == null) {
|
|
62
|
+
throw new TypeError('items is null or undefined');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const result = new Map<K, T[]>();
|
|
66
|
+
let index = 0;
|
|
67
|
+
|
|
68
|
+
for (const item of items) {
|
|
69
|
+
const key = callbackFn(item, index++);
|
|
70
|
+
const group = result.get(key);
|
|
71
|
+
if (group !== undefined) {
|
|
72
|
+
group.push(item);
|
|
73
|
+
} else {
|
|
74
|
+
result.set(key, [item]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return result;
|
|
79
|
+
},
|
|
80
|
+
writable: true,
|
|
81
|
+
enumerable: false,
|
|
82
|
+
configurable: true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ES2023+ Polyfills for Hermes Engine
|
|
3
|
+
*
|
|
4
|
+
* Installs all modern JavaScript polyfills that Hermes doesn't natively support.
|
|
5
|
+
* Each polyfill checks for existing implementations before installing.
|
|
6
|
+
*
|
|
7
|
+
* Covers:
|
|
8
|
+
* - Array: toSorted, toReversed, with, toSpliced, fromAsync
|
|
9
|
+
* - Object/Map: groupBy
|
|
10
|
+
* - Set: union, intersection, difference, symmetricDifference, isSubsetOf, isSupersetOf, isDisjointFrom
|
|
11
|
+
* - Promise: withResolvers
|
|
12
|
+
* - String: isWellFormed, toWellFormed
|
|
13
|
+
* - ArrayBuffer: transfer, transferToFixedLength
|
|
14
|
+
* - Iterator: map, filter, take, drop, flatMap, reduce, toArray, forEach, some, every, find, from
|
|
15
|
+
* - Intl: PluralRules, ListFormat, RelativeTimeFormat, Segmenter, DisplayNames,
|
|
16
|
+
* DateTimeFormat.formatRange/formatToParts, NumberFormat.formatRange/formatToParts
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { installArrayPolyfills } from './array';
|
|
20
|
+
import { installGroupByPolyfills } from './groupby';
|
|
21
|
+
import { installSetPolyfills } from './set';
|
|
22
|
+
import { installPromisePolyfills } from './promise';
|
|
23
|
+
import { installStringPolyfills } from './string';
|
|
24
|
+
import { installArrayBufferPolyfills } from './arraybuffer';
|
|
25
|
+
import { installTypedArrayPolyfills } from './typedarray';
|
|
26
|
+
import { installIteratorPolyfills } from './iterator';
|
|
27
|
+
import { installIntlPolyfills } from './intl';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Install all ES2023+ polyfills.
|
|
31
|
+
* Safe to call multiple times; each polyfill checks before installing.
|
|
32
|
+
*/
|
|
33
|
+
export function installPolyfills(): void {
|
|
34
|
+
installArrayPolyfills();
|
|
35
|
+
installGroupByPolyfills();
|
|
36
|
+
installSetPolyfills();
|
|
37
|
+
installPromisePolyfills();
|
|
38
|
+
installStringPolyfills();
|
|
39
|
+
installArrayBufferPolyfills();
|
|
40
|
+
installTypedArrayPolyfills();
|
|
41
|
+
installIteratorPolyfills();
|
|
42
|
+
|
|
43
|
+
// Intl polyfills are deferred until first access to reduce startup cost.
|
|
44
|
+
// Hermes provides an empty Intl object; we proxy it so that accessing
|
|
45
|
+
// any Intl method (e.g., Intl.DateTimeFormat) triggers the full install.
|
|
46
|
+
const g = globalThis as any;
|
|
47
|
+
if (typeof g.Intl === 'object' && g.Intl !== null) {
|
|
48
|
+
const realIntl = g.Intl;
|
|
49
|
+
let installed = false;
|
|
50
|
+
function ensureIntl() {
|
|
51
|
+
if (installed) return;
|
|
52
|
+
installed = true;
|
|
53
|
+
// Restore the real Intl before installing so the polyfills
|
|
54
|
+
// can detect what's already there.
|
|
55
|
+
g.Intl = realIntl;
|
|
56
|
+
installIntlPolyfills();
|
|
57
|
+
}
|
|
58
|
+
g.Intl = new Proxy(realIntl, {
|
|
59
|
+
get(target: any, prop: string | symbol, receiver: any) {
|
|
60
|
+
ensureIntl();
|
|
61
|
+
return Reflect.get(g.Intl, prop, receiver);
|
|
62
|
+
},
|
|
63
|
+
has(target: any, prop: string | symbol) {
|
|
64
|
+
ensureIntl();
|
|
65
|
+
return Reflect.has(g.Intl, prop);
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
// No Intl object at all — install eagerly
|
|
70
|
+
installIntlPolyfills();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Re-export individual installers for selective use
|
|
75
|
+
export {
|
|
76
|
+
installArrayPolyfills,
|
|
77
|
+
installGroupByPolyfills,
|
|
78
|
+
installSetPolyfills,
|
|
79
|
+
installPromisePolyfills,
|
|
80
|
+
installStringPolyfills,
|
|
81
|
+
installArrayBufferPolyfills,
|
|
82
|
+
installTypedArrayPolyfills,
|
|
83
|
+
installIteratorPolyfills,
|
|
84
|
+
installIntlPolyfills,
|
|
85
|
+
};
|