chore: fix all Proxy() to account for symbol properties (#21272)

Fixes #20940.
This commit is contained in:
Dmitry Gozman 2023-02-28 12:45:14 -08:00 коммит произвёл GitHub
Родитель 9b78b7151e
Коммит 27027658dc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 21 добавлений и 7 удалений

Просмотреть файл

@ -132,7 +132,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
private _createChannel(base: Object): T {
const channel = new Proxy(base, {
get: (obj: any, prop) => {
get: (obj: any, prop: string | symbol) => {
if (typeof prop === 'string') {
const validator = maybeFindValidator(this._type, prop, 'Params');
if (validator) {

Просмотреть файл

@ -31,7 +31,9 @@ export interface ClientInstrumentationListener {
export function createInstrumentation(): ClientInstrumentation {
const listeners: ClientInstrumentationListener[] = [];
return new Proxy({}, {
get: (obj: any, prop: string) => {
get: (obj: any, prop: string | symbol) => {
if (typeof prop !== 'string')
return obj[prop];
if (prop === 'addListener')
return (listener: ClientInstrumentationListener) => listeners.push(listener);
if (prop === 'removeListener')

Просмотреть файл

@ -84,7 +84,9 @@ export interface InstrumentationListener {
export function createInstrumentation(): Instrumentation {
const listeners = new Map<InstrumentationListener, BrowserContext | APIRequestContext | null>();
return new Proxy({}, {
get: (obj: any, prop: string) => {
get: (obj: any, prop: string | symbol) => {
if (typeof prop !== 'string')
return obj[prop];
if (prop === 'addListener')
return (listener: InstrumentationListener, context: BrowserContext | APIRequestContext | null) => listeners.set(listener, context);
if (prop === 'removeListener')

Просмотреть файл

@ -32,7 +32,7 @@ export class SocksInterceptor {
let lastId = -1;
this._channel = new Proxy(new EventEmitter(), {
get: (obj: any, prop) => {
get: (obj: any, prop: string | symbol) => {
if ((prop in obj) || obj[prop] !== undefined || typeof prop !== 'string')
return obj[prop];
return (params: any) => {

Просмотреть файл

@ -101,7 +101,7 @@ export const printReceivedStringContainExpectedResult = (
type ExpectMessageOrOptions = undefined | string | { message?: string, timeout?: number, intervals?: number[] };
function createExpect(actual: unknown, messageOrOptions: ExpectMessageOrOptions, isSoft: boolean, isPoll: boolean, generator?: Generator) {
function createExpect(actual: unknown, messageOrOptions: ExpectMessageOrOptions, isSoft: boolean, isPoll: boolean, generator?: Generator): any {
return new Proxy(expectLibrary(actual), new ExpectMetaInfoProxyHandler(messageOrOptions, isSoft, isPoll, generator));
}
@ -164,7 +164,7 @@ type ExpectMetaInfo = {
generator?: Generator;
};
class ExpectMetaInfoProxyHandler {
class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
private _info: ExpectMetaInfo;
constructor(messageOrOptions: ExpectMessageOrOptions, isSoft: boolean, isPoll: boolean, generator?: Generator) {
@ -178,8 +178,10 @@ class ExpectMetaInfoProxyHandler {
}
}
get(target: any, matcherName: any, receiver: any): any {
get(target: Object, matcherName: string | symbol, receiver: any): any {
let matcher = Reflect.get(target, matcherName, receiver);
if (typeof matcherName !== 'string')
return matcher;
if (matcher === undefined)
throw new Error(`expect: Property '${matcherName}' not found.`);
if (typeof matcher !== 'function') {

Просмотреть файл

@ -257,3 +257,11 @@ it('has navigator.webdriver set to true', async ({ page, browserName }) => {
it.skip(browserName === 'firefox');
expect(await page.evaluate(() => navigator.webdriver)).toBe(true);
});
it('should iterate over page properties', async ({ page }) => {
const props = [];
for (const prop in page) {
if (page[prop] && typeof page[prop] === 'object')
props.push(page[prop][Symbol.iterator]);
}
});