nan_converters_43_inl.h 1.69 KB
Newer Older
1 2 3
/*********************************************************************
 * NAN - Native Abstractions for Node.js
 *
4
 * Copyright (c) 2018 NAN contributors
5 6 7 8 9 10 11 12 13 14
 *
 * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
 ********************************************************************/

#ifndef NAN_CONVERTERS_43_INL_H_
#define NAN_CONVERTERS_43_INL_H_

#define X(TYPE)                                                                \
imp::ToFactory<v8::TYPE>::return_t                                             \
imp::ToFactory<v8::TYPE>::convert(v8::Local<v8::Value> val) {                  \
15 16 17
  v8::Isolate *isolate = v8::Isolate::GetCurrent();                            \
  v8::EscapableHandleScope scope(isolate);                                     \
  return scope.Escape(                                                         \
18
      val->To ## TYPE(isolate->GetCurrentContext())                            \
19
          .FromMaybe(v8::Local<v8::TYPE>()));                                  \
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
}

X(Boolean)
X(Number)
X(String)
X(Object)
X(Integer)
X(Uint32)
X(Int32)

#undef X

#define X(TYPE, NAME)                                                          \
imp::ToFactory<TYPE>::return_t                                                 \
imp::ToFactory<TYPE>::convert(v8::Local<v8::Value> val) {                      \
35 36 37
  v8::Isolate *isolate = v8::Isolate::GetCurrent();                            \
  v8::HandleScope scope(isolate);                                              \
  return val->NAME ## Value(isolate->GetCurrentContext());                     \
38 39 40 41 42 43 44 45 46 47 48
}

X(bool, Boolean)
X(double, Number)
X(int64_t, Integer)
X(uint32_t, Uint32)
X(int32_t, Int32)

#undef X

#endif  // NAN_CONVERTERS_43_INL_H_