From 46af39768d81d8c3af2580a851fab47203d45538 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 2 Dec 2015 11:49:35 -0500 Subject: 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: https://github.com/nodejs/node/pull/4100 PR-URL: https://github.com/nodejs/node/pull/4118 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- src/node_util.cc | 87 +++++++++++++++----------------------------------------- 1 file changed, 23 insertions(+), 64 deletions(-) (limited to 'src/node_util.cc') diff --git a/src/node_util.cc b/src/node_util.cc index b7eba15510..1e0f214ae4 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -14,63 +14,27 @@ using v8::String; using v8::Value; -static void IsRegExp(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsRegExp()); -} - - -static void IsDate(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsDate()); -} - - -static void IsMap(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsMap()); -} - - -static void IsMapIterator(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsMapIterator()); -} - - -static void IsSet(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsSet()); -} +#define VALUE_METHOD_MAP(V) \ + V(isArrayBuffer, IsArrayBuffer) \ + V(isDataView, IsDataView) \ + V(isDate, IsDate) \ + V(isMap, IsMap) \ + V(isMapIterator, IsMapIterator) \ + V(isPromise, IsPromise) \ + V(isRegExp, IsRegExp) \ + V(isSet, IsSet) \ + V(isSetIterator, IsSetIterator) \ + V(isTypedArray, IsTypedArray) -static void IsSetIterator(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsSetIterator()); -} - -static void IsPromise(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsPromise()); -} +#define V(_, ucname) \ + static void ucname(const FunctionCallbackInfo& args) { \ + CHECK_EQ(1, args.Length()); \ + args.GetReturnValue().Set(args[0]->ucname()); \ + } - -static void IsTypedArray(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsTypedArray()); -} - - -static void IsArrayBuffer(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsArrayBuffer()); -} - - -static void IsDataView(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsDataView()); -} + VALUE_METHOD_MAP(V) +#undef V static void GetHiddenValue(const FunctionCallbackInfo& args) { @@ -93,16 +57,11 @@ void Initialize(Local target, Local unused, Local context) { Environment* env = Environment::GetCurrent(context); - env->SetMethod(target, "isRegExp", IsRegExp); - env->SetMethod(target, "isDate", IsDate); - env->SetMethod(target, "isMap", IsMap); - env->SetMethod(target, "isMapIterator", IsMapIterator); - env->SetMethod(target, "isSet", IsSet); - env->SetMethod(target, "isSetIterator", IsSetIterator); - env->SetMethod(target, "isPromise", IsPromise); - env->SetMethod(target, "isTypedArray", IsTypedArray); - env->SetMethod(target, "isArrayBuffer", IsArrayBuffer); - env->SetMethod(target, "isDataView", IsDataView); + +#define V(lcname, ucname) env->SetMethod(target, #lcname, ucname); + VALUE_METHOD_MAP(V) +#undef V + env->SetMethod(target, "getHiddenValue", GetHiddenValue); } -- cgit v1.2.3