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

Create temporary HandleScope while reading properties

This commit is contained in:
Stefan Siegl 2013-10-03 01:05:03 +02:00
parent ab5fe1d4b6
commit 1f4caaeead
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,28 @@
--TEST--
Test V8::executeString() : Call passed-back function (property access)
--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 = $exports->hello;
echo $v8->executeString('PHP.func();')."\n";
?>
===EOF===
--EXPECT--
hello
===EOF===

View File

@ -118,6 +118,12 @@ static zval *php_v8js_v8_read_property(zval *object, zval *member, int type ZEND
if (Z_TYPE_P(member) == IS_STRING && obj->v8obj->IsObject() && !obj->v8obj->IsFunction()) if (Z_TYPE_P(member) == IS_STRING && obj->v8obj->IsObject() && !obj->v8obj->IsFunction())
{ {
v8::Locker locker(obj->isolate);
v8::Isolate::Scope isolate_scope(obj->isolate);
v8::HandleScope local_scope(obj->isolate);
v8::Local<v8::Context> temp_context = v8::Context::New(obj->isolate);
v8::Context::Scope temp_scope(temp_context);
v8::Local<v8::Object> jsObj = obj->v8obj->ToObject(); v8::Local<v8::Object> jsObj = obj->v8obj->ToObject();
v8::Local<v8::String> jsKey = V8JS_STRL(Z_STRVAL_P(member), Z_STRLEN_P(member)); v8::Local<v8::String> jsKey = V8JS_STRL(Z_STRVAL_P(member), Z_STRLEN_P(member));
v8::Local<v8::Value> jsVal; v8::Local<v8::Value> jsVal;