diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-07-22 01:59:41 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-07-25 17:52:14 +0300 |
commit | 83ddb49d6dccaa99e87a58b85a7edd1b47f10568 (patch) | |
tree | 3d5960074234221913e3a9b547d7834f67c8e2d4 /src/module_wrap.h | |
parent | e8d7fedf7cad6e612e4f2e0456e359af57608ac7 (diff) |
src: prefer internal fields in ModuleWrap
Use internal fields instead of `v8::Global`s where possible, since
they generally come with lower overhead and it’s much harder to
introduce memory leaks with them.
PR-URL: https://github.com/nodejs/node/pull/34470
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'src/module_wrap.h')
-rw-r--r-- | src/module_wrap.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/module_wrap.h b/src/module_wrap.h index 2b490fc4137..3d8bb577503 100644 --- a/src/module_wrap.h +++ b/src/module_wrap.h @@ -32,6 +32,14 @@ enum HostDefinedOptions : int { class ModuleWrap : public BaseObject { public: + enum InternalFields { + kModuleWrapBaseField = BaseObject::kInternalFieldCount, + kURLSlot, + kSyntheticEvaluationStepsSlot, + kContextObjectSlot, // Object whose creation context is the target Context + kInternalFieldCount + }; + static void Initialize(v8::Local<v8::Object> target, v8::Local<v8::Value> unused, v8::Local<v8::Context> context, @@ -42,11 +50,11 @@ class ModuleWrap : public BaseObject { v8::Local<v8::Object> meta); void MemoryInfo(MemoryTracker* tracker) const override { - tracker->TrackField("url", url_); tracker->TrackField("resolve_cache", resolve_cache_); } inline uint32_t id() { return id_; } + v8::Local<v8::Context> context() const; static ModuleWrap* GetFromID(node::Environment*, uint32_t id); SET_MEMORY_INFO_NAME(ModuleWrap) @@ -85,11 +93,8 @@ class ModuleWrap : public BaseObject { v8::Local<v8::Module> referrer); static ModuleWrap* GetFromModule(node::Environment*, v8::Local<v8::Module>); - v8::Global<v8::Function> synthetic_evaluation_steps_; v8::Global<v8::Module> module_; - v8::Global<v8::String> url_; std::unordered_map<std::string, v8::Global<v8::Promise>> resolve_cache_; - v8::Global<v8::Context> context_; contextify::ContextifyContext* contextify_context_ = nullptr; bool synthetic_ = false; bool linked_ = false; |