0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 16:35:19 +00:00

Pass back v8 functions, don't re-wrap

This commit is contained in:
Stefan Siegl 2013-10-03 00:34:50 +02:00
parent 7f147478e1
commit 662e491e1f
4 changed files with 42 additions and 10 deletions

View File

@ -129,6 +129,16 @@ struct php_v8js_timer_ctx
php_v8js_ctx *v8js_ctx;
};
/* {{{ Object container */
struct php_v8js_object {
zend_object std;
v8::Persistent<v8::Value> v8obj;
int flags;
v8::Isolate *isolate;
};
/* }}} */
/* Module globals */
ZEND_BEGIN_MODULE_GLOBALS(v8js)
int v8_initialized;

View File

@ -0,0 +1,28 @@
--TEST--
Test V8::executeString() : Call passed-back function
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$v8 = new V8Js();
$JS = <<< EOT
(function(exports) {
// begin module code
exports.hello = function() { return 'hello'; };
// end module code
return exports;
})({})
EOT;
$exports = $v8->executeString($JS, 'basic.js');
$v8->func = get_object_vars( $exports )['hello'];
echo $v8->executeString('PHP.func();')."\n";
?>
===EOF===
--EXPECT--
hello
===EOF===

View File

@ -101,15 +101,6 @@ struct php_v8js_jsext {
};
/* }}} */
/* {{{ Object container */
struct php_v8js_object {
zend_object std;
v8::Persistent<v8::Value> v8obj;
int flags;
v8::Isolate *isolate;
};
/* }}} */
#ifdef COMPILE_DL_V8JS
ZEND_GET_MODULE(v8js)
#endif

View File

@ -371,7 +371,10 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
}
/* Object methods */
if (ce) {
if (ce == php_ce_v8_function) {
php_v8js_object *c = (php_v8js_object *) zend_object_store_get_object(value TSRMLS_CC);
return c->v8obj;
} else if (ce) {
v8::Handle<v8::FunctionTemplate> new_tpl;
bool cached_tpl = true;
static TemplateCache tpl_map;