Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate JSTypeTraits by macro functions #123

Merged
merged 1 commit into from
Oct 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions core/js_type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,33 @@ inline Napi::Value JSTypeTraits(Napi::Env env, T value) {
return T();
}

template <>
inline Napi::Value JSTypeTraits(Napi::Env env, bool value) {
return Napi::Boolean::New(env, value);
}

template <>
inline Napi::Value JSTypeTraits(Napi::Env env, double value) {
return Napi::Number::New(env, value);
}

template <>
inline Napi::Value JSTypeTraits(Napi::Env env, int16_t value) {
return Napi::Number::New(env, value);
}

template <>
inline Napi::Value JSTypeTraits(Napi::Env env, int32_t value) {
return Napi::Number::New(env, value);
}

template <>
inline Napi::Value JSTypeTraits(Napi::Env env, int64_t value) {
return Napi::Number::New(env, value);
}

template <>
inline Napi::Value JSTypeTraits(Napi::Env env, const std::string value) {
return Napi::String::New(env, value);
}
#define JS_TYPE_TRAITS_NUMBER(type) \
template <> \
inline Napi::Value JSTypeTraits(Napi::Env env, type value) { \
return Napi::Number::New(env, value); \
}

#define JS_TYPE_TRAITS_BOOLEAN(type) \
template <> \
inline Napi::Value JSTypeTraits(Napi::Env env, type value) { \
return Napi::Boolean::New(env, value); \
}

#define JS_TYPE_TRAITS_STRING(type) \
template <> \
inline Napi::Value JSTypeTraits(Napi::Env env, type value) { \
return Napi::String::New(env, value); \
}

// TODO(corona10): Auto generate JS_TYPE_TRAITS_XXXX.

JS_TYPE_TRAITS_NUMBER(int16_t);
JS_TYPE_TRAITS_NUMBER(int32_t);
JS_TYPE_TRAITS_NUMBER(int64_t);
JS_TYPE_TRAITS_NUMBER(double);

JS_TYPE_TRAITS_BOOLEAN(bool);

JS_TYPE_TRAITS_STRING(std::string);

#endif // CORE_JS_TYPE_TRAITS_H_