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

Commit ed7f151

Browse files
committed
Fix segfault when zero args passed to V8\FunctionObject::NewInstance()
1 parent b446a1e commit ed7f151

3 files changed

+44
-3
lines changed

Diff for: src/php_v8_function.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static PHP_METHOD(V8Function, __construct) {
345345

346346
static PHP_METHOD(V8Function, NewInstance) {
347347
zval *php_v8_context_zv;
348-
zval* arguments_zv;
348+
zval *arguments_zv = NULL;
349349

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

389389
static PHP_METHOD(V8Function, Call) {
390390
zval *php_v8_context_zv;
391-
zval *php_v8_recv_zv = NULL;
391+
zval *php_v8_recv_zv;
392392
zval *arguments_zv = NULL;
393393

394394
int argc = 0;

Diff for: tests/V8FunctionObject_NewInstance.phpt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
V8\FunctionObject::NewInstance()
3+
--SKIPIF--
4+
<?php if (!extension_loaded("v8")) {
5+
print "skip";
6+
} ?>
7+
--FILE--
8+
<?php
9+
/** @var \Phpv8Testsuite $helper */
10+
$helper = require '.testsuite.php';
11+
12+
require '.v8-helpers.php';
13+
$v8_helper = new PhpV8Helpers($helper);
14+
15+
16+
// Tests:
17+
18+
$isolate = new \V8\Isolate();
19+
$context = new \V8\Context($isolate);
20+
21+
$global= $context->GlobalObject();
22+
23+
24+
$tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $args) {
25+
echo 'called as ', $args->IsConstructCall() ? 'constructor' : 'function', ' ';
26+
echo 'with ', count($args->Arguments()), ' arguments';
27+
28+
echo PHP_EOL;
29+
});
30+
31+
32+
$tpl->GetFunction($context)->NewInstance($context);
33+
$tpl->GetFunction($context)->NewInstance($context, [new \V8\StringValue($isolate, 'argument1')]);
34+
$tpl->GetFunction($context)->NewInstance($context, [new \V8\ObjectValue($context)]);
35+
36+
37+
?>
38+
--EXPECT--
39+
called as constructor with 0 arguments
40+
called as constructor with 1 arguments
41+
called as constructor with 1 arguments

Diff for: tests/V8ObjectTemplate_SetHandlerForNamedProperty.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $getter = function (\V8\NameValue $name, \V8\PropertyCallbackInfo $info) use (&$
2727
$info->GetReturnValue()->Set(new \V8\NumberValue($info->GetIsolate(), $foo));
2828
};
2929

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

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

0 commit comments

Comments
 (0)