chore: getProperties can use context stored in JSHandle (#34893)

This commit is contained in:
Yury Semikhatsky 2025-02-21 17:55:02 -08:00 committed by GitHub
parent 1af59ee523
commit e38099ef13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 10 additions and 10 deletions

View file

@ -104,7 +104,7 @@ export class BidiExecutionContext implements js.ExecutionContextDelegate {
throw new js.JavaScriptErrorInEvaluate('Unexpected response type: ' + JSON.stringify(response)); throw new js.JavaScriptErrorInEvaluate('Unexpected response type: ' + JSON.stringify(response));
} }
async getProperties(context: js.ExecutionContext, handle: js.JSHandle): Promise<Map<string, js.JSHandle>> { async getProperties(handle: js.JSHandle): Promise<Map<string, js.JSHandle>> {
const names = await handle.evaluate(object => { const names = await handle.evaluate(object => {
const names = []; const names = [];
const descriptors = Object.getOwnPropertyDescriptors(object); const descriptors = Object.getOwnPropertyDescriptors(object);

View file

@ -74,7 +74,7 @@ export class CRExecutionContext implements js.ExecutionContextDelegate {
return returnByValue ? parseEvaluationResultValue(remoteObject.value) : createHandle(utilityScript._context, remoteObject); return returnByValue ? parseEvaluationResultValue(remoteObject.value) : createHandle(utilityScript._context, remoteObject);
} }
async getProperties(context: js.ExecutionContext, object: js.JSHandle): Promise<Map<string, js.JSHandle>> { async getProperties(object: js.JSHandle): Promise<Map<string, js.JSHandle>> {
const response = await this._client.send('Runtime.getProperties', { const response = await this._client.send('Runtime.getProperties', {
objectId: object._objectId!, objectId: object._objectId!,
ownProperties: true ownProperties: true

View file

@ -71,14 +71,14 @@ export class FFExecutionContext implements js.ExecutionContextDelegate {
return createHandle(utilityScript._context, payload.result!); return createHandle(utilityScript._context, payload.result!);
} }
async getProperties(context: js.ExecutionContext, object: js.JSHandle): Promise<Map<string, js.JSHandle>> { async getProperties(object: js.JSHandle): Promise<Map<string, js.JSHandle>> {
const response = await this._session.send('Runtime.getObjectProperties', { const response = await this._session.send('Runtime.getObjectProperties', {
executionContextId: this._executionContextId, executionContextId: this._executionContextId,
objectId: object._objectId!, objectId: object._objectId!,
}); });
const result = new Map(); const result = new Map();
for (const property of response.properties) for (const property of response.properties)
result.set(property.name, createHandle(context, property.value)); result.set(property.name, createHandle(object._context, property.value));
return result; return result;
} }

View file

@ -51,7 +51,7 @@ export interface ExecutionContextDelegate {
rawEvaluateJSON(expression: string): Promise<any>; rawEvaluateJSON(expression: string): Promise<any>;
rawEvaluateHandle(expression: string): Promise<ObjectId>; rawEvaluateHandle(expression: string): Promise<ObjectId>;
evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: JSHandle<any>, values: any[], objectIds: ObjectId[]): Promise<any>; evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: JSHandle<any>, values: any[], objectIds: ObjectId[]): Promise<any>;
getProperties(context: ExecutionContext, object: JSHandle): Promise<Map<string, JSHandle>>; getProperties(object: JSHandle): Promise<Map<string, JSHandle>>;
releaseHandle(objectId: ObjectId): Promise<void>; releaseHandle(objectId: ObjectId): Promise<void>;
} }
@ -88,8 +88,8 @@ export class ExecutionContext extends SdkObject {
return this._raceAgainstContextDestroyed(this._delegate.evaluateWithArguments(expression, returnByValue, utilityScript, values, objectIds)); return this._raceAgainstContextDestroyed(this._delegate.evaluateWithArguments(expression, returnByValue, utilityScript, values, objectIds));
} }
getProperties(context: ExecutionContext, object: JSHandle): Promise<Map<string, JSHandle>> { getProperties(object: JSHandle): Promise<Map<string, JSHandle>> {
return this._raceAgainstContextDestroyed(this._delegate.getProperties(context, object)); return this._raceAgainstContextDestroyed(this._delegate.getProperties(object));
} }
releaseHandle(objectId: ObjectId): Promise<void> { releaseHandle(objectId: ObjectId): Promise<void> {
@ -174,7 +174,7 @@ export class JSHandle<T = any> extends SdkObject {
async getProperties(): Promise<Map<string, JSHandle>> { async getProperties(): Promise<Map<string, JSHandle>> {
if (!this._objectId) if (!this._objectId)
return new Map(); return new Map();
return this._context.getProperties(this._context, this); return this._context.getProperties(this);
} }
rawValue() { rawValue() {

View file

@ -87,7 +87,7 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
} }
} }
async getProperties(context: js.ExecutionContext, object: js.JSHandle): Promise<Map<string, js.JSHandle>> { async getProperties(object: js.JSHandle): Promise<Map<string, js.JSHandle>> {
const response = await this._session.send('Runtime.getProperties', { const response = await this._session.send('Runtime.getProperties', {
objectId: object._objectId!, objectId: object._objectId!,
ownProperties: true ownProperties: true
@ -96,7 +96,7 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
for (const property of response.properties) { for (const property of response.properties) {
if (!property.enumerable || !property.value) if (!property.enumerable || !property.value)
continue; continue;
result.set(property.name, createHandle(context, property.value)); result.set(property.name, createHandle(object._context, property.value));
} }
return result; return result;
} }