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));
}
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 = [];
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);
}
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', {
objectId: object._objectId!,
ownProperties: true

View File

@ -71,14 +71,14 @@ export class FFExecutionContext implements js.ExecutionContextDelegate {
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', {
executionContextId: this._executionContextId,
objectId: object._objectId!,
});
const result = new Map();
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;
}

View File

@ -51,7 +51,7 @@ export interface ExecutionContextDelegate {
rawEvaluateJSON(expression: string): Promise<any>;
rawEvaluateHandle(expression: string): Promise<ObjectId>;
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>;
}
@ -88,8 +88,8 @@ export class ExecutionContext extends SdkObject {
return this._raceAgainstContextDestroyed(this._delegate.evaluateWithArguments(expression, returnByValue, utilityScript, values, objectIds));
}
getProperties(context: ExecutionContext, object: JSHandle): Promise<Map<string, JSHandle>> {
return this._raceAgainstContextDestroyed(this._delegate.getProperties(context, object));
getProperties(object: JSHandle): Promise<Map<string, JSHandle>> {
return this._raceAgainstContextDestroyed(this._delegate.getProperties(object));
}
releaseHandle(objectId: ObjectId): Promise<void> {
@ -174,7 +174,7 @@ export class JSHandle<T = any> extends SdkObject {
async getProperties(): Promise<Map<string, JSHandle>> {
if (!this._objectId)
return new Map();
return this._context.getProperties(this._context, this);
return this._context.getProperties(this);
}
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', {
objectId: object._objectId!,
ownProperties: true
@ -96,7 +96,7 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
for (const property of response.properties) {
if (!property.enumerable || !property.value)
continue;
result.set(property.name, createHandle(context, property.value));
result.set(property.name, createHandle(object._context, property.value));
}
return result;
}