@secure-exec/nodejs 0.2.0-rc.1 → 0.2.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bridge/os.js CHANGED
@@ -12,6 +12,12 @@ const config = {
12
12
  tmpdir: (typeof _osConfig !== "undefined" && _osConfig.tmpdir) || "/tmp",
13
13
  hostname: (typeof _osConfig !== "undefined" && _osConfig.hostname) || "sandbox",
14
14
  };
15
+ function getRuntimeHomeDir() {
16
+ return globalThis.process?.env?.HOME || config.homedir;
17
+ }
18
+ function getRuntimeTmpDir() {
19
+ return globalThis.process?.env?.TMPDIR || config.tmpdir;
20
+ }
15
21
  // Signal constants (subset — sandbox only emulates Linux signals)
16
22
  const signals = {
17
23
  SIGHUP: 1,
@@ -159,10 +165,10 @@ const os = {
159
165
  },
160
166
  // Directory information
161
167
  homedir() {
162
- return config.homedir;
168
+ return getRuntimeHomeDir();
163
169
  },
164
170
  tmpdir() {
165
- return config.tmpdir;
171
+ return getRuntimeTmpDir();
166
172
  },
167
173
  // System information
168
174
  hostname() {
@@ -175,7 +181,7 @@ const os = {
175
181
  uid: 0,
176
182
  gid: 0,
177
183
  shell: "/bin/bash",
178
- homedir: config.homedir,
184
+ homedir: getRuntimeHomeDir(),
179
185
  };
180
186
  },
181
187
  // CPU information
@@ -1,9 +1,6 @@
1
- declare const TextEncoder: {
2
- new (): TextEncoder;
3
- prototype: TextEncoder;
4
- };
5
- declare const TextDecoder: {
6
- new (label?: string, options?: TextDecoderOptions): TextDecoder;
7
- prototype: TextDecoder;
8
- };
9
- export { TextEncoder, TextDecoder };
1
+ declare const TextEncoder: typeof globalThis.TextEncoder;
2
+ declare const TextDecoder: typeof globalThis.TextDecoder;
3
+ declare const Event: typeof globalThis.Event;
4
+ declare const CustomEvent: typeof globalThis.CustomEvent;
5
+ declare const EventTarget: typeof globalThis.EventTarget;
6
+ export { TextEncoder, TextDecoder, Event, CustomEvent, EventTarget };
@@ -1,6 +1,117 @@
1
1
  // Early polyfills - this file must be imported FIRST before any other modules
2
- // that might use TextEncoder/TextDecoder (like whatwg-url)
3
- import { TextDecoder as PolyfillTextDecoder, } from "text-encoding-utf-8";
2
+ // that might use TextEncoder/TextDecoder/EventTarget at module scope.
3
+ function defineGlobal(name, value) {
4
+ globalThis[name] = value;
5
+ }
6
+ if (typeof globalThis.global === "undefined") {
7
+ defineGlobal("global", globalThis);
8
+ }
9
+ if (typeof globalThis.RegExp === "function" &&
10
+ !("__secureExecRgiEmojiCompat" in globalThis.RegExp)) {
11
+ const NativeRegExp = globalThis.RegExp;
12
+ const rgiEmojiPattern = "^\\p{RGI_Emoji}$";
13
+ const rgiEmojiBaseClass = "[\\u{00A9}\\u{00AE}\\u{203C}\\u{2049}\\u{2122}\\u{2139}\\u{2194}-\\u{21AA}\\u{231A}-\\u{23FF}\\u{24C2}\\u{25AA}-\\u{27BF}\\u{2934}-\\u{2935}\\u{2B05}-\\u{2B55}\\u{3030}\\u{303D}\\u{3297}\\u{3299}\\u{1F000}-\\u{1FAFF}]";
14
+ const rgiEmojiKeycap = "[#*0-9]\\uFE0F?\\u20E3";
15
+ const rgiEmojiFallbackSource = "^(?:" +
16
+ rgiEmojiKeycap +
17
+ "|\\p{Regional_Indicator}{2}|" +
18
+ rgiEmojiBaseClass +
19
+ "(?:\\uFE0F|\\u200D(?:" +
20
+ rgiEmojiKeycap +
21
+ "|" +
22
+ rgiEmojiBaseClass +
23
+ ")|[\\u{1F3FB}-\\u{1F3FF}])*)$";
24
+ try {
25
+ new NativeRegExp(rgiEmojiPattern, "v");
26
+ }
27
+ catch (error) {
28
+ if (String(error?.message ?? error).includes("RGI_Emoji")) {
29
+ const CompatRegExp = function CompatRegExp(pattern, flags) {
30
+ const normalizedPattern = pattern instanceof NativeRegExp && flags === undefined
31
+ ? pattern.source
32
+ : String(pattern);
33
+ const normalizedFlags = flags === undefined
34
+ ? (pattern instanceof NativeRegExp ? pattern.flags : "")
35
+ : String(flags);
36
+ try {
37
+ return new NativeRegExp(pattern, flags);
38
+ }
39
+ catch (innerError) {
40
+ if (normalizedPattern === rgiEmojiPattern && normalizedFlags === "v") {
41
+ return new NativeRegExp(rgiEmojiFallbackSource, "u");
42
+ }
43
+ throw innerError;
44
+ }
45
+ };
46
+ Object.setPrototypeOf(CompatRegExp, NativeRegExp);
47
+ CompatRegExp.prototype = NativeRegExp.prototype;
48
+ Object.defineProperty(CompatRegExp.prototype, "constructor", {
49
+ value: CompatRegExp,
50
+ writable: true,
51
+ configurable: true,
52
+ });
53
+ defineGlobal("RegExp", Object.assign(CompatRegExp, { __secureExecRgiEmojiCompat: true }));
54
+ }
55
+ }
56
+ }
57
+ function withCode(error, code) {
58
+ error.code = code;
59
+ return error;
60
+ }
61
+ function createEncodingNotSupportedError(label) {
62
+ return withCode(new RangeError(`The "${label}" encoding is not supported`), "ERR_ENCODING_NOT_SUPPORTED");
63
+ }
64
+ function createEncodingInvalidDataError(encoding) {
65
+ return withCode(new TypeError(`The encoded data was not valid for encoding ${encoding}`), "ERR_ENCODING_INVALID_ENCODED_DATA");
66
+ }
67
+ function createInvalidDecodeInputError() {
68
+ return withCode(new TypeError('The "input" argument must be an instance of ArrayBuffer, SharedArrayBuffer, or ArrayBufferView.'), "ERR_INVALID_ARG_TYPE");
69
+ }
70
+ function trimAsciiWhitespace(value) {
71
+ return value.replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g, "");
72
+ }
73
+ function normalizeEncodingLabel(label) {
74
+ const normalized = trimAsciiWhitespace(label === undefined ? "utf-8" : String(label)).toLowerCase();
75
+ switch (normalized) {
76
+ case "utf-8":
77
+ case "utf8":
78
+ case "unicode-1-1-utf-8":
79
+ case "unicode11utf8":
80
+ case "unicode20utf8":
81
+ case "x-unicode20utf8":
82
+ return "utf-8";
83
+ case "utf-16":
84
+ case "utf-16le":
85
+ case "ucs-2":
86
+ case "ucs2":
87
+ case "csunicode":
88
+ case "iso-10646-ucs-2":
89
+ case "unicode":
90
+ case "unicodefeff":
91
+ return "utf-16le";
92
+ case "utf-16be":
93
+ case "unicodefffe":
94
+ return "utf-16be";
95
+ default:
96
+ throw createEncodingNotSupportedError(normalized);
97
+ }
98
+ }
99
+ function toUint8Array(input) {
100
+ if (input === undefined) {
101
+ return new Uint8Array(0);
102
+ }
103
+ if (ArrayBuffer.isView(input)) {
104
+ return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
105
+ }
106
+ if (input instanceof ArrayBuffer) {
107
+ return new Uint8Array(input);
108
+ }
109
+ if (typeof SharedArrayBuffer !== "undefined" &&
110
+ input instanceof SharedArrayBuffer) {
111
+ return new Uint8Array(input);
112
+ }
113
+ throw createInvalidDecodeInputError();
114
+ }
4
115
  function encodeUtf8ScalarValue(codePoint, bytes) {
5
116
  if (codePoint <= 0x7f) {
6
117
  bytes.push(codePoint);
@@ -43,25 +154,516 @@ function encodeUtf8(input = "") {
43
154
  }
44
155
  return new Uint8Array(bytes);
45
156
  }
157
+ function appendCodePoint(output, codePoint) {
158
+ if (codePoint <= 0xffff) {
159
+ output.push(String.fromCharCode(codePoint));
160
+ return;
161
+ }
162
+ const adjusted = codePoint - 0x10000;
163
+ output.push(String.fromCharCode(0xd800 + (adjusted >> 10)), String.fromCharCode(0xdc00 + (adjusted & 0x3ff)));
164
+ }
165
+ function isContinuationByte(value) {
166
+ return value >= 0x80 && value <= 0xbf;
167
+ }
168
+ function decodeUtf8(bytes, fatal, stream, encoding) {
169
+ const output = [];
170
+ for (let index = 0; index < bytes.length;) {
171
+ const first = bytes[index];
172
+ if (first <= 0x7f) {
173
+ output.push(String.fromCharCode(first));
174
+ index += 1;
175
+ continue;
176
+ }
177
+ let needed = 0;
178
+ let codePoint = 0;
179
+ if (first >= 0xc2 && first <= 0xdf) {
180
+ needed = 1;
181
+ codePoint = first & 0x1f;
182
+ }
183
+ else if (first >= 0xe0 && first <= 0xef) {
184
+ needed = 2;
185
+ codePoint = first & 0x0f;
186
+ }
187
+ else if (first >= 0xf0 && first <= 0xf4) {
188
+ needed = 3;
189
+ codePoint = first & 0x07;
190
+ }
191
+ else {
192
+ if (fatal) {
193
+ throw createEncodingInvalidDataError(encoding);
194
+ }
195
+ output.push("\ufffd");
196
+ index += 1;
197
+ continue;
198
+ }
199
+ if (index + needed >= bytes.length) {
200
+ if (stream) {
201
+ return {
202
+ text: output.join(""),
203
+ pending: Array.from(bytes.slice(index)),
204
+ };
205
+ }
206
+ if (fatal) {
207
+ throw createEncodingInvalidDataError(encoding);
208
+ }
209
+ output.push("\ufffd");
210
+ break;
211
+ }
212
+ const second = bytes[index + 1];
213
+ if (!isContinuationByte(second)) {
214
+ if (fatal) {
215
+ throw createEncodingInvalidDataError(encoding);
216
+ }
217
+ output.push("\ufffd");
218
+ index += 1;
219
+ continue;
220
+ }
221
+ if ((first === 0xe0 && second < 0xa0) ||
222
+ (first === 0xed && second > 0x9f) ||
223
+ (first === 0xf0 && second < 0x90) ||
224
+ (first === 0xf4 && second > 0x8f)) {
225
+ if (fatal) {
226
+ throw createEncodingInvalidDataError(encoding);
227
+ }
228
+ output.push("\ufffd");
229
+ index += 1;
230
+ continue;
231
+ }
232
+ codePoint = (codePoint << 6) | (second & 0x3f);
233
+ if (needed >= 2) {
234
+ const third = bytes[index + 2];
235
+ if (!isContinuationByte(third)) {
236
+ if (fatal) {
237
+ throw createEncodingInvalidDataError(encoding);
238
+ }
239
+ output.push("\ufffd");
240
+ index += 1;
241
+ continue;
242
+ }
243
+ codePoint = (codePoint << 6) | (third & 0x3f);
244
+ }
245
+ if (needed === 3) {
246
+ const fourth = bytes[index + 3];
247
+ if (!isContinuationByte(fourth)) {
248
+ if (fatal) {
249
+ throw createEncodingInvalidDataError(encoding);
250
+ }
251
+ output.push("\ufffd");
252
+ index += 1;
253
+ continue;
254
+ }
255
+ codePoint = (codePoint << 6) | (fourth & 0x3f);
256
+ }
257
+ if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
258
+ if (fatal) {
259
+ throw createEncodingInvalidDataError(encoding);
260
+ }
261
+ output.push("\ufffd");
262
+ index += needed + 1;
263
+ continue;
264
+ }
265
+ appendCodePoint(output, codePoint);
266
+ index += needed + 1;
267
+ }
268
+ return { text: output.join(""), pending: [] };
269
+ }
270
+ function decodeUtf16(bytes, encoding, fatal, stream, bomSeen) {
271
+ const output = [];
272
+ let endian = encoding === "utf-16be" ? "be" : "le";
273
+ if (!bomSeen && encoding === "utf-16le" && bytes.length >= 2) {
274
+ if (bytes[0] === 0xfe && bytes[1] === 0xff) {
275
+ endian = "be";
276
+ }
277
+ }
278
+ for (let index = 0; index < bytes.length;) {
279
+ if (index + 1 >= bytes.length) {
280
+ if (stream) {
281
+ return {
282
+ text: output.join(""),
283
+ pending: Array.from(bytes.slice(index)),
284
+ };
285
+ }
286
+ if (fatal) {
287
+ throw createEncodingInvalidDataError(encoding);
288
+ }
289
+ output.push("\ufffd");
290
+ break;
291
+ }
292
+ const first = bytes[index];
293
+ const second = bytes[index + 1];
294
+ const codeUnit = endian === "le" ? first | (second << 8) : (first << 8) | second;
295
+ index += 2;
296
+ if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
297
+ if (index + 1 >= bytes.length) {
298
+ if (stream) {
299
+ return {
300
+ text: output.join(""),
301
+ pending: Array.from(bytes.slice(index - 2)),
302
+ };
303
+ }
304
+ if (fatal) {
305
+ throw createEncodingInvalidDataError(encoding);
306
+ }
307
+ output.push("\ufffd");
308
+ continue;
309
+ }
310
+ const nextFirst = bytes[index];
311
+ const nextSecond = bytes[index + 1];
312
+ const nextCodeUnit = endian === "le"
313
+ ? nextFirst | (nextSecond << 8)
314
+ : (nextFirst << 8) | nextSecond;
315
+ if (nextCodeUnit >= 0xdc00 && nextCodeUnit <= 0xdfff) {
316
+ const codePoint = 0x10000 +
317
+ ((codeUnit - 0xd800) << 10) +
318
+ (nextCodeUnit - 0xdc00);
319
+ appendCodePoint(output, codePoint);
320
+ index += 2;
321
+ continue;
322
+ }
323
+ if (fatal) {
324
+ throw createEncodingInvalidDataError(encoding);
325
+ }
326
+ output.push("\ufffd");
327
+ continue;
328
+ }
329
+ if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
330
+ if (fatal) {
331
+ throw createEncodingInvalidDataError(encoding);
332
+ }
333
+ output.push("\ufffd");
334
+ continue;
335
+ }
336
+ output.push(String.fromCharCode(codeUnit));
337
+ }
338
+ return { text: output.join(""), pending: [] };
339
+ }
46
340
  class PatchedTextEncoder {
47
341
  encode(input = "") {
48
342
  return encodeUtf8(input);
49
343
  }
344
+ encodeInto(input, destination) {
345
+ const value = String(input);
346
+ let read = 0;
347
+ let written = 0;
348
+ for (let index = 0; index < value.length; index += 1) {
349
+ const codeUnit = value.charCodeAt(index);
350
+ let chunk = "";
351
+ if (codeUnit >= 0xd800 &&
352
+ codeUnit <= 0xdbff &&
353
+ index + 1 < value.length) {
354
+ const nextCodeUnit = value.charCodeAt(index + 1);
355
+ if (nextCodeUnit >= 0xdc00 && nextCodeUnit <= 0xdfff) {
356
+ chunk = value.slice(index, index + 2);
357
+ }
358
+ }
359
+ if (chunk === "") {
360
+ chunk = value[index] ?? "";
361
+ }
362
+ const encoded = encodeUtf8(chunk);
363
+ if (written + encoded.length > destination.length) {
364
+ break;
365
+ }
366
+ destination.set(encoded, written);
367
+ written += encoded.length;
368
+ read += chunk.length;
369
+ if (chunk.length === 2) {
370
+ index += 1;
371
+ }
372
+ }
373
+ return { read, written };
374
+ }
50
375
  get encoding() {
51
376
  return "utf-8";
52
377
  }
378
+ get [Symbol.toStringTag]() {
379
+ return "TextEncoder";
380
+ }
381
+ }
382
+ class PatchedTextDecoder {
383
+ normalizedEncoding;
384
+ fatalFlag;
385
+ ignoreBOMFlag;
386
+ pendingBytes = [];
387
+ bomSeen = false;
388
+ constructor(label, options) {
389
+ const normalizedOptions = options == null ? {} : Object(options);
390
+ this.normalizedEncoding = normalizeEncodingLabel(label);
391
+ this.fatalFlag = Boolean(normalizedOptions.fatal);
392
+ this.ignoreBOMFlag = Boolean(normalizedOptions.ignoreBOM);
393
+ }
394
+ get encoding() {
395
+ return this.normalizedEncoding;
396
+ }
397
+ get fatal() {
398
+ return this.fatalFlag;
399
+ }
400
+ get ignoreBOM() {
401
+ return this.ignoreBOMFlag;
402
+ }
403
+ get [Symbol.toStringTag]() {
404
+ return "TextDecoder";
405
+ }
406
+ decode(input, options) {
407
+ const normalizedOptions = options == null ? {} : Object(options);
408
+ const stream = Boolean(normalizedOptions.stream);
409
+ const incoming = toUint8Array(input);
410
+ const merged = new Uint8Array(this.pendingBytes.length + incoming.length);
411
+ merged.set(this.pendingBytes, 0);
412
+ merged.set(incoming, this.pendingBytes.length);
413
+ const decoded = this.normalizedEncoding === "utf-8"
414
+ ? decodeUtf8(merged, this.fatalFlag, stream, this.normalizedEncoding)
415
+ : decodeUtf16(merged, this.normalizedEncoding, this.fatalFlag, stream, this.bomSeen);
416
+ this.pendingBytes = decoded.pending;
417
+ let text = decoded.text;
418
+ if (!this.bomSeen && text.length > 0) {
419
+ if (!this.ignoreBOMFlag && text.charCodeAt(0) === 0xfeff) {
420
+ text = text.slice(1);
421
+ }
422
+ this.bomSeen = true;
423
+ }
424
+ if (!stream && this.pendingBytes.length > 0) {
425
+ const pending = this.pendingBytes;
426
+ this.pendingBytes = [];
427
+ if (this.fatalFlag) {
428
+ throw createEncodingInvalidDataError(this.normalizedEncoding);
429
+ }
430
+ return text + "\ufffd".repeat(Math.ceil(pending.length / 2));
431
+ }
432
+ return text;
433
+ }
434
+ }
435
+ function normalizeAddEventListenerOptions(options) {
436
+ if (typeof options === "boolean") {
437
+ return {
438
+ capture: options,
439
+ once: false,
440
+ passive: false,
441
+ };
442
+ }
443
+ if (options == null) {
444
+ return {
445
+ capture: false,
446
+ once: false,
447
+ passive: false,
448
+ };
449
+ }
450
+ const normalized = Object(options);
451
+ return {
452
+ capture: Boolean(normalized.capture),
453
+ once: Boolean(normalized.once),
454
+ passive: Boolean(normalized.passive),
455
+ signal: normalized.signal,
456
+ };
457
+ }
458
+ function normalizeRemoveEventListenerOptions(options) {
459
+ if (typeof options === "boolean") {
460
+ return options;
461
+ }
462
+ if (options == null) {
463
+ return false;
464
+ }
465
+ return Boolean(Object(options).capture);
466
+ }
467
+ function isAbortSignalLike(value) {
468
+ return (typeof value === "object" &&
469
+ value !== null &&
470
+ "aborted" in value &&
471
+ typeof value.addEventListener === "function" &&
472
+ typeof value.removeEventListener === "function");
473
+ }
474
+ class PatchedEvent {
475
+ static NONE = 0;
476
+ static CAPTURING_PHASE = 1;
477
+ static AT_TARGET = 2;
478
+ static BUBBLING_PHASE = 3;
479
+ type;
480
+ bubbles;
481
+ cancelable;
482
+ composed;
483
+ detail = null;
484
+ defaultPrevented = false;
485
+ target = null;
486
+ currentTarget = null;
487
+ eventPhase = 0;
488
+ returnValue = true;
489
+ cancelBubble = false;
490
+ timeStamp = Date.now();
491
+ isTrusted = false;
492
+ srcElement = null;
493
+ inPassiveListener = false;
494
+ propagationStopped = false;
495
+ immediatePropagationStopped = false;
496
+ constructor(type, init) {
497
+ if (arguments.length === 0) {
498
+ throw new TypeError("The event type must be provided");
499
+ }
500
+ const normalizedInit = init == null ? {} : Object(init);
501
+ this.type = String(type);
502
+ this.bubbles = Boolean(normalizedInit.bubbles);
503
+ this.cancelable = Boolean(normalizedInit.cancelable);
504
+ this.composed = Boolean(normalizedInit.composed);
505
+ }
506
+ get [Symbol.toStringTag]() {
507
+ return "Event";
508
+ }
509
+ preventDefault() {
510
+ if (this.cancelable && !this.inPassiveListener) {
511
+ this.defaultPrevented = true;
512
+ this.returnValue = false;
513
+ }
514
+ }
515
+ stopPropagation() {
516
+ this.propagationStopped = true;
517
+ this.cancelBubble = true;
518
+ }
519
+ stopImmediatePropagation() {
520
+ this.propagationStopped = true;
521
+ this.immediatePropagationStopped = true;
522
+ this.cancelBubble = true;
523
+ }
524
+ composedPath() {
525
+ return this.target ? [this.target] : [];
526
+ }
527
+ _setPassive(value) {
528
+ this.inPassiveListener = value;
529
+ }
530
+ _isPropagationStopped() {
531
+ return this.propagationStopped;
532
+ }
533
+ _isImmediatePropagationStopped() {
534
+ return this.immediatePropagationStopped;
535
+ }
53
536
  }
