MCPcopy Create free account
hub / github.com/electron/electron / GetBinding

Function GetBinding

shell/renderer/preload_utils.cc:61–85  ·  view source on GitHub ↗

adapted from node.cc

Source from the content-addressed store, hash-verified

59
60// adapted from node.cc
61v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
62 v8::Local<v8::String> key) {
63 v8::Local<v8::Object> exports;
64 const std::string binding_key = gin::V8ToString(isolate, key);
65 gin_helper::Dictionary cache(isolate, GetBindingCache(isolate));
66
67 if (cache.Get(binding_key, &exports)) {
68 return exports;
69 }
70
71 auto* const mod = node::binding::get_linked_module(binding_key.c_str());
72 if (!mod) {
73 gin_helper::ErrorThrower{isolate}.ThrowError(
74 base::StrCat({"No such binding: ", binding_key}));
75 return exports;
76 }
77
78 exports = v8::Object::New(isolate);
79 DCHECK_EQ(mod->nm_register_func, nullptr);
80 DCHECK_NE(mod->nm_context_register_func, nullptr);
81 mod->nm_context_register_func(exports, v8::Null(isolate),
82 isolate->GetCurrentContext(), mod->nm_priv);
83 cache.Set(binding_key, exports);
84 return exports;
85}
86
87namespace {
88

Callers

nothing calls this directly

Calls 4

GetBindingCacheFunction · 0.85
ThrowErrorMethod · 0.80
GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected