0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 14:01:53 +00:00

Unlock isolate on JS->PHP transition.

This commit is contained in:
Stefan Siegl 2013-10-12 22:51:23 +02:00
parent d69f2be50a
commit 3f049d3b91
2 changed files with 51 additions and 8 deletions

View File

@ -0,0 +1,36 @@
<?php
class LineProcessor {
protected $_processor;
public function readLineLoop() {
$fh = fopen('php://stdin', 'r');
$p = $this->_processor;
while(($line = fgets($fh))) {
echo $p($line);
}
}
public function setProcessor($p) {
$this->_processor = $p;
}
}
$v8 = new V8Js();
$v8->lp = new LineProcessor();
$v8->startDebugAgent('LineProcessor', 9222, V8Js::DEBUG_AUTO_BREAK_NEVER);
$JS = <<< EOT
print("Hello LineProcessor User!\\n");
PHP.lp.setProcessor(function (foo) {
return foo.toUpperCase();
});
PHP.lp.readLineLoop();
EOT;
$v8->executeString($JS, 'processor.js');

View File

@ -125,15 +125,22 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct
}
fci.no_separation = 1;
/* zend_fcall_info_cache */
fcc.initialized = 1;
fcc.function_handler = method_ptr;
fcc.calling_scope = ce;
fcc.called_scope = ce;
fcc.object_ptr = value;
{
isolate->Exit();
v8::Unlocker unlocker(isolate);
/* Call the method */
zend_call_function(&fci, &fcc TSRMLS_CC);
/* zend_fcall_info_cache */
fcc.initialized = 1;
fcc.function_handler = method_ptr;
fcc.calling_scope = ce;
fcc.called_scope = ce;
fcc.object_ptr = value;
/* Call the method */
zend_call_function(&fci, &fcc TSRMLS_CC);
}
isolate->Enter();
failure:
/* Cleanup */