0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-09 15:18:41 +00:00

Merge pull request #38 from stesie/fix-function-passback

Fix php_v8js_hash_to_jsobj for v8 functions
This commit is contained in:
Patrick Reilly 2013-10-02 15:50:00 -07:00
commit ab5fe1d4b6
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;