Преглед изворни кода

Merge branch master of github.com:preillyme/v8js

Patrick Reilly пре 12 година
родитељ
комит
713d4119da
12 измењених фајлова са 127 додато и 56 уклоњено
  1. 1 0
      CREDITS
  2. 74 0
      README.md
  3. 1 1
      config.m4
  4. 3 12
      package.xml
  5. 3 2
      php_v8js.h
  6. 3 2
      php_v8js_macros.h
  7. 20 18
      tests/object_method_call.phpt
  8. 6 9
      tests/return_value.phpt
  9. 3 2
      v8js.cc
  10. 8 7
      v8js_convert.cc
  11. 2 1
      v8js_methods.cc
  12. 3 2
      v8js_variables.cc

+ 1 - 0
CREDITS

@@ -1,2 +1,3 @@
 v8js
 Jani Taskinen
+Patrick Reilly

+ 74 - 0
README.md

@@ -0,0 +1,74 @@
+V8Js
+====
+
+This is a PHP extension for Google's V8 Javascript engine 
+
+
+Minimum requirements
+--------------------
+
+- V8 JavaScript Engine library version 2.5.8 <http://code.google.com/p/v8/> (trunk)
+
+	V8 is Google's open source JavaScript engine.
+	V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
+	V8 implements ECMAScript as specified in ECMA-262, 5th edition, and runs on Windows (XP or newer), 
+	Mac OS X (10.5 or newer), and Linux systems that use IA-32, x64, or ARM processors.
+	V8 can run standalone, or can be embedded into any C++ application.
+	You can find more information here:
+	<http://code.google.com/p/v8/>
+
+- PHP 5.3.3+ (non-ZTS build preferred)
+  Note: V8 engine is not natively thread safe and this extension
+  has not been designed to work around it either yet and might or
+  might not work properly with ZTS enabled PHP. :)
+
+
+API
+===
+
+    class V8Js
+    {
+        /* Constants */
+
+        const string V8_VERSION;
+        const int FLAG_NONE;
+        const int FLAG_FORCE_ARRAY;
+    
+        /* Methods */
+
+        // Initializes and starts V8 engine and Returns new V8Js object with it's own V8 context.
+        public __construct ( [string object_name = "PHP" [, array variables = NULL [, array extensions = NULL [, bool report_uncaught_exceptions = TRUE]]] )
+
+        // Compiles and executes script in object's context with optional identifier string.
+        public mixed V8Js::executeString( string script [, string identifier [, int flags = V8Js::FLAG_NONE]])
+
+        // Returns uncaught pending exception or null if there is no pending exception.
+        public V8JsException V8Js::getPendingException( void )
+
+        /** Static methods **/
+
+        // Registers persistent context independent global Javascript extension.
+        // NOTE! These extensions exist until PHP is shutdown and they need to be registered before V8 is initialized. 
+        // For best performance V8 is initialized only once per process thus this call has to be done before any V8Js objects are created!
+        public static bool V8Js::registerExtension(string ext_name, string script [, array deps [, bool auto_enable = FALSE]])
+
+        // Returns extensions successfully registered with V8Js::registerExtension().
+        public static array V8Js::getExtensions( void )
+    }
+
+    final class V8JsException extends Exception
+    {
+        /* Properties */
+        protected string JsFileName = NULL;
+        protected int JsLineNumber = NULL;
+        protected string JsSourceLine = NULL;
+        protected string JsTrace = NULL;
+        
+        /* Methods */
+        final public string getJsFileName( void )
+        final public int getJsLineNumber( void )
+        final public string getJsSourceLine( void )
+        final public string getJsTrace( void )
+    }
+    
+

+ 1 - 1
config.m4

@@ -51,7 +51,7 @@ int main ()
 		return 0;
 	}
 	return 1;
-}], [ac_cv_v8_version=`cat ./conftestval`], [ac_cv_v8_version=NONE], [ac_cv_v8_version=NONE])
+}], [ac_cv_v8_version=`cat ./conftestval|awk '{print $1}'`], [ac_cv_v8_version=NONE], [ac_cv_v8_version=NONE])
 AC_LANG_RESTORE
 LIBS=$old_LIBS
 LDFLAGS=$old_LDFLAGS

+ 3 - 12
package.xml

@@ -15,16 +15,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <email>[email protected]</email>
   <active>yes</active>
  </lead>
-
- <date>2012-06-12</date>
+ <date>2012-07-06</date>
  <version><release>0.1.3</release><api>0.1.3</api></version>
  <stability><release>beta</release><api>beta</api></stability>
  <license uri="http://www.php.net/license">PHP</license>
  <notes>
 - Fixed build in PHP 5.4+
 - Fixed bug #59553 (can't build due to missing class member)
+- Fixed crash bug in setting v8.flags ini directive.
+- Added notice to registerExtension() if trying to use it when V8 is already initialized.
  </notes>
-
  <contents>
   <dir name="/">
    <file name="CREDITS" role="doc" />
