瀏覽代碼

V8 needs to be notified when timezone changes. Keep track of timezone changes and notify it.
Also added a test.

Taneli Leppa 11 年之前
父節點
當前提交
0a85d27ee7
共有 4 個文件被更改,包括 52 次插入1 次删除
  1. 3 0
      package.xml
  2. 1 0
      php_v8js_macros.h
  3. 38 0
      tests/timezones.phpt
  4. 10 1
      v8js.cc

+ 3 - 0
package.xml

@@ -88,6 +88,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <file name="time_limit.phpt" role="test" />
    <file name="variable_passing.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>
  </contents>

+ 1 - 0
php_v8js_macros.h

@@ -184,6 +184,7 @@ struct php_v8js_ctx {
   std::vector<char *> modules_base;
   std::map<const char *,v8js_tmpl_t> template_cache;
   std::vector<php_v8js_accessor_ctx *> accessor_list;
+  char *tz;
 #ifdef ZTS
   void ***zts_ctx;
 #endif

+ 38 - 0
tests/timezones.phpt

@@ -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===

+ 10 - 1
v8js.cc

@@ -1006,7 +1006,7 @@ static void php_v8js_timer_thread(TSRMLS_D)
  */
 static PHP_METHOD(V8Js, executeString)
 {
-	char *str = NULL, *identifier = NULL;
+	char *str = NULL, *identifier = NULL, *tz = NULL;
 	int str_len = 0, identifier_len = 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 */
 	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 timer thread is not running then start it
 		if (!V8JSG(timer_thread)) {