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

Don't export methods of V8Js object to V8

This commit is contained in:
Stefan Siegl 2016-01-09 19:02:58 +01:00
parent e0f990bfa1
commit 1e86e2c9f7
2 changed files with 74 additions and 1 deletions

57
tests/issue_183_003.phpt Normal file
View File

@ -0,0 +1,57 @@
--TEST--
Test V8::executeString() : Method access on derived classes (V8Js methods)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
class Foo extends \V8Js
{
public function hello()
{
print("Hello World\n");
}
}
$JS = <<< EOT
var_dump(typeof PHP.hello);
var_dump(typeof PHP.executeString);
var_dump(typeof PHP.compileString);
var_dump(typeof PHP.executeScript);
var_dump(typeof PHP.checkString);
var_dump(typeof PHP.getPendingException);
var_dump(typeof PHP.setModuleNormaliser);
var_dump(typeof PHP.setModuleLoader);
var_dump(typeof PHP.registerExtension);
var_dump(typeof PHP.getExtensions);
var_dump(typeof PHP.setTimeLimit);
var_dump(typeof PHP.setMemoryLimit);
try {
PHP.setTimeLimit(100);
}
catch(e) {
var_dump('caught');
}
EOT;
$v8 = new Foo();
$v8->executeString($JS);
?>
===EOF===
--EXPECTF--
string(8) "function"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(9) "undefined"
string(6) "caught"
===EOF===

View File

@ -46,6 +46,9 @@ static zend_class_entry *php_ce_v8js;
static zend_object_handlers v8js_object_handlers;
/* }}} */
/* Forward declare v8js_methods, actually "static" but not possible in C++ */
extern const zend_function_entry v8js_methods[];
typedef struct _v8js_script {
char *name;
v8js_ctx *ctx;
@ -526,6 +529,19 @@ static PHP_METHOD(V8Js, __construct)
continue;
}
const zend_function_entry *fe;
for (fe = v8js_methods; fe->fname; fe ++) {
if (fe->fname == method_ptr->common.function_name) {
break;
}
}
if(fe->fname) {
/* Method belongs to \V8Js class itself, never export to V8, even if
* it is overriden in a derived class. */
continue;
}
v8::Local<v8::String> method_name = V8JS_STR(method_ptr->common.function_name);
v8::Local<v8::FunctionTemplate> ft;
@ -1119,7 +1135,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmemorylimit, 0, 0, 1)
ZEND_END_ARG_INFO()
static const zend_function_entry v8js_methods[] = { /* {{{ */
const zend_function_entry v8js_methods[] = { /* {{{ */
PHP_ME(V8Js, __construct, arginfo_v8js_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(V8Js, __sleep, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(V8Js, __wakeup, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)