Browse Source

fix: enter handle scope when creating custom event (#22657)

Cheng Zhao 5 years ago
parent
commit
7814c67830
1 changed files with 2 additions and 2 deletions
  1. 2 2
      shell/common/gin_helper/event_emitter.h

+ 2 - 2
shell/common/gin_helper/event_emitter.h

@@ -62,6 +62,8 @@ class EventEmitter : public gin_helper::Wrappable<T> {
   // this.emit(name, new Event(flags), args...);
   template <typename... Args>
   bool EmitWithFlags(base::StringPiece name, int flags, Args&&... args) {
+    v8::Locker locker(isolate());
+    v8::HandleScope handle_scope(isolate());
     return EmitCustomEvent(name,
                            internal::CreateEventFromFlags(isolate(), flags),
                            std::forward<Args>(args)...);
@@ -108,8 +110,6 @@ class EventEmitter : public gin_helper::Wrappable<T> {
     // It's possible that |this| will be deleted by EmitEvent, so save anything
     // we need from |this| before calling EmitEvent.
     auto* isolate = this->isolate();
-    v8::Locker locker(isolate);
-    v8::HandleScope handle_scope(isolate);
     auto context = isolate->GetCurrentContext();
     gin_helper::EmitEvent(isolate, GetWrapper(), name, event,
                           std::forward<Args>(args)...);