diff --git a/src/node_util.cc b/src/node_util.cc index ea800ff339..1e0f214ae4 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -14,45 +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()); -} - +#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 IsDate(const FunctionCallbackInfo& args) { - CHECK_EQ(1, args.Length()); - args.GetReturnValue().Set(args[0]->IsDate()); -} +#define V(_, ucname) \ + static void ucname(const FunctionCallbackInfo& args) { \ + CHECK_EQ(1, args.Length()); \ + args.GetReturnValue().Set(args[0]->ucname()); \ + } -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()); -} - - -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()); -} + VALUE_METHOD_MAP(V) +#undef V static void GetHiddenValue(const FunctionCallbackInfo& args) { @@ -75,13 +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); + +#define V(lcname, ucname) env->SetMethod(target, #lcname, ucname); + VALUE_METHOD_MAP(V) +#undef V + env->SetMethod(target, "getHiddenValue", GetHiddenValue); }