mirror of
https://github.com/phpv8/v8js.git
synced 2025-03-22 04:37:01 +00:00
V8 needs to be notified when timezone changes. Keep track of timezone changes and notify it.
Also added a test.
This commit is contained in:
parent
dd20670546
commit
0a85d27ee7
@ -88,6 +88,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
|||||||
<file name="time_limit.phpt" role="test" />
|
<file name="time_limit.phpt" role="test" />
|
||||||
<file name="variable_passing.phpt" role="test" />
|
<file name="variable_passing.phpt" role="test" />
|
||||||
<file name="checkstring.phpt" role="test" />
|
<file name="checkstring.phpt" role="test" />
|
||||||
|
<file name="array_pass.phpt" role="test" />
|
||||||
|
<file name="array_pass_flags.phpt" role="test" />
|
||||||
|
<file name="timezones.phpt" role="test" />
|
||||||
</dir>
|
</dir>
|
||||||
</dir>
|
</dir>
|
||||||
</contents>
|
</contents>
|
||||||
|
@ -184,6 +184,7 @@ struct php_v8js_ctx {
|
|||||||
std::vector<char *> modules_base;
|
std::vector<char *> modules_base;
|
||||||
std::map<const char *,v8js_tmpl_t> template_cache;
|
std::map<const char *,v8js_tmpl_t> template_cache;
|
||||||
std::vector<php_v8js_accessor_ctx *> accessor_list;
|
std::vector<php_v8js_accessor_ctx *> accessor_list;
|
||||||
|
char *tz;
|
||||||
#ifdef ZTS
|
#ifdef ZTS
|
||||||
void ***zts_ctx;
|
void ***zts_ctx;
|
||||||
#endif
|
#endif
|
||||||
|
38
tests/timezones.phpt
Normal file
38
tests/timezones.phpt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::executeString() : Check timezone handling
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$v8 = new V8Js();
|
||||||
|
try {
|
||||||
|
putenv('TZ=Europe/Helsinki');
|
||||||
|
$v8->executeString('print (new Date("Thu, 20 Mar 2014 09:03:24 +0000")).toString();');
|
||||||
|
echo "\n";
|
||||||
|
} catch (V8JsScriptException $e) {
|
||||||
|
var_dump($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
putenv('TZ=America/New_York');
|
||||||
|
$v8->executeString('print (new Date("Thu, 20 Mar 2014 09:03:24 +0000")).toString();');
|
||||||
|
echo "\n";
|
||||||
|
} catch (V8JsScriptException $e) {
|
||||||
|
var_dump($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
putenv('TZ=Europe/Helsinki');
|
||||||
|
$v8->executeString('print (new Date("Thu, 20 Mar 2014 09:03:24 +0000")).toString();');
|
||||||
|
echo "\n";
|
||||||
|
} catch (V8JsScriptException $e) {
|
||||||
|
var_dump($e->getMessage());
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
===EOF===
|
||||||
|
--EXPECT--
|
||||||
|
Thu Mar 20 2014 11:03:24 GMT+0200 (EET)
|
||||||
|
Thu Mar 20 2014 05:03:24 GMT-0400 (EDT)
|
||||||
|
Thu Mar 20 2014 11:03:24 GMT+0200 (EET)
|
||||||
|
===EOF===
|
11
v8js.cc
11
v8js.cc
@ -1006,7 +1006,7 @@ static void php_v8js_timer_thread(TSRMLS_D)
|
|||||||
*/
|
*/
|
||||||
static PHP_METHOD(V8Js, executeString)
|
static PHP_METHOD(V8Js, executeString)
|
||||||
{
|
{
|
||||||
char *str = NULL, *identifier = NULL;
|
char *str = NULL, *identifier = NULL, *tz = NULL;
|
||||||
int str_len = 0, identifier_len = 0;
|
int str_len = 0, identifier_len = 0;
|
||||||
long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
|
long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
|
||||||
|
|
||||||
@ -1040,6 +1040,15 @@ static PHP_METHOD(V8Js, executeString)
|
|||||||
/* Set flags for runtime use */
|
/* Set flags for runtime use */
|
||||||
V8JS_GLOBAL_SET_FLAGS(isolate, flags);
|
V8JS_GLOBAL_SET_FLAGS(isolate, flags);
|
||||||
|
|
||||||
|
/* Check if timezone has been changed and notify V8 */
|
||||||
|
tz = getenv("TZ");
|
||||||
|
if (c->tz != NULL) {
|
||||||
|
if (c->tz != NULL && strcmp(c->tz, tz) != 0) {
|
||||||
|
v8::Date::DateTimeConfigurationChangeNotification(c->isolate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c->tz = tz;
|
||||||
|
|
||||||
if (time_limit > 0 || memory_limit > 0) {
|
if (time_limit > 0 || memory_limit > 0) {
|
||||||
// If timer thread is not running then start it
|
// If timer thread is not running then start it
|
||||||
if (!V8JSG(timer_thread)) {
|
if (!V8JSG(timer_thread)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user