Skip to content

Commit

Permalink
fix(performance): cache isolatedHandle (#12150)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
Lightning00Blade and dependabot[bot] committed Apr 19, 2024
1 parent 3b70667 commit 9a17ec3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/update-browser-pins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion packages/puppeteer-core/src/api/ElementHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down

0 comments on commit 9a17ec3

Please sign in to comment.