mirror of
https://github.com/phpv8/v8js.git
synced 2025-01-18 11:51:51 +00:00
Merge branch master of github.com:preillyme/v8js
This commit is contained in:
commit
713d4119da
74
README.md
Normal file
74
README.md
Normal 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 )
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
15
package.xml
15
package.xml
@ -15,16 +15,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
||||
<email>jani@php.net</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>
|
||||
|
@ -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 @@
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Jani Taskinen <jani.taskinen@iki.fi> |
|
||||
| Author: Patrick Reilly <preilly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
/* $Id:$ */
|
||||
|
||||
#ifndef PHP_V8JS_H
|
||||
#define 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 @@
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Jani Taskinen <jani.taskinen@iki.fi> |
|
||||
| Author: Patrick Reilly <preilly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
/* $Id$ */¬
|
||||
|
||||
#ifndef PHP_V8JS_MACROS_H
|
||||
#define PHP_V8JS_MACROS_H
|
||||
|
@ -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]=>
|
||||
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"]=>
|
||||
|
@ -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"
|
||||
|
5
v8js.cc
5
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 @@
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Jani Taskinen <jani.taskinen@iki.fi> |
|
||||
| Author: Patrick Reilly <preilly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#define V8JS_DEBUG 0
|
||||
|
||||
#define PHP_V8_VERSION "0.1.4"
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -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 @@
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| 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) /* {{{ */
|
||||
{
|
||||
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);
|
||||
}
|
||||
@ -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();
|
||||
|
@ -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 @@
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Jani Taskinen <jani.taskinen@iki.fi> |
|
||||
| Author: Patrick Reilly <preilly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
@ -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 @@
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Jani Taskinen <jani.taskinen@iki.fi> |
|
||||
| Author: Patrick Reilly <preilly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
/* $Id:$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
|
Loading…
Reference in New Issue
Block a user