2010-12-30 14:04:51 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP Version 5 |
|
|
|
|
+----------------------------------------------------------------------+
|
2013-09-28 17:17:33 +00:00
|
|
|
| Copyright (c) 1997-2013 The PHP Group |
|
2010-12-30 14:04:51 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2013-09-28 17:17:33 +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> |
|
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
|
|
|
|
|
2013-04-12 23:00:27 +00:00
|
|
|
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>
|
|
|
|
|
2013-04-12 23:00:27 +00:00
|
|
|
#include <chrono>
|
2014-12-07 14:54:37 +00:00
|
|
|
#include <deque>
|
2013-04-12 23:00:27 +00:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include <map>
|
2014-08-10 21:48:54 +00:00
|
|
|
#include <list>
|
2013-04-12 23:00:27 +00:00
|
|
|
#include <vector>
|
2013-05-15 19:21:38 +00:00
|
|
|
#include <mutex>
|
2013-04-12 23:00:27 +00:00
|
|
|
|
2014-12-12 23:43:19 +00:00
|
|
|
#include "v8js_class.h"
|
|
|
|
#include "v8js_v8.h"
|
|
|
|
#include "v8js_timer.h"
|
|
|
|
|
2014-11-12 23:36:52 +00:00
|
|
|
#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 */
|
2015-07-25 22:07:58 +00:00
|
|
|
#define PHP_V8JS_VERSION "0.2.1"
|
2010-12-30 14:04:51 +00:00
|
|
|
|
2013-10-25 18:05:51 +00:00
|
|
|
/* Hidden field name used to link JS wrappers with underlying PHP object */
|
|
|
|
#define PHPJS_OBJECT_KEY "phpjs::object"
|
|
|
|
|
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());
|
|
|
|
|
2013-10-25 21:40:20 +00:00
|
|
|
/* method signatures of zend_update_property and zend_read_property were
|
|
|
|
* declared as 'char *' instead of 'const char *' before PHP 5.4 */
|
|
|
|
#if ZEND_MODULE_API_NO >= 20100525
|
|
|
|
# define V8JS_CONST
|
|
|
|
#else
|
|
|
|
# define V8JS_CONST (char *)
|
2012-06-13 02:24:48 +00:00
|
|
|
#endif
|
|
|
|
|
2010-12-30 14:04:51 +00:00
|
|
|
/* Global flags */
|
2013-12-21 00:18:08 +00:00
|
|
|
#define V8JS_GLOBAL_SET_FLAGS(isolate,flags) V8JS_GLOBAL(isolate)->SetHiddenValue(V8JS_SYM("__php_flags__"), V8JS_INT(flags))
|
|
|
|
#define V8JS_GLOBAL_GET_FLAGS(isolate) V8JS_GLOBAL(isolate)->GetHiddenValue(V8JS_SYM("__php_flags__"))->IntegerValue();
|
2010-12-30 14:04:51 +00:00
|
|
|
|
|
|
|
/* Options */
|
|
|
|
#define V8JS_FLAG_NONE (1<<0)
|
|
|
|
#define V8JS_FLAG_FORCE_ARRAY (1<<1)
|
|
|
|
|
2013-10-12 18:44:15 +00:00
|
|
|
#define V8JS_DEBUG_AUTO_BREAK_NEVER 0
|
|
|
|
#define V8JS_DEBUG_AUTO_BREAK_ONCE 1
|
|
|
|
#define V8JS_DEBUG_AUTO_BREAK_ALWAYS 2
|
|
|
|
|
2010-12-30 14:04:51 +00:00
|
|
|
/* Convert zval into V8 value */
|
2015-08-25 21:38:09 +00:00
|
|
|
v8::Handle<v8::Value> zval_to_v8js(zval *, v8::Isolate * TSRMLS_DC);
|
2010-12-30 14:04:51 +00:00
|
|
|
|
|
|
|
/* Convert V8 value into zval */
|
2013-04-13 23:36:05 +00:00
|
|
|
int v8js_to_zval(v8::Handle<v8::Value>, zval *, int, v8::Isolate * TSRMLS_DC);
|
2010-12-30 14:04:51 +00:00
|
|
|
|
2014-12-13 00:15:29 +00:00
|
|
|
struct v8js_accessor_ctx
|
2013-10-27 06:34:06 +00:00
|
|
|
{
|
2015-08-29 15:48:26 +00:00
|
|
|
zend_string *variable_name;
|
2013-10-27 06:34:06 +00:00
|
|
|
v8::Isolate *isolate;
|
|
|
|
};
|
|
|
|
|
2014-12-13 00:15:29 +00:00
|
|
|
void v8js_accessor_ctx_dtor(v8js_accessor_ctx * TSRMLS_DC);
|
2013-10-27 06:34:06 +00:00
|
|
|
|
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);
|
2013-10-27 06:34:06 +00:00
|
|
|
|
2014-09-16 14:09:58 +00:00
|
|
|
/* Resource declaration */
|
2013-10-02 22:34:50 +00:00
|
|
|
|
2013-04-12 23:00:27 +00:00
|
|
|
/* Module globals */
|
|
|
|
ZEND_BEGIN_MODULE_GLOBALS(v8js)
|
|
|
|
int v8_initialized;
|
2015-08-02 17:42:03 +00:00
|
|
|
#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
|
|
|
|
v8::Platform *v8_platform;
|
|
|
|
#endif
|
2013-04-12 23:00:27 +00:00
|
|
|
HashTable *extensions;
|
|
|
|
|
|
|
|
/* Ini globals */
|
|
|
|
char *v8_flags; /* V8 command line flags */
|
2014-03-20 14:06:18 +00:00
|
|
|
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 */
|
2013-04-12 23:00:27 +00:00
|
|
|
|
|
|
|
// Timer thread globals
|
2014-12-13 00:15:29 +00:00
|
|
|
std::deque<v8js_timer_ctx *> timer_stack;
|
2013-04-12 23:00:27 +00:00
|
|
|
std::thread *timer_thread;
|
|
|
|
std::mutex timer_mutex;
|
|
|
|
bool timer_stop;
|
|
|
|
|
2014-04-12 07:22:58 +00:00
|
|
|
bool fatal_error_abort;
|
2013-04-12 23:00:27 +00:00
|
|
|
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)
|
2013-04-12 23:00:27 +00:00
|
|
|
|
2013-03-24 16:27:13 +00:00
|
|
|
/* 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);
|
2014-09-16 14:09:58 +00:00
|
|
|
|
2010-12-30 14:04:51 +00:00
|
|
|
#endif /* PHP_V8JS_MACROS_H */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|