Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nan_maybe_pre_43_inl.h 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*********************************************************************
  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. #ifndef NAN_MAYBE_PRE_43_INL_H_
  9. #define NAN_MAYBE_PRE_43_INL_H_
  10. template<typename T>
  11. class MaybeLocal {
  12. public:
  13. inline MaybeLocal() : val_(v8::Local<T>()) {}
  14. template<typename S>
  15. # if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION
  16. inline
  17. MaybeLocal(v8::Local<S> that) : val_(that) {} // NOLINT(runtime/explicit)
  18. # else
  19. inline
  20. MaybeLocal(v8::Local<S> that) : // NOLINT(runtime/explicit)
  21. val_(*reinterpret_cast<v8::Local<T>*>(&that)) {}
  22. # endif
  23. inline bool IsEmpty() const { return val_.IsEmpty(); }
  24. template<typename S>
  25. inline bool ToLocal(v8::Local<S> *out) const {
  26. *out = val_;
  27. return !IsEmpty();
  28. }
  29. inline v8::Local<T> ToLocalChecked() const {
  30. #if defined(V8_ENABLE_CHECKS)
  31. assert(!IsEmpty() && "ToLocalChecked is Empty");
  32. #endif // V8_ENABLE_CHECKS
  33. return val_;
  34. }
  35. template<typename S>
  36. inline v8::Local<S> FromMaybe(v8::Local<S> default_value) const {
  37. return IsEmpty() ? default_value : v8::Local<S>(val_);
  38. }
  39. private:
  40. v8::Local<T> val_;
  41. };
  42. inline
  43. MaybeLocal<v8::String> ToDetailString(v8::Handle<v8::Value> val) {
  44. return MaybeLocal<v8::String>(val->ToDetailString());
  45. }
  46. inline
  47. MaybeLocal<v8::Uint32> ToArrayIndex(v8::Handle<v8::Value> val) {
  48. return MaybeLocal<v8::Uint32>(val->ToArrayIndex());
  49. }
  50. inline
  51. Maybe<bool> Equals(v8::Handle<v8::Value> a, v8::Handle<v8::Value>(b)) {
  52. return Just<bool>(a->Equals(b));
  53. }
  54. inline
  55. MaybeLocal<v8::Object> NewInstance(v8::Handle<v8::Function> h) {
  56. return MaybeLocal<v8::Object>(h->NewInstance());
  57. }
  58. inline
  59. MaybeLocal<v8::Object> NewInstance(
  60. v8::Local<v8::Function> h
  61. , int argc
  62. , v8::Local<v8::Value> argv[]) {
  63. return MaybeLocal<v8::Object>(h->NewInstance(argc, argv));
  64. }
  65. inline
  66. MaybeLocal<v8::Object> NewInstance(v8::Handle<v8::ObjectTemplate> h) {
  67. return MaybeLocal<v8::Object>(h->NewInstance());
  68. }
  69. inline
  70. MaybeLocal<v8::Function> GetFunction(v8::Handle<v8::FunctionTemplate> t) {
  71. return MaybeLocal<v8::Function>(t->GetFunction());
  72. }
  73. inline Maybe<bool> Set(
  74. v8::Handle<v8::Object> obj
  75. , v8::Handle<v8::Value> key
  76. , v8::Handle<v8::Value> value) {
  77. return Just<bool>(obj->Set(key, value));
  78. }
  79. inline Maybe<bool> Set(
  80. v8::Handle<v8::Object> obj
  81. , uint32_t index
  82. , v8::Handle<v8::Value> value) {
  83. return Just<bool>(obj->Set(index, value));
  84. }
  85. #include "nan_define_own_property_helper.h" // NOLINT(build/include)
  86. inline Maybe<bool> DefineOwnProperty(
  87. v8::Handle<v8::Object> obj
  88. , v8::Handle<v8::String> key
  89. , v8::Handle<v8::Value> value
  90. , v8::PropertyAttribute attribs = v8::None) {
  91. v8::PropertyAttribute current = obj->GetPropertyAttributes(key);
  92. return imp::DefineOwnPropertyHelper(current, obj, key, value, attribs);
  93. }
  94. NAN_DEPRECATED inline Maybe<bool> ForceSet(
  95. v8::Handle<v8::Object> obj
  96. , v8::Handle<v8::Value> key
  97. , v8::Handle<v8::Value> value
  98. , v8::PropertyAttribute attribs = v8::None) {
  99. return Just<bool>(obj->ForceSet(key, value, attribs));
  100. }
  101. inline MaybeLocal<v8::Value> Get(
  102. v8::Handle<v8::Object> obj
  103. , v8::Handle<v8::Value> key) {
  104. return MaybeLocal<v8::Value>(obj->Get(key));
  105. }
  106. inline MaybeLocal<v8::Value> Get(
  107. v8::Handle<v8::Object> obj
  108. , uint32_t index) {
  109. return MaybeLocal<v8::Value>(obj->Get(index));
  110. }
  111. inline Maybe<v8::PropertyAttribute> GetPropertyAttributes(
  112. v8::Handle<v8::Object> obj
  113. , v8::Handle<v8::Value> key) {
  114. return Just<v8::PropertyAttribute>(obj->GetPropertyAttributes(key));
  115. }
  116. inline Maybe<bool> Has(
  117. v8::Handle<v8::Object> obj
  118. , v8::Handle<v8::String> key) {
  119. return Just<bool>(obj->Has(key));
  120. }
  121. inline Maybe<bool> Has(
  122. v8::Handle<v8::Object> obj
  123. , uint32_t index) {
  124. return Just<bool>(obj->Has(index));
  125. }
  126. inline Maybe<bool> Delete(
  127. v8::Handle<v8::Object> obj
  128. , v8::Handle<v8::String> key) {
  129. return Just<bool>(obj->Delete(key));
  130. }
  131. inline Maybe<bool> Delete(
  132. v8::Handle<v8::Object> obj
  133. , uint32_t index) {
  134. return Just<bool>(obj->Delete(index));
  135. }
  136. inline
  137. MaybeLocal<v8::Array> GetPropertyNames(v8::Handle<v8::Object> obj) {
  138. return MaybeLocal<v8::Array>(obj->GetPropertyNames());
  139. }
  140. inline
  141. MaybeLocal<v8::Array> GetOwnPropertyNames(v8::Handle<v8::Object> obj) {
  142. return MaybeLocal<v8::Array>(obj->GetOwnPropertyNames());
  143. }
  144. inline Maybe<bool> SetPrototype(
  145. v8::Handle<v8::Object> obj
  146. , v8::Handle<v8::Value> prototype) {
  147. return Just<bool>(obj->SetPrototype(prototype));
  148. }
  149. inline MaybeLocal<v8::String> ObjectProtoToString(
  150. v8::Handle<v8::Object> obj) {
  151. return MaybeLocal<v8::String>(obj->ObjectProtoToString());
  152. }
  153. inline Maybe<bool> HasOwnProperty(
  154. v8::Handle<v8::Object> obj
  155. , v8::Handle<v8::String> key) {
  156. return Just<bool>(obj->HasOwnProperty(key));
  157. }
  158. inline Maybe<bool> HasRealNamedProperty(
  159. v8::Handle<v8::Object> obj
  160. , v8::Handle<v8::String> key) {
  161. return Just<bool>(obj->HasRealNamedProperty(key));
  162. }
  163. inline Maybe<bool> HasRealIndexedProperty(
  164. v8::Handle<v8::Object> obj
  165. , uint32_t index) {
  166. return Just<bool>(obj->HasRealIndexedProperty(index));
  167. }
  168. inline Maybe<bool> HasRealNamedCallbackProperty(
  169. v8::Handle<v8::Object> obj
  170. , v8::Handle<v8::String> key) {
  171. return Just<bool>(obj->HasRealNamedCallbackProperty(key));
  172. }
  173. inline MaybeLocal<v8::Value> GetRealNamedPropertyInPrototypeChain(
  174. v8::Handle<v8::Object> obj
  175. , v8::Handle<v8::String> key) {
  176. return MaybeLocal<v8::Value>(
  177. obj->GetRealNamedPropertyInPrototypeChain(key));
  178. }
  179. inline MaybeLocal<v8::Value> GetRealNamedProperty(
  180. v8::Handle<v8::Object> obj
  181. , v8::Handle<v8::String> key) {
  182. return MaybeLocal<v8::Value>(obj->GetRealNamedProperty(key));
  183. }
  184. inline MaybeLocal<v8::Value> CallAsFunction(
  185. v8::Handle<v8::Object> obj
  186. , v8::Handle<v8::Object> recv
  187. , int argc
  188. , v8::Handle<v8::Value> argv[]) {
  189. return MaybeLocal<v8::Value>(obj->CallAsFunction(recv, argc, argv));
  190. }
  191. inline MaybeLocal<v8::Value> CallAsConstructor(
  192. v8::Handle<v8::Object> obj
  193. , int argc
  194. , v8::Local<v8::Value> argv[]) {
  195. return MaybeLocal<v8::Value>(obj->CallAsConstructor(argc, argv));
  196. }
  197. inline
  198. MaybeLocal<v8::String> GetSourceLine(v8::Handle<v8::Message> msg) {
  199. return MaybeLocal<v8::String>(msg->GetSourceLine());
  200. }
  201. inline Maybe<int> GetLineNumber(v8::Handle<v8::Message> msg) {
  202. return Just<int>(msg->GetLineNumber());
  203. }
  204. inline Maybe<int> GetStartColumn(v8::Handle<v8::Message> msg) {
  205. return Just<int>(msg->GetStartColumn());
  206. }
  207. inline Maybe<int> GetEndColumn(v8::Handle<v8::Message> msg) {
  208. return Just<int>(msg->GetEndColumn());
  209. }
  210. inline MaybeLocal<v8::Object> CloneElementAt(
  211. v8::Handle<v8::Array> array
  212. , uint32_t index) {
  213. return MaybeLocal<v8::Object>(array->CloneElementAt(index));
  214. }
  215. inline MaybeLocal<v8::Value> Call(
  216. v8::Local<v8::Function> fun
  217. , v8::Local<v8::Object> recv
  218. , int argc
  219. , v8::Local<v8::Value> argv[]) {
  220. return MaybeLocal<v8::Value>(fun->Call(recv, argc, argv));
  221. }
  222. #endif // NAN_MAYBE_PRE_43_INL_H_