0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-09 22:08:40 +00:00

Merge branch master of github.com:preillyme/v8js

This commit is contained in:
Patrick Reilly 2013-05-09 09:17:39 -07:00
commit 713d4119da
12 changed files with 127 additions and 56 deletions

View File

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

74
README.md Normal file
View File

@ -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 )
}

View File

@ -51,7 +51,7 @@ int main ()
return 0; return 0;
} }
return 1; 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 AC_LANG_RESTORE
LIBS=$old_LIBS LIBS=$old_LIBS
LDFLAGS=$old_LDFLAGS LDFLAGS=$old_LDFLAGS

View File

@ -15,16 +15,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>jani@php.net</email> <email>jani@php.net</email>
<active>yes</active> <active>yes</active>
</lead> </lead>
<date>2012-07-06</date>
<date>2012-06-12</date>
<version><release>0.1.3</release><api>0.1.3</api></version> <version><release>0.1.3</release><api>0.1.3</api></version>
<stability><release>beta</release><api>beta</api></stability> <stability><release>beta</release><api>beta</api></stability>
<license uri="http://www.php.net/license">PHP</license> <license uri="http://www.php.net/license">PHP</license>
<notes> <notes>
- Fixed build in PHP 5.4+ - Fixed build in PHP 5.4+
- Fixed bug #59553 (can't build due to missing class member) - 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> </notes>
<contents> <contents>
<dir name="/"> <dir name="/">
<file name="CREDITS" role="doc" /> <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. - Added notice to registerExtension() if trying to use it when V8 is already initialized.
</notes> </notes>
</release> </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> </changelog>
</package> </package>

View File

@ -2,7 +2,7 @@
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 5 | | 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, | | 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 | | that is bundled with this package in the file LICENSE, and is |
@ -13,10 +13,11 @@
| license@php.net so we can mail you a copy immediately. | | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| Author: Jani Taskinen <jani.taskinen@iki.fi> | | Author: Jani Taskinen <jani.taskinen@iki.fi> |
| Author: Patrick Reilly <preilly@php.net> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
*/ */
/* $Id$ */ /* $Id:$ */
#ifndef PHP_V8JS_H #ifndef PHP_V8JS_H
#define PHP_V8JS_H #define PHP_V8JS_H

View File

@ -2,7 +2,7 @@
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 5 | | 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, | | 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 | | that is bundled with this package in the file LICENSE, and is |
@ -13,10 +13,11 @@
| license@php.net so we can mail you a copy immediately. | | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| Author: Jani Taskinen <jani.taskinen@iki.fi> | | Author: Jani Taskinen <jani.taskinen@iki.fi> |
| Author: Patrick Reilly <preilly@php.net> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
*/ */
/* $Id$ */ /* $Id$ */¬
#ifndef PHP_V8JS_MACROS_H #ifndef PHP_V8JS_MACROS_H
#define PHP_V8JS_MACROS_H #define PHP_V8JS_MACROS_H

View File

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

View File

@ -2,6 +2,8 @@
Test V8::executeString() : Return values Test V8::executeString() : Return values
--SKIPIF-- --SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
date.timezone=UTC
--FILE-- --FILE--
<?php <?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(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 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(1234567890);", "test5.js"));
var_dump($a->executeString("test(123.456789);", "test6.js")); var_dump($a->executeString("test(123.456789);", "test6.js"));
var_dump($a->executeString("test('some string');", "test7.js")); var_dump($a->executeString("test('some string');", "test7.js"));
@ -66,14 +70,7 @@ array(2) {
[1]=> [1]=>
string(3) "bar" string(3) "bar"
} }
object(DateTime)#3 (3) { Mon, 08 Sep 1975 09:00:00 +0000
["date"]=>
string(19) "1975-09-08 09:00:00"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+02:00"
}
int(1234567890) int(1234567890)
float(123.456789) float(123.456789)
string(11) "some string" string(11) "some string"

View File

