php_v8js_macros.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. extern "C" {
  28. #include "php_config.h"
  29. /* work around incompatibilities regarding isnan() and isfinite() macros,
  30. * affecting PHP versions before 7.4. */
  31. #undef HAVE_DECL_ISFINITE
  32. #undef HAVE_DECL_ISNAN
  33. #define HAVE_DECL_ISFINITE 0
  34. #define HAVE_DECL_ISNAN 0
  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 <v8-platform.h>
  45. #include "v8js_class.h"
  46. #include "v8js_v8.h"
  47. #ifndef PATH_MAX
  48. /* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
  49. * just assume an arbitrary upper bound of 4096 chars.
  50. * Anyways we should fix (get rid of) the code that uses PATH_MAX as it doesn't
  51. * even check for buffer overflows. FIXME */
  52. #define PATH_MAX 4096
  53. #endif
  54. /* V8Js Version */
  55. #define PHP_V8JS_VERSION "2.1.1"
  56. /* Options */
  57. #define V8JS_FLAG_NONE (1<<0)
  58. #define V8JS_FLAG_FORCE_ARRAY (1<<1)
  59. #define V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS (1<<2)
  60. /* These are not defined by Zend */
  61. #define ZEND_WAKEUP_FUNC_NAME "__wakeup"
  62. #define ZEND_SLEEP_FUNC_NAME "__sleep"
  63. #define ZEND_SET_STATE_FUNC_NAME "__set_state"
  64. /* Convert zval into V8 value */
  65. v8::Local<v8::Value> zval_to_v8js(zval *, v8::Isolate *);
  66. /* Convert zend_long into V8 value */
  67. v8::Local<v8::Value> zend_long_to_v8js(zend_long, v8::Isolate *);
  68. /* Convert V8 value into zval */
  69. int v8js_to_zval(v8::Local<v8::Value>, zval *, int, v8::Isolate *);
  70. struct v8js_accessor_ctx
  71. {
  72. zend_string *variable_name;
  73. v8::Isolate *isolate;
  74. };
  75. void v8js_accessor_ctx_dtor(v8js_accessor_ctx *);
  76. /* Register accessors into passed object */
  77. void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate *);
  78. /* Forward declarations */
  79. struct v8js_timer_ctx;
  80. /* Module globals */
  81. ZEND_BEGIN_MODULE_GLOBALS(v8js)
  82. // Thread-local cache whether V8 has been initialized so far
  83. bool v8_initialized;
  84. /* Ini globals */
  85. bool use_date; /* Generate JS Date objects instead of PHP DateTime */
  86. bool use_array_access; /* Convert ArrayAccess, Countable objects to array-like objects */
  87. // Timer thread globals
  88. std::deque<v8js_timer_ctx *> timer_stack;
  89. std::thread *timer_thread;
  90. std::mutex timer_mutex;
  91. bool timer_stop;
  92. bool fatal_error_abort;
  93. ZEND_END_MODULE_GLOBALS(v8js)
  94. extern zend_v8js_globals v8js_globals;
  95. ZEND_EXTERN_MODULE_GLOBALS(v8js)
  96. #define V8JSG(v) ZEND_MODULE_GLOBALS_ACCESSOR(v8js, v)
  97. /*
  98. * Process-wide globals
  99. *
  100. * The zend_v8js_globals structure declared above is created once per thread
  101. * (in a ZTS environment). If a multi-threaded PHP process uses V8 there is
  102. * some stuff shared among all of these threads
  103. *
  104. * - whether V8 has been initialized at all
  105. * - the V8 backend platform
  106. * - loaded extensions
  107. * - V8 "command line" flags
  108. *
  109. * In a ZTS-enabled environment access to all of these variables must happen
  110. * while holding a mutex lock.
  111. */
  112. struct _v8js_process_globals {
  113. #ifdef ZTS
  114. bool v8_initialized;
  115. std::mutex lock;
  116. #endif
  117. HashTable *extensions;
  118. /* V8 command line flags */
  119. char *v8_flags;
  120. /* Path to icudtl.dat file */
  121. char *icudtl_dat_path;
  122. std::unique_ptr<v8::Platform> v8_platform;
  123. };
  124. extern struct _v8js_process_globals v8js_process_globals;
  125. /* Register builtin methods into passed object */
  126. void v8js_register_methods(v8::Local<v8::ObjectTemplate>, v8js_ctx *c);
  127. #ifdef ZEND_HASH_INC_APPLY_COUNT
  128. #ifndef GC_PROTECT_RECURSION
  129. # define GC_PROTECT_RECURSION(ht) ZEND_HASH_INC_APPLY_COUNT(ht)
  130. #endif
  131. #endif
  132. #ifdef ZEND_HASH_DEC_APPLY_COUNT
  133. #ifndef GC_UNPROTECT_RECURSION
  134. # define GC_UNPROTECT_RECURSION(ht) ZEND_HASH_DEC_APPLY_COUNT(ht)
  135. #endif
  136. #endif
  137. #endif /* PHP_V8JS_MACROS_H */
  138. /*
  139. * Local variables:
  140. * tab-width: 4
  141. * c-basic-offset: 4
  142. * indent-tabs-mode: t
  143. * End:
  144. * vim600: noet sw=4 ts=4 fdm=marker
  145. * vim<600: noet sw=4 ts=4
  146. */