php_v8js_macros.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2017 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | http://www.opensource.org/licenses/mit-license.php MIT License |
  8. +----------------------------------------------------------------------+
  9. | Author: Jani Taskinen <[email protected]> |
  10. | Author: Patrick Reilly <[email protected]> |
  11. | Author: Stefan Siegl <[email protected]> |
  12. +----------------------------------------------------------------------+
  13. */
  14. #ifndef PHP_V8JS_MACROS_H
  15. #define PHP_V8JS_MACROS_H
  16. #if __GNUC__ == 4 && __GNUC_MINOR__ == 4
  17. #define _GLIBCXX_USE_NANOSLEEP 1
  18. #endif
  19. #include <chrono>
  20. #include <deque>
  21. #include <thread>
  22. #include <map>
  23. #include <list>
  24. #include <vector>
  25. #include <mutex>
  26. #include <cmath>
  27. #ifndef isnan
  28. /* php.h requires the isnan() macro, which is removed by c++ <cmath> header,
  29. * work around: re-define the macro to std::isnan function */
  30. #define isnan(a) std::isnan(a)
  31. /* likewise isfinite */
  32. #define isfinite(a) std::isfinite(a)
  33. #endif
  34. extern "C" {
  35. #include "php.h"
  36. #include "php_v8js.h"
  37. }
  38. #ifdef _WIN32
  39. /* On Windows a symbol COMPILER is defined. However v8.h has an enum with that
  40. * name which hence would be broken unless undefined here. */
  41. #undef COMPILER
  42. #endif
  43. #include <v8.h>
  44. #include "v8js_class.h"
  45. #include "v8js_v8.h"
  46. #ifndef PATH_MAX
  47. /* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
  48. * just assume an arbitrary upper bound of 4096 chars.
  49. * Anyways we should fix (get rid of) the code that uses PATH_MAX as it doesn't
  50. * even check for buffer overflows. FIXME */
  51. #define PATH_MAX 4096
  52. #endif
  53. /* V8Js Version */
  54. #define PHP_V8JS_VERSION "1.3.6"
  55. /* Helper macros */
  56. #define V8JS_GET_CLASS_NAME(var, obj) \
  57. v8::String::Utf8Value var(obj->GetConstructorName());
  58. /* Options */
  59. #define V8JS_FLAG_NONE (1<<0)
  60. #define V8JS_FLAG_FORCE_ARRAY (1<<1)
  61. #define V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS (1<<2)
  62. /* These are not defined by Zend */
  63. #define ZEND_WAKEUP_FUNC_NAME "__wakeup"
  64. #define ZEND_SLEEP_FUNC_NAME "__sleep"
  65. #define ZEND_SET_STATE_FUNC_NAME "__set_state"
  66. /* Convert zval into V8 value */
  67. v8::Local<v8::Value> zval_to_v8js(zval *, v8::Isolate *);
  68. /* Convert zend_long into V8 value */
  69. v8::Local<v8::Value> zend_long_to_v8js(zend_long, v8::Isolate *);
  70. /* Convert V8 value into zval */
  71. int v8js_to_zval(v8::Local<v8::Value>, zval *, int, v8::Isolate *);
  72. struct v8js_accessor_ctx
  73. {
  74. zend_string *variable_name;
  75. v8::Isolate *isolate;
  76. };
  77. void v8js_accessor_ctx_dtor(v8js_accessor_ctx *);
  78. /* Register accessors into passed object */
  79. void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate *);
  80. /* Forward declarations */
  81. struct v8js_timer_ctx;
  82. /* Module globals */
  83. ZEND_BEGIN_MODULE_GLOBALS(v8js)
  84. // Thread-local cache whether V8 has been initialized so far
  85. bool v8_initialized;
  86. /* Ini globals */
  87. bool use_date; /* Generate JS Date objects instead of PHP DateTime */
  88. bool use_array_access; /* Convert ArrayAccess, Countable objects to array-like objects */
  89. bool compat_php_exceptions; /* Don't stop JS execution on PHP exception */
  90. // Timer thread globals
  91. std::deque<v8js_timer_ctx *> timer_stack;
  92. std::thread *timer_thread;
  93. std::mutex timer_mutex;
  94. bool timer_stop;
  95. bool fatal_error_abort;
  96. ZEND_END_MODULE_GLOBALS(v8js)
  97. extern zend_v8js_globals v8js_globals;
  98. ZEND_EXTERN_MODULE_GLOBALS(v8js)
  99. #define V8JSG(v) ZEND_MODULE_GLOBALS_ACCESSOR(v8js, v)
  100. /*
  101. * Process-wide globals
  102. *
  103. * The zend_v8js_globals structure declared above is created once per thread
  104. * (in a ZTS environment). If a multi-threaded PHP process uses V8 there is
  105. * some stuff shared among all of these threads
  106. *
  107. * - whether V8 has been initialized at all
  108. * - the V8 backend platform
  109. * - loaded extensions
  110. * - V8 "command line" flags
  111. *
  112. * In a ZTS-enabled environment access to all of these variables must happen
  113. * while holding a mutex lock.
  114. */
  115. struct _v8js_process_globals {
  116. #ifdef ZTS
  117. bool v8_initialized;
  118. std::mutex lock;
  119. #endif
  120. HashTable *extensions;
  121. /* V8 command line flags */
  122. char *v8_flags;
  123. v8::Platform *v8_platform;
  124. };
  125. extern struct _v8js_process_globals v8js_process_globals;
  126. /* Register builtin methods into passed object */
  127. void v8js_register_methods(v8::Local<v8::ObjectTemplate>, v8js_ctx *c);
  128. #endif /* PHP_V8JS_MACROS_H */
  129. /*
  130. * Local variables:
  131. * tab-width: 4
  132. * c-basic-offset: 4
  133. * indent-tabs-mode: t
  134. * End:
  135. * vim600: noet sw=4 ts=4 fdm=marker
  136. * vim<600: noet sw=4 ts=4
  137. */