mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 09:21:52 +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:
commit
ab5fe1d4b6
@ -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