2014-12-12 22:59:28 +00:00
|
|
|
|
/*
|
|
|
|
|
+----------------------------------------------------------------------+
|
2017-03-11 11:33:49 +00:00
|
|
|
|
| PHP Version 7 |
|
2014-12-12 22:59:28 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
2017-03-10 23:09:51 +00:00
|
|
|
|
| Copyright (c) 1997-2017 The PHP Group |
|
2014-12-12 22:59:28 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
| http://www.opensource.org/licenses/mit-license.php MIT License |
|
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
| Author: Jani Taskinen <jani.taskinen@iki.fi> |
|
|
|
|
|
| Author: Patrick Reilly <preilly@php.net> |
|
2016-01-07 19:40:36 +00:00
|
|
|
|
| Author: Stefan Siegl <stesie@php.net> |
|
2014-12-12 22:59:28 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-01-06 09:01:35 +00:00
|
|
|
|
#include "php_v8js_macros.h"
|
|
|
|
|
#include "v8js_exceptions.h"
|
|
|
|
|
#include "v8js_v8.h"
|
|
|
|
|
#include "v8js_v8object_class.h"
|
|
|
|
|
|
2014-12-12 22:59:28 +00:00
|
|
|
|
extern "C" {
|
|
|
|
|
#include "ext/date/php_date.h"
|
|
|
|
|
#include "ext/standard/php_string.h"
|
|
|
|
|
#include "zend_interfaces.h"
|
|
|
|
|
#include "zend_closures.h"
|
|
|
|
|
#include "ext/spl/spl_exceptions.h"
|
|
|
|
|
#include "zend_exceptions.h"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* {{{ Class Entries */
|
2014-12-12 23:28:09 +00:00
|
|
|
|
zend_class_entry *php_ce_v8object;
|
|
|
|
|
zend_class_entry *php_ce_v8function;
|
2016-01-07 19:40:36 +00:00
|
|
|
|
zend_class_entry *php_ce_v8generator;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ Object Handlers */
|
2014-12-12 23:28:09 +00:00
|
|
|
|
static zend_object_handlers v8js_v8object_handlers;
|
2016-01-07 20:35:44 +00:00
|
|
|
|
static zend_object_handlers v8js_v8generator_handlers;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
#define V8JS_V8_INVOKE_FUNC_NAME "V8Js::V8::Invoke"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* V8 Object handlers */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static int v8js_v8object_has_property(zval *object, zval *member, int has_set_exists, void **cache_slot) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
|
|
|
|
/* param has_set_exists:
|
|
|
|
|
* 0 (has) whether property exists and is not NULL - isset()
|
|
|
|
|
* 1 (set) whether property exists and is true-ish - empty()
|
|
|
|
|
* 2 (exists) whether property exists - property_exists()
|
|
|
|
|
*/
|
|
|
|
|
int retval = false;
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 07:37:32 +00:00
|
|
|
|
V8JS_CTX_PROLOGUE_EX(obj->ctx, retval);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
|
|
|
|
2015-11-03 17:35:30 +00:00
|
|
|
|
if (Z_TYPE_P(member) == IS_STRING && v8obj->IsObject())
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2017-03-10 23:09:51 +00:00
|
|
|
|
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max()) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
|
|
|
|
"Member name length exceeds maximum supported length", 0);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
v8::Local<v8::Object> jsObj = v8obj->ToObject();
|
2017-03-10 23:09:51 +00:00
|
|
|
|
v8::Local<v8::String> jsKey = V8JS_STRL(Z_STRVAL_P(member), static_cast<int>(Z_STRLEN_P(member)));
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> jsVal;
|
|
|
|
|
|
|
|
|
|
/* Skip any prototype properties */
|
|
|
|
|
if (jsObj->HasRealNamedProperty(jsKey) || jsObj->HasRealNamedCallbackProperty(jsKey)) {
|
|
|
|
|
if (has_set_exists == 2) {
|
|
|
|
|
/* property_exists(), that's enough! */
|
|
|
|
|
retval = true;
|
|
|
|
|
} else {
|
|
|
|
|
/* We need to look at the value. */
|
|
|
|
|
jsVal = jsObj->Get(jsKey);
|
|
|
|
|
if (has_set_exists == 0 ) {
|
|
|
|
|
/* isset(): We make 'undefined' equivalent to 'null' */
|
|
|
|
|
retval = !( jsVal->IsNull() || jsVal->IsUndefined() );
|
|
|
|
|
} else {
|
|
|
|
|
/* empty() */
|
|
|
|
|
retval = jsVal->BooleanValue();
|
|
|
|
|
/* for PHP compatibility, [] should also be empty */
|
|
|
|
|
if (jsVal->IsArray() && retval) {
|
|
|
|
|
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(jsVal);
|
|
|
|
|
retval = (array->Length() != 0);
|
|
|
|
|
}
|
|
|
|
|
/* for PHP compatibility, '0' should also be empty */
|
|
|
|
|
if (jsVal->IsString() && retval) {
|
|
|
|
|
v8::Local<v8::String> str = jsVal->ToString();
|
|
|
|
|
if (str->Length() == 1) {
|
|
|
|
|
uint16_t c = 0;
|
|
|
|
|
str->Write(&c, 0, 1);
|
|
|
|
|
if (c == '0') {
|
|
|
|
|
retval = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static zval *v8js_v8object_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2015-08-29 14:47:37 +00:00
|
|
|
|
zval *retval = rv;
|
|
|
|
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 07:37:32 +00:00
|
|
|
|
V8JS_CTX_PROLOGUE_EX(obj->ctx, retval);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
|
|
|
|
2015-11-03 17:35:30 +00:00
|
|
|
|
if (Z_TYPE_P(member) == IS_STRING && v8obj->IsObject())
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2017-03-10 23:09:51 +00:00
|
|
|
|
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max()) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
|
|
|
|
"Member name length exceeds maximum supported length", 0);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
v8::Local<v8::Object> jsObj = v8obj->ToObject();
|
2017-03-10 23:09:51 +00:00
|
|
|
|
v8::Local<v8::String> jsKey = V8JS_STRL(Z_STRVAL_P(member), static_cast<int>(Z_STRLEN_P(member)));
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> jsVal;
|
|
|
|
|
|
|
|
|
|
/* Skip any prototype properties */
|
|
|
|
|
if (jsObj->HasRealNamedProperty(jsKey) || jsObj->HasRealNamedCallbackProperty(jsKey)) {
|
|
|
|
|
jsVal = jsObj->Get(jsKey);
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
if (v8js_to_zval(jsVal, retval, obj->flags, isolate) == SUCCESS) {
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static void v8js_v8object_write_property(zval *object, zval *member, zval *value, void **cache_slot ) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 07:37:32 +00:00
|
|
|
|
V8JS_CTX_PROLOGUE(obj->ctx);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
|
|
|
|
2017-03-10 23:09:51 +00:00
|
|
|
|
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max()) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
|
|
|
|
"Member name length exceeds maximum supported length", 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 17:35:30 +00:00
|
|
|
|
if (v8obj->IsObject()) {
|
2017-03-10 23:09:51 +00:00
|
|
|
|
v8obj->ToObject()->ForceSet(V8JS_SYML(Z_STRVAL_P(member), static_cast<int>(Z_STRLEN_P(member))), zval_to_v8js(value, isolate));
|
2014-12-12 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static void v8js_v8object_unset_property(zval *object, zval *member, void **cache_slot) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 07:37:32 +00:00
|
|
|
|
V8JS_CTX_PROLOGUE(obj->ctx);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
|
|
|
|
2017-03-10 23:09:51 +00:00
|
|
|
|
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max()) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
|
|
|
|
"Member name length exceeds maximum supported length", 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 17:35:30 +00:00
|
|
|
|
if (v8obj->IsObject()) {
|
2017-03-10 23:09:51 +00:00
|
|
|
|
v8obj->ToObject()->Delete(V8JS_SYML(Z_STRVAL_P(member), static_cast<int>(Z_STRLEN_P(member))));
|
2014-12-12 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static HashTable *v8js_v8object_get_properties(zval *object) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (obj->properties == NULL) {
|
|
|
|
|
if (GC_G(gc_active)) {
|
|
|
|
|
/* the garbage collector is running, don't create more zvals */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ALLOC_HASHTABLE(obj->properties);
|
|
|
|
|
zend_hash_init(obj->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
/* Half-constructed object, probably due to unserialize call.
|
|
|
|
|
* Just pass back properties hash so unserialize can write to
|
|
|
|
|
* it (instead of crashing the engine). */
|
|
|
|
|
return obj->properties;
|
|
|
|
|
}
|
2017-06-08 21:18:52 +00:00
|
|
|
|
} else if (!obj->properties->u.v.nIteratorsCount) {
|
2014-12-12 22:59:28 +00:00
|
|
|
|
zend_hash_clean(obj->properties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 07:37:32 +00:00
|
|
|
|
V8JS_CTX_PROLOGUE_EX(obj->ctx, NULL);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
if (v8js_get_properties_hash(v8obj, obj->properties, obj->flags, isolate) == SUCCESS) {
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return obj->properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static HashTable *v8js_v8object_get_debug_info(zval *object, int *is_temp) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
|
|
|
|
*is_temp = 0;
|
2017-03-11 12:35:21 +00:00
|
|
|
|
return v8js_v8object_get_properties(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static zend_function *v8js_v8object_get_method(zend_object **object_ptr, zend_string *method, const zval *key) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *obj = v8js_v8object_fetch_object(*object_ptr);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
zend_function *f;
|
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 23:09:51 +00:00
|
|
|
|
if (ZSTR_LEN(method) > std::numeric_limits<int>::max()) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
|
|
|
|
"Method name length exceeds maximum supported length", 0);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 07:37:32 +00:00
|
|
|
|
V8JS_CTX_PROLOGUE_EX(obj->ctx, NULL);
|
2017-03-10 23:09:51 +00:00
|
|
|
|
v8::Local<v8::String> jsKey = V8JS_STRL(ZSTR_VAL(method), static_cast<int>(ZSTR_LEN(method)));
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
|
|
|
|
|
|
|
|
if (!obj->v8obj.IsEmpty() && v8obj->IsObject() && !v8obj->IsFunction()) {
|
|
|
|
|
v8::Local<v8::Object> jsObj = v8obj->ToObject();
|
|
|
|
|
|
|
|
|
|
if (jsObj->Has(jsKey) && jsObj->Get(jsKey)->IsFunction()) {
|
|
|
|
|
f = (zend_function *) ecalloc(1, sizeof(*f));
|
|
|
|
|
f->type = ZEND_OVERLOADED_FUNCTION_TEMPORARY;
|
2015-08-29 14:47:37 +00:00
|
|
|
|
f->common.function_name = zend_string_copy(method);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2015-08-29 14:47:37 +00:00
|
|
|
|
static int v8js_v8object_call_method(zend_string *method, zend_object *object, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2015-08-29 14:47:37 +00:00
|
|
|
|
zval *argv = NULL;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
int argc = ZEND_NUM_ARGS();
|
|
|
|
|
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *obj = v8js_v8object_fetch_object(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (obj->v8obj.IsEmpty()) {
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 23:09:51 +00:00
|
|
|
|
if (ZSTR_LEN(method) > std::numeric_limits<int>::max()) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
|
|
|
|
"Method name length exceeds maximum supported length", 0);
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-12 22:59:28 +00:00
|
|
|
|
if (argc > 0) {
|
2015-08-29 14:47:37 +00:00
|
|
|
|
argv = (zval*)safe_emalloc(sizeof(zval), argc, 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
zend_get_parameters_array_ex(argc, argv);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-01 18:10:04 +00:00
|
|
|
|
/* std::function relies on its dtor to be executed, otherwise it leaks
|
|
|
|
|
* some memory on bailout. */
|
|
|
|
|
{
|
2017-03-11 12:35:21 +00:00
|
|
|
|
std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [obj, method, argc, argv, object, &return_value](v8::Isolate *isolate) {
|
2016-01-01 18:10:04 +00:00
|
|
|
|
int i = 0;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
2017-03-10 23:09:51 +00:00
|
|
|
|
v8::Local<v8::String> method_name = V8JS_SYML(ZSTR_VAL(method), static_cast<int>(ZSTR_LEN(method)));
|
2016-01-01 18:10:04 +00:00
|
|
|
|
v8::Local<v8::Object> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj)->ToObject();
|
|
|
|
|
v8::Local<v8::Object> thisObj;
|
|
|
|
|
v8::Local<v8::Function> cb;
|
2015-12-26 11:16:17 +00:00
|
|
|
|
|
2016-01-01 18:10:04 +00:00
|
|
|
|
if (method_name->Equals(V8JS_SYM(V8JS_V8_INVOKE_FUNC_NAME))) {
|
|
|
|
|
cb = v8::Local<v8::Function>::Cast(v8obj);
|
|
|
|
|
} else {
|
|
|
|
|
cb = v8::Local<v8::Function>::Cast(v8obj->Get(method_name));
|
|
|
|
|
}
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
2016-01-01 18:10:04 +00:00
|
|
|
|
// If a method is invoked on V8Object, then set the object itself as
|
|
|
|
|
// "this" on JS side. Otherwise fall back to global object.
|
|
|
|
|
if (obj->std.ce == php_ce_v8object) {
|
|
|
|
|
thisObj = v8obj;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
thisObj = V8JS_GLOBAL(isolate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::Value> *jsArgv = static_cast<v8::Local<v8::Value> *>(alloca(sizeof(v8::Local<v8::Value>) * argc));
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
2016-01-01 18:10:04 +00:00
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
|
new(&jsArgv[i]) v8::Local<v8::Value>;
|
2017-03-11 12:35:21 +00:00
|
|
|
|
jsArgv[i] = v8::Local<v8::Value>::New(isolate, zval_to_v8js(&argv[i], isolate));
|
2016-01-01 18:10:04 +00:00
|
|
|
|
}
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
2016-05-22 20:30:19 +00:00
|
|
|
|
v8::Local<v8::Value> result = cb->Call(thisObj, argc, jsArgv);
|
2016-03-25 21:15:05 +00:00
|
|
|
|
|
2016-05-22 20:30:19 +00:00
|
|
|
|
if (obj->std.ce == php_ce_v8object && result->StrictEquals(thisObj)) {
|
|
|
|
|
/* JS code did "return this", retain object identity */
|
|
|
|
|
ZVAL_OBJ(return_value, object);
|
|
|
|
|
zval_copy_ctor(return_value);
|
|
|
|
|
result.Clear();
|
|
|
|
|
}
|
2016-03-25 21:15:05 +00:00
|
|
|
|
|
2016-05-22 20:30:19 +00:00
|
|
|
|
return result;
|
2016-01-01 18:10:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
v8js_v8_call(obj->ctx, &return_value, obj->flags, obj->ctx->time_limit, obj->ctx->memory_limit, v8_call);
|
2016-01-01 18:10:04 +00:00
|
|
|
|
}
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
|
efree(argv);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-01 18:10:04 +00:00
|
|
|
|
if(V8JSG(fatal_error_abort)) {
|
|
|
|
|
/* Check for fatal error marker possibly set by v8js_error_handler; just
|
|
|
|
|
* rethrow the error since we're now out of V8. */
|
|
|
|
|
zend_bailout();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static int v8js_v8object_get_closure(zval *object, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **zobj_ptr) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
|
|
|
|
zend_function *invoke;
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (!obj->ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 07:37:32 +00:00
|
|
|
|
V8JS_CTX_PROLOGUE_EX(obj->ctx, FAILURE);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
|
|
|
|
|
|
|
|
if (!v8obj->IsFunction()) {
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
invoke = (zend_function *) ecalloc(1, sizeof(*invoke));
|
|
|
|
|
invoke->type = ZEND_OVERLOADED_FUNCTION_TEMPORARY;
|
2015-08-29 14:47:37 +00:00
|
|
|
|
invoke->common.function_name = zend_string_init(V8JS_V8_INVOKE_FUNC_NAME, sizeof(V8JS_V8_INVOKE_FUNC_NAME) - 1, 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
*fptr_ptr = invoke;
|
|
|
|
|
|
|
|
|
|
if (zobj_ptr) {
|
2015-08-29 14:47:37 +00:00
|
|
|
|
*zobj_ptr = Z_OBJ_P(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*ce_ptr = NULL;
|
|
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static void v8js_v8object_free_storage(zend_object *object) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *c = v8js_v8object_fetch_object(object);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if (c->properties) {
|
|
|
|
|
zend_hash_destroy(c->properties);
|
|
|
|
|
FREE_HASHTABLE(c->properties);
|
|
|
|
|
c->properties = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
zend_object_std_dtor(&c->std);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
if(c->ctx) {
|
|
|
|
|
c->v8obj.Reset();
|
2014-12-12 23:13:03 +00:00
|
|
|
|
c->ctx->v8js_v8objects.remove(c);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
static zend_object *v8js_v8object_new(zend_class_entry *ce) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2014-12-12 23:13:03 +00:00
|
|
|
|
v8js_v8object *c;
|
2015-08-29 14:47:37 +00:00
|
|
|
|
c = (v8js_v8object *) ecalloc(1, sizeof(v8js_v8object) + zend_object_properties_size(ce));
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
zend_object_std_init(&c->std, ce);
|
2015-08-29 16:52:30 +00:00
|
|
|
|
c->std.handlers = &v8js_v8object_handlers;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
new(&c->v8obj) v8::Persistent<v8::Value>();
|
|
|
|
|
|
2015-08-29 14:47:37 +00:00
|
|
|
|
return &c->std;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2014-12-12 23:28:09 +00:00
|
|
|
|
/* NOTE: We could also override v8js_v8object_handlers.get_constructor to throw
|
2014-12-12 22:59:28 +00:00
|
|
|
|
* an exception when invoked, but doing so causes the half-constructed object
|
|
|
|
|
* to leak -- this seems to be a PHP bug. So we'll define magic __construct
|
|
|
|
|
* methods instead. */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto V8Object::__construct()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Object,__construct)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't directly construct V8 objects!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto V8Object::__sleep()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Object, __sleep)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"You cannot serialize or unserialize V8Object instances", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto V8Object::__wakeup()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Object, __wakeup)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"You cannot serialize or unserialize V8Object instances", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto V8Function::__construct()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Function,__construct)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't directly construct V8 objects!", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto V8Function::__sleep()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Function, __sleep)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"You cannot serialize or unserialize V8Function instances", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto V8Function::__wakeup()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Function, __wakeup)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"You cannot serialize or unserialize V8Function instances", 0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2016-01-07 19:40:36 +00:00
|
|
|
|
|
2016-01-07 20:35:44 +00:00
|
|
|
|
static void v8js_v8generator_free_storage(zend_object *object) /* {{{ */
|
|
|
|
|
{
|
|
|
|
|
v8js_v8generator *c = v8js_v8generator_fetch_object(object);
|
2016-08-11 23:02:56 +00:00
|
|
|
|
zval_ptr_dtor(&c->value);
|
2016-01-07 20:35:44 +00:00
|
|
|
|
|
|
|
|
|
v8js_v8object_free_storage(object);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
static zend_object *v8js_v8generator_new(zend_class_entry *ce) /* {{{ */
|
|
|
|
|
{
|
2016-01-07 21:41:13 +00:00
|
|
|
|
v8js_v8generator *c;
|
|
|
|
|
c = (v8js_v8generator *) ecalloc(1, sizeof(v8js_v8generator) + zend_object_properties_size(ce));
|
2016-01-07 20:35:44 +00:00
|
|
|
|
|
2016-01-07 21:41:13 +00:00
|
|
|
|
zend_object_std_init(&c->v8obj.std, ce);
|
|
|
|
|
c->v8obj.std.handlers = &v8js_v8generator_handlers;
|
|
|
|
|
new(&c->v8obj.v8obj) v8::Persistent<v8::Value>();
|
2016-01-07 20:35:44 +00:00
|
|
|
|
|
2016-01-07 21:41:13 +00:00
|
|
|
|
return &c->v8obj.std;
|
2016-01-07 20:35:44 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
static void v8js_v8generator_next(v8js_v8generator *g) /* {{{ */
|
|
|
|
|
{
|
|
|
|
|
if (!g->v8obj.ctx) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
|
|
|
|
"Can't access V8Generator after V8Js instance is destroyed!", 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* std::function relies on its dtor to be executed, otherwise it leaks
|
|
|
|
|
* some memory on bailout. */
|
|
|
|
|
{
|
|
|
|
|
std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [g](v8::Isolate *isolate) {
|
|
|
|
|
v8::Local<v8::String> method_name = V8JS_STR("next");
|
|
|
|
|
v8::Local<v8::Object> v8obj = v8::Local<v8::Value>::New(isolate, g->v8obj.v8obj)->ToObject();
|
|
|
|
|
v8::Local<v8::Function> cb = v8::Local<v8::Function>::Cast(v8obj->Get(method_name));;
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::Value> result = cb->Call(v8obj, 0, NULL);
|
|
|
|
|
|
2016-01-07 22:12:43 +00:00
|
|
|
|
if(result.IsEmpty()) {
|
|
|
|
|
/* cb->Call probably threw (and already threw a zend exception), just return */
|
|
|
|
|
return V8JS_NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 20:35:44 +00:00
|
|
|
|
if(!result->IsObject()) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
|
|
|
|
"V8Generator returned non-object on next()", 0);
|
|
|
|
|
return V8JS_NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v8::Local<v8::Object> resultObj = result->ToObject();
|
|
|
|
|
v8::Local<v8::Value> val = resultObj->Get(V8JS_STR("value"));
|
|
|
|
|
v8::Local<v8::Value> done = resultObj->Get(V8JS_STR("done"));
|
|
|
|
|
|
2016-08-11 23:02:56 +00:00
|
|
|
|
zval_ptr_dtor(&g->value);
|
2016-01-07 20:35:44 +00:00
|
|
|
|
v8js_to_zval(val, &g->value, 0, isolate);
|
|
|
|
|
|
|
|
|
|
g->done = done->IsTrue();
|
|
|
|
|
g->primed = true;
|
|
|
|
|
return V8JS_NULL;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
v8js_v8_call(g->v8obj.ctx, NULL, g->v8obj.flags, g->v8obj.ctx->time_limit, g->v8obj.ctx->memory_limit, v8_call);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(V8JSG(fatal_error_abort)) {
|
|
|
|
|
/* Check for fatal error marker possibly set by v8js_error_handler; just
|
|
|
|
|
* rethrow the error since we're now out of V8. */
|
|
|
|
|
zend_bailout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2016-01-07 21:41:13 +00:00
|
|
|
|
static zend_function *v8js_v8generator_get_method(zend_object **object_ptr, zend_string *method, const zval *key) /* {{{ */
|
|
|
|
|
{
|
|
|
|
|
zend_function *result = std_object_handlers.get_method(object_ptr, method, key);
|
|
|
|
|
|
|
|
|
|
if(!result) {
|
|
|
|
|
result = v8js_v8object_get_method(object_ptr, method, key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2016-01-07 20:35:44 +00:00
|
|
|
|
|
2016-01-07 19:40:36 +00:00
|
|
|
|
/* {{{ proto V8Generator::__construct()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Generator,__construct)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"Can't directly construct V8 objects!", 0);
|
2016-01-07 19:40:36 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto V8Generator::__sleep()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Generator, __sleep)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"You cannot serialize or unserialize V8Generator instances", 0);
|
2016-01-07 19:40:36 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto V8Generator::__wakeup()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Generator, __wakeup)
|
|
|
|
|
{
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"You cannot serialize or unserialize V8Generator instances", 0);
|
2016-01-07 19:40:36 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ mixed V8Generator::current()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Generator, current)
|
|
|
|
|
{
|
2016-01-07 20:35:44 +00:00
|
|
|
|
v8js_v8generator *g = Z_V8JS_V8GENERATOR_OBJ_P(getThis());
|
2016-01-07 21:41:13 +00:00
|
|
|
|
|
|
|
|
|
if(!g->primed) {
|
|
|
|
|
v8js_v8generator_next(g);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 20:35:44 +00:00
|
|
|
|
RETVAL_ZVAL(&g->value, 1, 0);
|
2016-01-07 19:40:36 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ scalar V8Generator::key()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Generator, key)
|
|
|
|
|
{
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ void V8Generator::next()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Generator, next)
|
|
|
|
|
{
|
2016-01-07 20:35:44 +00:00
|
|
|
|
v8js_v8generator *g = Z_V8JS_V8GENERATOR_OBJ_P(getThis());
|
|
|
|
|
v8js_v8generator_next(g);
|
2016-01-07 19:40:36 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ void V8Generator::rewind()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Generator, rewind)
|
|
|
|
|
{
|
2016-01-07 21:48:01 +00:00
|
|
|
|
v8js_v8generator *g = Z_V8JS_V8GENERATOR_OBJ_P(getThis());
|
|
|
|
|
|
|
|
|
|
if(g->primed) {
|
|
|
|
|
zend_throw_exception(php_ce_v8js_exception,
|
2017-03-11 12:35:21 +00:00
|
|
|
|
"V8Generator::rewind not supported by ES6", 0);
|
2016-01-07 21:48:01 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 19:40:36 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ boolean V8Generator::valid()
|
|
|
|
|
*/
|
|
|
|
|
PHP_METHOD(V8Generator, valid)
|
|
|
|
|
{
|
2016-01-07 20:35:44 +00:00
|
|
|
|
v8js_v8generator *g = Z_V8JS_V8GENERATOR_OBJ_P(getThis());
|
|
|
|
|
|
|
|
|
|
if(!g->primed) {
|
|
|
|
|
v8js_v8generator_next(g);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETVAL_BOOL(!g->done);
|
2016-01-07 19:40:36 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
2017-03-11 12:35:21 +00:00
|
|
|
|
void v8js_v8object_create(zval *res, v8::Local<v8::Value> value, int flags, v8::Isolate *isolate) /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
{
|
2014-12-13 00:15:29 +00:00
|
|
|
|
v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
2016-01-07 19:40:36 +00:00
|
|
|
|
if(value->IsGeneratorObject()) {
|
|
|
|
|
object_init_ex(res, php_ce_v8generator);
|
|
|
|
|
}
|
2016-05-22 21:47:36 +00:00
|
|
|
|
else if(value->IsFunction()) {
|
2016-01-07 19:40:36 +00:00
|
|
|
|
object_init_ex(res, php_ce_v8function);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
object_init_ex(res, php_ce_v8object);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-29 14:47:37 +00:00
|
|
|
|
v8js_v8object *c = Z_V8JS_V8OBJECT_OBJ_P(res);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
c->v8obj.Reset(isolate, value);
|
|
|
|
|
c->flags = flags;
|
|
|
|
|
c->ctx = ctx;
|
|
|
|
|
|
2014-12-12 23:13:03 +00:00
|
|
|
|
ctx->v8js_v8objects.push_front(c);
|
2014-12-12 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
2014-12-12 23:28:09 +00:00
|
|
|
|
static const zend_function_entry v8js_v8object_methods[] = { /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
PHP_ME(V8Object, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
|
|
|
|
|
PHP_ME(V8Object, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
|
|
|
|
PHP_ME(V8Object, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2014-12-12 23:28:09 +00:00
|
|
|
|
static const zend_function_entry v8js_v8function_methods[] = { /* {{{ */
|
2014-12-12 22:59:28 +00:00
|
|
|
|
PHP_ME(V8Function, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
|
|
|
|
|
PHP_ME(V8Function, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
|
|
|
|
PHP_ME(V8Function, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2016-01-07 21:41:13 +00:00
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_current, 0)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_key, 0)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_next, 0)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_rewind, 0)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_v8generator_valid, 0)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
2016-01-07 19:40:36 +00:00
|
|
|
|
static const zend_function_entry v8js_v8generator_methods[] = { /* {{{ */
|
2016-01-07 21:41:13 +00:00
|
|
|
|
PHP_ME(V8Generator, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
|
|
|
|
|
PHP_ME(V8Generator, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
|
|
|
|
PHP_ME(V8Generator, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
2016-01-07 19:40:36 +00:00
|
|
|
|
|
2016-01-07 21:41:13 +00:00
|
|
|
|
PHP_ME(V8Generator, current, arginfo_v8generator_current, ZEND_ACC_PUBLIC)
|
|
|
|
|
PHP_ME(V8Generator, key, arginfo_v8generator_key, ZEND_ACC_PUBLIC)
|
|
|
|
|
PHP_ME(V8Generator, next, arginfo_v8generator_next, ZEND_ACC_PUBLIC)
|
|
|
|
|
PHP_ME(V8Generator, rewind, arginfo_v8generator_rewind, ZEND_ACC_PUBLIC)
|
|
|
|
|
PHP_ME(V8Generator, valid, arginfo_v8generator_valid, ZEND_ACC_PUBLIC)
|
2016-01-07 19:40:36 +00:00
|
|
|
|
|
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
|
|
|
|
|
{
|
|
|
|
|
zend_class_entry ce;
|
|
|
|
|
|
|
|
|
|
/* V8Object Class */
|
2014-12-12 23:28:09 +00:00
|
|
|
|
INIT_CLASS_ENTRY(ce, "V8Object", v8js_v8object_methods);
|
2017-03-11 12:35:21 +00:00
|
|
|
|
php_ce_v8object = zend_register_internal_class(&ce);
|
2014-12-12 23:28:09 +00:00
|
|
|
|
php_ce_v8object->ce_flags |= ZEND_ACC_FINAL;
|
|
|
|
|
php_ce_v8object->create_object = v8js_v8object_new;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
/* V8Function Class */
|
2014-12-12 23:28:09 +00:00
|
|
|
|
INIT_CLASS_ENTRY(ce, "V8Function", v8js_v8function_methods);
|
2017-03-11 12:35:21 +00:00
|
|
|
|
php_ce_v8function = zend_register_internal_class(&ce);
|
2014-12-12 23:28:09 +00:00
|
|
|
|
php_ce_v8function->ce_flags |= ZEND_ACC_FINAL;
|
|
|
|
|
php_ce_v8function->create_object = v8js_v8object_new;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
|
2016-01-07 19:40:36 +00:00
|
|
|
|
/* V8Generator Class */
|
|
|
|
|
INIT_CLASS_ENTRY(ce, "V8Generator", v8js_v8generator_methods);
|
2017-03-11 12:35:21 +00:00
|
|
|
|
php_ce_v8generator = zend_register_internal_class(&ce);
|
2016-01-07 19:40:36 +00:00
|
|
|
|
php_ce_v8generator->ce_flags |= ZEND_ACC_FINAL;
|
2016-01-07 20:35:44 +00:00
|
|
|
|
php_ce_v8generator->create_object = v8js_v8generator_new;
|
2016-01-07 19:40:36 +00:00
|
|
|
|
|
|
|
|
|
zend_class_implements(php_ce_v8generator, 1, zend_ce_iterator);
|
|
|
|
|
|
|
|
|
|
|
2014-12-12 22:59:28 +00:00
|
|
|
|
/* V8<Object|Function> handlers */
|
2014-12-12 23:28:09 +00:00
|
|
|
|
memcpy(&v8js_v8object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
|
|
|
|
v8js_v8object_handlers.clone_obj = NULL;
|
|
|
|
|
v8js_v8object_handlers.cast_object = NULL;
|
|
|
|
|
v8js_v8object_handlers.get_property_ptr_ptr = NULL;
|
|
|
|
|
v8js_v8object_handlers.has_property = v8js_v8object_has_property;
|
|
|
|
|
v8js_v8object_handlers.read_property = v8js_v8object_read_property;
|
|
|
|
|
v8js_v8object_handlers.write_property = v8js_v8object_write_property;
|
|
|
|
|
v8js_v8object_handlers.unset_property = v8js_v8object_unset_property;
|
|
|
|
|
v8js_v8object_handlers.get_properties = v8js_v8object_get_properties;
|
|
|
|
|
v8js_v8object_handlers.get_method = v8js_v8object_get_method;
|
|
|
|
|
v8js_v8object_handlers.call_method = v8js_v8object_call_method;
|
|
|
|
|
v8js_v8object_handlers.get_debug_info = v8js_v8object_get_debug_info;
|
|
|
|
|
v8js_v8object_handlers.get_closure = v8js_v8object_get_closure;
|
2016-01-07 20:35:44 +00:00
|
|
|
|
v8js_v8object_handlers.offset = XtOffsetOf(struct v8js_v8object, std);
|
|
|
|
|
v8js_v8object_handlers.free_obj = v8js_v8object_free_storage;
|
|
|
|
|
|
|
|
|
|
/* V8Generator handlers */
|
|
|
|
|
memcpy(&v8js_v8generator_handlers, &v8js_v8object_handlers, sizeof(zend_object_handlers));
|
2016-01-07 21:41:13 +00:00
|
|
|
|
v8js_v8generator_handlers.get_method = v8js_v8generator_get_method;
|
2016-01-07 20:35:44 +00:00
|
|
|
|
v8js_v8generator_handlers.offset = XtOffsetOf(struct v8js_v8generator, v8obj.std);
|
|
|
|
|
v8js_v8generator_handlers.free_obj = v8js_v8generator_free_storage;
|
2015-03-12 11:13:33 +00:00
|
|
|
|
|
|
|
|
|
return SUCCESS;
|
2014-12-12 22:59:28 +00:00
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* tab-width: 4
|
|
|
|
|
* c-basic-offset: 4
|
2016-07-02 20:41:01 +00:00
|
|
|
|
* indent-tabs-mode: t
|
2014-12-12 22:59:28 +00:00
|
|
|
|
* End:
|
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
|
*/
|