fix(performance): cache isolatedHandle (#12150)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
Nikolay Vitkov 2024-04-19 11:55:05 +02:00 committed by GitHub
parent 3b70667a47
commit 9a17ec3b2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View File

@ -32,7 +32,7 @@ jobs:
node tools/update_chrome_revision.mjs
- name: Create Pull Request
if: ${{ steps.update.outputs.commit }}
uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e # v6.0.2
uses: peter-evans/create-pull-request@c55203cfde3e5c11a452d352b4393e68b85b4533 # v6.0.3
with:
token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }}
branch: browser-automation-bot/update-browser-version-chrome
@ -64,7 +64,7 @@ jobs:
node packages/browsers/tools/updateVersions.mjs
- name: Create Pull Request
if: ${{ steps.update.outputs.commit }}
uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e # v6.0.2
uses: peter-evans/create-pull-request@c55203cfde3e5c11a452d352b4393e68b85b4533 # v6.0.3
with:
token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }}
branch: browser-automation-bot/update-browser-version-firefox

View File

@ -145,6 +145,13 @@ export abstract class ElementHandle<
*/
declare [_isElementHandle]: boolean;
/**
* @internal
* Cached isolatedHandle to prevent
* trying to adopt it multiple times
*/
isolatedHandle?: typeof this;
/**
* A given method will have it's `this` replaced with an isolated version of
* `this` when decorated with this decorator.
@ -163,7 +170,14 @@ export abstract class ElementHandle<
if (this.realm === this.frame.isolatedRealm()) {
return await target.call(this, ...args);
}
using adoptedThis = await this.frame.isolatedRealm().adoptHandle(this);
let adoptedThis: This;
if (this['isolatedHandle']) {
adoptedThis = this['isolatedHandle'];
} else {
this['isolatedHandle'] = adoptedThis = await this.frame
.isolatedRealm()
.adoptHandle(this);
}
const result = await target.call(adoptedThis, ...args);
// If the function returns `adoptedThis`, then we return `this`.
if (result === adoptedThis) {