2012-04-27 16:26:15 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2017-03-11 11:33:49 +00:00
|
|
|
| PHP Version 7 |
|
2012-04-27 16:26:15 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2017-03-11 09:17:10 +00:00
|
|
|
| Copyright (c) 1997-2017 The PHP Group |
|
2012-04-27 16:26:15 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2013-09-28 17:17:33 +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> |
|
2017-03-11 09:17:10 +00:00
|
|
|
| Author: Stefan Siegl <stesie@php.net> |
|
2012-04-27 16:26:15 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-04-12 23:00:27 +00:00
|
|
|
#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"
|
|
|
|
}
|
|
|
|
|
2014-12-12 22:59:28 +00:00
|
|
|
#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)
|
2015-09-26 16:58:12 +00:00
|
|
|
struct _v8js_process_globals v8js_process_globals;
|
2012-04-27 16:26:15 +00:00
|
|
|
|
|
|
|
/* {{{ INI Settings */
|
|
|
|
|
2017-04-21 16:20:12 +00:00
|
|
|
static bool v8js_ini_string(char **field, const zend_string *new_value)/* {{{ */
|
2012-04-27 16:26:15 +00:00
|
|
|
{
|
2015-09-26 19:39:26 +00:00
|
|
|
bool immutable = false;
|
|
|
|
|
|
|
|
#ifdef ZTS
|
|
|
|
v8js_process_globals.lock.lock();
|
|
|
|
|
|
|
|
if(v8js_process_globals.v8_initialized) {
|
|
|
|
v8js_process_globals.lock.unlock();
|
|
|
|
immutable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8js_process_globals.lock.unlock();
|
|
|
|
#else
|
|
|
|
immutable = V8JSG(v8_initialized);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(immutable) {
|
|
|
|
/* V8 already has been initialized -> cannot be changed anymore */
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-04-27 16:26:15 +00:00
|
|
|
if (new_value) {
|
2017-04-21 16:20:12 +00:00
|
|
|
if (*field) {
|
|
|
|
free(*field);
|
|
|
|
*field = NULL;
|
2012-04-27 16:26:15 +00:00
|
|
|
}
|
2017-04-21 16:20:12 +00:00
|
|
|
|
2015-12-04 18:55:20 +00:00
|
|
|
if (!ZSTR_VAL(new_value)[0]) {
|
2017-04-21 16:20:12 +00:00
|
|
|
return SUCCESS;
|
2012-04-27 16:26:15 +00:00
|
|
|
}
|
2017-04-21 16:20:12 +00:00
|
|
|
|
|
|
|
*field = zend_strndup(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
|
2012-04-27 16:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2017-04-21 16:20:12 +00:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */
|
|
|
|
{
|
|
|
|
return v8js_ini_string(&v8js_process_globals.v8_flags, new_value);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static ZEND_INI_MH(v8js_OnUpdateIcudatPath) /* {{{ */
|
|
|
|
{
|
|
|
|
return v8js_ini_string(&v8js_process_globals.icudtl_dat_path, new_value);
|
|
|
|
}
|
|
|
|
/* }}} */
|
2014-03-20 14:06:18 +00:00
|
|
|
|
2015-10-11 00:09:59 +00:00
|
|
|
static bool v8js_ini_to_bool(const zend_string *new_value) /* {{{ */
|
2014-03-20 14:06:18 +00:00
|
|
|
{
|
2015-12-04 18:55:20 +00:00
|
|
|
if (ZSTR_LEN(new_value) == 2 && strcasecmp("on", ZSTR_VAL(new_value)) == 0) {
|
2015-09-23 18:01:43 +00:00
|
|
|
return true;
|
2015-12-04 18:55:20 +00:00
|
|
|
} else if (ZSTR_LEN(new_value) == 3 && strcasecmp("yes", ZSTR_VAL(new_value)) == 0) {
|
2015-09-23 18:01:43 +00:00
|
|
|
return true;
|
2015-12-04 18:55:20 +00:00
|
|
|
} else if (ZSTR_LEN(new_value) == 4 && strcasecmp("true", ZSTR_VAL(new_value)) == 0) {
|
2015-09-23 18:01:43 +00:00
|
|
|
return true;
|
2014-03-20 14:06:18 +00:00
|
|
|
} else {
|
2017-03-10 21:49:23 +00:00
|
|
|
return 0 != atoi(ZSTR_VAL(new_value));
|
2014-03-20 14:06:18 +00:00
|
|
|
}
|
2015-09-23 18:01:43 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static ZEND_INI_MH(v8js_OnUpdateUseDate) /* {{{ */
|
|
|
|
{
|
2015-10-11 00:09:59 +00:00
|
|
|
V8JSG(use_date) = v8js_ini_to_bool(new_value);
|
2014-03-20 14:06:18 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2012-04-27 16:26:15 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2014-11-23 22:39:15 +00:00
|
|
|
static ZEND_INI_MH(v8js_OnUpdateUseArrayAccess) /* {{{ */
|
|
|
|
{
|
2015-10-11 00:09:59 +00:00
|
|
|
V8JSG(use_array_access) = v8js_ini_to_bool(new_value);
|
2014-11-23 22:39:15 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-09-16 14:09:58 +00:00
|
|
|
ZEND_INI_BEGIN() /* {{{ */
|
2012-04-27 16:26:15 +00:00
|
|
|
ZEND_INI_ENTRY("v8js.flags", NULL, ZEND_INI_ALL, v8js_OnUpdateV8Flags)
|
2017-04-21 16:20:12 +00:00
|
|
|
ZEND_INI_ENTRY("v8js.icudtl_dat_path", NULL, ZEND_INI_ALL, v8js_OnUpdateIcudatPath)
|
2014-03-20 14:06:18 +00:00
|
|
|
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
|
2015-08-29 15:48:26 +00:00
|
|
|
#ifdef ZTS
|
|
|
|
ZEND_TSRMLS_CACHE_DEFINE();
|
|
|
|
#endif
|
|
|
|
|
2012-04-27 16:26:15 +00:00
|
|
|
ZEND_GET_MODULE(v8js)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-12-12 22:59:28 +00:00
|
|
|
/* {{{ PHP_MINIT_FUNCTION
|
2014-12-11 21:28:01 +00:00
|
|
|
*/
|
2014-12-12 22:59:28 +00:00
|
|
|
PHP_MINIT_FUNCTION(v8js)
|
2014-12-11 21:28:01 +00:00
|
|
|
{
|
2014-12-12 22:59:28 +00:00
|
|
|
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);
|
2014-09-16 14:09:58 +00:00
|
|
|
|
2012-04-27 16:26:15 +00:00
|
|
|
REGISTER_INI_ENTRIES();
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MSHUTDOWN_FUNCTION
|
|
|
|
*/
|
|
|
|
static PHP_MSHUTDOWN_FUNCTION(v8js)
|
|
|
|
{
|
|
|
|
UNREGISTER_INI_ENTRIES();
|
2015-09-26 16:58:12 +00:00
|
|
|
|
2015-09-27 07:25:58 +00:00
|
|
|
bool v8_initialized;
|
|
|
|
|
|
|
|
#ifdef ZTS
|
|
|
|
v8_initialized = v8js_process_globals.v8_initialized;
|
|
|
|
#else
|
|
|
|
v8_initialized = V8JSG(v8_initialized);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(v8_initialized) {
|
2015-09-26 16:58:12 +00:00
|
|
|
v8::V8::Dispose();
|
2022-06-24 20:24:52 +00:00
|
|
|
#if PHP_V8_API_VERSION >= 10000000
|
2022-06-24 19:35:58 +00:00
|
|
|
v8::V8::DisposePlatform();
|
2022-06-24 20:24:52 +00:00
|
|
|
#else
|
|
|
|
v8::V8::ShutdownPlatform();
|
|
|
|
#endif
|
2015-09-26 16:58:12 +00:00
|
|
|
// @fixme call virtual destructor somehow
|
|
|
|
//delete v8js_process_globals.v8_platform;
|
|
|
|
}
|
|
|
|
|
2015-09-26 19:39:26 +00:00
|
|
|
if (v8js_process_globals.v8_flags) {
|
|
|
|
free(v8js_process_globals.v8_flags);
|
|
|
|
v8js_process_globals.v8_flags = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v8js_process_globals.extensions) {
|
|
|
|
zend_hash_destroy(v8js_process_globals.extensions);
|
|
|
|
free(v8js_process_globals.extensions);
|
|
|
|
v8js_process_globals.extensions = NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-27 16:26:15 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_RSHUTDOWN_FUNCTION
|
|
|
|
*/
|
|
|
|
static PHP_RSHUTDOWN_FUNCTION(v8js)
|
|
|
|
{
|
2013-04-09 21:52:42 +00:00
|
|
|
// If the timer thread is running then stop it
|
|
|
|
if (V8JSG(timer_thread)) {
|
|
|
|
V8JSG(timer_stop) = true;
|
|
|
|
V8JSG(timer_thread)->join();
|
2015-04-27 22:21:00 +00:00
|
|
|
V8JSG(timer_stop) = false;
|
2015-04-27 22:31:33 +00:00
|
|
|
delete V8JSG(timer_thread);
|
2015-04-27 22:21:00 +00:00
|
|
|
V8JSG(timer_thread) = NULL;
|
2013-04-09 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 08:14:23 +00:00
|
|
|
V8JSG(fatal_error_abort) = 0;
|
|
|
|
|
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)
|
|
|
|
{
|
2015-08-29 15:48:26 +00:00
|
|
|
#if defined(COMPILE_DL_MYSQLI) && defined(ZTS)
|
|
|
|
ZEND_TSRMLS_CACHE_UPDATE();
|
|
|
|
#endif
|
|
|
|
|
2013-10-27 02:38:44 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2013-10-26 22:29:50 +00:00
|
|
|
#ifdef ZTS
|
2012-04-27 16:26:15 +00:00
|
|
|
v8js_globals->v8_initialized = 0;
|
2014-09-19 22:36:22 +00:00
|
|
|
|
2013-04-09 21:52:42 +00:00
|
|
|
v8js_globals->timer_thread = NULL;
|
|
|
|
v8js_globals->timer_stop = false;
|
2013-10-26 05:19:34 +00:00
|
|
|
new(&v8js_globals->timer_mutex) std::mutex;
|
2014-12-13 00:15:29 +00:00
|
|
|
new(&v8js_globals->timer_stack) std::deque<v8js_timer_ctx *>;
|
2014-04-12 07:22:58 +00:00
|
|
|
|
|
|
|
v8js_globals->fatal_error_abort = 0;
|
2013-10-26 22:29:50 +00:00
|
|
|
#endif
|
2013-10-26 05:19:34 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_GSHUTDOWN_FUNCTION
|
|
|
|
*/
|
|
|
|
static PHP_GSHUTDOWN_FUNCTION(v8js)
|
|
|
|
{
|
2013-10-26 22:29:50 +00:00
|
|
|
#ifdef ZTS
|
2014-12-07 14:54:37 +00:00
|
|
|
v8js_globals->timer_stack.~deque();
|
2013-10-26 05:19:34 +00:00
|
|
|
v8js_globals->timer_mutex.~mutex();
|
2013-10-26 21:46:03 +00:00
|
|
|
#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),
|
2014-08-11 01:11:02 +00:00
|
|
|
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),
|
2013-10-26 05:19:34 +00:00
|
|
|
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
|
2016-07-02 20:41:01 +00:00
|
|
|
* indent-tabs-mode: t
|
2012-04-27 16:26:15 +00:00
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|