@@ -63,14 +63,5 @@ http://pear.php.net/dtd/package-2.0.xsd">
 - Added notice to registerExtension() if trying to use it when V8 is already initialized.
    </notes>
   </release>
-  <release>
-   <date>2010-12-30</date>
-   <version><release>0.1.0</release><api>0.1.0</api></version>
-   <stability><release>beta</release><api>beta</api></stability>
-   <license uri="http://www.php.net/license">PHP</license>
-   <notes>
-- Initial PECL release.
-   </notes>
-  </release>
  </changelog>
 </package>

+ 3 - 2
php_v8js.h

@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2010 The PHP Group                                |
+  | Copyright (c) 1997-2012 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -13,10 +13,11 @@
   | [email protected] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Jani Taskinen <[email protected]>                         |
+  | Author: Patrick Reilly <[email protected]>                             |
   +----------------------------------------------------------------------+
 */
 
-/* $Id$ */
+/* $Id:$ */
 
 #ifndef PHP_V8JS_H
 #define PHP_V8JS_H

+ 3 - 2
php_v8js_macros.h

@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2010 The PHP Group                                |
+  | Copyright (c) 1997-2012 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -13,10 +13,11 @@
   | [email protected] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Jani Taskinen <[email protected]>                         |
+  | Author: Patrick Reilly <[email protected]>                             |
   +----------------------------------------------------------------------+
 */
 
-/* $Id$ */
+/* $Id$ */¬
 
 #ifndef PHP_V8JS_MACROS_H
 #define PHP_V8JS_MACROS_H

+ 20 - 18
tests/object_method_call.phpt

@@ -2,6 +2,8 @@
 Test V8::executeString() : Calling methods of object passed from PHP
 --SKIPIF--
 <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--INI--
+date.timezone=UTC
 --FILE--
 <?php
 
@@ -16,6 +18,12 @@ class Testing
 	{
 		var_dump(func_get_args());
 	}
+
+  function mydatetest(DateTime $date, $b) {
+    $date->setTimeZone(new DateTimeZone(ini_get('date.timezone')));
+    echo $date->format(DateTime::RFC1123), "\n";
+    var_dump($b);
+  }
 }
 
 $a = new V8Js();
@@ -39,10 +47,9 @@ try {
 }
 
 try {
-	date_default_timezone_set("UTC");
 	echo "\nTEST: Javascript Date -> PHP DateTime\n";
 	echo "======================================\n";
-	$a->executeString("date = new Date('September 8, 1975 09:00:00'); print(date + '\\n'); PHP.myobj.mytest(date, 'foo');", "test6.js");
+	$a->executeString("date = new Date('September 8, 1975 09:00:00 GMT'); print(date.toUTCString() + '\\n'); PHP.myobj.mydatetest(date, 'foo');", "test6.js");
 } catch (V8JsException $e) {
 	echo $e->getMessage(), "\n";
 }
@@ -93,26 +100,18 @@ array(4) {
 
 TEST: Javascript Date -> PHP DateTime
 ======================================
-Mon Sep 08 1975 09:00:00 GMT+0200 (EET)
-array(2) {
-  [0]=>
-  object(DateTime)#4 (3) {
-    ["date"]=>
-    string(19) "1975-09-08 09:00:00"
-    ["timezone_type"]=>
-    int(1)
-    ["timezone"]=>
-    string(6) "+02:00"
-  }
-  [1]=>
-  string(3) "foo"
-}
+Mon, 08 Sep 1975 09:00:00 GMT
+Mon, 08 Sep 1975 09:00:00 +0000
+string(3) "foo"
 array(3) {
   [0]=>
-  object(V8Object)#4 (2) {
+  object(V8Object)#4 (3) {
     ["mytest"]=>
     object(V8Function)#6 (0) {
     }
+    ["mydatetest"]=>
+    object(V8Function)#7 (0) {
+    }
     ["foo"]=>
     string(8) "ORIGINAL"
   }
@@ -132,8 +131,11 @@ array(3) {
     [1]=>
     string(3) "bar"
     [2]=>
-    object(V8Object)#5 (2) {
+    object(V8Object)#5 (3) {
       ["mytest"]=>
+      object(V8Function)#7 (0) {
+      }
+      ["mydatetest"]=>
       object(V8Function)#6 (0) {
       }
       ["foo"]=>

+ 6 - 9
tests/return_value.phpt

@@ -2,6 +2,8 @@
 Test V8::executeString() : Return values
 --SKIPIF--
 <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--INI--
+date.timezone=UTC
 --FILE--
 <?php
 
@@ -29,7 +31,9 @@ var_dump($a->executeString("test(PHP.myobj);", "test1.js"));
 var_dump($a->executeString("test(new Array(1,2,3));", "test2.js"));
 var_dump($a->executeString("test(new Array('foo', 'bar'));", "test3.js"));
 var_dump($a->executeString("test(new Array('foo', 'bar'));", "test3.js"));
