refactor: EventEmitters without gin_helper (#22726)
This commit is contained in:
parent
fc661ec56b
commit
232ca8af39
12 changed files with 277 additions and 49 deletions
45
shell/browser/api/electron_api_event_emitter.cc
Normal file
45
shell/browser/api/electron_api_event_emitter.cc
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) 2019 Slack Technologies, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "shell/browser/api/electron_api_event_emitter.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/callback.h"
|
||||
#include "gin/dictionary.h"
|
||||
#include "shell/common/gin_converters/callback_converter.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace {
|
||||
|
||||
v8::Global<v8::Object> event_emitter_prototype;
|
||||
|
||||
void SetEventEmitterPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> proto) {
|
||||
event_emitter_prototype.Reset(isolate, proto);
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
|
||||
gin::Dictionary dict(isolate, exports);
|
||||
dict.Set("setEventEmitterPrototype",
|
||||
base::BindRepeating(&SetEventEmitterPrototype));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace electron {
|
||||
|
||||
v8::Local<v8::Object> GetEventEmitterPrototype(v8::Isolate* isolate) {
|
||||
CHECK(!event_emitter_prototype.IsEmpty());
|
||||
return event_emitter_prototype.Get(isolate);
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
||||
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_event_emitter, Initialize)
|
Loading…
Add table
Add a link
Reference in a new issue