v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
v8helpers.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <map>
5 #include <vector>
6 #include <iostream>
7 #include <set>
8 #include <typeinfo>
9 
10 
11 #include <fmt/ostream.h>
12 
13 #include <libplatform/libplatform.h>
14 #include <v8.h>
15 
16 
17 #include "stdfunctionreplacement.h"
18 
19 
20 // if it can be determined safely that cxxabi.h is available, include it for name demangling
21 #if defined __has_include
22 #if __has_include(<cxxabi.h>)
23 # define V8TOOLKIT_DEMANGLE_NAMES
24 # include <cxxabi.h>
25 #endif
26 #endif
27 
28 
29 namespace v8toolkit {
30 
31  template<class MemberT, class ClassT>
32  constexpr bool get_member_is_readonly(MemberT(ClassT::*member)) {
33  return std::is_const_v<MemberT>;
34  };
35 
36 
37  template<auto member>
39 
40 
41 
43  struct MethodAdderData {
46 
49  };
50 
51  /**
52  * Returns a string with the given stack trace and a leading and trailing newline
53  * @param stack_trace stack trace to return a string representation of
54  * @return string representation of the given stack trace
55  */
57 
58 
59 
60 
61  template<class T>
62  using void_t = void;
63 
64  template<class T>
65  using int_t = int;
66 
67 
68  namespace literals {
69 
70  // put the following in your code to use these:
71  // using namespace v8toolkit::literals;
72  inline v8::Local<v8::String> operator "" _v8(char const * string, unsigned long) {
73  v8::Isolate * isolate = v8::Isolate::GetCurrent();
74  return v8::String::NewFromUtf8(isolate, string);
75  }
76  inline v8::Local<v8::Number> operator"" _v8(long double number) {
77  v8::Isolate * isolate = v8::Isolate::GetCurrent();
78  return v8::Number::New(isolate, number);
79  }
80  inline v8::Local<v8::Integer> operator"" _v8(unsigned long long int number) {
81  v8::Isolate * isolate = v8::Isolate::GetCurrent();
82  return v8::Integer::New(isolate, number);
83  }
84 
85  }
86 
87 
88 
89 template<class ReturnType, class... Args, class... Ts>
90 auto run_function(func::function<ReturnType(Args...)> & function,
91  const v8::FunctionCallbackInfo<v8::Value> & info,
92  Ts&&... ts) -> ReturnType {
93  return function(std::forward<Args>(ts)...);
94 }
95 
96 
97 template<class ReturnType, class... Args, class Callable, class... Ts>
98 auto run_function(Callable callable,
99  const v8::FunctionCallbackInfo<v8::Value> & info,
100  Ts&&... ts) -> ReturnType {
101  return callable(std::forward<Args>(ts)...);
102 };
103 
104 
105 
106 
107 // thrown when data cannot be converted properly
108 class CastException : public std::exception {
109 private:
110  std::string reason;
111 
112 public:
113  template<class... Ts>
114  CastException(const std::string & reason, Ts&&... ts) : reason(fmt::format(reason, std::forward<Ts>(ts)...) + get_stack_trace_string(v8::StackTrace::CurrentStackTrace(v8::Isolate::GetCurrent(), 100))) {}
115  virtual const char * what() const noexcept override {return reason.c_str();}
116 };
117 
118 template<typename T, typename = void>
119 struct ProxyType {
120  using PROXY_TYPE = T;
121 };
122 
123 template<typename T>
124 struct ProxyType<T,void_t<typename T::V8TOOLKIT_PROXY_TYPE>>{
125  using PROXY_TYPE = typename T::V8TOOLKIT_PROXY_TYPE;
126 };
127 
128 void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch);
129 
130 // use V8TOOLKIT_MACRO_TYPE instead
131 #define V8TOOLKIT_COMMA ,
132 
133 // protects and allows subsequent calls to additional macros for types with commas (templated types)
134 #define V8TOOLKIT_MACRO_TYPE(...) __VA_ARGS__
135 
136 
137 
138 /**
139  * Returns a demangled version of the typeid(T).name() passed in if it knows how,
140  * otherwise returns the mangled name exactly as passed in
141  */
142 std::string demangle_typeid_name(const std::string & mangled_name);
143 
144 template<class T>
146  static std::string cached_name;
147  std::atomic<bool> cache_set = false;
148 
149  if (cache_set) {
150  return cached_name;
151  } else {
152  static std::mutex mutex;
153 
154  std::lock_guard<std::mutex> lock_guard(mutex);
155  if (!cache_set) {
156  auto demangled_name = demangle_typeid_name(typeid(T).name());
157  std::string constness = std::is_const<T>::value ? "const " : "";
158  std::string volatility = std::is_volatile<T>::value ? "volatile " : "";
159  cached_name = constness + volatility + demangled_name;
160  }
161  }
162 
163  return cached_name;
164  }
165 
166 // polymorphic types work just like normal
167 template<class Destination, class Source, std::enable_if_t<std::is_polymorphic<Source>::value, int> = 0>
168 Destination safe_dynamic_cast(Source * source) {
169  static_assert(std::is_pointer<Destination>::value, "must be a pointer type");
170  static_assert(!std::is_pointer<std::remove_pointer_t<Destination>>::value, "must be a single pointer type");
171 // fprintf(stderr, "safe dynamic cast doing real cast\n");
172  return dynamic_cast<Destination>(source);
173 };
174 
175 
176 // trivial casts always succeed even if the type isn't polymoprhic
177 template<class Destination>
178 Destination * safe_dynamic_cast(Destination * source) {
179  return source;
180 }
181 
182 // non-trivial casts for non-polymorphic types always fail
183 template<class Destination, class Source, std::enable_if_t<!std::is_polymorphic<Source>::value, int> = 0>
184 Destination safe_dynamic_cast(Source * source) {
185  static_assert(std::is_pointer<Destination>::value, "must be a pointer type");
186  static_assert(!std::is_pointer<std::remove_pointer_t<Destination>>::value, "must be a single pointer type");
187 // fprintf(stderr, "safe dynamic cast doing fake/stub cast\n");
188  return nullptr;
189 };
190 
191 
192 #define SAFE_MOVE_CONSTRUCTOR_SFINAE !std::is_const<T>::value && std::is_move_constructible<T>::value
193 template<class T, std::enable_if_t<SAFE_MOVE_CONSTRUCTOR_SFINAE, int> = 0>
194 std::unique_ptr<T> safe_move_constructor(T && original) {
195  return std::make_unique<T>(std::move(original));
196 };
197 template<class T, std::enable_if_t<!(SAFE_MOVE_CONSTRUCTOR_SFINAE), int> = 0>
198 std::unique_ptr<T> safe_move_constructor(T && original) {
199  assert(false); // This shouldn't be called
200  return std::unique_ptr<T>();
201 };
202 
203 
204 
205  template<typename Test, template<typename...> class Ref>
207 
208 template<template<typename...> class Ref, typename... Args>
210 
211 /**
212  * Returns a func::function type compatible with the lambda passed in
213  */
214 template<class T>
215 struct LTG {
216  template<class R, class... Args>
217  static auto go(R(T::*)(Args...)const)->func::function<R(Args...)>;
218 
219  template<class R, class... Args>
220  static auto go(R(T::*)(Args...))->func::function<R(Args...)>;
221 
222  template<class R, class... Args>
223  static auto go(R(T::*)(Args...)const &)->func::function<R(Args...)>;
224 
225  template<class R, class... Args>
226  static auto go(R(T::*)(Args...) &)->func::function<R(Args...)>;
227 
228 };
229 
230 template<class T>
231 struct LTG<T &&> {
232  template<class R, class... Args>
233  static auto go(R(T::*)(Args...)const &&)->func::function<R(Args...)>;
234 
235  template<class R, class... Args>
236  static auto go(R(T::*)(Args...) &&)->func::function<R(Args...)>;
237 
238 };
239 
240 
241 
242 template <class... > struct TypeList {};
243 
244 // for use inside a decltype only
245 template <class R, class... Ts>
246 auto get_typelist_for_function(func::function<R(Ts...)>) ->TypeList<Ts...>;
247 
248 // for use inside a decltype only
249 template <class R, class Head, class... Tail>
250 auto get_typelist_for_function_strip_first(func::function<R(Head, Tail...)>) -> TypeList<Tail...>;
251 
252 // for use inside a decltype only
253 template <class... Ts>
254 auto get_typelist_for_variables(Ts... ts) -> TypeList<Ts...>;
255 
256 template <class... Ts>
257 auto make_tuple_for_variables(Ts&&... ts) -> std::tuple<Ts...> {
258  return std::tuple<Ts...>(std::forward<Ts>(ts)...);
259 }
260 
261 
262 template<bool... b> struct static_any;
263 
264 template<bool... tail>
265 struct static_any<true, tail...> : std::true_type {};
266 
267 template<bool... tail>
268 struct static_any<false, tail...> : static_any<tail...> {};
269 
270 template<>
272 
273 
274 
275 template <bool... b> struct static_all_of;
276 
277 // If the first parameter is true, look at the rest of the list
278 template <bool... tail>
279 struct static_all_of<true, tail...> : static_all_of<tail...> {};
280 
281 // if any parameter is false, return false
282 template <bool... tail>
283 struct static_all_of<false, tail...> : std::false_type {};
284 
285 // If there are no parameters left, no false was found so return true
286 template <> struct static_all_of<> : std::true_type {};
287 
288 
289 /**
290 * General purpose exception for invalid uses of the v8toolkit API
291 */
292 class InvalidCallException : public std::exception {
293 private:
294  std::string message;
295 
296 public:
297  InvalidCallException(const std::string & message);
298  virtual const char * what() const noexcept override {return message.c_str();}
299 };
300 
301 /**
302  * Thrown when trying to register a function/method/member with the same name as
303  * something else already registered
304  */
305 class DuplicateNameException : public std::exception {
306 private:
307  std::string message;
308 
309 public:
310  DuplicateNameException(const std::string & message) : message(message) {}
311  virtual const char * what() const noexcept override {return message.c_str();}
312 };
313 
314 
315  class UndefinedPropertyException : public std::exception {
316  private:
317  std::string message;
318 
319  public:
320  UndefinedPropertyException(const std::string & message) : message(message) {}
321  virtual const char * what() const noexcept override {return message.c_str();}
322 
323 
324  };
325 
326 /**
327 * prints out a ton of info about a v8::Value
328 */
330 
331 
332 /**
333 * Returns the length of an array
334 */
335 int get_array_length(v8::Isolate * isolate, v8::Local<v8::Value> array_value);
336 
337 
338 std::set<std::string> make_set_from_object_keys(v8::Isolate * isolate,
339  v8::Local<v8::Object> & object,
340  bool own_properties_only = true);
341 
342 
343 /**d
344  * When passed a value representing an array, runs callable with each element of that array (but not on arrays
345  * contained within the outer array)
346  * On any other object type, runs callable with that element
347  */
348 template<class Callable>
349 void for_each_value(const v8::Local<v8::Context> context, const v8::Local<v8::Value> value, Callable callable) {
350 
351  if (value->IsArray()) {
352  auto array = v8::Local<v8::Object>::Cast(value);
353  auto length = get_array_length(context->GetIsolate(), array);
354  for (int i = 0; i < length; i++) {
355  callable(array->Get(context, i).ToLocalChecked());
356  }
357  } else {
358  callable(value);
359  }
360 }
361 
362 
363 /**
364 * Creates a variable with the given alias_name in the context's global object to point back to the global object
365 * Same as node.js "global" variable or a web browser "window" object
366 */
367 void set_global_object_alias(v8::Isolate * isolate, const v8::Local<v8::Context> context, std::string alias_name);
368 
369 
370 /**
371  * Returns a string corresponding to the type of the value passed
372  * @param value the value whose type to return a string version of
373  * @return a string for the type of value
374  */
376 
377 
378 /**
379 * parses v8-related flags and removes them, adjusting argc as needed
380 */
381 void process_v8_flags(int & argc, char ** argv);
382 
383 
384 /**
385 * exposes the garbage collector to javascript
386 * same as passing --expose-gc as a command-line flag
387 * To encourage the javascript garbage collector to run from c++ code, use:
388 * while(!v8::Isolate::IdleNotificationDeadline([time])) {};
389 */
390 void expose_gc();
391 
392 // calls a javascript function with no parameters and returns the value
394  v8::Local<v8::Function> function);
395 /**
396 * Calls callable with each javascript "own property" in the object passed.
397 */
398 template<class T>
399 void for_each_own_property(const v8::Local<v8::Context> context, const v8::Local<v8::Object> object, T callable)
400 {
401  auto own_properties = object->GetOwnPropertyNames(context).ToLocalChecked();
402  for_each_value(context, own_properties, [&object, &context, &callable](v8::Local<v8::Value> property_name){
403  auto property_value = object->Get(context, property_name);
404 
405  callable(property_name, property_value.ToLocalChecked());
406  });
407 }
408 
409 
410 
411 /**
412 * Takes a container, runs each element through Callable and returns a new container
413 * of the same container type but with a data type matching the returned type
414 * of the Callable
415 */
416 template<class Container,
417  class Callable>
419 
420 
421 /**
422 * Takes a container containing type Data (only for single-type containers, not maps)
423 * and runs each element through a Callable returning a new container of the same container type
424 * but with a data type matching the type returned by the Callable
425 */
426 template<template <typename, typename...> class Container,
427 class Data,
428 class... AddParams,
429 class Callable>
430 struct MapperHelper<Container<Data, AddParams...>, Callable>
431 {
432  using Results = Container<typename std::result_of<Callable(Data)>::type>;
433  Results operator()(const Container<Data, AddParams...> & container, Callable callable)
434  {
435  Results results;
436  for (auto && element : container) {
437  try {
438  results.push_back(callable(std::forward<decltype(element)>(element)));
439  }catch(...) {} // ignore exceptions, just don't copy the element
440  }
441  return results;
442  }
443 };
444 
445 
446 /**
447 * Takes a map with arbitrary key/value types and returns a new map with the types
448 * inside the std::pair returned by Callable
449 */
450 template<class Key,
451  class Value,
452  class... AddParams,
453  class Callable>
454 struct MapperHelper<std::map<Key, Value, AddParams...>, Callable>
455 {
456  using Source = std::map<Key, Value, AddParams...>;
457  using ResultPair = typename std::result_of<Callable(typename Source::value_type)>::type;
458  using Results = std::map<typename ResultPair::T1, typename ResultPair::T2>;
459  Results operator()(std::map<Key, Value, AddParams...> container, Callable callable)
460  {
461  Results results;
462 
463 
464  for (auto && element : container) {
465  results.insert(callable(std::forward<decltype(element)>(element)));
466  }
467  return results;
468  }
469 };
470 
471 
472 /** IF YOU GET AN ERROR ABOUT RESULT_OF::TYPE NOT EXISTING, MAKE SURE YOUR LAMBDA PARAMETER TYPE IS EXACTLY RIGHT,
473  * ESPECTIALLY RE; CONST
474  * @param container input container
475  * @param callable transformation callback
476  * @return container of the transformed results
477  */
478 template <class Container, class Callable>
479 auto mapper(const Container & container, Callable callable) -> decltype(MapperHelper<Container, Callable>()(container, callable))
480 {
481  return MapperHelper<Container, Callable>()(container, callable);
482 }
483 
484 
485 template <class Callable,
486  class Container>
487 auto reducer(const Container & container, Callable callable) ->
488  std::vector<typename std::result_of<Callable(typename Container::value_type)>::type>
489 {
490  using ResultType = typename std::result_of<Callable(typename Container::value_type)>::type;
491  std::vector<ResultType> results;
492  for(auto && pair : container) {
493  results.push_back(callable(std::forward<decltype(pair)>(pair)));
494  }
495  return results;
496 }
497 
498 
499 
500 
501 /**
502 * When passing an Any-type through a void *, always static_cast it to an AnyBase *
503 * pointer and pass that as the void *. This allows you to safely cast it back to
504 * a AnyBase* on the other side and then dynamic_cast to any child types to
505 * determine the type of the object actually stored.
506 */
507 
508 // if this is defined, AnyBase will store the actual typename but this is only needed for debugging
509 #define ANYBASE_DEBUG
510 
511 /**
512  * If ANYBASE_DEBUG is defined, then this flag controls whether type conversion information logs are printed to stderr
513  */
514 extern bool AnybaseDebugPrintFlag;
515 
516 
517 #ifdef ANYBASE_DEBUG
518 #define ANYBASE_PRINT(format_string, ...) \
519 if (AnybaseDebugPrintFlag) { \
520  std::cerr << fmt::format(format_string, ##__VA_ARGS__) << std::endl; \
521 }
522 #else
523 #define ANYBASE_PRINT(format_string, ...)
524 #endif
525 
526 
527  struct AnyBase
528 {
529  virtual ~AnyBase();
530 #ifdef ANYBASE_DEBUG
532 #endif
534 #ifdef ANYBASE_DEBUG
535  type_name
536 #endif
537  )
538 #ifdef ANYBASE_DEBUG
539 : type_name(std::move(type_name))
540 #endif
541  {}
542 };
543 
544 
545 template<class T, class = void>
546 struct AnyPtr;
547 
548 
549 template<class T>
550 struct AnyPtr<T, std::enable_if_t<!std::is_pointer<T>::value && !std::is_reference<T>::value>> : public AnyBase {
551  AnyPtr(T * data) : AnyBase(demangle<T>()), data(data) {}
552  virtual ~AnyPtr(){}
553  T* data;
554  T * get() {return data;}
555 };
556 
557 
558 
559 
560 struct StuffBase{
561  // virtual destructor makes sure derived class destructor is called to actually
562  // delete the data
563  virtual ~StuffBase(){}
564 };
565 
566 template<class T>
567 struct Stuff : public StuffBase {
568  Stuff(T && t) : stuffed(std::make_unique<T>(std::move(t))) {}
569  Stuff(std::unique_ptr<T> t) : stuffed(std::move(t)) {}
570 
571 
572  static std::unique_ptr<Stuff<T>> stuffer(T && t) {return std::make_unique<Stuff<T>>(std::move(t));}
573  static std::unique_ptr<Stuff<T>> stuffer(T const & t) {return std::make_unique<Stuff<T>>(std::move(const_cast<T &>(t)));}
574 
575  T * get(){return stuffed.get();}
576  std::unique_ptr<T> stuffed;
577 };
578 
579 
580 /**
581 * Best used for types that are intrinsically pointers like std::shared_ptr or
582 * std::exception_ptr
583 */
584 template<class T>
585 struct Any : public AnyBase {
586  Any(T data) : AnyBase(demangle<T>()), data(data) {}
587  virtual ~Any(){}
588  T data;
589  T get() {return data;}
590 };
591 
592 
593 template<class T>
595  bool valid = false;
596  if (std::is_same<T, v8::Function>::value) {
597  valid = value->IsFunction();
598  } else if (std::is_same<T, v8::Object>::value) {
599  valid = value->IsObject();
600  } else if (std::is_same<T, v8::Array>::value) {
601  valid = value->IsArray();
602  } else if (std::is_same<T, v8::String>::value) {
603  valid = value->IsString();
604  } else if (std::is_same<T, v8::Boolean>::value) {
605  valid = value->IsBoolean();
606  } else if (std::is_same<T, v8::Number>::value) {
607  valid = value->IsNumber();
608  } else if (std::is_same<T, v8::Value>::value) {
609  // this can be handy for dealing with global values
610  // passed in through the version that takes globals
611  valid = true;
612  }
613 
614  if (valid){
615  return v8::Local<T>::Cast(value);
616  } else {
617 
618  //printf("Throwing exception, failed while trying to cast value as type: %s\n", demangle<T>().c_str());
619  //print_v8_value_details(value);
620  throw v8toolkit::CastException(fmt::format("Couldn't cast value to requested type", demangle<T>().c_str()));
621  }
622 }
623 
624 
625 template<class T>
626 v8::Local<T> get_value_as(v8::Isolate * isolate, v8::Global<v8::Value> & value) {
627  return get_value_as<T>(value.Get(isolate));
628 }
629 
630 
631 
632 
633 template<class T>
635 
636  auto isolate = context->GetIsolate();
637  // printf("Looking up key %s\n", key.c_str());
638  auto get_maybe = object->Get(context, v8::String::NewFromUtf8(isolate, key.c_str()));
639 
640  if(get_maybe.IsEmpty() || get_maybe.ToLocalChecked()->IsUndefined()) {
641 // if (get_maybe.IsEmpty()) {
642 // std::cerr << "empty" << std::endl;
643 // } else {
644 // std::cerr << "undefined" << std::endl;
645 // }
646  throw UndefinedPropertyException(key);
647  }
648  return get_value_as<T>(get_maybe.ToLocalChecked());
649 }
650 
651 
652 
653 template<class T>
655  return get_key_as<T>(context, get_value_as<v8::Object>(object), key);
656 }
657 
659 
661 
662 
663 /**
664 * Takes a v8::Value and prints it out in a json-like form (but includes non-json types like function)
665 *
666 * Good for looking at the contents of a value and also used for printobj() method added by add_print
667 */
668 std::string stringify_value(v8::Isolate * isolate,
669  const v8::Local<v8::Value> & value,
670  bool show_all_properties=false,
671  std::vector<v8::Local<v8::Value>> && processed_values = std::vector<v8::Local<v8::Value>>{});
672 
673 /**
674  * Tests if the given name conflicts with a reserved javascript top-level name
675  * @param name value to check
676  * @return true if there is a conflict
677  */
678 bool global_name_conflicts(const std::string & name);
679 extern std::vector<std::string> reserved_global_names;
680 
681 
682 
684  if (!value->IsObject()) {
685  print_v8_value_details(value);
686  throw CastException(fmt::format("Value sent to CastToNative<{} &&> wasn't a JavaScript object, it was: '{}'", class_name, *v8::String::Utf8Value(value)));
687  }
688 
689  auto object = value->ToObject();
690 
691  if (object->InternalFieldCount() == 0) {
692  throw CastException(fmt::format("Object sent to CastToNative<{} &&> wasn't a wrapped native object, it was a pure JavaScript object: '{}'", class_name, *v8::String::Utf8Value(value)));
693  }
694 
695  return object;
696 
697 }
698 
699 } // End v8toolkit namespace
std::set< std::string > make_set_from_object_keys(v8::Isolate *isolate, v8::Local< v8::Object > &object, bool own_properties_only=true)
Definition: v8helpers.cpp:160
bool global_name_conflicts(const std::string &name)
Definition: v8helpers.cpp:358
std::unique_ptr< T > safe_move_constructor(T &&original)
Definition: v8helpers.h:194
std::string get_stack_trace_string(v8::Local< v8::StackTrace > stack_trace)
Definition: v8helpers.cpp:28
constexpr bool get_member_is_readonly(MemberT(ClassT::*member))
Definition: v8helpers.h:32
void expose_gc()
Definition: v8toolkit.cpp:52
auto mapper(const Container &container, Callable callable) -> decltype(MapperHelper< Container, Callable >()(container, callable))
Definition: v8helpers.h:479
void for_each_value(const v8::Local< v8::Context > context, const v8::Local< v8::Value > value, Callable callable)
Definition: v8helpers.h:349
static std::unique_ptr< Stuff< T > > stuffer(T &&t)
Definition: v8helpers.h:572
::std::string string
Definition: gtest-port.h:1097
std::map< typename ResultPair::T1, typename ResultPair::T2 > Results
Definition: v8helpers.h:458
int get_array_length(v8::Isolate *isolate, v8::Local< v8::Value > array_value)
Definition: v8helpers.cpp:85
virtual const char * what() const noexcept override
Definition: v8helpers.h:298
auto get_typelist_for_function_strip_first(func::function< R(Head, Tail...)>) -> TypeList< Tail... >
v8::Local< T > get_value_as(v8::Local< v8::Value > value)
Definition: v8helpers.h:594
STL namespace.
constexpr bool is_pointer_to_const_data_member_v
Definition: v8helpers.h:38
CastException(const std::string &reason, Ts &&...ts)
Definition: v8helpers.h:114
std::string stringify_value(v8::Isolate *isolate, const v8::Local< v8::Value > &value, bool show_all_properties=false, std::vector< v8::Local< v8::Value >> &&processed_values=std::vector< v8::Local< v8::Value >>{})
Definition: v8helpers.cpp:187
v8::Local< v8::Object > check_value_is_object(v8::Local< v8::Value > value, std::string const &class_name)
Definition: v8helpers.h:683
virtual const char * what() const noexcept override
Definition: v8helpers.h:311
virtual ~Any()
Definition: v8helpers.h:587
bool AnybaseDebugPrintFlag
Definition: v8helpers.cpp:11
bool_constant< true > true_type
Definition: gtest-port.h:2210
DuplicateNameException(const std::string &message)
Definition: v8helpers.h:310
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
auto get_typelist_for_variables(Ts...ts) -> TypeList< Ts... >
auto get_typelist_for_function(func::function< R(Ts...)>) -> TypeList< Ts... >
bool_constant< false > false_type
Definition: gtest-port.h:2209
UndefinedPropertyException(const std::string &message)
Definition: v8helpers.h:320
void void_t
Definition: v8helpers.h:62
std::unique_ptr< T > stuffed
Definition: v8helpers.h:576
auto reducer(const Container &container, Callable callable) -> std::vector< typename std::result_of< Callable(typename Container::value_type)>::type >
Definition: v8helpers.h:487
v8::Local< v8::Value > get_key(v8::Local< v8::Context > context, v8::Local< v8::Object > object, std::string key)
Definition: v8helpers.cpp:289
Definition: sample.cpp:29
Container< typename std::result_of< Callable(Data)>::type > Results
Definition: v8helpers.h:432
std::string & demangle()
Definition: v8helpers.h:145
bool Value(const T &value, M matcher)
virtual ~StuffBase()
Definition: v8helpers.h:563
auto run_function(func::function< ReturnType(Args...)> &function, const v8::FunctionCallbackInfo< v8::Value > &info, Ts &&...ts) -> ReturnType
Definition: v8helpers.h:90
Destination safe_dynamic_cast(Source *source)
Definition: v8helpers.h:168
std::string type_name
Definition: v8helpers.h:531
v8::Local< T > get_key_as(v8::Local< v8::Context > context, v8::Local< v8::Object > object, std::string key)
Definition: v8helpers.h:634
Stuff(std::unique_ptr< T > t)
Definition: v8helpers.h:569
Results operator()(const Container< Data, AddParams... > &container, Callable callable)
Definition: v8helpers.h:433
StdFunctionCallbackType callback
Definition: v8helpers.h:45
virtual const char * what() const noexcept override
Definition: v8helpers.h:115
#define ANYBASE_DEBUG
Definition: v8helpers.h:509
Definition: sample.cpp:93
static std::unique_ptr< Stuff< T > > stuffer(T const &t)
Definition: v8helpers.h:573
void ReportException(v8::Isolate *isolate, v8::TryCatch *try_catch)
Definition: v8helpers.cpp:316
int int_t
Definition: v8helpers.h:65
AnyBase(const std::string type_name)
Definition: v8helpers.h:533
void print_v8_value_details(v8::Local< v8::Value > local_value)
Definition: v8helpers.cpp:129
typename std::result_of< Callable(typename Source::value_type)>::type ResultPair
Definition: v8helpers.h:457
void process_v8_flags(int &argc, char **argv)
Definition: v8toolkit.cpp:46
std::vector< std::string > reserved_global_names
Definition: v8helpers.cpp:368
Results operator()(std::map< Key, Value, AddParams... > container, Callable callable)
Definition: v8helpers.h:459
auto make_tuple_for_variables(Ts &&...ts) -> std::tuple< Ts... >
Definition: v8helpers.h:257
virtual const char * what() const noexcept override
Definition: v8helpers.h:321
void for_each_own_property(const v8::Local< v8::Context > context, const v8::Local< v8::Object > object, T callable)
Definition: v8helpers.h:399
internal::KeyMatcher< M > Key(M inner_matcher)
v8::Local< v8::Value > call_simple_javascript_function(v8::Isolate *isolate, v8::Local< v8::Function > function)
Definition: v8helpers.cpp:299
Any(T data)
Definition: v8helpers.h:586
const T & move(const T &t)
Definition: gtest-port.h:1317
std::string demangle_typeid_name(const std::string &mangled_name)
Definition: v8helpers.cpp:45
void set_global_object_alias(v8::Isolate *isolate, const v8::Local< v8::Context > context, std::string alias_name)
Definition: v8helpers.cpp:96
internal::RefMatcher< T & > Ref(T &x)
std::string get_type_string_for_value(v8::Local< v8::Value > value)
Definition: v8helpers.cpp:104