Skip to content

Commit 6905258

Browse files
Renegade334aduh95
authored andcommitted
src: simplify adding fast APIs to ExternalReferenceRegistry
PR-URL: #58896 Backport-PR-URL: #59065 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent a381b4d commit 6905258

File tree

13 files changed

+53
-177
lines changed

13 files changed

+53
-177
lines changed

src/crypto/crypto_timing.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace node {
1212

13+
using v8::CFunction;
1314
using v8::FastApiCallbackOptions;
1415
using v8::FastApiTypedArray;
1516
using v8::FunctionCallbackInfo;
@@ -67,16 +68,18 @@ bool FastTimingSafeEqual(Local<Value> receiver,
6768
return CRYPTO_memcmp(data_a, data_b, a.length()) == 0;
6869
}
6970

70-
static v8::CFunction fast_equal(v8::CFunction::Make(FastTimingSafeEqual));
71+
static CFunction fast_timing_safe_equal(CFunction::Make(FastTimingSafeEqual));
7172

7273
void Initialize(Environment* env, Local<Object> target) {
73-
SetFastMethodNoSideEffect(
74-
env->context(), target, "timingSafeEqual", TimingSafeEqual, &fast_equal);
74+
SetFastMethodNoSideEffect(env->context(),
75+
target,
76+
"timingSafeEqual",
77+
TimingSafeEqual,
78+
&fast_timing_safe_equal);
7579
}
7680
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
7781
registry->Register(TimingSafeEqual);
78-
registry->Register(FastTimingSafeEqual);
79-
registry->Register(fast_equal.GetTypeInfo());
82+
registry->Register(fast_timing_safe_equal);
8083
}
8184
} // namespace Timing
8285

src/histogram.cc

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,14 @@ void HistogramImpl::RegisterExternalReferences(
116116
registry->Register(GetPercentiles);
117117
registry->Register(GetPercentilesBigInt);
118118
registry->Register(DoReset);
119-
registry->Register(fast_reset_.GetTypeInfo());
120-
registry->Register(fast_get_count_.GetTypeInfo());
121-
registry->Register(fast_get_min_.GetTypeInfo());
122-
registry->Register(fast_get_max_.GetTypeInfo());
123-
registry->Register(fast_get_mean_.GetTypeInfo());
124-
registry->Register(fast_get_exceeds_.GetTypeInfo());
125-
registry->Register(fast_get_stddev_.GetTypeInfo());
126-
registry->Register(fast_get_percentile_.GetTypeInfo());
127-
registry->Register(FastReset);
128-
registry->Register(FastGetCount);
129-
registry->Register(FastGetMin);
130-
registry->Register(FastGetMax);
131-
registry->Register(FastGetMean);
132-
registry->Register(FastGetExceeds);
133-
registry->Register(FastGetStddev);
134-
registry->Register(FastGetPercentile);
119+
registry->Register(fast_reset_);
120+
registry->Register(fast_get_count_);
121+
registry->Register(fast_get_min_);
122+
registry->Register(fast_get_max_);
123+
registry->Register(fast_get_mean_);
124+
registry->Register(fast_get_exceeds_);
125+
registry->Register(fast_get_stddev_);
126+
registry->Register(fast_get_percentile_);
135127
is_registered = true;
136128
}
137129

@@ -300,10 +292,8 @@ void HistogramBase::RegisterExternalReferences(
300292
registry->Register(Add);
301293
registry->Register(Record);
302294
registry->Register(RecordDelta);
303-
registry->Register(fast_record_.GetTypeInfo());
304-
registry->Register(fast_record_delta_.GetTypeInfo());
305-
registry->Register(FastRecord);
306-
registry->Register(FastRecordDelta);
295+
registry->Register(fast_record_);
296+
registry->Register(fast_record_delta_);
307297
HistogramImpl::RegisterExternalReferences(registry);
308298
}
309299

@@ -354,10 +344,8 @@ void IntervalHistogram::RegisterExternalReferences(
354344
ExternalReferenceRegistry* registry) {
355345
registry->Register(Start);
356346
registry->Register(Stop);
357-
registry->Register(fast_start_.GetTypeInfo());
358-
registry->Register(fast_stop_.GetTypeInfo());
359-
registry->Register(FastStart);
360-
registry->Register(FastStop);
347+
registry->Register(fast_start_);
348+
registry->Register(fast_stop_);
361349
HistogramImpl::RegisterExternalReferences(registry);
362350
}
363351

