Book/v8js-Phpdoc专题
V8 Javascript Engine Integration
目录
- 简介
- 安装/配置
- 范例
- V8Js — The V8Js class
- V8Js::__construct — Construct a new V8Js object
- V8Js::executeString — Execute a string as Javascript code
- V8Js::getExtensions — Return an array of registered extensions
- V8Js::getPendingException — Return pending uncaught Javascript exception
- V8Js::registerExtension — Register Javascript extensions for V8Js
- V8JsException — The V8JsException class
- V8JsException::getJsFileName — The getJsFileName purpose
- V8JsException::getJsLineNumber — The getJsLineNumber purpose
- V8JsException::getJsSourceLine — The getJsSourceLine purpose
- V8JsException::getJsTrace — The getJsTrace purpose
简介
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 int
V8Js::FLAG_NONE
= 1 ;
const int
V8Js::FLAG_FORCE_ARRAY
= 2 ;
/* Methods */
public <span
class="methodname">__construct ([ <span
class="methodparam">string $object_name
<span
class="initializer"> = "PHP" [, <span
class="methodparam">array $variables
<span
class="initializer"> = array() [, <span
class="methodparam">array $extensions
<span
class="initializer"> = array() [, <span
class="methodparam">bool
$report_uncaught_exceptions
=
true
]]]] )
public mixed
executeString ( <span
class="methodparam">string $script
[, string
$identifier
=
"V8Js::executeString()" [, <span
class="methodparam">int $flags
<span
class="initializer"> = V8Js::FLAG_NONE
]] )
public <span class="modifier">static array <span class="methodname">getExtensions ( <span class="methodparam">void )
public <span class="type">V8JsException <span class="methodname">getPendingException ( <span class="methodparam">void )
public <span
class="modifier">static bool <span
class="methodname">registerExtension ( <span
class="methodparam">string
$extension_name
, <span
class="type">string $script
[, <span
class="methodparam">array $dependencies
<span
class="initializer"> = array() [, <span
class="methodparam">bool $auto_enable
<span
class="initializer"> = 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 <span
class="methodname">V8Js::__construct ([ <span
class="methodparam">string $object_name
<span
class="initializer"> = "PHP" [, <span
class="methodparam">array $variables
<span
class="initializer"> = array() [, <span
class="methodparam">array $extensions
<span
class="initializer"> = array() [, <span
class="methodparam">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 <span
class="function">V8Js::registerExtension which should be
available in the Javascript context of the created <span
class="classname">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 <span
class="function">V8Js::getPendingException.
返回值
Returns a new V8Js context object.
V8Js::executeString
Execute a string as Javascript code
说明
public mixed
V8Js::executeString ( <span
class="methodparam">string $script
[, string
$identifier
=
"V8Js::executeString()" [, <span
class="methodparam">int $flags
<span
class="initializer"> = 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 <span class="modifier">static array <span class="methodname">V8Js::getExtensions ( <span class="methodparam">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 <span class="type">V8JsException <span class="methodname">V8Js::getPendingException ( <span class="methodparam">void )
Returns any pending uncaught Javascript exception as <span class="classname">V8JsException left from earlier <span class="function">V8Js::executeString call(s).
参数
此函数没有参数。
返回值
Either V8JsException or null
.
V8Js::registerExtension
Register Javascript extensions for V8Js
说明
public <span
class="modifier">static bool <span
class="methodname">V8Js::registerExtension ( <span
class="methodparam">string
$extension_name
, <span
class="type">string $script
[, <span
class="methodparam">array $dependencies
<span
class="initializer"> = array() [, <span
class="methodparam">bool $auto_enable
<span
class="initializer"> = false
]] )
Registers passed Javascript script
as extension to be used in <span
class="classname">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 <span class="ooclass"> 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 <span class="methodname">getJsFileName ( <span class="methodparam">void )
final public int <span class="methodname">getJsLineNumber ( <span class="methodparam">void )
final public string <span class="methodname">getJsSourceLine ( <span class="methodparam">void )
final public string <span class="methodname">getJsTrace ( <span class="methodparam">void )
/* 继承的方法 */
final public string <span class="methodname">Exception::getMessage ( <span class="methodparam">void )
final public Throwable <span class="methodname">Exception::getPrevious ( <span class="methodparam">void )
final public mixed <span class="methodname">Exception::getCode ( <span class="methodparam">void )
final public string <span class="methodname">Exception::getFile ( <span class="methodparam">void )
final public int <span class="methodname">Exception::getLine ( <span class="methodparam">void )
final public array <span class="methodname">Exception::getTrace ( <span class="methodparam">void )
final public string <span class="methodname">Exception::getTraceAsString ( <span class="methodparam">void )
public string Exception::__toString ( <span class="methodparam">void )
final <span class="modifier">private void <span class="methodname">Exception::__clone ( <span class="methodparam">void )
}
属性
JsFileName
JsLineNumber
JsSourceLine
JsTrace
V8JsException::getJsFileName
The getJsFileName purpose
说明
final public string <span class="methodname">V8JsException::getJsFileName ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
V8JsException::getJsLineNumber
The getJsLineNumber purpose
说明
final public int <span class="methodname">V8JsException::getJsLineNumber ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
V8JsException::getJsSourceLine
The getJsSourceLine purpose
说明
final public string <span class="methodname">V8JsException::getJsSourceLine ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
V8JsException::getJsTrace
The getJsTrace purpose
说明
final public string <span class="methodname">V8JsException::getJsTrace ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。