0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 14:48:40 +00:00
phpv8/v8js.cc

249 lines
5.8 KiB
C++
Raw Normal View History

2012-04-27 16:26:15 +00:00
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
2012-04-27 16:26:15 +00:00
+----------------------------------------------------------------------+
| http://www.opensource.org/licenses/mit-license.php MIT License |
2012-04-27 16:26:15 +00:00
+----------------------------------------------------------------------+
| Author: Jani Taskinen <jani.taskinen@iki.fi> |
2012-04-27 16:41:32 +00:00
| Author: Patrick Reilly <preilly@php.net> |
2012-04-27 16:26:15 +00:00
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php_v8js_macros.h"
2012-04-27 16:26:15 +00:00
extern "C" {
#include "php_ini.h"
#include "ext/standard/info.h"
#include "ext/standard/php_string.h"
}
#include "v8js_class.h"
#include "v8js_exceptions.h"
#include "v8js_v8object_class.h"
2012-04-27 16:26:15 +00:00
ZEND_DECLARE_MODULE_GLOBALS(v8js)
/* {{{ INI Settings */
static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */
{
if (new_value) {
if (V8JSG(v8_flags)) {
free(V8JSG(v8_flags));
V8JSG(v8_flags) = NULL;
}
2015-08-24 19:35:29 +00:00
if (!new_value->val[0]) {
2012-04-27 16:26:15 +00:00
return FAILURE;
}
2015-08-24 19:35:29 +00:00
V8JSG(v8_flags) = zend_strndup(new_value->val, new_value->len);
2012-04-27 16:26:15 +00:00
}
return SUCCESS;
}
static ZEND_INI_MH(v8js_OnUpdateUseDate) /* {{{ */
{
bool value;
2015-08-24 19:35:29 +00:00
if (new_value->len == 2 && strcasecmp("on", new_value->val) == 0) {
value = (bool) 1;
2015-08-24 19:35:29 +00:00
} else if (new_value->len == 3 && strcasecmp("yes", new_value->val) == 0) {
value = (bool) 1;
2015-08-24 19:35:29 +00:00
} else if (new_value->len == 4 && strcasecmp("true", new_value->val) == 0) {
value = (bool) 1;
} else {
2015-08-24 19:35:29 +00:00
value = (bool) atoi(new_value->val);
}
V8JSG(use_date) = value;
return SUCCESS;
}
2012-04-27 16:26:15 +00:00
/* }}} */
2014-11-23 22:39:15 +00:00
static ZEND_INI_MH(v8js_OnUpdateUseArrayAccess) /* {{{ */
{
bool value;
2015-08-24 19:35:29 +00:00
if (new_value->len == 2 && strcasecmp("on", new_value->val) == 0) {
2014-11-23 22:39:15 +00:00
value = (bool) 1;
2015-08-24 19:35:29 +00:00
} else if (new_value->len == 3 && strcasecmp("yes", new_value->val) == 0) {
2014-11-23 22:39:15 +00:00
value = (bool) 1;
2015-08-24 19:35:29 +00:00
} else if (new_value->len == 4 && strcasecmp("true", new_value->val) == 0) {
2014-11-23 22:39:15 +00:00
value = (bool) 1;
} else {
2015-08-24 19:35:29 +00:00
value = (bool) atoi(new_value->val);
2014-11-23 22:39:15 +00:00
}
V8JSG(use_array_access) = value;
return SUCCESS;
}
/* }}} */
ZEND_INI_BEGIN() /* {{{ */
2012-04-27 16:26:15 +00:00
ZEND_INI_ENTRY("v8js.flags", NULL, ZEND_INI_ALL, v8js_OnUpdateV8Flags)
ZEND_INI_ENTRY("v8js.use_date", "0", ZEND_INI_ALL, v8js_OnUpdateUseDate)
2014-11-23 22:39:15 +00:00
ZEND_INI_ENTRY("v8js.use_array_access", "0", ZEND_INI_ALL, v8js_OnUpdateUseArrayAccess)
2012-04-27 16:26:15 +00:00
ZEND_INI_END()
/* }}} */
/* }}} INI */
2013-10-12 18:44:15 +00:00
2012-04-27 16:26:15 +00:00
#ifdef COMPILE_DL_V8JS
ZEND_GET_MODULE(v8js)
#endif
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(v8js)
{
PHP_MINIT(v8js_class)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(v8js_exceptions)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(v8js_v8object_class)(INIT_FUNC_ARGS_PASSTHRU);
2012-04-27 16:26:15 +00:00
REGISTER_INI_ENTRIES();
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
static PHP_MSHUTDOWN_FUNCTION(v8js)
{
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
static PHP_RSHUTDOWN_FUNCTION(v8js)
{
// If the timer thread is running then stop it
if (V8JSG(timer_thread)) {
V8JSG(timer_stop) = true;
V8JSG(timer_thread)->join();
V8JSG(timer_stop) = false;
delete V8JSG(timer_thread);
V8JSG(timer_thread) = NULL;
}
2012-04-27 16:26:15 +00:00
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
static PHP_MINFO_FUNCTION(v8js)
{
php_info_print_table_start();
php_info_print_table_header(2, "V8 Javascript Engine", "enabled");
php_info_print_table_header(2, "V8 Engine Compiled Version", PHP_V8_VERSION);
php_info_print_table_header(2, "V8 Engine Linked Version", v8::V8::GetVersion());
2013-10-15 15:42:02 +00:00
php_info_print_table_header(2, "Version", PHP_V8JS_VERSION);
2012-04-27 16:26:15 +00:00
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
/* {{{ PHP_GINIT_FUNCTION
*/
static PHP_GINIT_FUNCTION(v8js)
{
/*
If ZTS is disabled, the v8js_globals instance is declared right
in the BSS and hence automatically initialized by C++ compiler.
Most of the variables are just zeroed.
If ZTS is enabled however, v8js_globals just points to a freshly
allocated, uninitialized piece of memory, hence we need to
initialize all fields on our own. Likewise on shutdown we have to
run the destructors manually.
*/
#ifdef ZTS
2012-04-27 16:26:15 +00:00
v8js_globals->extensions = NULL;
v8js_globals->v8_initialized = 0;
v8js_globals->v8_flags = NULL;
v8js_globals->timer_thread = NULL;
v8js_globals->timer_stop = false;
new(&v8js_globals->timer_mutex) std::mutex;
new(&v8js_globals->timer_stack) std::deque<v8js_timer_ctx *>;
2014-04-12 07:22:58 +00:00
v8js_globals->fatal_error_abort = 0;
#endif
}
/* }}} */
/* {{{ PHP_GSHUTDOWN_FUNCTION
*/
static PHP_GSHUTDOWN_FUNCTION(v8js)
{
if (v8js_globals->extensions) {
zend_hash_destroy(v8js_globals->extensions);
free(v8js_globals->extensions);
v8js_globals->extensions = NULL;
}
if (v8js_globals->v8_flags) {
free(v8js_globals->v8_flags);
v8js_globals->v8_flags = NULL;
}
#ifdef ZTS
v8js_globals->timer_stack.~deque();
v8js_globals->timer_mutex.~mutex();
#endif
2015-08-02 17:42:03 +00:00
if (v8js_globals->v8_initialized) {
v8::V8::Dispose();
#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
v8::V8::ShutdownPlatform();
2015-08-02 17:42:03 +00:00
delete v8js_globals->v8_platform;
#endif
}
2012-04-27 16:26:15 +00:00
}
/* }}} */
/* {{{ v8js_functions[] */
static const zend_function_entry v8js_functions[] = {
{NULL, NULL, NULL}
};
/* }}} */
/* {{{ v8js_module_entry
*/
zend_module_entry v8js_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
NULL,
"v8js",
v8js_functions,
PHP_MINIT(v8js),
PHP_MSHUTDOWN(v8js),
NULL,
2012-04-27 16:26:15 +00:00
PHP_RSHUTDOWN(v8js),
PHP_MINFO(v8js),
2013-10-15 15:42:02 +00:00
PHP_V8JS_VERSION,
2012-04-27 16:26:15 +00:00
PHP_MODULE_GLOBALS(v8js),
PHP_GINIT(v8js),
PHP_GSHUTDOWN(v8js),
2012-04-27 16:26:15 +00:00
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
/*
* 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
*/