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

Commit 89ded89

Browse files
committed
Take V8\FunctionCallbackInfo::Length() method back
1 parent 463b618 commit 89ded89

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/php_v8_function_callback_info.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ php_v8_return_value_t * php_v8_callback_info_create_from_info(zval *return_value
2929
zval tmp;
3030
zval arg_zv;
3131
php_v8_return_value_t *php_v8_return_value;
32-
v8::Local<v8::Value> local_value;
3332

3433
v8::Isolate *isolate = args.GetIsolate();
3534
v8::Local<v8::Context> context = isolate->GetEnteredContext();
@@ -87,6 +86,19 @@ php_v8_return_value_t * php_v8_callback_info_create_from_info(zval *return_value
8786
return php_v8_return_value;
8887
}
8988

89+
static PHP_METHOD(V8FunctionCallbackInfo, Length) {
90+
zval rv;
91+
zval *tmp;
92+
93+
if (zend_parse_parameters_none() == FAILURE) {
94+
return;
95+
}
96+
97+
tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("arguments"), 0, &rv);
98+
99+
RETURN_LONG(zend_array_count(Z_ARRVAL_P(tmp)));
100+
}
101+
90102
static PHP_METHOD(V8FunctionCallbackInfo, Arguments) {
91103
zval rv;
92104
zval *tmp;
@@ -124,6 +136,9 @@ static PHP_METHOD(V8FunctionCallbackInfo, IsConstructCall) {
124136
}
125137

126138

139+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_function_callback_info_Length, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
140+
ZEND_END_ARG_INFO()
141+
127142
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_function_callback_info_Arguments, ZEND_RETURN_VALUE, 0, IS_ARRAY, 0)
128143
ZEND_END_ARG_INFO()
129144

@@ -135,6 +150,7 @@ ZEND_END_ARG_INFO()
135150

136151

137152
static const zend_function_entry php_v8_function_callback_info_methods[] = {
153+
PHP_ME(V8FunctionCallbackInfo, Length, arginfo_v8_function_callback_info_Length, ZEND_ACC_PUBLIC)
138154
PHP_ME(V8FunctionCallbackInfo, Arguments, arginfo_v8_function_callback_info_Arguments, ZEND_ACC_PUBLIC)
139155
PHP_ME(V8FunctionCallbackInfo, NewTarget, arginfo_v8_function_callback_info_NewTarget, ZEND_ACC_PUBLIC)
140156
PHP_ME(V8FunctionCallbackInfo, IsConstructCall, arginfo_v8_function_callback_info_IsConstructCall, ZEND_ACC_PUBLIC)

stubs/src/FunctionCallbackInfo.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
*/
2525
class FunctionCallbackInfo extends CallbackInfo
2626
{
27+
/**
28+
* @return int
29+
*/
30+
public function Length() : int
31+
{
32+
}
33+
2734
/**
2835
* @return Value[] | StringValue[] | SymbolValue[] | NumberValue[] | ObjectValue[] | ArrayObject[] | FunctionObject[] | StringObject[] | SymbolObject[]
2936
*/

tests/V8FunctionCallbackInfo.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ $func = new v8Tests\TrackingDtors\FunctionObject($context1, function (V8\Functio
3333

3434
$callback_info = $info;
3535
$helper->assert('Original arguments number passed', count($info->Arguments()) == 2);
36+
$helper->assert('Arguments number matches Length() method output', count($info->Arguments()) == $info->Length());
3637

3738
$helper->assert('Callback info holds original isolate object', $info->GetIsolate(), $isolate1);
3839
$helper->assert('Callback info holds original isolate object', $info->GetContext(), $context1);
@@ -274,6 +275,7 @@ object(V8\FunctionCallbackInfo)#10 (8) {
274275

275276

276277
Original arguments number passed: ok
278+
Arguments number matches Length() method output: ok
277279
Callback info holds original isolate object: ok
278280
Callback info holds original isolate object: ok
279281
Scalars hold no info about their zval, so that their zvals are recreated on each access: ok

0 commit comments

Comments
 (0)