0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-09 16:28:41 +00:00

Test unserialization with properties

This commit is contained in:
Stefan Siegl 2014-12-11 22:15:38 +01:00
parent c0d1e2fa6d
commit 73d022cca1
3 changed files with 37 additions and 6 deletions

View File

@ -20,6 +20,18 @@ catch(\V8JsException $e) {
$stored = 'O:8:"V8Object":0:{}'; $stored = 'O:8:"V8Object":0:{}';
try {
$obj2 = unserialize($stored);
}
catch(\V8JsException $e) {
var_dump(get_class($e));
var_dump($e->getMessage());
}
var_dump(isset($obj2));
$stored = 'O:8:"V8Object":1:{s:3:"foo";i:23;}';
try { try {
$obj = unserialize($stored); $obj = unserialize($stored);
} }
@ -28,8 +40,7 @@ catch(\V8JsException $e) {
var_dump($e->getMessage()); var_dump($e->getMessage());
} }
$v8->foo = $obj; var_dump(isset($obj3));
?> ?>
===EOF=== ===EOF===
@ -42,4 +53,8 @@ string(13) "V8JsException"
string(54) "You cannot serialize or unserialize V8Object instances" string(54) "You cannot serialize or unserialize V8Object instances"
string(13) "V8JsException" string(13) "V8JsException"
string(54) "You cannot serialize or unserialize V8Object instances" string(54) "You cannot serialize or unserialize V8Object instances"
bool(false)
string(13) "V8JsException"
string(54) "You cannot serialize or unserialize V8Object instances"
bool(false)
===EOF=== ===EOF===

View File

@ -25,6 +25,16 @@ catch(\V8JsException $e) {
var_dump($e->getMessage()); var_dump($e->getMessage());
} }
$stored = 'O:4:"V8Js":1:{s:3:"foo";i:23;}';
try {
$b = unserialize($stored);
}
catch(\V8JsException $e) {
var_dump(get_class($e));
var_dump($e->getMessage());
}
?> ?>
===EOF=== ===EOF===
--EXPECT-- --EXPECT--
@ -32,4 +42,6 @@ string(13) "V8JsException"
string(50) "You cannot serialize or unserialize V8Js instances" string(50) "You cannot serialize or unserialize V8Js instances"
string(13) "V8JsException" string(13) "V8JsException"
string(50) "You cannot serialize or unserialize V8Js instances" string(50) "You cannot serialize or unserialize V8Js instances"
string(13) "V8JsException"
string(50) "You cannot serialize or unserialize V8Js instances"
===EOF=== ===EOF===

12
v8js.cc
View File

@ -385,12 +385,16 @@ static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */
/* the garbage collector is running, don't create more zvals */ /* the garbage collector is running, don't create more zvals */
return NULL; return NULL;
} }
if (obj->ctx == NULL) {
/* Half-constructed object. Shouldn't happen, but be safe. */
return NULL;
}
ALLOC_HASHTABLE(obj->properties); ALLOC_HASHTABLE(obj->properties);
zend_hash_init(obj->properties, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_init(obj->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
if (!obj->ctx) {
/* Half-constructed object, probably due to unserialize call.
* Just pass back properties hash so unserialize can write to
* it (instead of crashing the engine). */
return obj->properties;
}
} else { } else {
zend_hash_clean(obj->properties); zend_hash_clean(obj->properties);
} }