![trop[bot]](/assets/img/avatar_default.png)
* refactor: avoid redundant GetIsolate() calls in NodeBindings::CreateEnvironment() Xref: https://chromium-review.googlesource.com/c/v8/v8/+/6563615 Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: use v8::Isolate::GetCurrent() in Initialize() methods Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment() Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! refactor: use v8::Isolate::GetCurrent() in Initialize() methods Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add v8::Isolate* arg to RendererClientBase::DidCreateScriptContext() Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment() Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! fixup! refactor: use v8::Isolate::GetCurrent() in Initialize() methods refactor: prefer JavascriptEnvironment::GetIsolate() in the browser layer Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
// 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/functional/bind.h"
|
|
#include "base/no_destructor.h"
|
|
#include "gin/dictionary.h"
|
|
#include "shell/browser/javascript_environment.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>* GetEventEmitterPrototypeReference() {
|
|
static base::NoDestructor<v8::Global<v8::Object>> event_emitter_prototype;
|
|
return event_emitter_prototype.get();
|
|
}
|
|
|
|
void SetEventEmitterPrototype(v8::Isolate* isolate,
|
|
v8::Local<v8::Object> proto) {
|
|
GetEventEmitterPrototypeReference()->Reset(isolate, proto);
|
|
}
|
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
v8::Local<v8::Value> unused,
|
|
v8::Local<v8::Context> context,
|
|
void* priv) {
|
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
|
gin::Dictionary dict{isolate, exports};
|
|
dict.Set("setEventEmitterPrototype",
|
|
base::BindRepeating(&SetEventEmitterPrototype));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace electron {
|
|
|
|
v8::Local<v8::Object> GetEventEmitterPrototype(v8::Isolate* isolate) {
|
|
CHECK(!GetEventEmitterPrototypeReference()->IsEmpty());
|
|
return GetEventEmitterPrototypeReference()->Get(isolate);
|
|
}
|
|
|
|
} // namespace electron
|
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_browser_event_emitter, Initialize)
|