Skip to content

Commit 6cfba9f

Browse files
MayaLekovatargos
authored andcommitted
process: update v8 fast api calls usage
This commit removes the WrapperTraits specialization for FastHrtime according to recent changes in the V8 API. Refs: #33374 PR-URL: #35415 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent b65e5ae commit 6cfba9f

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/node_process_methods.cc

+18-15
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ class FastHrtime : public BaseObject {
457457
SET_MEMORY_INFO_NAME(FastHrtime)
458458
SET_SELF_SIZE(FastHrtime)
459459

460+
static FastHrtime* FromV8ApiObject(v8::ApiObject api_object) {
461+
v8::Object* v8_object = reinterpret_cast<v8::Object*>(&api_object);
462+
return static_cast<FastHrtime*>(
463+
v8_object->GetAlignedPointerFromInternalField(BaseObject::kSlot));
464+
}
465+
460466
// This is the legacy version of hrtime before BigInt was introduced in
461467
// JavaScript.
462468
// The value returned by uv_hrtime() is a 64-bit int representing nanoseconds,
@@ -466,26 +472,34 @@ class FastHrtime : public BaseObject {
466472
// broken into the upper/lower 32 bits to be converted back in JS,
467473
// because there is no Uint64Array in JS.
468474
// The third entry contains the remaining nanosecond part of the value.
469-
static void FastNumber(FastHrtime* receiver) {
475+
static void NumberImpl(FastHrtime* receiver) {
470476
uint64_t t = uv_hrtime();
471477
uint32_t* fields = static_cast<uint32_t*>(receiver->backing_store_->Data());
472478
fields[0] = (t / NANOS_PER_SEC) >> 32;
473479
fields[1] = (t / NANOS_PER_SEC) & 0xffffffff;
474480
fields[2] = t % NANOS_PER_SEC;
475481
}
476482

483+
static void FastNumber(v8::ApiObject receiver) {
484+
NumberImpl(FromV8ApiObject(receiver));
485+
}
486+
477487
static void SlowNumber(const FunctionCallbackInfo<Value>& args) {
478-
FastNumber(FromJSObject<FastHrtime>(args.Holder()));
488+
NumberImpl(FromJSObject<FastHrtime>(args.Holder()));
479489
}
480490

481-
static void FastBigInt(FastHrtime* receiver) {
491+
static void BigIntImpl(FastHrtime* receiver) {
482492
uint64_t t = uv_hrtime();
483493
uint64_t* fields = static_cast<uint64_t*>(receiver->backing_store_->Data());
484494
fields[0] = t;
485495
}
486496

497+
static void FastBigInt(v8::ApiObject receiver) {
498+
BigIntImpl(FromV8ApiObject(receiver));
499+
}
500+
487501
static void SlowBigInt(const FunctionCallbackInfo<Value>& args) {
488-
FastBigInt(FromJSObject<FastHrtime>(args.Holder()));
502+
BigIntImpl(FromJSObject<FastHrtime>(args.Holder()));
489503
}
490504

491505
v8::Global<ArrayBuffer> array_buffer_;
@@ -563,17 +577,6 @@ void RegisterProcessMethodsExternalReferences(
563577

564578
} // namespace node
565579

566-
namespace v8 {
567-
template <>
568-
class WrapperTraits<node::FastHrtime> {
569-
public:
570-
static const void* GetTypeInfo() {
571-
static const int tag = 0;
572-
return reinterpret_cast<const void*>(&tag);
573-
}
574-
};
575-
} // namespace v8
576-
577580
NODE_MODULE_CONTEXT_AWARE_INTERNAL(process_methods,
578581
node::InitializeProcessMethods)
579582
NODE_MODULE_EXTERNAL_REFERENCE(process_methods,

0 commit comments

Comments
 (0)