54
- const TextEncoder = typeof globalThis.TextEncoder === "function"
55
- ? globalThis.TextEncoder
56
- : PatchedTextEncoder;
57
- const TextDecoder = typeof globalThis.TextDecoder === "function"
58
- ? globalThis.TextDecoder
59
- : PolyfillTextDecoder;
60
- // Install on globalThis so other modules can use them
61
- if (typeof globalThis.TextEncoder === "undefined") {
62
- globalThis.TextEncoder = TextEncoder;
537
+ class PatchedCustomEvent extends PatchedEvent {
538
+ constructor(type, init) {
539
+ super(type, init);
540
+ const normalizedInit = init == null ? null : Object(init);
541
+ this.detail =
542
+ normalizedInit && "detail" in normalizedInit
543
+ ? normalizedInit.detail
544
+ : null;
545
+ }
546
+ get [Symbol.toStringTag]() {
547
+ return "CustomEvent";
548
+ }
63
549
  }
64
- if (typeof globalThis.TextDecoder === "undefined") {
65
- globalThis.TextDecoder = TextDecoder;
550
+ class PatchedEventTarget {
551
+ listeners = new Map();
552
+ addEventListener(type, listener, options) {
553
+ const normalized = normalizeAddEventListenerOptions(options);
554
+ if (normalized.signal !== undefined && !isAbortSignalLike(normalized.signal)) {
555
+ throw new TypeError('The "signal" option must be an instance of AbortSignal.');
556
+ }
557
+ if (listener == null) {
558
+ return undefined;
559
+ }
560
+ if (typeof listener !== "function" &&
561
+ (typeof listener !== "object" || listener === null)) {
562
+ return undefined;
563
+ }
564
+ if (normalized.signal?.aborted) {
565
+ return undefined;
566
+ }
567
+ const records = this.listeners.get(type) ?? [];
568
+ const existing = records.find((record) => record.listener === listener && record.capture === normalized.capture);
569
+ if (existing) {
570
+ return undefined;
571
+ }
572
+ const record = {
573
+ listener,
574
+ capture: normalized.capture,
575
+ once: normalized.once,
576
+ passive: normalized.passive,
577
+ kind: typeof listener === "function" ? "function" : "object",
578
+ signal: normalized.signal,
579
+ };
580
+ if (normalized.signal) {
581
+ record.abortListener = () => {
582
+ this.removeEventListener(type, listener, normalized.capture);
583
+ };
584
+ normalized.signal.addEventListener("abort", record.abortListener, {
585
+ once: true,
586
+ });
587
+ }
588
+ records.push(record);
589
+ this.listeners.set(type, records);
590
+ return undefined;
591
+ }
592
+ removeEventListener(type, listener, options) {
593
+ if (listener == null) {
594
+ return;
595
+ }
596
+ const capture = normalizeRemoveEventListenerOptions(options);
597
+ const records = this.listeners.get(type);
598
+ if (!records) {
599
+ return;
600
+ }
601
+ const nextRecords = records.filter((record) => {
602
+ const match = record.listener === listener && record.capture === capture;
603
+ if (match && record.signal && record.abortListener) {
604
+ record.signal.removeEventListener("abort", record.abortListener);
605
+ }
606
+ return !match;
607
+ });
608
+ if (nextRecords.length === 0) {
609
+ this.listeners.delete(type);
610
+ return;
611
+ }
612
+ this.listeners.set(type, nextRecords);
613
+ }
614
+ dispatchEvent(event) {
615
+ if (typeof event !== "object" ||
616
+ event === null ||
617
+ typeof event.type !== "string") {
618
+ throw new TypeError("Argument 1 must be an Event");
619
+ }
620
+ const patchedEvent = event;
621
+ const records = (this.listeners.get(patchedEvent.type) ?? []).slice();
622
+ patchedEvent.target = this;
623
+ patchedEvent.currentTarget = this;
624
+ patchedEvent.eventPhase = 2;
625
+ for (const record of records) {
626
+ const active = this.listeners
627
+ .get(patchedEvent.type)
628
+ ?.includes(record);
629
+ if (!active) {
630
+ continue;
631
+ }
632
+ if (record.once) {
633
+ this.removeEventListener(patchedEvent.type, record.listener, record.capture);
634
+ }
635
+ patchedEvent._setPassive(record.passive);
636
+ if (record.kind === "function") {
637
+ record.listener.call(this, patchedEvent);
638
+ }
639
+ else {
640
+ const handleEvent = record.listener.handleEvent;
641
+ if (typeof handleEvent === "function") {
642
+ handleEvent.call(record.listener, patchedEvent);
643
+ }
644
+ }
645
+ patchedEvent._setPassive(false);
646
+ if (patchedEvent._isImmediatePropagationStopped()) {
647
+ break;
648
+ }
649
+ if (patchedEvent._isPropagationStopped()) {
650
+ break;
651
+ }
652
+ }
653
+ patchedEvent.currentTarget = null;
654
+ patchedEvent.eventPhase = 0;
655
+ return !patchedEvent.defaultPrevented;
656
+ }
66
657
  }
67
- export { TextEncoder, TextDecoder };
658
+ const TextEncoder = PatchedTextEncoder;
659
+ const TextDecoder = PatchedTextDecoder;
660
+ const Event = PatchedEvent;
661
+ const CustomEvent = PatchedCustomEvent;
662
+ const EventTarget = PatchedEventTarget;
663
+ // Install on globalThis so other modules can use them during load.
664
+ defineGlobal("TextEncoder", TextEncoder);
665
+ defineGlobal("TextDecoder", TextDecoder);
666
+ defineGlobal("Event", Event);
667
+ defineGlobal("CustomEvent", CustomEvent);
668
+ defineGlobal("EventTarget", EventTarget);
669
+ export { TextEncoder, TextDecoder, Event, CustomEvent, EventTarget };