php_v8js_macros.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. extern "C" {
  19. #include "php.h"
  20. #include "php_v8js.h"
  21. }
  22. #ifdef _WIN32
  23. /* On Windows a symbol COMPILER is defined. However v8.h has an enum with that
  24. * name which hence would be broken unless undefined here. */
  25. #undef COMPILER
  26. #endif
  27. #include <v8.h>
  28. #include <chrono>
  29. #include <deque>
  30. #include <thread>
  31. #include <map>
  32. #include <list>
  33. #include <vector>
  34. #include <mutex>
  35. #include "v8js_class.h"
  36. #include "v8js_v8.h"
  37. #include "v8js_timer.h"
  38. #ifndef PATH_MAX
  39. /* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
  40. * just assume an arbitrary upper bound of 4096 chars.
  41. * Anyways we should fix (get rid of) the code that uses PATH_MAX as it doesn't
  42. * even check for buffer overflows. FIXME */
  43. #define PATH_MAX 4096
  44. #endif
  45. /* V8Js Version */
  46. #define PHP_V8JS_VERSION "0.2.1"
  47. /* Hidden field name used to link JS wrappers with underlying PHP object */
  48. #define PHPJS_OBJECT_KEY "phpjs::object"
  49. /* Helper macros */
  50. #define V8JS_GET_CLASS_NAME(var, obj) \
  51. v8::String::Utf8Value var(obj->GetConstructorName());
  52. /* method signatures of zend_update_property and zend_read_property were
  53. * declared as 'char *' instead of 'const char *' before PHP 5.4 */
  54. #if ZEND_MODULE_API_NO >= 20100525
  55. # define V8JS_CONST
  56. #else
  57. # define V8JS_CONST (char *)
  58. #endif
  59. /* Global flags */
  60. #define V8JS_GLOBAL_SET_FLAGS(isolate,flags) V8JS_GLOBAL(isolate)->SetHiddenValue(V8JS_SYM("__php_flags__"), V8JS_INT(flags))
  61. #define V8JS_GLOBAL_GET_FLAGS(isolate) V8JS_GLOBAL(isolate)->GetHiddenValue(V8JS_SYM("__php_flags__"))->IntegerValue();
  62. /* Options */
  63. #define V8JS_FLAG_NONE (1<<0)
  64. #define V8JS_FLAG_FORCE_ARRAY (1<<1)
  65. #define V8JS_DEBUG_AUTO_BREAK_NEVER 0
  66. #define V8JS_DEBUG_AUTO_BREAK_ONCE 1
  67. #define V8JS_DEBUG_AUTO_BREAK_ALWAYS 2
  68. /* Convert zval into V8 value */
  69. v8::Handle<v8::Value> zval_to_v8js(zval *, v8::Isolate * TSRMLS_DC);
  70. /* Convert V8 value into zval */
  71. int v8js_to_zval(v8::Handle<v8::Value>, zval *, int, v8::Isolate * TSRMLS_DC);
  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 * TSRMLS_DC);
  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 * TSRMLS_DC);
  80. /* Resource declaration */
  81. /* Module globals */
  82. ZEND_BEGIN_MODULE_GLOBALS(v8js)
  83. int v8_initialized;
  84. #if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
  85. v8::Platform *v8_platform;
  86. #endif
  87. HashTable *extensions;
  88. /* Ini globals */
  89. char *v8_flags; /* V8 command line flags */
  90. bool use_date; /* Generate JS Date objects instead of PHP DateTime */
  91. bool use_array_access; /* Convert ArrayAccess, Countable objects to array-like objects */
  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. /* Register builtin methods into passed object */
  103. void v8js_register_methods(v8::Handle<v8::ObjectTemplate>, v8js_ctx *c);
  104. #endif /* PHP_V8JS_MACROS_H */
  105. /*
  106. * Local variables:
  107. * tab-width: 4
  108. * c-basic-offset: 4
  109. * End:
  110. * vim600: noet sw=4 ts=4 fdm=marker
  111. * vim<600: noet sw=4 ts=4
  112. */