File: nan_converters_43_inl.h

package info (click to toggle)
node-nan 2.14.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,396 kB
  • sloc: cpp: 7,564; python: 3,408; ansic: 1,548; javascript: 1,535; makefile: 114; sh: 34
file content (68 lines) | stat: -rw-r--r-- 2,748 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*********************************************************************
 * NAN - Native Abstractions for Node.js
 *
 * Copyright (c) 2018 NAN contributors
 *
 * 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) {                  \
  v8::Isolate *isolate = v8::Isolate::GetCurrent();                            \
  v8::EscapableHandleScope scope(isolate);                                     \
  return scope.Escape(                                                         \
      val->To ## TYPE(isolate->GetCurrentContext())                            \
          .FromMaybe(v8::Local<v8::TYPE>()));                                  \
}

X(Number)
X(String)
X(Object)
X(Integer)
X(Uint32)
X(Int32)
// V8 <= 7.0
#if V8_MAJOR_VERSION < 7 || (V8_MAJOR_VERSION == 7 && V8_MINOR_VERSION == 0)
X(Boolean)
#else
imp::ToFactory<v8::Boolean>::return_t                                          \
imp::ToFactory<v8::Boolean>::convert(v8::Local<v8::Value> val) {               \
  v8::Isolate *isolate = v8::Isolate::GetCurrent();                            \
  v8::EscapableHandleScope scope(isolate);                                     \
  return scope.Escape(val->ToBoolean(isolate));                                \
}
#endif

#undef X

#define X(TYPE, NAME)                                                          \
imp::ToFactory<TYPE>::return_t                                                 \
imp::ToFactory<TYPE>::convert(v8::Local<v8::Value> val) {                      \
  v8::Isolate *isolate = v8::Isolate::GetCurrent();                            \
  v8::HandleScope scope(isolate);                                              \
  return val->NAME ## Value(isolate->GetCurrentContext());                     \
}

X(double, Number)
X(int64_t, Integer)
X(uint32_t, Uint32)
X(int32_t, Int32)
// V8 <= 7.0
#if V8_MAJOR_VERSION < 7 || (V8_MAJOR_VERSION == 7 && V8_MINOR_VERSION == 0)
X(bool, Boolean)
#else
imp::ToFactory<bool>::return_t                                                 \
imp::ToFactory<bool>::convert(v8::Local<v8::Value> val) {                      \
  v8::Isolate *isolate = v8::Isolate::GetCurrent();                            \
  v8::HandleScope scope(isolate);                                              \
  return Just<bool>(val->BooleanValue(isolate));                               \
}
#endif

#undef X

#endif  // NAN_CONVERTERS_43_INL_H_