fix: crash in utilityProcess when generating code from strings (#38014)
This commit is contained in:
parent
f12e12b341
commit
0240f6664e
14 changed files with 72 additions and 48 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "base/cxx17_backports.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "gin/dictionary.h"
|
||||
#include "shell/common/process_util.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
||||
|
@ -70,7 +71,7 @@ void CallTranslater(v8::Local<v8::External> external,
|
|||
struct DeleteOnUIThread {
|
||||
template <typename T>
|
||||
static void Destruct(const T* x) {
|
||||
if (gin_helper::Locker::IsBrowserProcess() &&
|
||||
if (electron::IsBrowserProcess() &&
|
||||
!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||
content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE,
|
||||
x);
|
||||
|
|
|
@ -4,19 +4,15 @@
|
|||
|
||||
#include "shell/common/gin_helper/locker.h"
|
||||
|
||||
#include "shell/common/process_util.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
||||
Locker::Locker(v8::Isolate* isolate) {
|
||||
if (IsBrowserProcess())
|
||||
if (electron::IsBrowserProcess())
|
||||
locker_ = std::make_unique<v8::Locker>(isolate);
|
||||
}
|
||||
|
||||
Locker::~Locker() = default;
|
||||
|
||||
void Locker::SetIsBrowserProcess(bool is_browser_process) {
|
||||
g_is_browser_process = is_browser_process;
|
||||
}
|
||||
|
||||
bool Locker::g_is_browser_process = false;
|
||||
|
||||
} // namespace gin_helper
|
||||
|
|
|
@ -21,12 +21,6 @@ class Locker {
|
|||
Locker(const Locker&) = delete;
|
||||
Locker& operator=(const Locker&) = delete;
|
||||
|
||||
// Returns whether current process is browser process, currently we detect it
|
||||
// by checking whether current has used V8 Lock, but it might be a bad idea.
|
||||
static inline bool IsBrowserProcess() { return g_is_browser_process; }
|
||||
|
||||
static void SetIsBrowserProcess(bool is_browser_process);
|
||||
|
||||
private:
|
||||
void* operator new(size_t size);
|
||||
void operator delete(void*, size_t);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "shell/common/gin_helper/microtasks_scope.h"
|
||||
|
||||
#include "shell/common/gin_helper/locker.h"
|
||||
#include "shell/common/process_util.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
||||
|
@ -12,7 +12,7 @@ MicrotasksScope::MicrotasksScope(v8::Isolate* isolate,
|
|||
v8::MicrotaskQueue* microtask_queue,
|
||||
bool ignore_browser_checkpoint,
|
||||
v8::MicrotasksScope::Type scope_type) {
|
||||
if (Locker::IsBrowserProcess()) {
|
||||
if (electron::IsBrowserProcess()) {
|
||||
if (!ignore_browser_checkpoint)
|
||||
v8::MicrotasksScope::PerformCheckpoint(isolate);
|
||||
} else {
|
||||
|
|
|
@ -68,7 +68,7 @@ v8::Local<v8::Promise::Resolver> PromiseBase::GetInner() const {
|
|||
|
||||
// static
|
||||
void Promise<void>::ResolvePromise(Promise<void> promise) {
|
||||
if (gin_helper::Locker::IsBrowserProcess() &&
|
||||
if (electron::IsBrowserProcess() &&
|
||||
!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "shell/common/gin_converters/std_converter.h"
|
||||
#include "shell/common/gin_helper/locker.h"
|
||||
#include "shell/common/gin_helper/microtasks_scope.h"
|
||||
#include "shell/common/process_util.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
||||
|
@ -46,7 +47,7 @@ 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) {
|
||||
if (gin_helper::Locker::IsBrowserProcess() &&
|
||||
if (electron::IsBrowserProcess() &&
|
||||
!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
|
@ -89,7 +90,7 @@ class Promise : public PromiseBase {
|
|||
|
||||
// Helper for resolving the promise with |result|.
|
||||
static void ResolvePromise(Promise<RT> promise, RT result) {
|
||||
if (gin_helper::Locker::IsBrowserProcess() &&
|
||||
if (electron::IsBrowserProcess() &&
|
||||
!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE, base::BindOnce([](Promise<RT> promise,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "base/functional/bind.h"
|
||||
#include "base/supports_user_data.h"
|
||||
#include "shell/browser/electron_browser_main_parts.h"
|
||||
#include "shell/common/gin_helper/locker.h"
|
||||
#include "shell/common/process_util.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
||||
|
@ -31,7 +31,7 @@ class IDUserData : public base::SupportsUserData::Data {
|
|||
|
||||
TrackableObjectBase::TrackableObjectBase() {
|
||||
// TODO(zcbenz): Make TrackedObject work in renderer process.
|
||||
DCHECK(gin_helper::Locker::IsBrowserProcess())
|
||||
DCHECK(electron::IsBrowserProcess())
|
||||
<< "This class only works for browser process";
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue