utilityScriptObjects

This commit is contained in:
Yury Semikhatsky 2025-02-24 10:45:27 -08:00
parent fdda58d738
commit bad7da51c3

View file

@ -256,11 +256,11 @@ export async function evaluateExpression(context: ExecutionContext, expression:
return { fallThrough: handle }; return { fallThrough: handle };
})); }));
const utilityScriptObjectIds: JSHandle[] = []; const utilityScriptObjects: JSHandle[] = [];
for (const handle of await Promise.all(handles)) { for (const handle of await Promise.all(handles)) {
if (handle._context !== context) if (handle._context !== context)
throw new JavaScriptErrorInEvaluate('JSHandles can be evaluated only in the context they were created!'); throw new JavaScriptErrorInEvaluate('JSHandles can be evaluated only in the context they were created!');
utilityScriptObjectIds.push(handle); utilityScriptObjects.push(handle);
} }
// See UtilityScript for arguments. // See UtilityScript for arguments.
@ -268,7 +268,7 @@ export async function evaluateExpression(context: ExecutionContext, expression:
const script = `(utilityScript, ...args) => utilityScript.evaluate(...args)`; const script = `(utilityScript, ...args) => utilityScript.evaluate(...args)`;
try { try {
return await context.evaluateWithArguments(script, options.returnByValue || false, utilityScriptValues, utilityScriptObjectIds); return await context.evaluateWithArguments(script, options.returnByValue || false, utilityScriptValues, utilityScriptObjects);
} finally { } finally {
toDispose.map(handlePromise => handlePromise.then(handle => handle.dispose())); toDispose.map(handlePromise => handlePromise.then(handle => handle.dispose()));
} }