From a68305157eb89de9a04d3c2692da8c92bd160a46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rub=C3=A9n=20Norte?= <rubennorte@meta.com>
Date: Sat, 4 Jan 2025 11:14:10 -0800
Subject: [PATCH] Further optimizations for event dispatching (#48426)

Summary:

Changelog: [internal]

This improves the performance of DOM `Event` interface implementation by migrating away from private fields.

Differential Revision: D67751821
---
 .../src/private/webapis/dom/events/Event.js   | 36 +++++++++----------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/packages/react-native/src/private/webapis/dom/events/Event.js b/packages/react-native/src/private/webapis/dom/events/Event.js
index 7985a1bbe7e24a..f76d3782dd3b3f 100644
--- a/packages/react-native/src/private/webapis/dom/events/Event.js
+++ b/packages/react-native/src/private/webapis/dom/events/Event.js
@@ -48,13 +48,13 @@ export default class Event {
   static AT_TARGET: 2 = 2;
   static BUBBLING_PHASE: 3 = 3;
 
-  #bubbles: boolean;
-  #cancelable: boolean;
-  #composed: boolean;
-  #type: string;
+  _bubbles: boolean;
+  _cancelable: boolean;
+  _composed: boolean;
+  _type: string;
 
-  #defaultPrevented: boolean = false;
-  #timeStamp: number = performance.now();
+  _defaultPrevented: boolean = false;
+  _timeStamp: number = performance.now();
 
   // $FlowExpectedError[unsupported-syntax]
   [COMPOSED_PATH_KEY]: boolean = [];
@@ -93,22 +93,22 @@ export default class Event {
       );
     }
 
-    this.#type = String(type);
-    this.#bubbles = Boolean(options?.bubbles);
-    this.#cancelable = Boolean(options?.cancelable);
-    this.#composed = Boolean(options?.composed);
+    this._type = String(type);
+    this._bubbles = Boolean(options?.bubbles);
+    this._cancelable = Boolean(options?.cancelable);
+    this._composed = Boolean(options?.composed);
   }
 
   get bubbles(): boolean {
-    return this.#bubbles;
+    return this._bubbles;
   }
 
   get cancelable(): boolean {
-    return this.#cancelable;
+    return this._cancelable;
   }
 
   get composed(): boolean {
-    return this.#composed;
+    return this._composed;
   }
 
   get currentTarget(): EventTarget | null {
@@ -116,7 +116,7 @@ export default class Event {
   }
 
   get defaultPrevented(): boolean {
-    return this.#defaultPrevented;
+    return this._defaultPrevented;
   }
 
   get eventPhase(): EventPhase {
@@ -132,11 +132,11 @@ export default class Event {
   }
 
   get timeStamp(): number {
-    return this.#timeStamp;
+    return this._timeStamp;
   }
 
   get type(): string {
-    return this.#type;
+    return this._type;
   }
 
   composedPath(): $ReadOnlyArray<EventTarget> {
@@ -144,7 +144,7 @@ export default class Event {
   }
 
   preventDefault(): void {
-    if (!this.#cancelable) {
+    if (!this._cancelable) {
       return;
     }
 
@@ -157,7 +157,7 @@ export default class Event {
       return;
     }
 
-    this.#defaultPrevented = true;
+    this._defaultPrevented = true;
   }
 
   stopImmediatePropagation(): void {