mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 16:28:41 +00:00
Pass back v8 functions, don't re-wrap
This commit is contained in:
parent
7f147478e1
commit
662e491e1f
@ -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;
|
||||
|
28
tests/function_passback.phpt
Normal file
28
tests/function_passback.phpt
Normal 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===
|
9
v8js.cc
9
v8js.cc
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user