Projekt

Obecné

Profil

Stáhnout (2.06 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
/*********************************************************************
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
9
#ifndef NAN_CONVERTERS_H_
10
#define NAN_CONVERTERS_H_
11
12
namespace imp {
13
template<typename T> struct ToFactoryBase {
14
  typedef MaybeLocal<T> return_t;
15
};
16
template<typename T> struct ValueFactoryBase { typedef Maybe<T> return_t; };
17
18
template<typename T> struct ToFactory;
19
20
template<>
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>());
25
  }
26
};
27
28
#define X(TYPE)                                                                \
29
    template<>                                                                 \
30
    struct ToFactory<v8::TYPE> : ToFactoryBase<v8::TYPE> {                     \
31
      static inline return_t convert(v8::Local<v8::Value> val);                \
32
    };
33
34
X(Boolean)
35
X(Number)
36
X(String)
37
X(Object)
38
X(Integer)
39
X(Uint32)
40
X(Int32)
41
42
#undef X
43
44
#define X(TYPE)                                                                \
45
    template<>                                                                 \
46
    struct ToFactory<TYPE> : ValueFactoryBase<TYPE> {                          \
47
      static inline return_t convert(v8::Local<v8::Value> val);                \
48
    };
49
50
X(bool)
51
X(double)
52
X(int64_t)
53
X(uint32_t)
54
X(int32_t)
55
56
#undef X
57
}  // end of namespace imp
58
59
template<typename T>
60
inline
61
typename imp::ToFactory<T>::return_t To(v8::Local<v8::Value> val) {
62
  return imp::ToFactory<T>::convert(val);
63
}
64
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"
68
#else
69
# include "nan_converters_pre_43_inl.h"
70
#endif
71
72
#endif  // NAN_CONVERTERS_H_