chore: migrate base::StringPiece to std::string_view (#40915)
* chore: migrate from base::StringPiece to std::string_view in keyboard_util.cc
* chore: migrate from base::StringPiece to std::string_view in error_thrower.cc
* chore: migrate from base::StringPiece to std::string_view in electron_api_web_contents.cc
* chore: migrate from base::StringPiece to std::string_view in gin_helper/dictionary.h
* chore: migrate from base::StringPiece to std::string_view in electron_api_url_loader.cc
* chore: phase out internal use of base:::StringPiece
`base::StringPiece` is being phased out upstream. Its code has been
removed upstream and it's just a typedef for `std::string_view`.
They haven't removed the typedef yet, so this PR tries to get ahead
of future breakage by migrating "internal" use (i.e. leaving alone the
places where the `base::StringPiece` name is coming from an upstream
method that we override).
Xref: https://bugs.chromium.org/p/chromium/issues/detail?id=691162
Xref: 4294483
Xref: https://docs.google.com/document/d/1d4RnD1uAE2t4iANR0nXy82ASIPGsPuw2mpO6v6T7JKs
This commit is contained in:
parent
892c9d78a3
commit
f36ceae024
45 changed files with 223 additions and 174 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -68,7 +69,7 @@ struct Converter<network::mojom::CredentialsMode> {
|
|||
network::mojom::CredentialsMode* out) {
|
||||
using Val = network::mojom::CredentialsMode;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"include", Val::kInclude},
|
||||
{"omit", Val::kOmit},
|
||||
// Note: This only makes sense if the request
|
||||
|
@ -86,7 +87,7 @@ struct Converter<blink::mojom::FetchCacheMode> {
|
|||
blink::mojom::FetchCacheMode* out) {
|
||||
using Val = blink::mojom::FetchCacheMode;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"default", Val::kDefault},
|
||||
{"force-cache", Val::kForceCache},
|
||||
{"no-cache", Val::kValidateCache},
|
||||
|
@ -106,7 +107,7 @@ struct Converter<net::ReferrerPolicy> {
|
|||
using Val = net::ReferrerPolicy;
|
||||
// clang-format off
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"", Val::REDUCE_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN},
|
||||
{"no-referrer", Val::NO_REFERRER},
|
||||
{"no-referrer-when-downgrade", Val::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE},
|
||||
|
@ -546,7 +547,7 @@ gin::Handle<SimpleURLLoaderWrapper> SimpleURLLoaderWrapper::Create(
|
|||
if (std::string mode; opts.Get("mode", &mode)) {
|
||||
using Val = network::mojom::RequestMode;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"cors", Val::kCors},
|
||||
{"navigate", Val::kNavigate},
|
||||
{"no-cors", Val::kNoCors},
|
||||
|
@ -559,7 +560,7 @@ gin::Handle<SimpleURLLoaderWrapper> SimpleURLLoaderWrapper::Create(
|
|||
if (std::string destination; opts.Get("destination", &destination)) {
|
||||
using Val = network::mojom::RequestDestination;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"audio", Val::kAudio},
|
||||
{"audioworklet", Val::kAudioWorklet},
|
||||
{"document", Val::kDocument},
|
||||
|
@ -694,7 +695,7 @@ gin::Handle<SimpleURLLoaderWrapper> SimpleURLLoaderWrapper::Create(
|
|||
return ret;
|
||||
}
|
||||
|
||||
void SimpleURLLoaderWrapper::OnDataReceived(base::StringPiece string_piece,
|
||||
void SimpleURLLoaderWrapper::OnDataReceived(std::string_view string_piece,
|
||||
base::OnceClosure resume) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "shell/common/asar/archive.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -105,7 +106,7 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
|
|||
|
||||
const std::string* offset = node->FindString("offset");
|
||||
if (offset &&
|
||||
base::StringToUint64(base::StringPiece(*offset), &info->offset)) {
|
||||
base::StringToUint64(std::string_view{*offset}, &info->offset)) {
|
||||
info->offset += header_size;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/fixed_flat_map.h"
|
||||
|
@ -135,7 +136,7 @@ struct Converter<blink::WebMouseEvent::Button> {
|
|||
blink::WebMouseEvent::Button* out) {
|
||||
using Val = blink::WebMouseEvent::Button;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"left", Val::kLeft},
|
||||
{"middle", Val::kMiddle},
|
||||
{"right", Val::kRight},
|
||||
|
@ -148,7 +149,7 @@ struct Converter<blink::WebMouseEvent::Button> {
|
|||
|
||||
// these are the modifier names we both accept and return
|
||||
static constexpr auto Modifiers =
|
||||
base::MakeFixedFlatMap<base::StringPiece, blink::WebInputEvent::Modifiers>({
|
||||
base::MakeFixedFlatMap<std::string_view, blink::WebInputEvent::Modifiers>({
|
||||
{"alt", blink::WebInputEvent::Modifiers::kAltKey},
|
||||
{"capslock", blink::WebInputEvent::Modifiers::kCapsLockOn},
|
||||
{"control", blink::WebInputEvent::Modifiers::kControlKey},
|
||||
|
@ -167,14 +168,14 @@ static constexpr auto Modifiers =
|
|||
|
||||
// these are the modifier names we accept but do not return
|
||||
static constexpr auto ModifierAliases =
|
||||
base::MakeFixedFlatMap<base::StringPiece, blink::WebInputEvent::Modifiers>({
|
||||
base::MakeFixedFlatMap<std::string_view, blink::WebInputEvent::Modifiers>({
|
||||
{"cmd", blink::WebInputEvent::Modifiers::kMetaKey},
|
||||
{"command", blink::WebInputEvent::Modifiers::kMetaKey},
|
||||
{"ctrl", blink::WebInputEvent::Modifiers::kControlKey},
|
||||
});
|
||||
|
||||
static constexpr auto ReferrerPolicies =
|
||||
base::MakeFixedFlatMap<base::StringPiece, network::mojom::ReferrerPolicy>({
|
||||
base::MakeFixedFlatMap<std::string_view, network::mojom::ReferrerPolicy>({
|
||||
{"default", network::mojom::ReferrerPolicy::kDefault},
|
||||
{"no-referrer", network::mojom::ReferrerPolicy::kNever},
|
||||
{"no-referrer-when-downgrade", network::mojom::ReferrerPolicy::kNoReferrerWhenDowngrade},
|
||||
|
@ -197,8 +198,8 @@ struct Converter<blink::WebInputEvent::Modifiers> {
|
|||
}
|
||||
};
|
||||
|
||||
std::vector<base::StringPiece> ModifiersToArray(int modifiers) {
|
||||
std::vector<base::StringPiece> modifier_strings;
|
||||
std::vector<std::string_view> ModifiersToArray(int modifiers) {
|
||||
std::vector<std::string_view> modifier_strings;
|
||||
|
||||
for (const auto& [name, mask] : Modifiers)
|
||||
if (mask & modifiers)
|
||||
|
@ -463,7 +464,7 @@ v8::Local<v8::Value>
|
|||
Converter<std::optional<blink::mojom::FormControlType>>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const std::optional<blink::mojom::FormControlType>& in) {
|
||||
base::StringPiece str{"none"};
|
||||
std::string_view str{"none"};
|
||||
if (in.has_value()) {
|
||||
switch (*in) {
|
||||
case blink::mojom::FormControlType::kButtonButton:
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "shell/common/gin_converters/content_converter.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/containers/fixed_flat_map.h"
|
||||
#include "content/public/browser/context_menu_params.h"
|
||||
|
@ -24,7 +25,7 @@
|
|||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] constexpr base::StringPiece FormControlToInputFieldTypeString(
|
||||
[[nodiscard]] constexpr std::string_view FormControlToInputFieldTypeString(
|
||||
const std::optional<blink::mojom::FormControlType> form_control_type) {
|
||||
if (!form_control_type)
|
||||
return "none";
|
||||
|
@ -70,7 +71,7 @@ namespace {
|
|||
namespace gin {
|
||||
|
||||
static constexpr auto MenuSourceTypes =
|
||||
base::MakeFixedFlatMap<base::StringPiece, ui::MenuSourceType>({
|
||||
base::MakeFixedFlatMap<std::string_view, ui::MenuSourceType>({
|
||||
{"adjustSelection", ui::MENU_SOURCE_ADJUST_SELECTION},
|
||||
{"adjustSelectionReset", ui::MENU_SOURCE_ADJUST_SELECTION_RESET},
|
||||
{"keyboard", ui::MENU_SOURCE_KEYBOARD},
|
||||
|
@ -285,12 +286,11 @@ bool Converter<content::StopFindAction>::FromV8(v8::Isolate* isolate,
|
|||
v8::Local<v8::Value> val,
|
||||
content::StopFindAction* out) {
|
||||
using Val = content::StopFindAction;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
{"activateSelection", Val::STOP_FIND_ACTION_ACTIVATE_SELECTION},
|
||||
{"clearSelection", Val::STOP_FIND_ACTION_CLEAR_SELECTION},
|
||||
{"keepSelection", Val::STOP_FIND_ACTION_KEEP_SELECTION},
|
||||
});
|
||||
static constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"activateSelection", Val::STOP_FIND_ACTION_ACTIVATE_SELECTION},
|
||||
{"clearSelection", Val::STOP_FIND_ACTION_CLEAR_SELECTION},
|
||||
{"keepSelection", Val::STOP_FIND_ACTION_KEEP_SELECTION},
|
||||
});
|
||||
return FromV8WithLookup(isolate, val, Lookup, out);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "shell/common/gin_converters/net_converter.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -691,7 +692,7 @@ bool Converter<net::DnsQueryType>::FromV8(v8::Isolate* isolate,
|
|||
v8::Local<v8::Value> val,
|
||||
net::DnsQueryType* out) {
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, net::DnsQueryType>({
|
||||
base::MakeFixedFlatMap<std::string_view, net::DnsQueryType>({
|
||||
{"A", net::DnsQueryType::A},
|
||||
{"AAAA", net::DnsQueryType::AAAA},
|
||||
});
|
||||
|
@ -703,14 +704,13 @@ bool Converter<net::HostResolverSource>::FromV8(v8::Isolate* isolate,
|
|||
v8::Local<v8::Value> val,
|
||||
net::HostResolverSource* out) {
|
||||
using Val = net::HostResolverSource;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
{"any", Val::ANY},
|
||||
{"dns", Val::DNS},
|
||||
{"localOnly", Val::LOCAL_ONLY},
|
||||
{"mdns", Val::MULTICAST_DNS},
|
||||
{"system", Val::SYSTEM},
|
||||
});
|
||||
static constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"any", Val::ANY},
|
||||
{"dns", Val::DNS},
|
||||
{"localOnly", Val::LOCAL_ONLY},
|
||||
{"mdns", Val::MULTICAST_DNS},
|
||||
{"system", Val::SYSTEM},
|
||||
});
|
||||
return FromV8WithLookup(isolate, val, Lookup, out);
|
||||
}
|
||||
|
||||
|
@ -720,12 +720,11 @@ bool Converter<network::mojom::ResolveHostParameters::CacheUsage>::FromV8(
|
|||
v8::Local<v8::Value> val,
|
||||
network::mojom::ResolveHostParameters::CacheUsage* out) {
|
||||
using Val = network::mojom::ResolveHostParameters::CacheUsage;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
{"allowed", Val::ALLOWED},
|
||||
{"disallowed", Val::DISALLOWED},
|
||||
{"staleAllowed", Val::STALE_ALLOWED},
|
||||
});
|
||||
static constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"allowed", Val::ALLOWED},
|
||||
{"disallowed", Val::DISALLOWED},
|
||||
{"staleAllowed", Val::STALE_ALLOWED},
|
||||
});
|
||||
return FromV8WithLookup(isolate, val, Lookup, out);
|
||||
}
|
||||
|
||||
|
@ -735,11 +734,10 @@ bool Converter<network::mojom::SecureDnsPolicy>::FromV8(
|
|||
v8::Local<v8::Value> val,
|
||||
network::mojom::SecureDnsPolicy* out) {
|
||||
using Val = network::mojom::SecureDnsPolicy;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
{"allow", Val::ALLOW},
|
||||
{"disable", Val::DISABLE},
|
||||
});
|
||||
static constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"allow", Val::ALLOW},
|
||||
{"disable", Val::DISABLE},
|
||||
});
|
||||
return FromV8WithLookup(isolate, val, Lookup, out);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE.chromium file.
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shell/common/gin_helper/arguments.h"
|
||||
|
||||
#include "v8/include/v8-exception.h"
|
||||
|
@ -15,7 +17,7 @@ void Arguments::ThrowError() const {
|
|||
gin::Arguments::ThrowError();
|
||||
}
|
||||
|
||||
void Arguments::ThrowError(base::StringPiece message) const {
|
||||
void Arguments::ThrowError(const std::string_view message) const {
|
||||
isolate()->ThrowException(
|
||||
v8::Exception::Error(gin::StringToV8(isolate(), message)));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef ELECTRON_SHELL_COMMON_GIN_HELPER_ARGUMENTS_H_
|
||||
#define ELECTRON_SHELL_COMMON_GIN_HELPER_ARGUMENTS_H_
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "gin/arguments.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
@ -40,7 +42,7 @@ class Arguments : public gin::Arguments {
|
|||
|
||||
// Throw error with custom error message.
|
||||
void ThrowError() const;
|
||||
void ThrowError(base::StringPiece message) const;
|
||||
void ThrowError(std::string_view message) const;
|
||||
|
||||
private:
|
||||
// MUST NOT ADD ANY DATA MEMBER.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define ELECTRON_SHELL_COMMON_GIN_HELPER_DICTIONARY_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
|
@ -68,7 +69,7 @@ class Dictionary : public gin::Dictionary {
|
|||
|
||||
// Like normal Get but put result in an std::optional.
|
||||
template <typename T>
|
||||
bool GetOptional(base::StringPiece key, std::optional<T>* out) const {
|
||||
bool GetOptional(const std::string_view key, std::optional<T>* out) const {
|
||||
T ret;
|
||||
if (Get(key, &ret)) {
|
||||
out->emplace(std::move(ret));
|
||||
|
@ -79,7 +80,7 @@ class Dictionary : public gin::Dictionary {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool GetHidden(base::StringPiece key, T* out) const {
|
||||
bool GetHidden(std::string_view key, T* out) const {
|
||||
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
|
||||
v8::Local<v8::Private> privateKey =
|
||||
v8::Private::ForApi(isolate(), gin::StringToV8(isolate(), key));
|
||||
|
@ -92,7 +93,7 @@ class Dictionary : public gin::Dictionary {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool SetHidden(base::StringPiece key, T val) {
|
||||
bool SetHidden(std::string_view key, T val) {
|
||||
v8::Local<v8::Value> v8_value;
|
||||
if (!gin::TryConvertToV8(isolate(), val, &v8_value))
|
||||
return false;
|
||||
|
@ -105,7 +106,7 @@ class Dictionary : public gin::Dictionary {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool SetMethod(base::StringPiece key, const T& callback) {
|
||||
bool SetMethod(std::string_view key, const T& callback) {
|
||||
auto context = isolate()->GetCurrentContext();
|
||||
auto templ = CallbackTraits<T>::CreateTemplate(isolate(), callback);
|
||||
return GetHandle()
|
||||
|
@ -147,7 +148,7 @@ class Dictionary : public gin::Dictionary {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool SetReadOnly(base::StringPiece key, const T& val) {
|
||||
bool SetReadOnly(std::string_view key, const T& val) {
|
||||
v8::Local<v8::Value> v8_value;
|
||||
if (!gin::TryConvertToV8(isolate(), val, &v8_value))
|
||||
return false;
|
||||
|
@ -160,7 +161,7 @@ class Dictionary : public gin::Dictionary {
|
|||
// Note: If we plan to add more Set methods, consider adding an option instead
|
||||
// of copying code.
|
||||
template <typename T>
|
||||
bool SetReadOnlyNonConfigurable(base::StringPiece key, T val) {
|
||||
bool SetReadOnlyNonConfigurable(std::string_view key, T val) {
|
||||
v8::Local<v8::Value> v8_value;
|
||||
if (!gin::TryConvertToV8(isolate(), val, &v8_value))
|
||||
return false;
|
||||
|
@ -171,13 +172,13 @@ class Dictionary : public gin::Dictionary {
|
|||
return !result.IsNothing() && result.FromJust();
|
||||
}
|
||||
|
||||
bool Has(base::StringPiece key) const {
|
||||
bool Has(std::string_view key) const {
|
||||
v8::Maybe<bool> result = GetHandle()->Has(isolate()->GetCurrentContext(),
|
||||
gin::StringToV8(isolate(), key));
|
||||
return !result.IsNothing() && result.FromJust();
|
||||
}
|
||||
|
||||
bool Delete(base::StringPiece key) {
|
||||
bool Delete(std::string_view key) {
|
||||
v8::Maybe<bool> result = GetHandle()->Delete(
|
||||
isolate()->GetCurrentContext(), gin::StringToV8(isolate(), key));
|
||||
return !result.IsNothing() && result.FromJust();
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shell/common/gin_helper/error_thrower.h"
|
||||
|
||||
#include "gin/converter.h"
|
||||
|
@ -15,27 +17,28 @@ ErrorThrower::ErrorThrower(v8::Isolate* isolate) : isolate_(isolate) {}
|
|||
// costly to invoke
|
||||
ErrorThrower::ErrorThrower() : isolate_(v8::Isolate::GetCurrent()) {}
|
||||
|
||||
void ErrorThrower::ThrowError(base::StringPiece err_msg) const {
|
||||
void ErrorThrower::ThrowError(const std::string_view err_msg) const {
|
||||
Throw(v8::Exception::Error, err_msg);
|
||||
}
|
||||
|
||||
void ErrorThrower::ThrowTypeError(base::StringPiece err_msg) const {
|
||||
void ErrorThrower::ThrowTypeError(const std::string_view err_msg) const {
|
||||
Throw(v8::Exception::TypeError, err_msg);
|
||||
}
|
||||
|
||||
void ErrorThrower::ThrowRangeError(base::StringPiece err_msg) const {
|
||||
void ErrorThrower::ThrowRangeError(const std::string_view err_msg) const {
|
||||
Throw(v8::Exception::RangeError, err_msg);
|
||||
}
|
||||
|
||||
void ErrorThrower::ThrowReferenceError(base::StringPiece err_msg) const {
|
||||
void ErrorThrower::ThrowReferenceError(const std::string_view err_msg) const {
|
||||
Throw(v8::Exception::ReferenceError, err_msg);
|
||||
}
|
||||
|
||||
void ErrorThrower::ThrowSyntaxError(base::StringPiece err_msg) const {
|
||||
void ErrorThrower::ThrowSyntaxError(const std::string_view err_msg) const {
|
||||
Throw(v8::Exception::SyntaxError, err_msg);
|
||||
}
|
||||
|
||||
void ErrorThrower::Throw(ErrorGenerator gen, base::StringPiece err_msg) const {
|
||||
void ErrorThrower::Throw(ErrorGenerator gen,
|
||||
const std::string_view err_msg) const {
|
||||
v8::Local<v8::Value> exception = gen(gin::StringToV8(isolate_, err_msg), {});
|
||||
if (!isolate_->IsExecutionTerminating())
|
||||
isolate_->ThrowException(exception);
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
#ifndef ELECTRON_SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
|
||||
#define ELECTRON_SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
@ -17,18 +18,18 @@ class ErrorThrower {
|
|||
ErrorThrower();
|
||||
~ErrorThrower() = default;
|
||||
|
||||
void ThrowError(base::StringPiece err_msg) const;
|
||||
void ThrowTypeError(base::StringPiece err_msg) const;
|
||||
void ThrowRangeError(base::StringPiece err_msg) const;
|
||||
void ThrowReferenceError(base::StringPiece err_msg) const;
|
||||
void ThrowSyntaxError(base::StringPiece err_msg) const;
|
||||
void ThrowError(std::string_view err_msg) const;
|
||||
void ThrowTypeError(std::string_view err_msg) const;
|
||||
void ThrowRangeError(std::string_view err_msg) const;
|
||||
void ThrowReferenceError(std::string_view err_msg) const;
|
||||
void ThrowSyntaxError(std::string_view err_msg) const;
|
||||
|
||||
v8::Isolate* isolate() const { return isolate_; }
|
||||
|
||||
private:
|
||||
using ErrorGenerator = v8::Local<v8::Value> (*)(v8::Local<v8::String> err_msg,
|
||||
v8::Local<v8::Value> options);
|
||||
void Throw(ErrorGenerator gen, base::StringPiece err_msg) const;
|
||||
void Throw(ErrorGenerator gen, std::string_view err_msg) const;
|
||||
|
||||
raw_ptr<v8::Isolate> isolate_;
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef ELECTRON_SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_H_
|
||||
#define ELECTRON_SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_H_
|
||||
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -38,7 +39,7 @@ class EventEmitter : public gin_helper::Wrappable<T> {
|
|||
|
||||
// this.emit(name, new Event(), args...);
|
||||
template <typename... Args>
|
||||
bool Emit(base::StringPiece name, Args&&... args) {
|
||||
bool Emit(const std::string_view name, Args&&... args) {
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
v8::Local<v8::Object> wrapper = GetWrapper();
|
||||
if (wrapper.IsEmpty())
|
||||
|
@ -58,7 +59,7 @@ class EventEmitter : public gin_helper::Wrappable<T> {
|
|||
private:
|
||||
// this.emit(name, event, args...);
|
||||
template <typename... Args>
|
||||
bool EmitWithEvent(base::StringPiece name,
|
||||
bool EmitWithEvent(const std::string_view name,
|
||||
gin::Handle<gin_helper::internal::Event> event,
|
||||
Args&&... args) {
|
||||
// It's possible that |this| will be deleted by EmitEvent, so save anything
|
||||
|
|
|
@ -12,14 +12,14 @@ ObjectTemplateBuilder::ObjectTemplateBuilder(
|
|||
: isolate_(isolate), template_(templ) {}
|
||||
|
||||
ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(
|
||||
const base::StringPiece& name,
|
||||
const std::string_view name,
|
||||
v8::Local<v8::Data> val) {
|
||||
template_->Set(gin::StringToSymbol(isolate_, name), val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl(
|
||||
const base::StringPiece& name,
|
||||
const std::string_view name,
|
||||
v8::Local<v8::FunctionTemplate> getter,
|
||||
v8::Local<v8::FunctionTemplate> setter) {
|
||||
template_->SetAccessorProperty(gin::StringToSymbol(isolate_, name), getter,
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef ELECTRON_SHELL_COMMON_GIN_HELPER_OBJECT_TEMPLATE_BUILDER_H_
|
||||
#define ELECTRON_SHELL_COMMON_GIN_HELPER_OBJECT_TEMPLATE_BUILDER_H_
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "shell/common/gin_helper/function_template.h"
|
||||
|
||||
|
@ -28,7 +30,7 @@ class ObjectTemplateBuilder {
|
|||
// poetic license here in order that all calls to Set() can be via the '.'
|
||||
// operator and line up nicely.
|
||||
template <typename T>
|
||||
ObjectTemplateBuilder& SetValue(const base::StringPiece& name, T val) {
|
||||
ObjectTemplateBuilder& SetValue(const std::string_view name, T val) {
|
||||
return SetImpl(name, ConvertToV8(isolate_, val));
|
||||
}
|
||||
|
||||
|
@ -37,19 +39,19 @@ class ObjectTemplateBuilder {
|
|||
// will want to use one of the first two options. Also see
|
||||
// gin::CreateFunctionTemplate() for creating raw function templates.
|
||||
template <typename T>
|
||||
ObjectTemplateBuilder& SetMethod(const base::StringPiece& name,
|
||||
ObjectTemplateBuilder& SetMethod(const std::string_view name,
|
||||
const T& callback) {
|
||||
return SetImpl(name, CallbackTraits<T>::CreateTemplate(isolate_, callback));
|
||||
}
|
||||
template <typename T>
|
||||
ObjectTemplateBuilder& SetProperty(const base::StringPiece& name,
|
||||
ObjectTemplateBuilder& SetProperty(const std::string_view name,
|
||||
const T& getter) {
|
||||
return SetPropertyImpl(name,
|
||||
CallbackTraits<T>::CreateTemplate(isolate_, getter),
|
||||
v8::Local<v8::FunctionTemplate>());
|
||||
}
|
||||
template <typename T, typename U>
|
||||
ObjectTemplateBuilder& SetProperty(const base::StringPiece& name,
|
||||
ObjectTemplateBuilder& SetProperty(const std::string_view name,
|
||||
const T& getter,
|
||||
const U& setter) {
|
||||
return SetPropertyImpl(name,
|
||||
|
@ -60,10 +62,10 @@ class ObjectTemplateBuilder {
|
|||
v8::Local<v8::ObjectTemplate> Build();
|
||||
|
||||
private:
|
||||
ObjectTemplateBuilder& SetImpl(const base::StringPiece& name,
|
||||
ObjectTemplateBuilder& SetImpl(const std::string_view name,
|
||||
v8::Local<v8::Data> val);
|
||||
ObjectTemplateBuilder& SetPropertyImpl(
|
||||
const base::StringPiece& name,
|
||||
const std::string_view name,
|
||||
v8::Local<v8::FunctionTemplate> getter,
|
||||
v8::Local<v8::FunctionTemplate> setter);
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shell/common/gin_helper/promise.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
@ -43,7 +45,8 @@ v8::Maybe<bool> PromiseBase::Reject(v8::Local<v8::Value> except) {
|
|||
return GetInner()->Reject(GetContext(), except);
|
||||
}
|
||||
|
||||
v8::Maybe<bool> PromiseBase::RejectWithErrorMessage(base::StringPiece message) {
|
||||
v8::Maybe<bool> PromiseBase::RejectWithErrorMessage(
|
||||
const std::string_view message) {
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
gin_helper::MicrotasksScope microtasks_scope(
|
||||
isolate(), GetContext()->GetMicrotaskQueue());
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
#define ELECTRON_SHELL_COMMON_GIN_HELPER_PROMISE_H_
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "shell/common/gin_converters/std_converter.h"
|
||||
|
@ -47,19 +47,20 @@ class PromiseBase {
|
|||
//
|
||||
// Note: The parameter type is PromiseBase&& so it can take the instances of
|
||||
// Promise<T> type.
|
||||
static void RejectPromise(PromiseBase&& promise, base::StringPiece errmsg) {
|
||||
static void RejectPromise(PromiseBase&& promise,
|
||||
const std::string_view errmsg) {
|
||||
if (electron::IsBrowserProcess() &&
|
||||
!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
// Note that this callback can not take StringPiece,
|
||||
// Note that this callback can not take std::string_view,
|
||||
// as StringPiece only references string internally and
|
||||
// will blow when a temporary string is passed.
|
||||
[](PromiseBase&& promise, std::string str) {
|
||||
promise.RejectWithErrorMessage(str);
|
||||
},
|
||||
std::move(promise), std::string(errmsg.data(), errmsg.size())));
|
||||
std::move(promise), std::string{errmsg}));
|
||||
} else {
|
||||
promise.RejectWithErrorMessage(errmsg);
|
||||
}
|
||||
|
@ -67,7 +68,7 @@ class PromiseBase {
|
|||
|
||||
v8::Maybe<bool> Reject();
|
||||
v8::Maybe<bool> Reject(v8::Local<v8::Value> except);
|
||||
v8::Maybe<bool> RejectWithErrorMessage(base::StringPiece message);
|
||||
v8::Maybe<bool> RejectWithErrorMessage(std::string_view message);
|
||||
|
||||
v8::Local<v8::Context> GetContext() const;
|
||||
v8::Local<v8::Promise> GetHandle() const;
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace {
|
|||
using CodeAndShiftedChar = std::pair<ui::KeyboardCode, std::optional<char16_t>>;
|
||||
|
||||
constexpr CodeAndShiftedChar KeyboardCodeFromKeyIdentifier(
|
||||
base::StringPiece str) {
|
||||
const std::string_view str) {
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
constexpr auto CommandOrControl = ui::VKEY_COMMAND;
|
||||
#else
|
||||
|
@ -26,7 +26,7 @@ constexpr CodeAndShiftedChar KeyboardCodeFromKeyIdentifier(
|
|||
#endif
|
||||
|
||||
constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, CodeAndShiftedChar>({
|
||||
base::MakeFixedFlatMap<std::string_view, CodeAndShiftedChar>({
|
||||
{"alt", {ui::VKEY_MENU, {}}},
|
||||
{"altgr", {ui::VKEY_ALTGR, {}}},
|
||||
{"backspace", {ui::VKEY_BACK, {}}},
|
||||
|
@ -272,7 +272,7 @@ constexpr CodeAndShiftedChar KeyboardCodeFromCharCode(char16_t c) {
|
|||
|
||||
} // namespace
|
||||
|
||||
ui::KeyboardCode KeyboardCodeFromStr(base::StringPiece str,
|
||||
ui::KeyboardCode KeyboardCodeFromStr(const std::string_view str,
|
||||
std::optional<char16_t>* shifted_char) {
|
||||
auto const [code, shifted] =
|
||||
str.size() == 1 ? KeyboardCodeFromCharCode(base::ToLowerASCII(str[0]))
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#define ELECTRON_SHELL_COMMON_KEYBOARD_UTIL_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "ui/events/keycodes/keyboard_codes.h"
|
||||
|
||||
namespace electron {
|
||||
|
@ -15,7 +15,7 @@ namespace electron {
|
|||
// Return key code of the |str|, if the original key is a shifted character,
|
||||
// for example + and /, set it in |shifted_char|.
|
||||
// pressed.
|
||||
ui::KeyboardCode KeyboardCodeFromStr(base::StringPiece str,
|
||||
ui::KeyboardCode KeyboardCodeFromStr(std::string_view str,
|
||||
std::optional<char16_t>* shifted_char);
|
||||
|
||||
} // namespace electron
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "shell/common/logging.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/base_switches.h"
|
||||
#include "base/command_line.h"
|
||||
|
@ -19,8 +20,8 @@
|
|||
|
||||
namespace logging {
|
||||
|
||||
constexpr base::StringPiece kLogFileName("ELECTRON_LOG_FILE");
|
||||
constexpr base::StringPiece kElectronEnableLogging("ELECTRON_ENABLE_LOGGING");
|
||||
constexpr std::string_view kLogFileName{"ELECTRON_LOG_FILE"};
|
||||
constexpr std::string_view kElectronEnableLogging{"ELECTRON_ENABLE_LOGGING"};
|
||||
|
||||
base::FilePath GetLogFileName(const base::CommandLine& command_line) {
|
||||
std::string filename = command_line.GetSwitchValueASCII(switches::kLogFile);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -293,9 +294,9 @@ void ErrorMessageListener(v8::Local<v8::Message> message,
|
|||
|
||||
// Only allow a specific subset of options in non-ELECTRON_RUN_AS_NODE mode.
|
||||
// If node CLI inspect support is disabled, allow no debug options.
|
||||
bool IsAllowedOption(base::StringPiece option) {
|
||||
bool IsAllowedOption(const std::string_view option) {
|
||||
static constexpr auto debug_options =
|
||||
base::MakeFixedFlatSet<base::StringPiece>({
|
||||
base::MakeFixedFlatSet<std::string_view>({
|
||||
"--debug",
|
||||
"--debug-brk",
|
||||
"--debug-port",
|
||||
|
@ -307,7 +308,7 @@ bool IsAllowedOption(base::StringPiece option) {
|
|||
});
|
||||
|
||||
// This should be aligned with what's possible to set via the process object.
|
||||
static constexpr auto options = base::MakeFixedFlatSet<base::StringPiece>({
|
||||
static constexpr auto options = base::MakeFixedFlatSet<std::string_view>({
|
||||
"--dns-result-order",
|
||||
"--no-deprecation",
|
||||
"--throw-deprecation",
|
||||
|
@ -325,7 +326,7 @@ bool IsAllowedOption(base::StringPiece option) {
|
|||
// See https://nodejs.org/api/cli.html#cli_node_options_options
|
||||
void SetNodeOptions(base::Environment* env) {
|
||||
// Options that are unilaterally disallowed
|
||||
static constexpr auto disallowed = base::MakeFixedFlatSet<base::StringPiece>({
|
||||
static constexpr auto disallowed = base::MakeFixedFlatSet<std::string_view>({
|
||||
"--enable-fips",
|
||||
"--experimental-policy",
|
||||
"--force-fips",
|
||||
|
@ -334,7 +335,7 @@ void SetNodeOptions(base::Environment* env) {
|
|||
"--use-openssl-ca",
|
||||
});
|
||||
|
||||
static constexpr auto pkg_opts = base::MakeFixedFlatSet<base::StringPiece>({
|
||||
static constexpr auto pkg_opts = base::MakeFixedFlatSet<std::string_view>({
|
||||
"--http-parser",
|
||||
"--max-http-header-size",
|
||||
});
|
||||
|
@ -475,7 +476,7 @@ std::vector<std::string> NodeBindings::ParseNodeCliFlags() {
|
|||
#else
|
||||
const auto& option = arg;
|
||||
#endif
|
||||
const auto stripped = base::StringPiece(option).substr(0, option.find('='));
|
||||
const auto stripped = std::string_view{option}.substr(0, option.find('='));
|
||||
// Only allow no-op or a small set of debug/trace related options.
|
||||
if (IsAllowedOption(stripped) || stripped == "--")
|
||||
args.push_back(option);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue