fix: missing handlescopes in event emission (#23140)
* fix: missing event emitter handlescopes * refactor: add static getter to js env
This commit is contained in:
parent
9bb8e43c9b
commit
ac5c30a707
5 changed files with 32 additions and 0 deletions
|
@ -93,14 +93,20 @@ gin::Handle<Tray> Tray::New(gin_helper::ErrorThrower thrower,
|
||||||
void Tray::OnClicked(const gfx::Rect& bounds,
|
void Tray::OnClicked(const gfx::Rect& bounds,
|
||||||
const gfx::Point& location,
|
const gfx::Point& location,
|
||||||
int modifiers) {
|
int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
EmitCustomEvent("click", CreateEventFromFlags(modifiers), bounds, location);
|
EmitCustomEvent("click", CreateEventFromFlags(modifiers), bounds, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
void Tray::OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
EmitCustomEvent("double-click", CreateEventFromFlags(modifiers), bounds);
|
EmitCustomEvent("double-click", CreateEventFromFlags(modifiers), bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnRightClicked(const gfx::Rect& bounds, int modifiers) {
|
void Tray::OnRightClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
EmitCustomEvent("right-click", CreateEventFromFlags(modifiers), bounds);
|
EmitCustomEvent("right-click", CreateEventFromFlags(modifiers), bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,22 +135,32 @@ void Tray::OnDropText(const std::string& text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnMouseEntered(const gfx::Point& location, int modifiers) {
|
void Tray::OnMouseEntered(const gfx::Point& location, int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
EmitCustomEvent("mouse-enter", CreateEventFromFlags(modifiers), location);
|
EmitCustomEvent("mouse-enter", CreateEventFromFlags(modifiers), location);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnMouseExited(const gfx::Point& location, int modifiers) {
|
void Tray::OnMouseExited(const gfx::Point& location, int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
EmitCustomEvent("mouse-leave", CreateEventFromFlags(modifiers), location);
|
EmitCustomEvent("mouse-leave", CreateEventFromFlags(modifiers), location);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnMouseMoved(const gfx::Point& location, int modifiers) {
|
void Tray::OnMouseMoved(const gfx::Point& location, int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
EmitCustomEvent("mouse-move", CreateEventFromFlags(modifiers), location);
|
EmitCustomEvent("mouse-move", CreateEventFromFlags(modifiers), location);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnMouseUp(const gfx::Point& location, int modifiers) {
|
void Tray::OnMouseUp(const gfx::Point& location, int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
EmitCustomEvent("mouse-up", CreateEventFromFlags(modifiers), location);
|
EmitCustomEvent("mouse-up", CreateEventFromFlags(modifiers), location);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnMouseDown(const gfx::Point& location, int modifiers) {
|
void Tray::OnMouseDown(const gfx::Point& location, int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
EmitCustomEvent("mouse-down", CreateEventFromFlags(modifiers), location);
|
EmitCustomEvent("mouse-down", CreateEventFromFlags(modifiers), location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "gin/handle.h"
|
#include "gin/handle.h"
|
||||||
#include "gin/wrappable.h"
|
#include "gin/wrappable.h"
|
||||||
#include "shell/browser/event_emitter_mixin.h"
|
#include "shell/browser/event_emitter_mixin.h"
|
||||||
|
#include "shell/browser/javascript_environment.h"
|
||||||
#include "shell/browser/ui/tray_icon.h"
|
#include "shell/browser/ui/tray_icon.h"
|
||||||
#include "shell/browser/ui/tray_icon_observer.h"
|
#include "shell/browser/ui/tray_icon_observer.h"
|
||||||
#include "shell/common/gin_converters/guid_converter.h"
|
#include "shell/common/gin_converters/guid_converter.h"
|
||||||
|
|
|
@ -39,6 +39,7 @@ class EventEmitterMixin {
|
||||||
v8::Local<v8::Object> custom_event,
|
v8::Local<v8::Object> custom_event,
|
||||||
Args&&... args) {
|
Args&&... args) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
v8::Local<v8::Object> wrapper;
|
v8::Local<v8::Object> wrapper;
|
||||||
if (!static_cast<T*>(this)->GetWrapper(isolate).ToLocal(&wrapper))
|
if (!static_cast<T*>(this)->GetWrapper(isolate).ToLocal(&wrapper))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "tracing/trace_event.h"
|
#include "tracing/trace_event.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
v8::Isolate* g_isolate;
|
||||||
|
}
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
JavascriptEnvironment::JavascriptEnvironment(uv_loop_t* event_loop)
|
JavascriptEnvironment::JavascriptEnvironment(uv_loop_t* event_loop)
|
||||||
|
@ -46,6 +50,7 @@ JavascriptEnvironment::~JavascriptEnvironment() {
|
||||||
context_.Get(isolate_)->Exit();
|
context_.Get(isolate_)->Exit();
|
||||||
}
|
}
|
||||||
isolate_->Exit();
|
isolate_->Exit();
|
||||||
|
g_isolate = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Isolate* JavascriptEnvironment::Initialize(uv_loop_t* event_loop) {
|
v8::Isolate* JavascriptEnvironment::Initialize(uv_loop_t* event_loop) {
|
||||||
|
@ -73,10 +78,17 @@ v8::Isolate* JavascriptEnvironment::Initialize(uv_loop_t* event_loop) {
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::Allocate();
|
v8::Isolate* isolate = v8::Isolate::Allocate();
|
||||||
platform_->RegisterIsolate(isolate, event_loop);
|
platform_->RegisterIsolate(isolate, event_loop);
|
||||||
|
g_isolate = isolate;
|
||||||
|
|
||||||
return isolate;
|
return isolate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
v8::Isolate* JavascriptEnvironment::GetIsolate() {
|
||||||
|
CHECK(g_isolate);
|
||||||
|
return g_isolate;
|
||||||
|
}
|
||||||
|
|
||||||
void JavascriptEnvironment::OnMessageLoopCreated() {
|
void JavascriptEnvironment::OnMessageLoopCreated() {
|
||||||
DCHECK(!microtasks_runner_);
|
DCHECK(!microtasks_runner_);
|
||||||
microtasks_runner_ = std::make_unique<MicrotasksRunner>(isolate());
|
microtasks_runner_ = std::make_unique<MicrotasksRunner>(isolate());
|
||||||
|
|
|
@ -34,6 +34,8 @@ class JavascriptEnvironment {
|
||||||
return v8::Local<v8::Context>::New(isolate_, context_);
|
return v8::Local<v8::Context>::New(isolate_, context_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static v8::Isolate* GetIsolate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
v8::Isolate* Initialize(uv_loop_t* event_loop);
|
v8::Isolate* Initialize(uv_loop_t* event_loop);
|
||||||
// Leaked on exit.
|
// Leaked on exit.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue