UNPKG

1.82 kBtext/x-cView Raw
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
9#ifndef NAN_CONVERTERS_H_
10#define NAN_CONVERTERS_H_
11
12namespace imp {
13template<typename T> struct ToFactoryBase {
14 typedef MaybeLocal<T> return_t;
15};
16template<typename T> struct ValueFactoryBase { typedef Maybe<T> return_t; };
17
18template<typename T> struct ToFactory;
19
20#define X(TYPE) \
21 template<> \
22 struct ToFactory<v8::TYPE> : ToFactoryBase<v8::TYPE> { \
23 static inline return_t convert(v8::Local<v8::Value> val); \
24 };
25
26X(Boolean)
27X(Number)
28X(String)
29X(Object)
30X(Integer)
31X(Uint32)
32X(Int32)
33
34#undef X
35
36#define X(TYPE) \
37 template<> \
38 struct ToFactory<TYPE> : ValueFactoryBase<TYPE> { \
39 static inline return_t convert(v8::Local<v8::Value> val); \
40 };
41
42X(bool)
43X(double)
44X(int64_t)
45X(uint32_t)
46X(int32_t)
47
48#undef X
49} // end of namespace imp
50
51template<typename T>
52inline
53typename imp::ToFactory<T>::return_t To(v8::Local<v8::Value> val) {
54 return imp::ToFactory<T>::convert(val);
55}
56
57#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \
58 (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
59# include "nan_converters_43_inl.h"
60#else
61# include "nan_converters_pre_43_inl.h"
62#endif
63
64#endif // NAN_CONVERTERS_H_