mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 15:18:41 +00:00
Unlock isolate on JS->PHP transition.
This commit is contained in:
parent
d69f2be50a
commit
3f049d3b91
36
samples/debug_callback_line_processor.php
Normal file
36
samples/debug_callback_line_processor.php
Normal 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');
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user