src/node_buffer.cc

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,20 +1608,16 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
16081608
registry->Register(SetBufferPrototype);
16091609

16101610
registry->Register(SlowByteLengthUtf8);
1611-
registry->Register(fast_byte_length_utf8.GetTypeInfo());
1612-
registry->Register(FastByteLengthUtf8);
1611+
registry->Register(fast_byte_length_utf8);
16131612
registry->Register(SlowCopy);
1614-
registry->Register(fast_copy.GetTypeInfo());
1615-
registry->Register(FastCopy);
1613+
registry->Register(fast_copy);
16161614
registry->Register(Compare);
1617-
registry->Register(FastCompare);
1618-
registry->Register(fast_compare.GetTypeInfo());
1615+
registry->Register(fast_compare);
16191616
registry->Register(CompareOffset);
16201617
registry->Register(Fill);
16211618
registry->Register(IndexOfBuffer);
16221619
registry->Register(SlowIndexOfNumber);
1623-
registry->Register(FastIndexOfNumber);
1624-
registry->Register(fast_index_of_number.GetTypeInfo());
1620+
registry->Register(fast_index_of_number);
16251621
registry->Register(IndexOfString);
16261622

16271623
registry->Register(Swap16);
@@ -1642,12 +1638,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
16421638
registry->Register(SlowWriteString<ASCII>);
16431639
registry->Register(SlowWriteString<LATIN1>);
16441640
registry->Register(SlowWriteString<UTF8>);
1645-
registry->Register(FastWriteString<ASCII>);
1646-
registry->Register(fast_write_string_ascii.GetTypeInfo());
1647-
registry->Register(FastWriteString<LATIN1>);
1648-
registry->Register(fast_write_string_latin1.GetTypeInfo());
1649-
registry->Register(FastWriteString<UTF8>);
1650-
registry->Register(fast_write_string_utf8.GetTypeInfo());
1641+
registry->Register(fast_write_string_ascii);
1642+
registry->Register(fast_write_string_latin1);
1643+
registry->Register(fast_write_string_utf8);
16511644
registry->Register(StringWrite<ASCII>);
16521645
registry->Register(StringWrite<BASE64>);
16531646
registry->Register(StringWrite<BASE64URL>);

src/node_external_reference.h

Lines changed: 7 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10,110 +10,13 @@
1010

