0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 16:35:19 +00:00
phpv8/php_v8js_macros.h

175 lines
4.7 KiB
C
Raw Normal View History

2010-12-30 14:04:51 +00:00
/*
+----------------------------------------------------------------------+
2017-03-11 11:33:49 +00:00
| PHP Version 7 |
2010-12-30 14:04:51 +00:00
+----------------------------------------------------------------------+
2017-03-10 21:58:53 +00:00
| Copyright (c) 1997-2017 The PHP Group |
2010-12-30 14:04:51 +00:00
+----------------------------------------------------------------------+
| http://www.opensource.org/licenses/mit-license.php MIT License |
2010-12-30 14:04:51 +00:00
+----------------------------------------------------------------------+
| Author: Jani Taskinen <jani.taskinen@iki.fi> |
2012-04-27 16:41:32 +00:00
| Author: Patrick Reilly <preilly@php.net> |
| Author: Stefan Siegl <stesie@php.net> |
2010-12-30 14:04:51 +00:00
+----------------------------------------------------------------------+
*/
#ifndef PHP_V8JS_MACROS_H
#define PHP_V8JS_MACROS_H
2014-03-19 14:24:24 +00:00
#if __GNUC__ == 4 && __GNUC_MINOR__ == 4
#define _GLIBCXX_USE_NANOSLEEP 1
#endif
#include <chrono>
#include <deque>
#include <thread>
#include <map>
#include <list>
#include <vector>
#include <mutex>
#include <cmath>
#ifndef isnan
/* php.h requires the isnan() macro, which is removed by c++ <cmath> header,
* work around: re-define the macro to std::isnan function */
#define isnan(a) std::isnan(a)
#endif
extern "C" {
#include "php.h"
#include "php_v8js.h"
}
2014-11-12 23:15:00 +00:00
#ifdef _WIN32
/* On Windows a symbol COMPILER is defined. However v8.h has an enum with that
* name which hence would be broken unless undefined here. */
#undef COMPILER
#endif
2010-12-30 14:04:51 +00:00
#include <v8.h>
#include "v8js_class.h"
#include "v8js_v8.h"
#ifndef PATH_MAX
/* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
* just assume an arbitrary upper bound of 4096 chars.
* Anyways we should fix (get rid of) the code that uses PATH_MAX as it doesn't
* even check for buffer overflows. FIXME */
#define PATH_MAX 4096
#endif
2010-12-30 14:04:51 +00:00
/* V8Js Version */
2017-03-05 19:21:04 +00:00
#define PHP_V8JS_VERSION "1.3.4"
2010-12-30 14:04:51 +00:00
/* Helper macros */
2014-10-19 12:09:53 +00:00
#define V8JS_GET_CLASS_NAME(var, obj) \
2010-12-30 14:04:51 +00:00
v8::String::Utf8Value var(obj->GetConstructorName());
/* Options */
#define V8JS_FLAG_NONE (1<<0)
#define V8JS_FLAG_FORCE_ARRAY (1<<1)
2015-08-22 13:16:02 +00:00
#define V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS (1<<2)
2010-12-30 14:04:51 +00:00
/* These are not defined by Zend */
#define ZEND_WAKEUP_FUNC_NAME "__wakeup"
#define ZEND_SLEEP_FUNC_NAME "__sleep"
#define ZEND_SET_STATE_FUNC_NAME "__set_state"
2010-12-30 14:04:51 +00:00
/* Convert zval into V8 value */
2017-03-10 21:58:53 +00:00
v8::Handle<v8::Value> zval_to_v8js(zval *, v8::Isolate *);
/* Convert zend_long into V8 value */
v8::Handle<v8::Value> zend_long_to_v8js(zend_long, v8::Isolate *);
2010-12-30 14:04:51 +00:00
/* Convert V8 value into zval */
int v8js_to_zval(v8::Handle<v8::Value>, zval *, int, v8::Isolate * TSRMLS_DC);
2010-12-30 14:04:51 +00:00
struct v8js_accessor_ctx
{
2015-08-29 15:48:26 +00:00
zend_string *variable_name;
v8::Isolate *isolate;
};
void v8js_accessor_ctx_dtor(v8js_accessor_ctx * TSRMLS_DC);
2010-12-30 14:04:51 +00:00
/* Register accessors into passed object */
2014-12-13 00:30:23 +00:00
void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC);
/* Forward declarations */
struct v8js_timer_ctx;
2013-10-02 22:34:50 +00:00
/* Module globals */
ZEND_BEGIN_MODULE_GLOBALS(v8js)
// Thread-local cache whether V8 has been initialized so far
2017-03-10 21:47:24 +00:00
bool v8_initialized;
/* Ini globals */
bool use_date; /* Generate JS Date objects instead of PHP DateTime */
2014-11-23 22:39:15 +00:00
bool use_array_access; /* Convert ArrayAccess, Countable objects to array-like objects */
bool compat_php_exceptions; /* Don't stop JS execution on PHP exception */
// Timer thread globals
std::deque<v8js_timer_ctx *> timer_stack;
std::thread *timer_thread;
std::mutex timer_mutex;
bool timer_stop;
2014-04-12 07:22:58 +00:00
bool fatal_error_abort;
ZEND_END_MODULE_GLOBALS(v8js)
extern zend_v8js_globals v8js_globals;
2013-10-19 20:11:17 +00:00
ZEND_EXTERN_MODULE_GLOBALS(v8js)
2015-08-29 15:48:26 +00:00
#define V8JSG(v) ZEND_MODULE_GLOBALS_ACCESSOR(v8js, v)
/*
* Process-wide globals
*
* The zend_v8js_globals structure declared above is created once per thread
* (in a ZTS environment). If a multi-threaded PHP process uses V8 there is
* some stuff shared among all of these threads
*
* - whether V8 has been initialized at all
* - the V8 backend platform
* - loaded extensions
* - V8 "command line" flags
*
* In a ZTS-enabled environment access to all of these variables must happen
* while holding a mutex lock.
*/
struct _v8js_process_globals {
#ifdef ZTS
2017-03-10 21:47:24 +00:00
bool v8_initialized;
std::mutex lock;
#endif
HashTable *extensions;
/* V8 command line flags */
char *v8_flags;
v8::Platform *v8_platform;
};
extern struct _v8js_process_globals v8js_process_globals;
/* Register builtin methods into passed object */
2014-12-13 00:30:23 +00:00
void v8js_register_methods(v8::Handle<v8::ObjectTemplate>, v8js_ctx *c);
2010-12-30 14:04:51 +00:00
#endif /* PHP_V8JS_MACROS_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
2010-12-30 14:04:51 +00:00
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/