You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nan_converters_43_inl.h 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*********************************************************************
  2. * NAN - Native Abstractions for Node.js
  3. *
  4. * Copyright (c) 2018 NAN contributors
  5. *
  6. * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
  7. ********************************************************************/
  8. #ifndef NAN_CONVERTERS_43_INL_H_
  9. #define NAN_CONVERTERS_43_INL_H_
  10. #define X(TYPE) \
  11. imp::ToFactory<v8::TYPE>::return_t \
  12. imp::ToFactory<v8::TYPE>::convert(v8::Local<v8::Value> val) { \
  13. v8::Isolate *isolate = v8::Isolate::GetCurrent(); \
  14. v8::EscapableHandleScope scope(isolate); \
  15. return scope.Escape( \
  16. val->To ## TYPE(isolate->GetCurrentContext()) \
  17. .FromMaybe(v8::Local<v8::TYPE>())); \
  18. }
  19. X(Number)
  20. X(String)
  21. X(Object)
  22. X(Integer)
  23. X(Uint32)
  24. X(Int32)
  25. // V8 <= 7.0
  26. #if V8_MAJOR_VERSION < 7 || (V8_MAJOR_VERSION == 7 && V8_MINOR_VERSION == 0)
  27. X(Boolean)
  28. #else
  29. imp::ToFactory<v8::Boolean>::return_t \
  30. imp::ToFactory<v8::Boolean>::convert(v8::Local<v8::Value> val) { \
  31. v8::Isolate *isolate = v8::Isolate::GetCurrent(); \
  32. v8::EscapableHandleScope scope(isolate); \
  33. return scope.Escape(val->ToBoolean(isolate)); \
  34. }
  35. #endif
  36. #undef X
  37. #define X(TYPE, NAME) \
  38. imp::ToFactory<TYPE>::return_t \
  39. imp::ToFactory<TYPE>::convert(v8::Local<v8::Value> val) { \
  40. v8::Isolate *isolate = v8::Isolate::GetCurrent(); \
  41. v8::HandleScope scope(isolate); \
  42. return val->NAME ## Value(isolate->GetCurrentContext()); \
  43. }
  44. X(double, Number)
  45. X(int64_t, Integer)
  46. X(uint32_t, Uint32)
  47. X(int32_t, Int32)
  48. // V8 <= 7.0
  49. #if V8_MAJOR_VERSION < 7 || (V8_MAJOR_VERSION == 7 && V8_MINOR_VERSION == 0)
  50. X(bool, Boolean)
  51. #else
  52. imp::ToFactory<bool>::return_t \
  53. imp::ToFactory<bool>::convert(v8::Local<v8::Value> val) { \
  54. v8::Isolate *isolate = v8::Isolate::GetCurrent(); \
  55. v8::HandleScope scope(isolate); \
  56. return Just<bool>(val->BooleanValue(isolate)); \
  57. }
  58. #endif
  59. #undef X
  60. #endif // NAN_CONVERTERS_43_INL_H_