1 /*********************************************************************
2 * NAN - Native Abstractions for Node.js
4 * Copyright (c) 2018 NAN contributors
6 * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
7 ********************************************************************/
9 #ifndef NAN_CONVERTERS_H_
10 #define NAN_CONVERTERS_H_
13 template<typename T> struct ToFactoryBase {
14 typedef MaybeLocal<T> return_t;
16 template<typename T> struct ValueFactoryBase { typedef Maybe<T> return_t; };
18 template<typename T> struct ToFactory;
21 struct ToFactory<v8::Function> : ToFactoryBase<v8::Function> {
22 static inline return_t convert(v8::Local<v8::Value> val) {
23 if (val.IsEmpty() || !val->IsFunction()) return MaybeLocal<v8::Function>();
24 return MaybeLocal<v8::Function>(val.As<v8::Function>());
30 struct ToFactory<v8::TYPE> : ToFactoryBase<v8::TYPE> { \
31 static inline return_t convert(v8::Local<v8::Value> val); \
46 struct ToFactory<TYPE> : ValueFactoryBase<TYPE> { \
47 static inline return_t convert(v8::Local<v8::Value> val); \
57 } // end of namespace imp
61 typename imp::ToFactory<T>::return_t To(v8::Local<v8::Value> val) {
62 return imp::ToFactory<T>::convert(val);
65 #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \
66 (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
67 # include "nan_converters_43_inl.h"
69 # include "nan_converters_pre_43_inl.h"
72 #endif // NAN_CONVERTERS_H_