chore: don't use Object.freeze for internal properties (#10945)

This commit is contained in:
Nikolay Vitkov 2023-09-20 15:59:00 +02:00 committed by GitHub
parent 3fc8da9955
commit ce5461d0d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 19 deletions

View File

@ -104,7 +104,7 @@ export class BidiPage extends Page {
], ],
['browsingContext.userPromptOpened', this.#onDialog.bind(this)], ['browsingContext.userPromptOpened', this.#onDialog.bind(this)],
]); ]);
#networkManagerEvents = Object.freeze([ readonly #networkManagerEvents = [
[ [
NetworkManagerEvent.Request, NetworkManagerEvent.Request,
(request: BidiHTTPRequest) => { (request: BidiHTTPRequest) => {
@ -135,9 +135,9 @@ export class BidiPage extends Page {
this.emit(PageEvent.Response, response); this.emit(PageEvent.Response, response);
}, },
], ],
] as const); ] as const;
#browsingContextEvents = new Map<symbol, Handler<any>>([ readonly #browsingContextEvents = new Map<symbol, Handler<any>>([
[BrowsingContextEvent.Created, this.#onContextCreated.bind(this)], [BrowsingContextEvent.Created, this.#onContextCreated.bind(this)],
[BrowsingContextEvent.Destroyed, this.#onContextDestroyed.bind(this)], [BrowsingContextEvent.Destroyed, this.#onContextDestroyed.bind(this)],
]); ]);

View File

@ -44,11 +44,10 @@ interface ARIASelector {
role?: string; role?: string;
} }
const KNOWN_ATTRIBUTES = Object.freeze(['name', 'role']);
const isKnownAttribute = ( const isKnownAttribute = (
attribute: string attribute: string
): attribute is keyof ARIASelector => { ): attribute is keyof ARIASelector => {
return KNOWN_ATTRIBUTES.includes(attribute); return ['name', 'role'].includes(attribute);
}; };
const normalizeValue = (value: string): string => { const normalizeValue = (value: string): string => {

View File

@ -113,7 +113,7 @@ export class NetworkManager extends EventEmitter<CdpNetworkManagerEvents> {
#userAgent?: string; #userAgent?: string;
#userAgentMetadata?: Protocol.Emulation.UserAgentMetadata; #userAgentMetadata?: Protocol.Emulation.UserAgentMetadata;
#handlers = Object.freeze([ readonly #handlers = [
['Fetch.requestPaused', this.#onRequestPaused], ['Fetch.requestPaused', this.#onRequestPaused],
['Fetch.authRequired', this.#onAuthRequired], ['Fetch.authRequired', this.#onAuthRequired],
['Network.requestWillBeSent', this.#onRequestWillBeSent], ['Network.requestWillBeSent', this.#onRequestWillBeSent],
@ -123,7 +123,7 @@ export class NetworkManager extends EventEmitter<CdpNetworkManagerEvents> {
['Network.loadingFailed', this.#onLoadingFailed], ['Network.loadingFailed', this.#onLoadingFailed],
['Network.responseReceivedExtraInfo', this.#onResponseReceivedExtraInfo], ['Network.responseReceivedExtraInfo', this.#onResponseReceivedExtraInfo],
[CDPSessionEvent.Disconnected, this.#removeClient], [CDPSessionEvent.Disconnected, this.#removeClient],
] as const); ] as const;
#clients = new Map<CDPSession, DisposableStack>(); #clients = new Map<CDPSession, DisposableStack>();

View File

@ -143,7 +143,7 @@ export class CdpPage extends Page {
#serviceWorkerBypassed = false; #serviceWorkerBypassed = false;
#userDragInterceptionEnabled = false; #userDragInterceptionEnabled = false;
#frameManagerHandlers = Object.freeze([ readonly #frameManagerHandlers = [
[ [
FrameManagerEvent.FrameAttached, FrameManagerEvent.FrameAttached,
(frame: CdpFrame) => { (frame: CdpFrame) => {
@ -162,9 +162,9 @@ export class CdpPage extends Page {
this.emit(PageEvent.FrameNavigated, frame); this.emit(PageEvent.FrameNavigated, frame);
}, },
], ],
] as const); ] as const;
#networkManagerHandlers = Object.freeze([ readonly #networkManagerHandlers = [
[ [
NetworkManagerEvent.Request, NetworkManagerEvent.Request,
(request: HTTPRequest) => { (request: HTTPRequest) => {
@ -195,9 +195,9 @@ export class CdpPage extends Page {
this.emit(PageEvent.RequestFinished, request); this.emit(PageEvent.RequestFinished, request);
}, },
], ],
] as const); ] as const;
#sessionHandlers = Object.freeze([ readonly #sessionHandlers = [
[ [
CDPSessionEvent.Disconnected, CDPSessionEvent.Disconnected,
() => { () => {
@ -226,7 +226,7 @@ export class CdpPage extends Page {
['Performance.metrics', this.#emitMetrics.bind(this)], ['Performance.metrics', this.#emitMetrics.bind(this)],
['Log.entryAdded', this.#onLogEntryAdded.bind(this)], ['Log.entryAdded', this.#onLogEntryAdded.bind(this)],
['Page.fileChooserOpened', this.#onFileChooser.bind(this)], ['Page.fileChooserOpened', this.#onFileChooser.bind(this)],
] as const); ] as const;
constructor( constructor(
client: CDPSession, client: CDPSession,

View File

@ -23,15 +23,12 @@ import type {QueryHandler} from './QueryHandler.js';
import {TextQueryHandler} from './TextQueryHandler.js'; import {TextQueryHandler} from './TextQueryHandler.js';
import {XPathQueryHandler} from './XPathQueryHandler.js'; import {XPathQueryHandler} from './XPathQueryHandler.js';
/** const BUILTIN_QUERY_HANDLERS = {
* @internal
*/
export const BUILTIN_QUERY_HANDLERS = Object.freeze({
aria: ARIAQueryHandler, aria: ARIAQueryHandler,
pierce: PierceQueryHandler, pierce: PierceQueryHandler,
xpath: XPathQueryHandler, xpath: XPathQueryHandler,
text: TextQueryHandler, text: TextQueryHandler,
}); } as const;
const QUERY_SEPARATORS = ['=', '/']; const QUERY_SEPARATORS = ['=', '/'];
@ -42,7 +39,7 @@ export function getQueryHandlerByName(
name: string name: string
): typeof QueryHandler | undefined { ): typeof QueryHandler | undefined {
if (name in BUILTIN_QUERY_HANDLERS) { if (name in BUILTIN_QUERY_HANDLERS) {
return BUILTIN_QUERY_HANDLERS[name as 'aria']; return BUILTIN_QUERY_HANDLERS[name as keyof typeof BUILTIN_QUERY_HANDLERS];
} }
return customQueryHandlers.get(name); return customQueryHandlers.get(name);
} }