Skip to content

Commit cc5bab8

Browse files
rubennortefacebook-github-bot
authored andcommitted
Use private fields in performance APIs
Summary: Changelog: [internal] This migrates all the classes related to performance in `react-native/src/private` to use private fields instead of regular fields prefixed with `_`. Reviewed By: yungsters Differential Revision: D55931659 fbshipit-source-id: e8b2018048dbb6c8d6e8a4d143357bf2ac39dd1e
1 parent 59688a1 commit cc5bab8

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

packages/react-native/src/private/webapis/performance/MemoryInfo.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,36 @@ type MemoryInfoLike = {
1919

2020
// Read-only object with JS memory information. This is returned by the performance.memory API.
2121
export default class MemoryInfo {
22-
_jsHeapSizeLimit: ?number;
23-
_totalJSHeapSize: ?number;
24-
_usedJSHeapSize: ?number;
22+
#jsHeapSizeLimit: ?number;
23+
#totalJSHeapSize: ?number;
24+
#usedJSHeapSize: ?number;
2525

2626
constructor(memoryInfo: ?MemoryInfoLike) {
2727
if (memoryInfo != null) {
28-
this._jsHeapSizeLimit = memoryInfo.jsHeapSizeLimit;
29-
this._totalJSHeapSize = memoryInfo.totalJSHeapSize;
30-
this._usedJSHeapSize = memoryInfo.usedJSHeapSize;
28+
this.#jsHeapSizeLimit = memoryInfo.jsHeapSizeLimit;
29+
this.#totalJSHeapSize = memoryInfo.totalJSHeapSize;
30+
this.#usedJSHeapSize = memoryInfo.usedJSHeapSize;
3131
}
3232
}
3333

3434
/**
3535
* The maximum size of the heap, in bytes, that is available to the context
3636
*/
3737
get jsHeapSizeLimit(): ?number {
38-
return this._jsHeapSizeLimit;
38+
return this.#jsHeapSizeLimit;
3939
}
4040

4141
/**
4242
* The total allocated heap size, in bytes
4343
*/
4444
get totalJSHeapSize(): ?number {
45-
return this._totalJSHeapSize;
45+
return this.#totalJSHeapSize;
4646
}
4747

4848
/**
4949
* The currently active segment of JS heap, in bytes.
5050
*/
5151
get usedJSHeapSize(): ?number {
52-
return this._usedJSHeapSize;
52+
return this.#usedJSHeapSize;
5353
}
5454
}

packages/react-native/src/private/webapis/performance/PerformanceObserver.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ export type PerformanceEntryList = $ReadOnlyArray<PerformanceEntry>;
2525
export {PerformanceEntry} from './PerformanceEntry';
2626

2727
export class PerformanceObserverEntryList {
28-
_entries: PerformanceEntryList;
28+
#entries: PerformanceEntryList;
2929

3030
constructor(entries: PerformanceEntryList) {
31-
this._entries = entries;
31+
this.#entries = entries;
3232
}
3333

3434
getEntries(): PerformanceEntryList {
35-
return this._entries;
35+
return this.#entries;
3636
}
3737

3838
getEntriesByType(type: PerformanceEntryType): PerformanceEntryList {
39-
return this._entries.filter(entry => entry.entryType === type);
39+
return this.#entries.filter(entry => entry.entryType === type);
4040
}
4141

4242
getEntriesByName(
4343
name: string,
4444
type?: PerformanceEntryType,
4545
): PerformanceEntryList {
4646
if (type === undefined) {
47-
return this._entries.filter(entry => entry.name === name);
47+
return this.#entries.filter(entry => entry.name === name);
4848
} else {
49-
return this._entries.filter(
49+
return this.#entries.filter(
5050
entry => entry.name === name && entry.entryType === type,
5151
);
5252
}
@@ -175,11 +175,11 @@ function getSupportedPerformanceEntryTypes(): $ReadOnlyArray<PerformanceEntryTyp
175175
* observer.observe({ type: "event" });
176176
*/
177177
export default class PerformanceObserver {
178-
_callback: PerformanceObserverCallback;
179-
_type: 'single' | 'multiple' | void;
178+
#callback: PerformanceObserverCallback;
179+
#type: 'single' | 'multiple' | void;
180180

181181
constructor(callback: PerformanceObserverCallback) {
182-
this._callback = callback;
182+
this.#callback = callback;
183183
}
184184

185185
observe(options: PerformanceObserverInit): void {
@@ -188,17 +188,17 @@ export default class PerformanceObserver {
188188
return;
189189
}
190190

191-
this._validateObserveOptions(options);
191+
this.#validateObserveOptions(options);
192192

193193
let requestedEntryTypes;
194194

195195
if (options.entryTypes) {
196-
this._type = 'multiple';
196+
this.#type = 'multiple';
197197
requestedEntryTypes = new Map(
198198
options.entryTypes.map(t => [t, undefined]),
199199
);
200200
} else {
201-
this._type = 'single';
201+
this.#type = 'single';
202202
requestedEntryTypes = new Map([
203203
[options.type, options.durationThreshold],
204204
]);
@@ -217,7 +217,7 @@ export default class PerformanceObserver {
217217
}
218218

219219
registeredObservers.set(this, {
220-
callback: this._callback,
220+
callback: this.#callback,
221221
entryTypes: nextEntryTypes,
222222
});
223223

@@ -284,7 +284,7 @@ export default class PerformanceObserver {
284284
applyDurationThresholds();
285285
}
286286

287-
_validateObserveOptions(options: PerformanceObserverInit): void {
287+
#validateObserveOptions(options: PerformanceObserverInit): void {
288288
const {type, entryTypes, durationThreshold} = options;
289289

290290
if (!type && !entryTypes) {
@@ -299,13 +299,13 @@ export default class PerformanceObserver {
299299
);
300300
}
301301

302-
if (this._type === 'multiple' && type) {
302+
if (this.#type === 'multiple' && type) {
303303
throw new Error(
304304
"Failed to execute 'observe' on 'PerformanceObserver': This observer has performed observe({entryTypes:...}, therefore it cannot perform observe({type:...})",
305305
);
306306
}
307307

308-
if (this._type === 'single' && entryTypes) {
308+
if (this.#type === 'single' && entryTypes) {
309309
throw new Error(
310310
"Failed to execute 'observe' on 'PerformanceObserver': This PerformanceObserver has performed observe({type:...}, therefore it cannot perform observe({entryTypes:...})",
311311
);

packages/react-native/src/private/webapis/performance/ReactNativeStartupTiming.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ export default class ReactNativeStartupTiming {
2727
// We do NOT match web spect here for two reasons:
2828
// 1. The `ReactNativeStartupTiming` is non-standard API
2929
// 2. The timing information is relative to the time origin, which means `0` has valid meaning
30-
_startTime: ?number;
31-
_endTime: ?number;
32-
_initializeRuntimeStart: ?number;
33-
_initializeRuntimeEnd: ?number;
34-
_executeJavaScriptBundleEntryPointStart: ?number;
35-
_executeJavaScriptBundleEntryPointEnd: ?number;
30+
#startTime: ?number;
31+
#endTime: ?number;
32+
#initializeRuntimeStart: ?number;
33+
#initializeRuntimeEnd: ?number;
34+
#executeJavaScriptBundleEntryPointStart: ?number;
35+
#executeJavaScriptBundleEntryPointEnd: ?number;
3636

3737
constructor(startUpTiming: ?ReactNativeStartupTimingLike) {
3838
if (startUpTiming != null) {
39-
this._startTime = startUpTiming.startTime;
40-
this._endTime = startUpTiming.endTime;
41-
this._initializeRuntimeStart = startUpTiming.initializeRuntimeStart;
42-
this._initializeRuntimeEnd = startUpTiming.initializeRuntimeEnd;
43-
this._executeJavaScriptBundleEntryPointStart =
39+
this.#startTime = startUpTiming.startTime;
40+
this.#endTime = startUpTiming.endTime;
41+
this.#initializeRuntimeStart = startUpTiming.initializeRuntimeStart;
42+
this.#initializeRuntimeEnd = startUpTiming.initializeRuntimeEnd;
43+
this.#executeJavaScriptBundleEntryPointStart =
4444
startUpTiming.executeJavaScriptBundleEntryPointStart;
45-
this._executeJavaScriptBundleEntryPointEnd =
45+
this.#executeJavaScriptBundleEntryPointEnd =
4646
startUpTiming.executeJavaScriptBundleEntryPointEnd;
4747
}
4848
}
@@ -51,41 +51,41 @@ export default class ReactNativeStartupTiming {
5151
* Start time of the RN app startup process. This is provided by the platform by implementing the `ReactMarker.setAppStartTime` API in the native platform code.
5252
*/
5353
get startTime(): ?number {
54-
return this._startTime;
54+
return this.#startTime;
5555
}
5656

5757
/**
5858
* End time of the RN app startup process. This is equal to `executeJavaScriptBundleEntryPointEnd`.
5959
*/
6060
get endTime(): ?number {
61-
return this._endTime;
61+
return this.#endTime;
6262
}
6363

6464
/**
6565
* Start time when RN runtime get initialized. This is when RN infra first kicks in app startup process.
6666
*/
6767
get initializeRuntimeStart(): ?number {
68-
return this._initializeRuntimeStart;
68+
return this.#initializeRuntimeStart;
6969
}
7070

7171
/**
7272
* End time when RN runtime get initialized. This is the last marker before ends of the app startup process.
7373
*/
7474
get initializeRuntimeEnd(): ?number {
75-
return this._initializeRuntimeEnd;
75+
return this.#initializeRuntimeEnd;
7676
}
7777

7878
/**
7979
* Start time of JS bundle being executed. This indicates the RN JS bundle is loaded and start to be evaluated.
8080
*/
8181
get executeJavaScriptBundleEntryPointStart(): ?number {
82-
return this._executeJavaScriptBundleEntryPointStart;
82+
return this.#executeJavaScriptBundleEntryPointStart;
8383
}
8484

8585
/**
8686
* End time of JS bundle being executed. This indicates all the synchronous entry point jobs are finished.
8787
*/
8888
get executeJavaScriptBundleEntryPointEnd(): ?number {
89-
return this._executeJavaScriptBundleEntryPointEnd;
89+
return this.#executeJavaScriptBundleEntryPointEnd;
9090
}
9191
}

0 commit comments

Comments
 (0)