nan_converters.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*********************************************************************
  2. * NAN - Native Abstractions for Node.js
  3. *
  4. * Copyright (c) 2017 NAN contributors
  5. *
  6. * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
  7. ********************************************************************/
  8. #ifndef NAN_CONVERTERS_H_
  9. #define NAN_CONVERTERS_H_
  10. namespace imp {
  11. template<typename T> struct ToFactoryBase {
  12. typedef MaybeLocal<T> return_t;
  13. };
  14. template<typename T> struct ValueFactoryBase { typedef Maybe<T> return_t; };
  15. template<typename T> struct ToFactory;
  16. #define X(TYPE) \
  17. template<> \
  18. struct ToFactory<v8::TYPE> : ToFactoryBase<v8::TYPE> { \
  19. static inline return_t convert(v8::Local<v8::Value> val); \
  20. };
  21. X(Boolean)
  22. X(Number)
  23. X(String)
  24. X(Object)
  25. X(Integer)
  26. X(Uint32)
  27. X(Int32)
  28. #undef X
  29. #define X(TYPE) \
  30. template<> \
  31. struct ToFactory<TYPE> : ValueFactoryBase<TYPE> { \
  32. static inline return_t convert(v8::Local<v8::Value> val); \
  33. };
  34. X(bool)
  35. X(double)
  36. X(int64_t)
  37. X(uint32_t)
  38. X(int32_t)
  39. #undef X
  40. } // end of namespace imp
  41. template<typename T>
  42. inline
  43. typename imp::ToFactory<T>::return_t To(v8::Local<v8::Value> val) {
  44. return imp::ToFactory<T>::convert(val);
  45. }
  46. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \
  47. (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
  48. # include "nan_converters_43_inl.h"
  49. #else
  50. # include "nan_converters_pre_43_inl.h"
  51. #endif
  52. #endif // NAN_CONVERTERS_H_