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

Experiment to see if #172 is easy to fix

This commit is contained in:
Matt Kynaston 2015-11-03 17:35:30 +00:00
parent b29bb886bb
commit a58f944804
2 changed files with 33 additions and 4 deletions

View File

@ -0,0 +1,29 @@
--TEST--
Test V8::executeString() : Set property on 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');
$exports->hello->foo = "bar";
$v8->func = $exports->hello;
$v8->executeString('print(PHP.func.foo + "\n");');
?>
===EOF===
--EXPECT--
bar
===EOF===

View File

@ -63,7 +63,7 @@ static int v8js_v8object_has_property(zval *object, zval *member, int has_set_ex
V8JS_CTX_PROLOGUE_EX(obj->ctx, retval); V8JS_CTX_PROLOGUE_EX(obj->ctx, retval);
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj); v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
if (Z_TYPE_P(member) == IS_STRING && v8obj->IsObject() && !v8obj->IsFunction()) if (Z_TYPE_P(member) == IS_STRING && v8obj->IsObject())
{ {
v8::Local<v8::Object> jsObj = v8obj->ToObject(); v8::Local<v8::Object> jsObj = v8obj->ToObject();
@ -123,7 +123,7 @@ static zval *v8js_v8object_read_property(zval *object, zval *member, int type ZE
V8JS_CTX_PROLOGUE_EX(obj->ctx, retval); V8JS_CTX_PROLOGUE_EX(obj->ctx, retval);
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj); v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
if (Z_TYPE_P(member) == IS_STRING && v8obj->IsObject() && !v8obj->IsFunction()) if (Z_TYPE_P(member) == IS_STRING && v8obj->IsObject())
{ {
v8::Local<v8::Object> jsObj = v8obj->ToObject(); v8::Local<v8::Object> jsObj = v8obj->ToObject();
@ -166,7 +166,7 @@ static void v8js_v8object_write_property(zval *object, zval *member, zval *value
V8JS_CTX_PROLOGUE(obj->ctx); V8JS_CTX_PROLOGUE(obj->ctx);
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj); v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
if (v8obj->IsObject() && !v8obj->IsFunction()) { if (v8obj->IsObject()) {
v8obj->ToObject()->ForceSet(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)), zval_to_v8js(value, isolate TSRMLS_CC)); v8obj->ToObject()->ForceSet(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)), zval_to_v8js(value, isolate TSRMLS_CC));
} }
} }
@ -185,7 +185,7 @@ static void v8js_v8object_unset_property(zval *object, zval *member ZEND_HASH_KE
V8JS_CTX_PROLOGUE(obj->ctx); V8JS_CTX_PROLOGUE(obj->ctx);
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj); v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
if (v8obj->IsObject() && !v8obj->IsFunction()) { if (v8obj->IsObject()) {
v8obj->ToObject()->Delete(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member))); v8obj->ToObject()->Delete(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)));
} }
} }