-var_dump($a->executeString("test(new Date('September 8, 1975 09:00:00'));", "test4.js"));
+$date = $a->executeString("test(new Date('September 8, 1975 09:00:00 GMT'));", "test4.js");
+$date->setTimeZone(new DateTimeZone('GMT'));
+echo $date->format(DateTime::RFC1123), "\n";
 var_dump($a->executeString("test(1234567890);", "test5.js"));
 var_dump($a->executeString("test(123.456789);", "test6.js"));
 var_dump($a->executeString("test('some string');", "test7.js"));
@@ -66,14 +70,7 @@ array(2) {
   [1]=>
   string(3) "bar"
 }
-object(DateTime)#3 (3) {
-  ["date"]=>
-  string(19) "1975-09-08 09:00:00"
-  ["timezone_type"]=>
-  int(1)
-  ["timezone"]=>
-  string(6) "+02:00"
-}
+Mon, 08 Sep 1975 09:00:00 +0000
 int(1234567890)
 float(123.456789)
 string(11) "some string"

+ 3 - 2
v8js.cc

@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2010 The PHP Group                                |
+  | Copyright (c) 1997-2012 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -13,13 +13,14 @@
   | [email protected] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Jani Taskinen <[email protected]>                         |
+  | Author: Patrick Reilly <[email protected]>                             |
   +----------------------------------------------------------------------+
 */
 
 /* $Id$ */
 
 #define V8JS_DEBUG 0
-
+#define PHP_V8_VERSION "0.1.4"
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif

+ 8 - 7
v8js_convert.cc

@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2010 The PHP Group                                |
+  | Copyright (c) 1997-2012 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -13,6 +13,7 @@
   | [email protected] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Jani Taskinen <[email protected]>                         |
+  | Author: Patrick Reilly <[email protected]>                             |
   +----------------------------------------------------------------------+
 */
 
@@ -36,7 +37,7 @@ extern "C" {
 static v8::Handle<v8::Value> php_v8js_php_callback(const v8::Arguments &args) /* {{{ */
 {
 	v8::Handle<v8::Value> return_value;
-	zval *value = reinterpret_cast<zval *>(args.This()->GetPointerFromInternalField(0));
+	zval *value = reinterpret_cast<zval *>(args.This()->GetAlignedPointerFromInternalField(0));
 	zend_function *method_ptr;
 	zend_fcall_info fci;
 	zend_fcall_info_cache fcc;
@@ -49,7 +50,7 @@ static v8::Handle<v8::Value> php_v8js_php_callback(const v8::Arguments &args) /*
 
 	/* Set method_ptr from v8::External or fetch the closure invoker */
 	if (!args.Data().IsEmpty() && args.Data()->IsExternal()) {
-		method_ptr = static_cast<zend_function *>(v8::External::Unwrap(args.Data()));
+		method_ptr = static_cast<zend_function *>(v8::External::Cast(*args.Data())->Value());
 	} else {
 		method_ptr = zend_get_closure_invoke_method(value TSRMLS_CC);
 	}
@@ -185,9 +186,9 @@ static v8::Handle<v8::Value> php_v8js_property_caller(const v8::Arguments &args)
 				argv[i] = args[i];
 			}
 			value = cb->Call(self, argc, argv);
-		} 
+		}
 		else /* __call() */
-		{ 
+		{
 			v8::Local<v8::Array> argsarr = v8::Array::New(argc);
 			for (; i < argc; ++i) {
 				argsarr->Set(i, args[i]);
@@ -383,7 +384,7 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value TSRMLS_DC) /* {{
 				newobj->SetHiddenValue(V8JS_SYM(ZEND_ISSET_FUNC_NAME), PHP_V8JS_CALLBACK(isset_ptr));
 			}
 		}
-		newobj->SetPointerInInternalField(0, (void *) value);
+		newobj->SetAlignedPointerInInternalField(0, (void *) value);
 	} else {
 		new_tpl->SetClassName(V8JS_SYM("Array"));
 		newobj = new_tpl->InstanceTemplate()->NewInstance();
@@ -517,7 +518,7 @@ v8::Handle<v8::Value> zval_to_v8js(zval *value TSRMLS_DC) /* {{{ */
 			jsValue = V8JS_NULL;
 			break;
 	}
-	return jsValue; 
+	return jsValue;
 }
 /* }}} */
 

+ 2 - 1
v8js_methods.cc

@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2010 The PHP Group                                |
+  | Copyright (c) 1997-2012 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -13,6 +13,7 @@
   | [email protected] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Jani Taskinen <[email protected]>                         |
+  | Author: Patrick Reilly <[email protected]>                             |
   +----------------------------------------------------------------------+
 */
 

+ 3 - 2
v8js_variables.cc

@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2010 The PHP Group                                |
+  | Copyright (c) 1997-2012 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -13,10 +13,11 @@
   | [email protected] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Jani Taskinen <[email protected]>                         |
+  | Author: Patrick Reilly <[email protected]>                             |
   +----------------------------------------------------------------------+
 */
 
-/* $Id$ */
+/* $Id:$ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"