1111
namespace node {
1212

13-
using CFunctionCallbackWithOneByteString =
14-
uint32_t (*)(v8::Local<v8::Value>, const v8::FastOneByteString&);
15-
16-
using CFunctionCallbackReturnBool = bool (*)(v8::Local<v8::Value> unused,
17-
v8::Local<v8::Value> receiver);
18-
using CFunctionCallback = void (*)(v8::Local<v8::Value> unused,
19-
v8::Local<v8::Value> receiver);
20-
using CFunctionCallbackReturnDouble =
21-
double (*)(v8::Local<v8::Object> unused, v8::Local<v8::Object> receiver);
22-
using CFunctionCallbackReturnInt32 =
23-
int32_t (*)(v8::Local<v8::Value> receiver,
24-
v8::Local<v8::Value> input,
25-
// NOLINTNEXTLINE(runtime/references) This is V8 api.
26-
v8::FastApiCallbackOptions& options);
27-
using CFunctionCallbackValueReturnDouble =
28-
double (*)(v8::Local<v8::Value> receiver);
29-
using CFunctionCallbackValueReturnDoubleUnusedReceiver =
30-
double (*)(v8::Local<v8::Value> unused, v8::Local<v8::Value> receiver);
31-
using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> unused,
32-
v8::Local<v8::Object> receiver,
33-
int64_t);
34-
using CFunctionCallbackWithBool = void (*)(v8::Local<v8::Object> unused,
35-
v8::Local<v8::Object> receiver,
36-
bool);
37-
using CFunctionCallbackWithString =
38-
bool (*)(v8::Local<v8::Value>, const v8::FastOneByteString& input);
39-
using CFunctionCallbackWithStrings =
40-
bool (*)(v8::Local<v8::Value>,
41-
const v8::FastOneByteString& input,
42-
const v8::FastOneByteString& base);
43-
using CFunctionCallbackWithTwoUint8Arrays =
44-
int32_t (*)(v8::Local<v8::Value>,
45-
const v8::FastApiTypedArray<uint8_t>&,
46-
const v8::FastApiTypedArray<uint8_t>&);
47-
using CFunctionCallbackWithTwoUint8ArraysFallback =
48-
bool (*)(v8::Local<v8::Value>,
49-
const v8::FastApiTypedArray<uint8_t>&,
50-
const v8::FastApiTypedArray<uint8_t>&,
51-
v8::FastApiCallbackOptions&);
52-
using CFunctionCallbackWithUint8ArrayUint32Int64Bool =
53-
int32_t (*)(v8::Local<v8::Value>,
54-
const v8::FastApiTypedArray<uint8_t>&,
55-
uint32_t,
56-
int64_t,
57-
bool);
58-
using CFunctionWithUint32 = uint32_t (*)(v8::Local<v8::Value>,
59-
const uint32_t input);
60-
using CFunctionWithReturnUint32 = uint32_t (*)(v8::Local<v8::Value>);
61-
using CFunctionWithReturnDouble = double (*)(v8::Local<v8::Value>);
62-
using CFunctionWithDoubleReturnDouble = double (*)(v8::Local<v8::Value>,
63-
v8::Local<v8::Value>,
64-
const double);
65-
using CFunctionWithInt64Fallback = void (*)(v8::Local<v8::Value>,
66-
v8::Local<v8::Value>,
67-
const int64_t,
68-
v8::FastApiCallbackOptions&);
69-
using CFunctionWithBool = void (*)(v8::Local<v8::Value>,
70-
v8::Local<v8::Value>,
71-
bool);
72-
73-
using CFunctionWriteString =
74-
uint32_t (*)(v8::Local<v8::Value> receiver,
75-
const v8::FastApiTypedArray<uint8_t>& dst,
76-
const v8::FastOneByteString& src,
77-
uint32_t offset,
78-
uint32_t max_length);
79-
80-
using CFunctionBufferCopy =
81-
uint32_t (*)(v8::Local<v8::Value> receiver,
82-
const v8::FastApiTypedArray<uint8_t>& source,
83-
const v8::FastApiTypedArray<uint8_t>& target,
84-
uint32_t target_start,
85-
uint32_t source_start,
86-
uint32_t to_copy);
87-
8813
// This class manages the external references from the V8 heap
8914
// to the C++ addresses in Node.js.
9015
class ExternalReferenceRegistry {
9116
public:
9217
ExternalReferenceRegistry();
9318

9419
#define ALLOWED_EXTERNAL_REFERENCE_TYPES(V) \
95-
V(CFunctionCallback) \
96-
V(CFunctionCallbackWithOneByteString) \
97-
V(CFunctionCallbackReturnBool) \
98-
V(CFunctionCallbackReturnDouble) \
99-
V(CFunctionCallbackReturnInt32) \
100-
V(CFunctionWithReturnUint32) \
101-
V(CFunctionCallbackValueReturnDouble) \
102-
V(CFunctionCallbackValueReturnDoubleUnusedReceiver) \
103-
V(CFunctionCallbackWithInt64) \
104-
V(CFunctionCallbackWithBool) \
105-
V(CFunctionCallbackWithString) \
106-
V(CFunctionCallbackWithStrings) \
107-
V(CFunctionCallbackWithTwoUint8Arrays) \
108-
V(CFunctionCallbackWithTwoUint8ArraysFallback) \
109-
V(CFunctionCallbackWithUint8ArrayUint32Int64Bool) \
110-
V(CFunctionWithUint32) \
111-
V(CFunctionWithDoubleReturnDouble) \
112-
V(CFunctionWithInt64Fallback) \
113-
V(CFunctionWithBool) \
114-
V(CFunctionBufferCopy) \
115-
V(CFunctionWriteString) \
116-
V(const v8::CFunctionInfo*) \
11720
V(v8::FunctionCallback) \
11821
V(v8::AccessorNameGetterCallback) \
11922
V(v8::AccessorNameSetterCallback) \
@@ -135,6 +38,13 @@ class ExternalReferenceRegistry {
13538
ALLOWED_EXTERNAL_REFERENCE_TYPES(V)
13639
#undef V
13740

41+
// Registers both the underlying function pointer
42+
// and the corresponding CFunctionInfo.
43+
void Register(const v8::CFunction& c_func) {
44+
RegisterT(c_func.GetAddress());
45+
RegisterT(c_func.GetTypeInfo());
46+
}
47+
13848
// This can be called only once.
13949
const std::vector<intptr_t>& external_references();
14050

src/node_os.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,20 +467,17 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
467467
registry->Register(GetLoadAvg);
468468
registry->Register(GetUptime);
469469
registry->Register(GetTotalMemory);
470-
registry->Register(FastGetTotalMemory);
471-
registry->Register(fast_get_total_memory.GetTypeInfo());
470+
registry->Register(fast_get_total_memory);
472471
registry->Register(GetFreeMemory);
473-
registry->Register(FastGetFreeMemory);
474-
registry->Register(fast_get_free_memory.GetTypeInfo());
472+
registry->Register(fast_get_free_memory);
475473
registry->Register(GetCPUInfo);
476474
registry->Register(GetInterfaceAddresses);
477475
registry->Register(GetHomeDirectory);
478476
registry->Register(GetUserInfo);
479477
registry->Register(SetPriority);
480478
registry->Register(GetPriority);
481479
registry->Register(GetAvailableParallelism);
482-
registry->Register(FastGetAvailableParallelism);
483-
registry->Register(fast_get_available_parallelism.GetTypeInfo());
480+
registry->Register(fast_get_available_parallelism);
484481
registry->Register(GetOSInformation);
485482
}
486483

src/node_perf.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
410410
registry->Register(MarkBootstrapComplete);
411411
registry->Register(UvMetricsInfo);
412412
registry->Register(SlowPerformanceNow);
413-
registry->Register(FastPerformanceNow);
414-
registry->Register(fast_performance_now.GetTypeInfo());
413+
registry->Register(fast_performance_now);
415414
HistogramBase::RegisterExternalReferences(registry);
416415
IntervalHistogram::RegisterExternalReferences(registry);
417416
}

