Skip to content

Commit 46af397

Browse files
committed
src: define Is* util functions with macros
The Is* type checking functions in node_util.cc are mostly the same boilerplate. This commit defines them using a macro. Refs: #4100 PR-URL: #4118 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2922188 commit 46af397

File tree

1 file changed

+23
-64
lines changed

1 file changed

+23
-64
lines changed

src/node_util.cc

+23-64
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,27 @@ using v8::String;
1414
using v8::Value;
1515

1616

17-
static void IsRegExp(const FunctionCallbackInfo<Value>& args) {
18-
CHECK_EQ(1, args.Length());
19-
args.GetReturnValue().Set(args[0]->IsRegExp());
20-
}
21-
22-
23-
static void IsDate(const FunctionCallbackInfo<Value>& args) {
24-
CHECK_EQ(1, args.Length());
25-
args.GetReturnValue().Set(args[0]->IsDate());
26-
}
27-
28-
29-
static void IsMap(const FunctionCallbackInfo<Value>& args) {
30-
CHECK_EQ(1, args.Length());
31-
args.GetReturnValue().Set(args[0]->IsMap());
32-
}
33-
34-
35-
static void IsMapIterator(const FunctionCallbackInfo<Value>& args) {
36-
CHECK_EQ(1, args.Length());
37-
args.GetReturnValue().Set(args[0]->IsMapIterator());
38-
}
39-
40-
41-
static void IsSet(const FunctionCallbackInfo<Value>& args) {
42-
CHECK_EQ(1, args.Length());
43-
args.GetReturnValue().Set(args[0]->IsSet());
44-
}
17+
#define VALUE_METHOD_MAP(V) \
18+
V(isArrayBuffer, IsArrayBuffer) \
19+
V(isDataView, IsDataView) \
20+
V(isDate, IsDate) \
21+
V(isMap, IsMap) \
22+
V(isMapIterator, IsMapIterator) \
23+
V(isPromise, IsPromise) \
24+
V(isRegExp, IsRegExp) \
25+
V(isSet, IsSet) \
26+
V(isSetIterator, IsSetIterator) \
27+
V(isTypedArray, IsTypedArray)
4528

4629

47-
static void IsSetIterator(const FunctionCallbackInfo<Value>& args) {
48-
CHECK_EQ(1, args.Length());
49-
args.GetReturnValue().Set(args[0]->IsSetIterator());
50-
}
51-
52-
static void IsPromise(const FunctionCallbackInfo<Value>& args) {
53-
CHECK_EQ(1, args.Length());
54-
args.GetReturnValue().Set(args[0]->IsPromise());
55-
}
30+
#define V(_, ucname) \
31+
static void ucname(const FunctionCallbackInfo<Value>& args) { \
32+
CHECK_EQ(1, args.Length()); \
33+
args.GetReturnValue().Set(args[0]->ucname()); \
34+
}
5635

57-
58-
static void IsTypedArray(const FunctionCallbackInfo<Value>& args) {
59-
CHECK_EQ(1, args.Length());
60-
args.GetReturnValue().Set(args[0]->IsTypedArray());
61-
}
62-
63-
64-
static void IsArrayBuffer(const FunctionCallbackInfo<Value>& args) {
65-
CHECK_EQ(1, args.Length());
66-
args.GetReturnValue().Set(args[0]->IsArrayBuffer());
67-
}
68-
69-
70-
static void IsDataView(const FunctionCallbackInfo<Value>& args) {
71-
CHECK_EQ(1, args.Length());
72-
args.GetReturnValue().Set(args[0]->IsDataView());
73-
}
36+
VALUE_METHOD_MAP(V)
37+
#undef V
7438

7539

7640
static void GetHiddenValue(const FunctionCallbackInfo<Value>& args) {
@@ -93,16 +57,11 @@ void Initialize(Local<Object> target,
9357
Local<Value> unused,
9458
Local<Context> context) {
9559
Environment* env = Environment::GetCurrent(context);
96-
env->SetMethod(target, "isRegExp", IsRegExp);
97-
env->SetMethod(target, "isDate", IsDate);
98-
env->SetMethod(target, "isMap", IsMap);
99-
env->SetMethod(target, "isMapIterator", IsMapIterator);
100-
env->SetMethod(target, "isSet", IsSet);
101-
env->SetMethod(target, "isSetIterator", IsSetIterator);
102-
env->SetMethod(target, "isPromise", IsPromise);
103-
env->SetMethod(target, "isTypedArray", IsTypedArray);
104-
env->SetMethod(target, "isArrayBuffer", IsArrayBuffer);
105-
env->SetMethod(target, "isDataView", IsDataView);
60+
61+
#define V(lcname, ucname) env->SetMethod(target, #lcname, ucname);
62+
VALUE_METHOD_MAP(V)
63+
#undef V
64+
10665
env->SetMethod(target, "getHiddenValue", GetHiddenValue);
10766
}
10867

0 commit comments

Comments
 (0)