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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use base::Value::Take*() #41169

Merged
merged 3 commits into from
May 13, 2024
Merged

Conversation

ckerr
Copy link
Member

@ckerr ckerr commented Jan 30, 2024

Description of Change

Use base::Value::TakeDict(), TakeList(), and TakeString() where appropriate.

  1. The docs recommend changing our current std::move(value.Get*()) to std::move(value).Take*() for better build-time checks.
  2. In some cases, e.g. when we're pulling data out of a temporary base::Value::Dict, we can avoid extra work by Take*()ing objects directly from the temporary dict instead of copying them.

Description from values.h code comments:

// Transfers ownership of the underlying value. Similarly to Get...()
// variants above, fails with a CHECK() on a type mismatch. After
// transferring the ownership *this is in a valid, but unspecified, state.
// Prefer over std::move(value.Get...()) so clang-tidy can warn about
// potential use-after-move mistakes.
std::string TakeString() &&;
Dict TakeDict() &&;
List TakeList() &&;

Checklist

Release Notes

Notes: none.

@ckerr ckerr added semver/patch backwards-compatible bug fixes target/28-x-y PR should also be added to the "28-x-y" branch. target/29-x-y PR should also be added to the "29-x-y" branch. labels Jan 30, 2024
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 30, 2024
Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckerr these two tests are failing consistently on macOS & Linux:

  • protocol module protocol.registerSchemesAsPrivileged stream successfully plays videos when content is buffered (stream: false)
  • protocol module protocol.registerSchemesAsPrivileged stream successfully plays videos when streaming content (stream: true)

Looks like this change inadvertently broke them somehow 🤔

@ckerr ckerr marked this pull request as draft January 31, 2024 15:13
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jan 31, 2024
@ckerr ckerr force-pushed the refactor/use-base-Value-Take branch from 6c1a1d1 to e0192dd Compare February 1, 2024 16:08
@ckerr ckerr marked this pull request as ready for review February 1, 2024 16:10
@electron-cation electron-cation bot added new-pr 🌱 PR opened in the last 24 hours and removed new-pr 🌱 PR opened in the last 24 hours labels Feb 1, 2024
@ckerr ckerr marked this pull request as draft February 3, 2024 17:31
@github-actions github-actions bot added the target/30-x-y PR should also be added to the "30-x-y" branch. label Feb 21, 2024
@github-actions github-actions bot added the target/31-x-y PR should also be added to the "31-x-y" branch. label Apr 17, 2024
@ckerr ckerr removed target/28-x-y PR should also be added to the "28-x-y" branch. target/29-x-y PR should also be added to the "29-x-y" branch. target/30-x-y PR should also be added to the "30-x-y" branch. target/31-x-y PR should also be added to the "31-x-y" branch. labels May 9, 2024
ckerr added 2 commits May 8, 2024 21:59
As per the base::Value docs: "prefer over `std::move(value.Get...())`
so clang-tidy can warn about potential use-after-move mistakes."
@ckerr ckerr force-pushed the refactor/use-base-Value-Take branch from e0192dd to 4556cef Compare May 9, 2024 03:01
@ckerr ckerr marked this pull request as ready for review May 9, 2024 15:05
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label May 9, 2024
@ckerr ckerr requested a review from codebytere May 10, 2024 14:55
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label May 10, 2024
@codebytere codebytere merged commit 10fd0ba into main May 13, 2024
20 checks passed
@codebytere codebytere deleted the refactor/use-base-Value-Take branch May 13, 2024 13:58
Copy link

release-clerk bot commented May 13, 2024

No Release Notes

Mrnikifabio pushed a commit to Mrnikifabio/electron that referenced this pull request May 14, 2024
* perf: avoid temporary strings in Converter<net::HttpRequestHeaders>::FromV8()

* perf: take strings instead of copying them in ToResponseHead()

* refactor: prefer base::Value::Take*() where appropriate

As per the base::Value docs: "prefer over `std::move(value.Get...())`
so clang-tidy can warn about potential use-after-move mistakes."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants