0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 00:25:18 +00:00

Catch serialization of V8Object instances

This commit is contained in:
Stefan Siegl 2014-12-11 20:58:53 +01:00
parent dfb6b1db46
commit c0d1e2fa6d
2 changed files with 67 additions and 0 deletions

45
tests/serialize_001.phpt Normal file
View File

@ -0,0 +1,45 @@
--TEST--
Test serialize(V8Object) : __sleep and __wakeup throw
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$v8 = new V8Js();
$obj = $v8->executeString('({ foo: 23 })');
var_dump($obj);
try {
$stored = serialize($obj);
}
catch(\V8JsException $e) {
var_dump(get_class($e));
var_dump($e->getMessage());
}
$stored = 'O:8:"V8Object":0:{}';
try {
$obj = unserialize($stored);
}
catch(\V8JsException $e) {
var_dump(get_class($e));
var_dump($e->getMessage());
}
$v8->foo = $obj;
?>
===EOF===
--EXPECT--
object(V8Object)#2 (1) {
["foo"]=>
int(23)
}
string(13) "V8JsException"
string(54) "You cannot serialize or unserialize V8Object instances"
string(13) "V8JsException"
string(54) "You cannot serialize or unserialize V8Object instances"
===EOF===

22
v8js.cc
View File

@ -615,6 +615,26 @@ PHP_METHOD(V8Object,__construct)
}
/* }}} */
/* {{{ proto V8Object::__sleep()
*/
PHP_METHOD(V8Object, __sleep)
{
zend_throw_exception(php_ce_v8js_exception,
"You cannot serialize or unserialize V8Object instances", 0 TSRMLS_CC);
RETURN_FALSE;
}
/* }}} */
/* {{{ proto V8Object::__wakeup()
*/
PHP_METHOD(V8Object, __wakeup)
{
zend_throw_exception(php_ce_v8js_exception,
"You cannot serialize or unserialize V8Object instances", 0 TSRMLS_CC);
RETURN_FALSE;
}
/* }}} */
/* {{{ proto V8Function::__construct()
*/
PHP_METHOD(V8Function,__construct)
@ -1922,6 +1942,8 @@ ZEND_END_ARG_INFO()
static const zend_function_entry v8_object_methods[] = { /* {{{ */
PHP_ME(V8Object, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(V8Object, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(V8Object, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
{NULL, NULL, NULL}
};
/* }}} */