diff --git a/shell/common/promise_util.h b/shell/common/promise_util.h index 7d12bc0ebc89..334d69c12785 100644 --- a/shell/common/promise_util.h +++ b/shell/common/promise_util.h @@ -10,6 +10,7 @@ #include #include +#include "base/strings/string_piece.h" #include "base/task/post_task.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -75,14 +76,15 @@ class Promise { } } - static void RejectPromise(Promise promise, std::string errmsg) { + static void RejectPromise(Promise promise, base::StringPiece errmsg) { if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { - base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI}, - base::BindOnce( - [](Promise promise, std::string errmsg) { - promise.RejectWithErrorMessage(errmsg); - }, - std::move(promise), std::move(errmsg))); + base::PostTaskWithTraits( + FROM_HERE, {content::BrowserThread::UI}, + base::BindOnce( + [](Promise promise, base::StringPiece err) { + promise.RejectWithErrorMessage(err); + }, + std::move(promise), std::move(errmsg))); } else { promise.RejectWithErrorMessage(errmsg); } @@ -174,19 +176,15 @@ class Promise { gin::ConvertToV8(isolate(), value)); } - v8::Maybe RejectWithErrorMessage(const std::string& string) { + v8::Maybe RejectWithErrorMessage(base::StringPiece string) { v8::HandleScope handle_scope(isolate()); v8::MicrotasksScope script_scope(isolate(), v8::MicrotasksScope::kRunMicrotasks); v8::Context::Scope context_scope( v8::Local::New(isolate(), GetContext())); - v8::Local error_message = - v8::String::NewFromUtf8(isolate(), string.c_str(), - v8::NewStringType::kNormal, - static_cast(string.size())) - .ToLocalChecked(); - v8::Local error = v8::Exception::Error(error_message); + v8::Local error = + v8::Exception::Error(gin::StringToV8(isolate(), string)); return GetInner()->Reject(GetContext(), (error)); }