@ -2,7 +2,7 @@
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 5 | | 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, | | 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 | | that is bundled with this package in the file LICENSE, and is |
@ -13,13 +13,14 @@
| license@php.net so we can mail you a copy immediately. | | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| Author: Jani Taskinen <jani.taskinen@iki.fi> | | Author: Jani Taskinen <jani.taskinen@iki.fi> |
| Author: Patrick Reilly <preilly@php.net> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
*/ */
/* $Id$ */ /* $Id$ */
#define V8JS_DEBUG 0 #define V8JS_DEBUG 0
#define PHP_V8_VERSION "0.1.4"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif

View File

@ -2,7 +2,7 @@
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 5 | | 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, | | 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 | | that is bundled with this package in the file LICENSE, and is |
@ -13,6 +13,7 @@
| license@php.net so we can mail you a copy immediately. | | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| Author: Jani Taskinen <jani.taskinen@iki.fi> | | Author: Jani Taskinen <jani.taskinen@iki.fi> |
| Author: Patrick Reilly <preilly@php.net> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
*/ */
@ -36,7 +37,7 @@ extern "C" {
static v8::Handle<v8::Value> php_v8js_php_callback(const v8::Arguments &args) /* {{{ */ static v8::Handle<v8::Value> php_v8js_php_callback(const v8::Arguments &args) /* {{{ */
{ {
v8::Handle<v8::Value> return_value; 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_function *method_ptr;
zend_fcall_info fci; zend_fcall_info fci;
zend_fcall_info_cache fcc; 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 */ /* Set method_ptr from v8::External or fetch the closure invoker */
if (!args.Data().IsEmpty() && args.Data()->IsExternal()) { 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 { } else {
method_ptr = zend_get_closure_invoke_method(value TSRMLS_CC); 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]; argv[i] = args[i];
} }
value = cb->Call(self, argc, argv); value = cb->Call(self, argc, argv);
} }
else /* __call() */ else /* __call() */
{ {
v8::Local<v8::Array> argsarr = v8::Array::New(argc); v8::Local<v8::Array> argsarr = v8::Array::New(argc);
for (; i < argc; ++i) { for (; i < argc; ++i) {
argsarr->Set(i, args[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->SetHiddenValue(V8JS_SYM(ZEND_ISSET_FUNC_NAME), PHP_V8JS_CALLBACK(isset_ptr));
} }
} }
newobj->SetPointerInInternalField(0, (void *) value); newobj->SetAlignedPointerInInternalField(0, (void *) value);
} else { } else {
new_tpl->SetClassName(V8JS_SYM("Array")); new_tpl->SetClassName(V8JS_SYM("Array"));
newobj = new_tpl->InstanceTemplate()->NewInstance(); newobj = new_tpl->InstanceTemplate()->NewInstance();
@ -517,7 +518,7 @@ v8::Handle<v8::Value> zval_to_v8js(zval *value TSRMLS_DC) /* {{{ */
jsValue = V8JS_NULL; jsValue = V8JS_NULL;
break; break;
} }
return jsValue; return jsValue;
} }
/* }}} */ /* }}} */

View File

@ -2,7 +2,7 @@
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 5 | | 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, | | 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 | | that is bundled with this package in the file LICENSE, and is |
@ -13,6 +13,7 @@
| license@php.net so we can mail you a copy immediately. | | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| Author: Jani Taskinen <jani.taskinen@iki.fi> | | Author: Jani Taskinen <jani.taskinen@iki.fi> |
| Author: Patrick Reilly <preilly@php.net> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
*/ */

View File

@ -2,7 +2,7 @@
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| PHP Version 5 | | 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, | | 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 | | that is bundled with this package in the file LICENSE, and is |
@ -13,10 +13,11 @@
| license@php.net so we can mail you a copy immediately. | | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
| Author: Jani Taskinen <jani.taskinen@iki.fi> | | Author: Jani Taskinen <jani.taskinen@iki.fi> |
| Author: Patrick Reilly <preilly@php.net> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
*/ */
/* $Id$ */ /* $Id:$ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"