v8js_class.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 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 V8JS_CLASS_H
  15. #define V8JS_CLASS_H
  16. /* Abbreviate long type names */
  17. typedef v8::Persistent<v8::FunctionTemplate, v8::CopyablePersistentTraits<v8::FunctionTemplate> > v8js_tmpl_t;
  18. typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > v8js_persistent_obj_t;
  19. /* Forward declarations */
  20. struct v8js_v8object;
  21. struct v8js_accessor_ctx;
  22. struct _v8js_script;
  23. struct cmp_str {
  24. bool operator()(char const *a, char const *b) const {
  25. return strcmp(a, b) < 0;
  26. }
  27. };
  28. /* {{{ Context container */
  29. struct v8js_ctx {
  30. v8::Persistent<v8::String> object_name;
  31. v8::Persistent<v8::Context> context;
  32. zend_bool report_uncaught;
  33. zval pending_exception;
  34. int in_execution;
  35. v8::Isolate *isolate;
  36. long flags;
  37. long time_limit;
  38. bool time_limit_hit;
  39. long memory_limit;
  40. bool memory_limit_hit;
  41. v8js_tmpl_t global_template;
  42. v8js_tmpl_t array_tmpl;
  43. zval module_normaliser;
  44. zval module_loader;
  45. std::vector<char *> modules_stack;
  46. std::vector<char *> modules_base;
  47. std::map<char *, v8js_persistent_obj_t, cmp_str> modules_loaded;
  48. std::map<const zend_string *,v8js_tmpl_t> template_cache;
  49. std::map<zend_object *, v8js_persistent_obj_t> weak_objects;
  50. std::map<v8js_tmpl_t *, v8js_persistent_obj_t> weak_closures;
  51. std::map<v8js_tmpl_t *, v8js_tmpl_t> call_impls;
  52. std::map<zend_function *, v8js_tmpl_t> method_tmpls;
  53. std::list<v8js_v8object *> v8js_v8objects;
  54. std::vector<v8js_accessor_ctx *> accessor_list;
  55. std::vector<struct _v8js_script *> script_objects;
  56. char *tz;
  57. #if PHP_V8_API_VERSION >= 4003007
  58. v8::Isolate::CreateParams create_params;
  59. zval zval_snapshot_blob;
  60. v8::StartupData snapshot_blob;
  61. #endif
  62. #ifdef ZTS
  63. void ***zts_ctx;
  64. #endif
  65. zend_object std;
  66. };
  67. /* }}} */
  68. #ifdef ZTS
  69. # define V8JS_TSRMLS_FETCH() TSRMLS_FETCH_FROM_CTX(((v8js_ctx *) isolate->GetData(0))->zts_ctx);
  70. #else
  71. # define V8JS_TSRMLS_FETCH()
  72. #endif
  73. static inline struct v8js_ctx *v8js_ctx_fetch_object(zend_object *obj) {
  74. return (struct v8js_ctx *)((char *)obj - XtOffsetOf(struct v8js_ctx, std));
  75. }
  76. #define Z_V8JS_CTX_OBJ_P(zv) v8js_ctx_fetch_object(Z_OBJ_P(zv));
  77. PHP_MINIT_FUNCTION(v8js_class);
  78. #endif /* V8JS_CLASS_H */
  79. /*
  80. * Local variables:
  81. * tab-width: 4
  82. * c-basic-offset: 4
  83. * End:
  84. * vim600: noet sw=4 ts=4 fdm=marker
  85. * vim<600: noet sw=4 ts=4
  86. */