Skip to content

Commit

Permalink
process: update v8 fast api calls usage
Browse files Browse the repository at this point in the history
This commit removes the WrapperTraits specialization for FastHrtime
according to recent changes in the V8 API.

Refs: #33374
  • Loading branch information
MayaLekova authored and targos committed Sep 29, 2020
1 parent 0ee6c2c commit dacc6b9
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/node_process_methods.cc
Expand Up @@ -470,6 +470,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<v8::Object*>(&api_object);
return static_cast<FastHrtime*>(
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,
Expand All @@ -479,26 +485,34 @@ 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<uint32_t*>(receiver->backing_store_->Data());
fields[0] = (t / NANOS_PER_SEC) >> 32;
fields[1] = (t / NANOS_PER_SEC) & 0xffffffff;
fields[2] = t % NANOS_PER_SEC;
}

static void FastNumber(v8::ApiObject receiver) {
NumberImpl(FromV8ApiObject(receiver));
}

static void SlowNumber(const FunctionCallbackInfo<Value>& args) {
FastNumber(FromJSObject<FastHrtime>(args.Holder()));
NumberImpl(FromJSObject<FastHrtime>(args.Holder()));
}

static void FastBigInt(FastHrtime* receiver) {
static void BigIntImpl(FastHrtime* receiver) {
uint64_t t = uv_hrtime();
uint64_t* fields = static_cast<uint64_t*>(receiver->backing_store_->Data());
fields[0] = t;
}

static void FastBigInt(v8::ApiObject receiver) {
BigIntImpl(FromV8ApiObject(receiver));
}

static void SlowBigInt(const FunctionCallbackInfo<Value>& args) {
FastBigInt(FromJSObject<FastHrtime>(args.Holder()));
BigIntImpl(FromJSObject<FastHrtime>(args.Holder()));
}

v8::Global<ArrayBuffer> array_buffer_;
Expand Down Expand Up @@ -576,17 +590,6 @@ void RegisterProcessMethodsExternalReferences(

} // namespace node

namespace v8 {
template <>
class WrapperTraits<node::FastHrtime> {
public:
static const void* GetTypeInfo() {
static const int tag = 0;
return reinterpret_cast<const void*>(&tag);
}
};
} // namespace v8

NODE_MODULE_CONTEXT_AWARE_INTERNAL(process_methods,
node::InitializeProcessMethods)
NODE_MODULE_EXTERNAL_REFERENCE(process_methods,
Expand Down

0 comments on commit dacc6b9

Please sign in to comment.