diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-06-12 01:23:16 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-06-19 18:35:36 +0300 |
commit | 52de4cb107a6fc1a06f7c98f4fd36c7f7fd539d5 (patch) | |
tree | dd24d54040f785452a612b0fc6a486c67743e314 /src/node_process_methods.cc | |
parent | 2899588f28f4d02a61a19ecc8454ddaf14c7b6b3 (diff) |
src: minor updates to FastHrtime
- Don’t use 12 as a magic number for the buffer size
- Mark the object as weak (which is conceptually the right thing to do,
even if there is little practical impact)
- Keep a reference to the `ArrayBuffer` in question for memory tracking
PR-URL: https://github.com/nodejs/node/pull/33851
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_process_methods.cc')
-rw-r--r-- | src/node_process_methods.cc | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 800ce031364..88d5f843f30 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -1,6 +1,7 @@ #include "base_object-inl.h" #include "debug_utils-inl.h" #include "env-inl.h" +#include "memory_tracker-inl.h" #include "node.h" #include "node_errors.h" #include "node_internals.h" @@ -451,8 +452,10 @@ class FastHrtime : public BaseObject { Local<Object> obj = otmpl->NewInstance(env->context()).ToLocalChecked(); - Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), 12); - new FastHrtime(env, obj, ab->GetBackingStore()); + Local<ArrayBuffer> ab = + ArrayBuffer::New(env->isolate(), + std::max(sizeof(uint64_t), sizeof(uint32_t) * 3)); + new FastHrtime(env, obj, ab); obj->Set( env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "buffer"), ab) .ToChecked(); @@ -463,11 +466,16 @@ class FastHrtime : public BaseObject { private: FastHrtime(Environment* env, Local<Object> object, - std::shared_ptr<v8::BackingStore> backing_store) - : BaseObject(env, object), backing_store_(backing_store) {} - - void MemoryInfo(MemoryTracker* tracker) const override {} + Local<ArrayBuffer> ab) + : BaseObject(env, object), + array_buffer_(env->isolate(), ab), + backing_store_(ab->GetBackingStore()) { + MakeWeak(); + } + void MemoryInfo(MemoryTracker* tracker) const override { + tracker->TrackField("array_buffer", array_buffer_); + } SET_MEMORY_INFO_NAME(FastHrtime) SET_SELF_SIZE(FastHrtime) @@ -502,6 +510,7 @@ class FastHrtime : public BaseObject { FastBigInt(FromJSObject<FastHrtime>(args.Holder())); } + v8::Global<ArrayBuffer> array_buffer_; std::shared_ptr<BackingStore> backing_store_; }; |