php_v8js_macros.h 4.9 KB

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