refactor: use base::StringPiece over std::string (#20119)
This commit is contained in:
parent
432ae81823
commit
6087f89aac
1 changed files with 12 additions and 14 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "base/strings/string_piece.h"
|
||||||
#include "base/task/post_task.h"
|
#include "base/task/post_task.h"
|
||||||
#include "content/public/browser/browser_task_traits.h"
|
#include "content/public/browser/browser_task_traits.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
|
@ -75,14 +76,15 @@ class Promise {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RejectPromise(Promise<RT> promise, std::string errmsg) {
|
static void RejectPromise(Promise<RT> promise, base::StringPiece errmsg) {
|
||||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||||
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
|
base::PostTaskWithTraits(
|
||||||
base::BindOnce(
|
FROM_HERE, {content::BrowserThread::UI},
|
||||||
[](Promise<RT> promise, std::string errmsg) {
|
base::BindOnce(
|
||||||
promise.RejectWithErrorMessage(errmsg);
|
[](Promise<RT> promise, base::StringPiece err) {
|
||||||
},
|
promise.RejectWithErrorMessage(err);
|
||||||
std::move(promise), std::move(errmsg)));
|
},
|
||||||
|
std::move(promise), std::move(errmsg)));
|
||||||
} else {
|
} else {
|
||||||
promise.RejectWithErrorMessage(errmsg);
|
promise.RejectWithErrorMessage(errmsg);
|
||||||
}
|
}
|
||||||
|
@ -174,19 +176,15 @@ class Promise {
|
||||||
gin::ConvertToV8(isolate(), value));
|
gin::ConvertToV8(isolate(), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Maybe<bool> RejectWithErrorMessage(const std::string& string) {
|
v8::Maybe<bool> RejectWithErrorMessage(base::StringPiece string) {
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::MicrotasksScope script_scope(isolate(),
|
v8::MicrotasksScope script_scope(isolate(),
|
||||||
v8::MicrotasksScope::kRunMicrotasks);
|
v8::MicrotasksScope::kRunMicrotasks);
|
||||||
v8::Context::Scope context_scope(
|
v8::Context::Scope context_scope(
|
||||||
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
||||||
|
|
||||||
v8::Local<v8::String> error_message =
|
v8::Local<v8::Value> error =
|
||||||
v8::String::NewFromUtf8(isolate(), string.c_str(),
|
v8::Exception::Error(gin::StringToV8(isolate(), string));
|
||||||
v8::NewStringType::kNormal,
|
|
||||||
static_cast<int>(string.size()))
|
|
||||||
.ToLocalChecked();
|
|
||||||
v8::Local<v8::Value> error = v8::Exception::Error(error_message);
|
|
||||||
return GetInner()->Reject(GetContext(), (error));
|
return GetInner()->Reject(GetContext(), (error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue