V8 Javascript Engine Integration

目录

简介

This is the core class for V8Js extension. Each instance created from this class has own context in which all JavaScript is compiled and executed.

See V8Js::__construct for more information.

类摘要

V8Js

class V8Js {

/* Constants */

const string V8Js::V8_VERSION ;

const integer V8Js::FLAG_NONE = 1 ;

const integer V8Js::FLAG_FORCE_ARRAY = 2 ;

/* Methods */

public __construct ([ string $object_name = "PHP" [, array $variables = array() [, array $extensions = array() [, bool $report_uncaught_exceptions = TRUE ]]]] )

public mixed executeString ( string $script [, string $identifier = "V8Js::executeString()" [, int $flags = V8Js::FLAG_NONE ]] )

public static array getExtensions ( void )

public V8JsException getPendingException ( void )

public static bool registerExtension ( string $extension_name , string $script [, array $dependencies = array() [, bool $auto_enable = FALSE ]] )

}

预定义常量

V8Js::V8_VERSION
The V8 Javascript Engine version.

V8Js::FLAG_NONE
No flags.

V8Js::FLAG_FORCE_ARRAY
Forces all JS objects to be associative arrays in PHP.

V8Js::__construct

Construct a new V8Js object

说明

public V8Js::__construct ([ string $object_name = "PHP" [, array $variables = array() [, array $extensions = array() [, bool $report_uncaught_exceptions = TRUE ]]]] )

Constructs a new V8Js object.

参数

object_name
The name of the object passed to Javascript.

variables
Map of PHP variables that will be available in Javascript. Must be an associative array in format array("name-for-js" => "name-of-php-variable"). Defaults to empty array.

extensions
List of extensions registered using V8Js::registerExtension which should be available in the Javascript context of the created V8Js object.

Note:

Extensions registered to be enabled automatically do not need to be listed in this array. Also if an extension has dependencies, those dependencies can be omitted as well. Defaults to empty array.

report_uncaught_exceptions
Controls whether uncaught Javascript exceptions are reported immediately or not. Defaults to TRUE. If set to FALSE the uncaught exception can be accessed using V8Js::getPendingException.

返回值

Returns a new V8Js context object.

V8Js::executeString

Execute a string as Javascript code

说明

public mixed V8Js::executeString ( string $script [, string $identifier = "V8Js::executeString()" [, int $flags = V8Js::FLAG_NONE ]] )

Compiles and executes the string passed with script as Javascript code.

参数

script
The code string to be executed.

identifier
Identifier string for the executed code. Used for debugging.

flags
Execution flags. This value must be one of the V8Js::FLAG_* constants, defaulting to V8Js::FLAG_NONE.

  • V8Js::FLAG_NONE: no flags

  • V8Js::FLAG_FORCE_ARRAY: forces all Javascript objects passed to PHP to be associative arrays

返回值

Returns the last variable instantiated in the Javascript code converted to matching PHP variable type.

V8Js::getExtensions

Return an array of registered extensions

说明

public static array V8Js::getExtensions ( void )

This function returns array of Javascript extensions registered using V8Js::registerExtension.

参数

此函数没有参数。

返回值

Returns an array of registered extensions or an empty array if there are none.

V8Js::getPendingException

Return pending uncaught Javascript exception

说明

public V8JsException V8Js::getPendingException ( void )

Returns any pending uncaught Javascript exception as V8JsException left from earlier V8Js::executeString call(s).

参数

此函数没有参数。

返回值

Either V8JsException or NULL.

V8Js::registerExtension

Register Javascript extensions for V8Js

说明

public static bool V8Js::registerExtension ( string $extension_name , string $script [, array $dependencies = array() [, bool $auto_enable = FALSE ]] )

Registers passed Javascript script as extension to be used in V8Js contexts.

参数

extension_name
Name of the extension to be registered.

script
The Javascript code to be registered.

dependencies
Array of extension names the extension to be registered depends on. Any such extension is enabled automatically when this extension is loaded.

Note:

All extensions, including the dependencies, must be registered before any V8Js are created which use them.

auto_enable
If set to TRUE, the extension will be enabled automatically in all V8Js contexts.

返回值

Returns TRUE if extension was registered successfully, FALSE otherwise.

简介

类摘要

V8JsException

class V8JsException extends Exception {

/* 属性 */

protected $JsFileName ;

protected $JsLineNumber ;

protected $JsSourceLine ;

protected $JsTrace ;

/* 继承的属性 */

protected string $message ;

protected int $code ;

protected string $file ;

protected int $line ;

/* 方法 */

final public string getJsFileName ( void )

final public int getJsLineNumber ( void )

final public string getJsSourceLine ( void )

final public string getJsTrace ( void )

/* 继承的方法 */

final public string Exception::getMessage ( void )

final public Throwable Exception::getPrevious ( void )

final public int Exception::getCode ( void )

final public string Exception::getFile ( void )

final public int Exception::getLine ( void )

final public array Exception::getTrace ( void )

final public string Exception::getTraceAsString ( void )

public string Exception::__toString ( void )

final private void Exception::__clone ( void )

}

属性

JsFileName

JsLineNumber

JsSourceLine

JsTrace

V8JsException::getJsFileName

The getJsFileName purpose

说明

final public string V8JsException::getJsFileName ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

V8JsException::getJsLineNumber

The getJsLineNumber purpose

说明

final public int V8JsException::getJsLineNumber ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

V8JsException::getJsSourceLine

The getJsSourceLine purpose

说明

final public string V8JsException::getJsSourceLine ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

V8JsException::getJsTrace

The getJsTrace purpose

说明

final public string V8JsException::getJsTrace ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值