Skip to content

Commit

Permalink
chore: remove obsolete queryAllArray (#8847)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Aug 25, 2022
1 parent b49e742 commit 498fbf9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 43 deletions.
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

0 comments on commit 498fbf9

Please sign in to comment.