2
2
#include " node.h"
3
3
#include " node_external_reference.h"
4
4
5
+ using v8::CFunction;
5
6
using v8::Context;
6
7
using v8::FunctionCallbackInfo;
7
8
using v8::Local;
@@ -42,7 +43,11 @@ namespace {
42
43
#define V (type ) \
43
44
static void Is##type(const FunctionCallbackInfo<Value>& args) { \
44
45
args.GetReturnValue ().Set (args[0 ]->Is ##type ()); \
45
- }
46
+ } \
47
+ static bool Is##type##FastApi(Local<Value> unused, Local<Value> receiver) { \
48
+ return receiver->Is ##type (); \
49
+ } \
50
+ static CFunction fast_is_##type##_ = CFunction::Make(Is##type##FastApi);
46
51
47
52
VALUE_METHOD_MAP (V)
48
53
#undef V
@@ -52,6 +57,14 @@ static void IsAnyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
52
57
args[0 ]->IsArrayBuffer () || args[0 ]->IsSharedArrayBuffer ());
53
58
}
54
59
60
+ static bool IsAnyArrayBufferFastApi (Local<Value> unused,
61
+ Local<Value> receiver) {
62
+ return receiver->IsArrayBuffer () || receiver->IsSharedArrayBuffer ();
63
+ }
64
+
65
+ static CFunction fast_is_any_array_buffer_ =
66
+ CFunction::Make (IsAnyArrayBufferFastApi);
67
+
55
68
static void IsBoxedPrimitive (const FunctionCallbackInfo<Value>& args) {
56
69
args.GetReturnValue ().Set (
57
70
args[0 ]->IsNumberObject () ||
@@ -61,27 +74,52 @@ static void IsBoxedPrimitive(const FunctionCallbackInfo<Value>& args) {
61
74
args[0 ]->IsSymbolObject ());
62
75
}
63
76
77
+ static bool IsBoxedPrimitiveFastApi (Local<Value> unused,
78
+ Local<Value> receiver) {
79
+ return receiver->IsNumberObject () ||
80
+ receiver->IsStringObject () ||
81
+ receiver->IsBooleanObject () ||
82
+ receiver->IsBigIntObject () ||
83
+ receiver->IsSymbolObject ();
84
+ }
85
+
86
+ static CFunction fast_is_boxed_primitive_ =
87
+ CFunction::Make (IsBoxedPrimitiveFastApi);
88
+
64
89
void InitializeTypes (Local<Object> target,
65
90
Local<Value> unused,
66
91
Local<Context> context,
67
92
void * priv) {
68
- #define V (type ) SetMethodNoSideEffect(context, target, " is" #type, Is##type);
93
+ #define V (type ) \
94
+ SetFastMethodNoSideEffect (context, target, " is" #type, \
95
+ Is##type, &fast_is_##type##_);
96
+
69
97
VALUE_METHOD_MAP (V)
70
98
#undef V
71
99
72
- SetMethodNoSideEffect (context, target, " isAnyArrayBuffer" , IsAnyArrayBuffer);
73
- SetMethodNoSideEffect (context, target, " isBoxedPrimitive" , IsBoxedPrimitive);
100
+ SetFastMethodNoSideEffect (context, target, " isAnyArrayBuffer" ,
101
+ IsAnyArrayBuffer, &fast_is_any_array_buffer_);
102
+ SetFastMethodNoSideEffect (context, target, " isBoxedPrimitive" ,
103
+ IsBoxedPrimitive, &fast_is_boxed_primitive_);
74
104
}
75
105
76
106
} // anonymous namespace
77
107
78
108
void RegisterTypesExternalReferences (ExternalReferenceRegistry* registry) {
79
- #define V (type ) registry->Register (Is##type);
109
+ #define V (type ) \
110
+ registry->Register (Is##type); \
111
+ registry->Register (Is##type##FastApi); \
112
+ registry->Register (fast_is_##type##_.GetTypeInfo ());
113
+
80
114
VALUE_METHOD_MAP (V)
81
115
#undef V
82
116
83
117
registry->Register (IsAnyArrayBuffer);
118
+ registry->Register (IsAnyArrayBufferFastApi);
119
+ registry->Register (fast_is_any_array_buffer_.GetTypeInfo ());
84
120
registry->Register (IsBoxedPrimitive);
121
+ registry->Register (IsBoxedPrimitiveFastApi);
122
+ registry->Register (fast_is_boxed_primitive_.GetTypeInfo ());
85
123
}
86
124
} // namespace node
87
125
0 commit comments