Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: node::Environment self-cleanup #39604

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

ckerr
Copy link
Member

@ckerr ckerr commented Aug 22, 2023

Description of Change

  • NodeBindings::CreateEnvironment() now returns a std::shared_ptr<node::Environment> instead of a raw pointer. The new shared pointer has a custom deleter that knows how to cleanup both the node::Environment and its node::IsolateData.
  • Remove duplicated cleanup code from ElectronRenderClient, WebWorkerObserver, and NodeEnvironment, which all had code similar to the new deleter.
  • Removed now-unused class NodeEnvironment.
  • side refactor: since only NodeBindings uses kElectronContextEmbedderDataIndex, make it a private field.

The initial motivation for this PR was to fix a dangling raw_ptr bug in NodeEnvironment; but when investigating the code, it looks like there's an opportunity to reduce coupling across the above classes and remove some code duplication.

note: I'd particularly like revewer 馃憖 on the changes in NodeBindings.cc, e.g. is the v8::Context being handled correctly when it's passed to the deleter lambda?

Checklist

Release Notes

Notes: none.

@electron-cation electron-cation bot added the new-pr 馃尡 PR opened in the last 24 hours label Aug 22, 2023
@ckerr ckerr marked this pull request as draft August 22, 2023 00:17
@ckerr ckerr added semver/patch backwards-compatible bug fixes target/26-x-y PR should also be added to the "26-x-y" branch. target/27-x-y PR should also be added to the "27-x-y" branch. labels Aug 22, 2023
@ckerr ckerr marked this pull request as ready for review August 22, 2023 01:29
@ckerr ckerr changed the title refactor: Node environment self-cleanup refactor: node::Environment self-cleanup Aug 22, 2023
@electron-cation electron-cation bot removed the new-pr 馃尡 PR opened in the last 24 hours label Aug 23, 2023
@jkleinsc jkleinsc merged commit 3596993 into main Aug 23, 2023
27 checks passed
@jkleinsc jkleinsc deleted the refactor-node-environment-self-cleanup branch August 23, 2023 13:56
@release-clerk
Copy link

release-clerk bot commented Aug 23, 2023

No Release Notes

@trop
Copy link
Contributor

trop bot commented Aug 23, 2023

I was unable to backport this PR to "26-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot added needs-manual-bp/26-x-y and removed target/26-x-y PR should also be added to the "26-x-y" branch. labels Aug 23, 2023
@trop
Copy link
Contributor

trop bot commented Aug 23, 2023

I have automatically backported this PR to "27-x-y", please check out #39628

@trop trop bot added in-flight/27-x-y merged/27-x-y PR was merged to the "27-x-y" branch. and removed target/27-x-y PR should also be added to the "27-x-y" branch. in-flight/27-x-y labels Aug 23, 2023
MrHuangJser pushed a commit to MrHuangJser/electron that referenced this pull request Dec 11, 2023
* chore: savepoint

* chore: turn raw_ptr tests back off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged/27-x-y PR was merged to the "27-x-y" branch. semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants