0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 15:25:19 +00:00

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

This commit is contained in:
Stefan Siegl 2014-03-22 19:09:53 +01:00
parent ddbef50ea6
commit 0355a95c78
2 changed files with 23 additions and 4 deletions

View File

@ -62,7 +62,13 @@ extern "C" {
#define V8JS_FLOAT(v) v8::Number::New(isolate, v) #define V8JS_FLOAT(v) v8::Number::New(isolate, v)
#define V8JS_BOOL(v) ((v)?v8::True(isolate):v8::False(isolate)) #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) #define V8JS_DATE(v) v8::Date::New(isolate, v)
#endif
#define V8JS_NULL v8::Null(isolate) #define V8JS_NULL v8::Null(isolate)
#define V8JS_UNDEFINED v8::Undefined(isolate) #define V8JS_UNDEFINED v8::Undefined(isolate)
#define V8JS_MN(name) v8js_method_##name #define V8JS_MN(name) v8js_method_##name

21
v8js.cc
View File

@ -643,6 +643,9 @@ static void php_v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
} }
c->weak_closures.~map(); c->weak_closures.~map();
if(c->tz != NULL) {
free(c->tz);
}
c->modules_stack.~vector(); c->modules_stack.~vector();
c->modules_base.~vector(); c->modules_base.~vector();
@ -1083,12 +1086,22 @@ static PHP_METHOD(V8Js, executeString)
/* Check if timezone has been changed and notify V8 */ /* Check if timezone has been changed and notify V8 */
tz = getenv("TZ"); 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); v8::Date::DateTimeConfigurationChangeNotification(c->isolate);
#endif
free(c->tz);
c->tz = strdup(tz);
} }
} }
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
@ -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. */ /* 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::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? */ /* Compile errors? */
if (script.IsEmpty()) { if (script.IsEmpty()) {