0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-16 19:15:17 +00:00

Catch serialization of V8Function instances

This commit is contained in:
Stefan Siegl 2014-12-11 22:28:01 +01:00
parent 73d022cca1
commit af58f4ec9e
2 changed files with 80 additions and 0 deletions

58
tests/serialize_002.phpt Normal file
View File

@ -0,0 +1,58 @@
--TEST--
Test serialize(V8Function) : __sleep and __wakeup throw
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$v8 = new V8Js();
$obj = $v8->executeString('(function() { })');
var_dump($obj);
try {
$stored = serialize($obj);
}
catch(\V8JsException $e) {
var_dump(get_class($e));
var_dump($e->getMessage());
}
$stored = 'O:10:"V8Function":0:{}';
try {
$obj2 = unserialize($stored);
}
catch(\V8JsException $e) {
var_dump(get_class($e));
var_dump($e->getMessage());
}
var_dump(isset($obj2));
$stored = 'O:10:"V8Function":1:{s:3:"foo";i:23;}';
try {
$obj = unserialize($stored);
}
catch(\V8JsException $e) {
var_dump(get_class($e));
var_dump($e->getMessage());
}
var_dump(isset($obj3));
?>
===EOF===
--EXPECT--
object(V8Function)#2 (0) {
}
string(13) "V8JsException"
string(56) "You cannot serialize or unserialize V8Function instances"
string(13) "V8JsException"
string(56) "You cannot serialize or unserialize V8Function instances"
bool(false)
string(13) "V8JsException"
string(56) "You cannot serialize or unserialize V8Function instances"
bool(false)
===EOF===

22
v8js.cc
View File

@ -649,6 +649,26 @@ PHP_METHOD(V8Function,__construct)
}
/* }}} */
/* {{{ proto V8Function::__sleep()
*/
PHP_METHOD(V8Function, __sleep)
{
zend_throw_exception(php_ce_v8js_exception,
"You cannot serialize or unserialize V8Function instances", 0 TSRMLS_CC);
RETURN_FALSE;
}
/* }}} */
/* {{{ proto V8Function::__wakeup()
*/
PHP_METHOD(V8Function, __wakeup)
{
zend_throw_exception(php_ce_v8js_exception,
"You cannot serialize or unserialize V8Function instances", 0 TSRMLS_CC);
RETURN_FALSE;
}
/* }}} */
void php_v8js_create_v8(zval *res, v8::Handle<v8::Value> value, int flags, v8::Isolate *isolate TSRMLS_DC) /* {{{ */
{
php_v8js_ctx *ctx = (php_v8js_ctx *) isolate->GetData(0);
@ -1954,6 +1974,8 @@ static const zend_function_entry v8_object_methods[] = { /* {{{ */
static const zend_function_entry v8_function_methods[] = { /* {{{ */
PHP_ME(V8Function, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(V8Function, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(V8Function, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
{NULL, NULL, NULL}
};
/* }}} */