php_v8js_macros.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. /* $Id$ */
  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. extern "C" {
  20. #include "php.h"
  21. #include "php_v8js.h"
  22. }
  23. #ifdef _WIN32
  24. /* On Windows a symbol COMPILER is defined. However v8.h has an enum with that
  25. * name which hence would be broken unless undefined here. */
  26. #undef COMPILER
  27. #endif
  28. #include <v8.h>
  29. #include <chrono>
  30. #include <deque>
  31. #include <thread>
  32. #include <map>
  33. #include <list>
  34. #include <vector>
  35. #include <mutex>
  36. #include "v8js_class.h"
  37. #include "v8js_v8.h"
  38. #include "v8js_timer.h"
  39. #ifndef PATH_MAX
  40. /* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
  41. * just assume an arbitrary upper bound of 4096 chars.
  42. * Anyways we should fix (get rid of) the code that uses PATH_MAX as it doesn't
  43. * even check for buffer overflows. FIXME */
  44. #define PATH_MAX 4096
  45. #endif
  46. /* V8Js Version */
  47. #define V8JS_VERSION "0.1.5"
  48. /* Hidden field name used to link JS wrappers with underlying PHP object */
  49. #define PHPJS_OBJECT_KEY "phpjs::object"
  50. /* Helper macros */
  51. #define V8JS_GET_CLASS_NAME(var, obj) \
  52. v8::String::Utf8Value var(obj->GetConstructorName());
  53. #if ZEND_MODULE_API_NO >= 20100409
  54. # define ZEND_HASH_KEY_DC , const zend_literal *key
  55. # define ZEND_HASH_KEY_CC , key
  56. # define ZEND_HASH_KEY_NULL , NULL
  57. #else
  58. # define ZEND_HASH_KEY_DC
  59. # define ZEND_HASH_KEY_CC
  60. # define ZEND_HASH_KEY_NULL
  61. #endif
  62. /* method signatures of zend_update_property and zend_read_property were
  63. * declared as 'char *' instead of 'const char *' before PHP 5.4 */
  64. #if ZEND_MODULE_API_NO >= 20100525
  65. # define V8JS_CONST
  66. #else
  67. # define V8JS_CONST (char *)
  68. #endif
  69. /* Global flags */
  70. #define V8JS_GLOBAL_SET_FLAGS(isolate,flags) V8JS_GLOBAL(isolate)->SetHiddenValue(V8JS_SYM("__php_flags__"), V8JS_INT(flags))
  71. #define V8JS_GLOBAL_GET_FLAGS(isolate) V8JS_GLOBAL(isolate)->GetHiddenValue(V8JS_SYM("__php_flags__"))->IntegerValue();
  72. /* Options */
  73. #define V8JS_FLAG_NONE (1<<0)
  74. #define V8JS_FLAG_FORCE_ARRAY (1<<1)
  75. #define V8JS_DEBUG_AUTO_BREAK_NEVER 0
  76. #define V8JS_DEBUG_AUTO_BREAK_ONCE 1
  77. #define V8JS_DEBUG_AUTO_BREAK_ALWAYS 2
  78. /* Create PHP V8 object */
  79. void php_v8js_create_v8(zval *, v8::Handle<v8::Value>, int, v8::Isolate * TSRMLS_DC);
  80. /* Convert zval into V8 value */
  81. v8::Handle<v8::Value> zval_to_v8js(zval *, v8::Isolate * TSRMLS_DC);
  82. /* Convert V8 value into zval */
  83. int v8js_to_zval(v8::Handle<v8::Value>, zval *, int, v8::Isolate * TSRMLS_DC);
  84. struct php_v8js_accessor_ctx
  85. {
  86. char *variable_name_string;
  87. uint variable_name_string_len;
  88. v8::Isolate *isolate;
  89. };
  90. void php_v8js_accessor_ctx_dtor(php_v8js_accessor_ctx * TSRMLS_DC);
  91. /* Register accessors into passed object */
  92. void php_v8js_register_accessors(std::vector<php_v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC);
  93. /* Resource declaration */
  94. /* Module globals */
  95. ZEND_BEGIN_MODULE_GLOBALS(v8js)
  96. int v8_initialized;
  97. HashTable *extensions;
  98. /* Ini globals */
  99. char *v8_flags; /* V8 command line flags */
  100. bool use_date; /* Generate JS Date objects instead of PHP DateTime */
  101. bool use_array_access; /* Convert ArrayAccess, Countable objects to array-like objects */
  102. // Timer thread globals
  103. std::deque<php_v8js_timer_ctx *> timer_stack;
  104. std::thread *timer_thread;
  105. std::mutex timer_mutex;
  106. bool timer_stop;
  107. bool fatal_error_abort;
  108. ZEND_END_MODULE_GLOBALS(v8js)
  109. extern zend_v8js_globals v8js_globals;
  110. ZEND_EXTERN_MODULE_GLOBALS(v8js)
  111. #ifdef ZTS
  112. # define V8JSG(v) TSRMG(v8js_globals_id, zend_v8js_globals *, v)
  113. #else
  114. # define V8JSG(v) (v8js_globals.v)
  115. #endif
  116. /* Register builtin methods into passed object */
  117. void php_v8js_register_methods(v8::Handle<v8::ObjectTemplate>, php_v8js_ctx *c);
  118. typedef struct _php_v8js_script {
  119. char *name;
  120. v8::Isolate *isolate;
  121. v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>> *script;
  122. } php_v8js_script;
  123. static void php_v8js_script_free(php_v8js_script *res, bool dispose_persistent);
  124. #endif /* PHP_V8JS_MACROS_H */
  125. /*
  126. * Local variables:
  127. * tab-width: 4
  128. * c-basic-offset: 4
  129. * End:
  130. * vim600: noet sw=4 ts=4 fdm=marker
  131. * vim<600: noet sw=4 ts=4
  132. */