Skip to content

Commit d969c09

Browse files
cjihrigrvagg
authored andcommitted
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 0cd4a52 commit d969c09

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

src/node_util.cc

+23-43
Original file line numberDiff line numberDiff line change
@@ -14,45 +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-
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)
2228

23-
static void IsDate(const FunctionCallbackInfo<Value>& args) {
24-
CHECK_EQ(1, args.Length());
25-
args.GetReturnValue().Set(args[0]->IsDate());
26-
}
2729

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+
}
2835

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-
}
45-
46-
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-
}
36+
VALUE_METHOD_MAP(V)
37+
#undef V
5638

5739

5840
static void GetHiddenValue(const FunctionCallbackInfo<Value>& args) {
@@ -75,13 +57,11 @@ void Initialize(Local<Object> target,
7557
Local<Value> unused,
7658
Local<Context> context) {
7759
Environment* env = Environment::GetCurrent(context);
78-
env->SetMethod(target, "isRegExp", IsRegExp);
79-
env->SetMethod(target, "isDate", IsDate);
80-
env->SetMethod(target, "isMap", IsMap);
81-
env->SetMethod(target, "isMapIterator", IsMapIterator);
82-
env->SetMethod(target, "isSet", IsSet);
83-
env->SetMethod(target, "isSetIterator", IsSetIterator);
84-
env->SetMethod(target, "isPromise", IsPromise);
60+
61+
#define V(lcname, ucname) env->SetMethod(target, #lcname, ucname);
62+
VALUE_METHOD_MAP(V)
63+
#undef V
64+
8565
env->SetMethod(target, "getHiddenValue", GetHiddenValue);
8666
}
8767

0 commit comments

Comments
 (0)