adapted from node.cc
| 59 | |
| 60 | // adapted from node.cc |
| 61 | v8::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 | |
| 87 | namespace { |
| 88 |
nothing calls this directly
no test coverage detected