src/node_process_methods.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,8 @@ void BindingData::RegisterExternalReferences(
642642
ExternalReferenceRegistry* registry) {
643643
registry->Register(SlowNumber);
644644
registry->Register(SlowBigInt);
645-
registry->Register(FastNumber);
646-
registry->Register(FastBigInt);
647-
registry->Register(fast_number_.GetTypeInfo());
648-
registry->Register(fast_bigint_.GetTypeInfo());
645+
registry->Register(fast_number_);
646+
registry->Register(fast_bigint_);
649647
}
650648

651649
BindingData* BindingData::FromV8Value(Local<Value> value) {

src/node_types.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,15 @@ void InitializeTypes(Local<Object> target,
113113
void RegisterTypesExternalReferences(ExternalReferenceRegistry* registry) {
114114
#define V(type) \
115115
registry->Register(Is##type); \
116-
registry->Register(Is##type##FastApi); \
117-
registry->Register(fast_is_##type##_.GetTypeInfo());
116+
registry->Register(fast_is_##type##_);
118117

119118
VALUE_METHOD_MAP(V)
120119
#undef V
121120

122121
registry->Register(IsAnyArrayBuffer);
123-
registry->Register(IsAnyArrayBufferFastApi);
124-
registry->Register(fast_is_any_array_buffer_.GetTypeInfo());
122+
registry->Register(fast_is_any_array_buffer_);
125123
registry->Register(IsBoxedPrimitive);
126-
registry->Register(IsBoxedPrimitiveFastApi);
127-
registry->Register(fast_is_boxed_primitive_.GetTypeInfo());
124+
registry->Register(fast_is_boxed_primitive_);
128125
}
129126
} // namespace node
130127

src/node_url.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,8 @@ void BindingData::RegisterExternalReferences(
516516
registry->Register(PathToFileURL);
517517
registry->Register(Update);
518518
registry->Register(CanParse);
519-
registry->Register(FastCanParse);
520-
registry->Register(FastCanParseWithBase);
521-
522519
for (const CFunction& method : fast_can_parse_methods_) {
523-
registry->Register(method.GetTypeInfo());
520+
registry->Register(method);
524521
}
525522
}
526523

src/node_util.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
442442
registry->Register(Sleep);
443443
registry->Register(ArrayBufferViewHasBuffer);
444444
registry->Register(GuessHandleType);
445-
registry->Register(FastGuessHandleType);
446-
registry->Register(fast_guess_handle_type_.GetTypeInfo());
445+
registry->Register(fast_guess_handle_type_);
447446
registry->Register(ParseEnv);
448447
registry->Register(IsInsideNodeModules);
449448
registry->Register(DefineLazyProperties);

0 commit comments

Comments
 (0)