Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove obsolete queryAllArray #8847

Merged
merged 1 commit into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/common/AriaQueryHandler.ts
Expand Up @@ -17,13 +17,12 @@
import {Protocol} from 'devtools-protocol';
import {assert} from '../util/assert.js';
import {CDPSession} from './Connection.js';
import {ElementHandle} from './ElementHandle.js';
import {
IsolatedWorld,
PageBinding,
WaitForSelectorOptions,
} from './IsolatedWorld.js';
import {ElementHandle} from './ElementHandle.js';
import {JSHandle} from './JSHandle.js';
import {InternalQueryHandler} from './QueryHandler.js';

async function queryAXTree(
Expand Down Expand Up @@ -149,24 +148,11 @@ const queryAll = async (
);
};

const queryAllArray = async (
element: ElementHandle<Node>,
selector: string
): Promise<JSHandle<Node[]>> => {
const elementHandles = await queryAll(element, selector);
const exeCtx = element.executionContext();
const jsHandle = exeCtx.evaluateHandle((...elements) => {
return elements;
}, ...elementHandles);
return jsHandle;
};

/**
* @internal
*/
export const ariaHandler: InternalQueryHandler = {
queryOne,
waitFor,
queryAll,
queryAllArray,
};
23 changes: 17 additions & 6 deletions src/common/ElementHandle.ts
Expand Up @@ -19,7 +19,7 @@ import {
} from './JSHandle.js';
import {Page, ScreenshotOptions} from './Page.js';
import {getQueryHandlerAndSelector} from './QueryHandler.js';
import {EvaluateFunc, NodeFor} from './types.js';
import {EvaluateFunc, HandleFor, NodeFor} from './types.js';
import {KeyInput} from './USKeyboardLayout.js';
import {debugError, isString} from './util.js';

Expand Down Expand Up @@ -236,13 +236,24 @@ export class ElementHandle<
): Promise<Awaited<ReturnType<Func>>> {
const {updatedSelector, queryHandler} =
getQueryHandlerAndSelector(selector);
assert(queryHandler.queryAllArray);
const arrayHandle = (await queryHandler.queryAllArray(
assert(
queryHandler.queryAll,
'Cannot handle queries for a multiple element with the given selector'
);
const handles = (await queryHandler.queryAll(
this,
updatedSelector
)) as JSHandle<Array<NodeFor<Selector>>>;
const result = await arrayHandle.evaluate(pageFunction, ...args);
await arrayHandle.dispose();
)) as Array<HandleFor<NodeFor<Selector>>>;
const elements = await this.evaluateHandle((_, ...elements) => {
return elements;
}, ...handles);
const [result] = await Promise.all([
elements.evaluate(pageFunction, ...args),
...handles.map(handle => {
return handle.dispose();
}),
]);
await elements.dispose();
return result;
}

Expand Down
23 changes: 1 addition & 22 deletions src/common/QueryHandler.ts
Expand Up @@ -15,9 +15,8 @@
*/

import {ariaHandler} from './AriaQueryHandler.js';
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
import {ElementHandle} from './ElementHandle.js';
import {JSHandle} from './JSHandle.js';
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';

/**
* @public
Expand Down Expand Up @@ -55,16 +54,6 @@ export interface InternalQueryHandler {
element: ElementHandle<Node>,
selector: string
) => Promise<Array<ElementHandle<Node>>>;
/**
* Queries for multiple nodes given a selector and {@link ElementHandle}.
* Unlike {@link queryAll}, this returns a handle to a node array.
*
* Akin to {@link Window.prototype.querySelectorAll}.
*/
queryAllArray?: (
element: ElementHandle<Node>,
selector: string
) => Promise<JSHandle<Node[]>>;

/**
* Waits until a single node appears for a given selector and
Expand Down Expand Up @@ -119,16 +108,6 @@ function internalizeCustomQueryHandler(
}
return result;
};
internalHandler.queryAllArray = async (element, selector) => {
const resultHandle = (await element.evaluateHandle(
queryAll,
selector
)) as JSHandle<Element[] | NodeListOf<Element>>;
const arrayHandle = await resultHandle.evaluateHandle(res => {
return Array.from(res);
});
return arrayHandle;
};
}

return internalHandler;
Expand Down