php_v8js_macros.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2010 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | [email protected] so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Jani Taskinen <[email protected]> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id: php_v8js_macros.h 306926 2010-12-31 14:15:54Z felipe $ */
  19. #ifndef PHP_V8JS_MACROS_H
  20. #define PHP_V8JS_MACROS_H
  21. #include <v8.h>
  22. /* V8Js Version */
  23. #define V8JS_VERSION "0.1.1"
  24. /* Helper macros */
  25. #define V8JS_SYM(v) v8::String::NewSymbol(v, sizeof(v) - 1)
  26. #define V8JS_SYML(v, l) v8::String::NewSymbol(v, l)
  27. #define V8JS_STR(v) v8::String::New(v)
  28. #define V8JS_STRL(v, l) v8::String::New(v, l)
  29. #define V8JS_INT(v) v8::Integer::New(v)
  30. #define V8JS_FLOAT(v) v8::Number::New(v)
  31. #define V8JS_BOOL(v) v8::Boolean::New(v)
  32. #define V8JS_NULL v8::Null()
  33. #define V8JS_MN(name) v8js_method_##name
  34. #define V8JS_METHOD(name) v8::Handle<v8::Value> V8JS_MN(name)(const v8::Arguments& args)
  35. #define V8JS_THROW(type, message, message_len) v8::ThrowException(v8::Exception::type(V8JS_STRL(message, message_len)))
  36. #define V8JS_GLOBAL v8::Context::GetCurrent()->Global()
  37. /* Helper macros */
  38. #if PHP_V8_API_VERSION < 2005009
  39. # define V8JS_GET_CLASS_NAME(var, obj) \
  40. /* Hack to prevent calling possibly set user-defined __toString() messing class name */ \
  41. v8::Local<v8::Function> constructor = v8::Local<v8::Function>::Cast(obj->Get(V8JS_SYM("constructor"))); \
  42. v8::String::Utf8Value var(constructor->GetName());
  43. #else
  44. # define V8JS_GET_CLASS_NAME(var, obj) \
  45. v8::String::Utf8Value var(obj->GetConstructorName());
  46. #endif
  47. /* Global flags */
  48. #define V8JS_GLOBAL_SET_FLAGS(flags) V8JS_GLOBAL->SetHiddenValue(V8JS_SYM("__php_flags__"), V8JS_INT(flags))
  49. #define V8JS_GLOBAL_GET_FLAGS() V8JS_GLOBAL->GetHiddenValue(V8JS_SYM("__php_flags__"))->IntegerValue();
  50. /* Options */
  51. #define V8JS_FLAG_NONE (1<<0)
  52. #define V8JS_FLAG_FORCE_ARRAY (1<<1)
  53. /* Extracts a C string from a V8 Utf8Value. */
  54. static const char * ToCString(const v8::String::Utf8Value &value) /* {{{ */
  55. {
  56. return *value ? *value : "<string conversion failed>";
  57. }
  58. /* }}} */
  59. /* Extern Class entries */
  60. extern zend_class_entry *php_ce_v8_object;
  61. extern zend_class_entry *php_ce_v8_function;
  62. /* Create PHP V8 object */
  63. void php_v8js_create_v8(zval *, v8::Handle<v8::Value>, int TSRMLS_DC);
  64. /* Fetch V8 object properties */
  65. int php_v8js_v8_get_properties_hash(v8::Handle<v8::Value>, HashTable *, int TSRMLS_DC);
  66. /* Convert zval into V8 value */
  67. v8::Handle<v8::Value> zval_to_v8js(zval * TSRMLS_DC);
  68. /* Convert V8 value into zval */
  69. int v8js_to_zval(v8::Handle<v8::Value>, zval *, int TSRMLS_DC);
  70. /* Register builtin methods into passed object */
  71. void php_v8js_register_methods(v8::Handle<v8::ObjectTemplate>);
  72. /* Register accessors into passed object */
  73. void php_v8js_register_accessors(v8::Local<v8::ObjectTemplate>, zval * TSRMLS_DC);
  74. #endif /* PHP_V8JS_MACROS_H */
  75. /*
  76. * Local variables:
  77. * tab-width: 4
  78. * c-basic-offset: 4
  79. * End:
  80. * vim600: noet sw=4 ts=4 fdm=marker
  81. * vim<600: noet sw=4 ts=4
  82. */