From 6cfba9f7f6a54c539f10966e87dff70ba80ab6c6 Mon Sep 17 00:00:00 2001 From: Maya Lekova Date: Thu, 23 Jul 2020 10:24:41 +0200 Subject: [PATCH] process: update v8 fast api calls usage This commit removes the WrapperTraits specialization for FastHrtime according to recent changes in the V8 API. Refs: https://github.com/nodejs/node/issues/33374 PR-URL: https://github.com/nodejs/node/pull/35415 Reviewed-By: Rich Trott Reviewed-By: Jiawen Geng Reviewed-By: Daniel Bevenius Reviewed-By: Matteo Collina Reviewed-By: Myles Borins --- src/node_process_methods.cc | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index e708fe7f090385..6e7b1c929468c9 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -457,6 +457,12 @@ class FastHrtime : public BaseObject { SET_MEMORY_INFO_NAME(FastHrtime) SET_SELF_SIZE(FastHrtime) + static FastHrtime* FromV8ApiObject(v8::ApiObject api_object) { + v8::Object* v8_object = reinterpret_cast(&api_object); + return static_cast( + v8_object->GetAlignedPointerFromInternalField(BaseObject::kSlot)); + } + // This is the legacy version of hrtime before BigInt was introduced in // JavaScript. // The value returned by uv_hrtime() is a 64-bit int representing nanoseconds, @@ -466,7 +472,7 @@ class FastHrtime : public BaseObject { // broken into the upper/lower 32 bits to be converted back in JS, // because there is no Uint64Array in JS. // The third entry contains the remaining nanosecond part of the value. - static void FastNumber(FastHrtime* receiver) { + static void NumberImpl(FastHrtime* receiver) { uint64_t t = uv_hrtime(); uint32_t* fields = static_cast(receiver->backing_store_->Data()); fields[0] = (t / NANOS_PER_SEC) >> 32; @@ -474,18 +480,26 @@ class FastHrtime : public BaseObject { fields[2] = t % NANOS_PER_SEC; } + static void FastNumber(v8::ApiObject receiver) { + NumberImpl(FromV8ApiObject(receiver)); + } + static void SlowNumber(const FunctionCallbackInfo& args) { - FastNumber(FromJSObject(args.Holder())); + NumberImpl(FromJSObject(args.Holder())); } - static void FastBigInt(FastHrtime* receiver) { + static void BigIntImpl(FastHrtime* receiver) { uint64_t t = uv_hrtime(); uint64_t* fields = static_cast(receiver->backing_store_->Data()); fields[0] = t; } + static void FastBigInt(v8::ApiObject receiver) { + BigIntImpl(FromV8ApiObject(receiver)); + } + static void SlowBigInt(const FunctionCallbackInfo& args) { - FastBigInt(FromJSObject(args.Holder())); + BigIntImpl(FromJSObject(args.Holder())); } v8::Global array_buffer_; @@ -563,17 +577,6 @@ void RegisterProcessMethodsExternalReferences( } // namespace node -namespace v8 { -template <> -class WrapperTraits { - public: - static const void* GetTypeInfo() { - static const int tag = 0; - return reinterpret_cast(&tag); - } -}; -} // namespace v8 - NODE_MODULE_CONTEXT_AWARE_INTERNAL(process_methods, node::InitializeProcessMethods) NODE_MODULE_EXTERNAL_REFERENCE(process_methods,