Jelajahi Sumber

Fix strdup+getenv behaviour; multi api version support, closes #86

Stefan Siegl 11 tahun lalu
induk
melakukan
0355a95c78
2 mengubah file dengan 23 tambahan dan 4 penghapusan
  1. 6 0
      php_v8js_macros.h
  2. 17 4
      v8js.cc

+ 6 - 0
php_v8js_macros.h

@@ -62,7 +62,13 @@ extern "C" {
 
 #define V8JS_FLOAT(v)		v8::Number::New(isolate, v)
 #define V8JS_BOOL(v)		((v)?v8::True(isolate):v8::False(isolate))
+
+#if PHP_V8_API_VERSION <= 3023012
+#define V8JS_DATE(v)		v8::Date::New(v)
+#else
 #define V8JS_DATE(v)		v8::Date::New(isolate, v)
+#endif
+
 #define V8JS_NULL			v8::Null(isolate)
 #define V8JS_UNDEFINED		v8::Undefined(isolate)
 #define V8JS_MN(name)		v8js_method_##name

+ 17 - 4
v8js.cc

@@ -643,6 +643,9 @@ static void php_v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
 	}
 	c->weak_closures.~map();
 
+	if(c->tz != NULL) {
+		free(c->tz);
+	}
 
 	c->modules_stack.~vector();
 	c->modules_base.~vector();
@@ -1083,12 +1086,22 @@ static PHP_METHOD(V8Js, executeString)
 
 	/* 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) {
+
+	if (tz != NULL) {
+		if (c->tz == NULL) {
+			c->tz = strdup(tz);
+		}
+		else if (strcmp(c->tz, tz) != 0) {
+#if PHP_V8_API_VERSION <= 3023012
+			v8::Date::DateTimeConfigurationChangeNotification();
+#else
 			v8::Date::DateTimeConfigurationChangeNotification(c->isolate);
+#endif
+
+			free(c->tz);
+			c->tz = strdup(tz);
 		}
 	}
-	c->tz = tz;
 
 	if (time_limit > 0 || memory_limit > 0) {
 		// If timer thread is not running then start it
@@ -1201,7 +1214,7 @@ static PHP_METHOD(V8Js, checkString)
 
 	/* Compiles a string context independently. TODO: Add a php function which calls this and returns the result as resource which can be executed later. */
 	v8::Local<v8::String> source = V8JS_STRL(str, str_len);
-	v8::Local<v8::Script> script = v8::Script::New(source, sname);
+	v8::Local<v8::Script> script = v8::Script::Compile(source, sname);
 
 	/* Compile errors? */
 	if (script.IsEmpty()) {