Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Fix segfault when zero args passed to V8\FunctionObject::NewInstance()
Browse files Browse the repository at this point in the history
  • Loading branch information
pinepain committed May 2, 2017
1 parent b446a1e commit ed7f151
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/php_v8_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static PHP_METHOD(V8Function, __construct) {

static PHP_METHOD(V8Function, NewInstance) {
zval *php_v8_context_zv;
zval* arguments_zv;
zval *arguments_zv = NULL;

int argc = 0;
v8::Local<v8::Value> *argv = NULL;
Expand Down Expand Up @@ -388,7 +388,7 @@ static PHP_METHOD(V8Function, NewInstance) {

static PHP_METHOD(V8Function, Call) {
zval *php_v8_context_zv;
zval *php_v8_recv_zv = NULL;
zval *php_v8_recv_zv;
zval *arguments_zv = NULL;

int argc = 0;
Expand Down
41 changes: 41 additions & 0 deletions tests/V8FunctionObject_NewInstance.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
V8\FunctionObject::NewInstance()
--SKIPIF--
<?php if (!extension_loaded("v8")) {
print "skip";
} ?>
--FILE--
<?php
/** @var \Phpv8Testsuite $helper */
$helper = require '.testsuite.php';

require '.v8-helpers.php';
$v8_helper = new PhpV8Helpers($helper);


// Tests:

$isolate = new \V8\Isolate();
$context = new \V8\Context($isolate);

$global= $context->GlobalObject();


$tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $args) {
echo 'called as ', $args->IsConstructCall() ? 'constructor' : 'function', ' ';
echo 'with ', count($args->Arguments()), ' arguments';

echo PHP_EOL;
});


$tpl->GetFunction($context)->NewInstance($context);
$tpl->GetFunction($context)->NewInstance($context, [new \V8\StringValue($isolate, 'argument1')]);
$tpl->GetFunction($context)->NewInstance($context, [new \V8\ObjectValue($context)]);


?>
--EXPECT--
called as constructor with 0 arguments
called as constructor with 1 arguments
called as constructor with 1 arguments
2 changes: 1 addition & 1 deletion tests/V8ObjectTemplate_SetHandlerForNamedProperty.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $getter = function (\V8\NameValue $name, \V8\PropertyCallbackInfo $info) use (&$
$info->GetReturnValue()->Set(new \V8\NumberValue($info->GetIsolate(), $foo));
};

$setter = function (\V8\NameValue$name, \V8\Value $value, \V8\PropertyCallbackInfo $info) use (&$foo) {
$setter = function (\V8\NameValue $name, \V8\Value $value, \V8\PropertyCallbackInfo $info) use (&$foo) {
echo 'I am named setter for ', $name->ToString($info->GetContext())->Value(), '!', PHP_EOL;

$foo = $value->ToNumber($info->GetContext())->Value() / 2;
Expand Down

0 comments on commit ed7f151

Please sign in to comment.