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

Commit 2695b51

Browse files
committed
Introduce CallbackInfoInterface, closes #72
1 parent d90b4a9 commit 2695b51

12 files changed

+199
-54
lines changed

config.m4

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ if test "$PHP_V8" != "no"; then
211211
src/php_v8_symbol_object.cc \
212212
src/php_v8_template.cc \
213213
src/php_v8_return_value.cc \
214+
src/php_v8_callback_info_interface.cc \
214215
src/php_v8_function_callback_info.cc \
215216
src/php_v8_property_callback_info.cc \
216217
src/php_v8_named_property_handler_configuration.cc \

src/php_v8_callback_info_interface.cc

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This file is part of the pinepain/php-v8 PHP extension.
3+
*
4+
* Copyright (c) 2015-2017 Bogdan Padalko <[email protected]>
5+
*
6+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
7+
*
8+
* For the full copyright and license information, please view the
9+
* LICENSE file that was distributed with this source or visit
10+
* http://opensource.org/licenses/MIT
11+
*/
12+
13+
#ifdef HAVE_CONFIG_H
14+
#include "config.h"
15+
#endif
16+
17+
#include "php_v8_callback_info_interface.h"
18+
#include "php_v8.h"
19+
20+
21+
zend_class_entry *php_v8_callback_info_interface_class_entry;
22+
#define this_ce php_v8_callback_info_interface_class_entry
23+
24+
25+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIsolate, ZEND_RETURN_VALUE, 0, V8\\Isolate, 0)
26+
ZEND_END_ARG_INFO()
27+
28+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0)
29+
ZEND_END_ARG_INFO()
30+
31+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_this, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0)
32+
ZEND_END_ARG_INFO()
33+
34+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_holder, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0)
35+
ZEND_END_ARG_INFO()
36+
37+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getReturnValue, ZEND_RETURN_VALUE, 0, V8\\ReturnValue, 0)
38+
ZEND_END_ARG_INFO()
39+
40+
41+
static const zend_function_entry php_v8_callback_info_interface_methods[] = {
42+
PHP_V8_ABSTRACT_ME(CallbackInfoInterface, getIsolate)
43+
PHP_V8_ABSTRACT_ME(CallbackInfoInterface, getContext)
44+
PHP_V8_ABSTRACT_ME(CallbackInfoInterface, this)
45+
PHP_V8_ABSTRACT_ME(CallbackInfoInterface, holder)
46+
PHP_V8_ABSTRACT_ME(CallbackInfoInterface, getReturnValue)
47+
PHP_FE_END
48+
};
49+
50+
PHP_MINIT_FUNCTION (php_v8_callback_info_interface) {
51+
zend_class_entry ce;
52+
53+
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "CallbackInfoInterface", php_v8_callback_info_interface_methods);
54+
this_ce = zend_register_internal_interface(&ce);
55+
56+
return SUCCESS;
57+
}

src/php_v8_callback_info_interface.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* This file is part of the pinepain/php-v8 PHP extension.
3+
*
4+
* Copyright (c) 2015-2017 Bogdan Padalko <[email protected]>
5+
*
6+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
7+
*
8+
* For the full copyright and license information, please view the
9+
* LICENSE file that was distributed with this source or visit
10+
* http://opensource.org/licenses/MIT
11+
*/
12+
13+
#ifndef PHP_V8_CALLBACK_INFO_H
14+
#define PHP_V8_CALLBACK_INFO_H
15+
16+
extern "C" {
17+
#include "php.h"
18+
19+
#ifdef ZTS
20+
#include "TSRM.h"
21+
#endif
22+
}
23+
24+
extern zend_class_entry* php_v8_callback_info_interface_class_entry;
25+
26+
27+
PHP_MINIT_FUNCTION(php_v8_callback_info_interface);
28+
29+
#endif //PHP_V8_CALLBACK_INFO_H

src/php_v8_function_callback_info.cc

+12-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "php_v8_function_callback_info.h"
1818
#include "php_v8_exceptions.h"
1919
#include "php_v8_return_value.h"
20+
#include "php_v8_callback_info_interface.h"
2021
#include "php_v8_value.h"
2122
#include "php_v8.h"
2223

@@ -85,7 +86,7 @@ php_v8_return_value_t * php_v8_callback_info_create_from_info(zval *return_value
8586
return php_v8_return_value;
8687
}
8788

88-
static PHP_METHOD(CallbackInfo, getIsolate) {
89+
static PHP_METHOD(FunctionCallbackInfo, getIsolate) {
8990
zval rv;
9091
zval *tmp;
9192

@@ -97,7 +98,7 @@ static PHP_METHOD(CallbackInfo, getIsolate) {
9798
ZVAL_COPY(return_value, tmp);
9899
}
99100

100-
static PHP_METHOD(CallbackInfo, getContext) {
101+
static PHP_METHOD(FunctionCallbackInfo, getContext) {
101102
zval rv;
102103
zval *tmp;
103104

@@ -109,7 +110,7 @@ static PHP_METHOD(CallbackInfo, getContext) {
109110
ZVAL_COPY(return_value, tmp);
110111
}
111112

112-
static PHP_METHOD(CallbackInfo, this) {
113+
static PHP_METHOD(FunctionCallbackInfo, this) {
113114
zval rv;
114115
zval *tmp;
115116

@@ -121,7 +122,7 @@ static PHP_METHOD(CallbackInfo, this) {
121122
ZVAL_COPY(return_value, tmp);
122123
}
123124

124-
static PHP_METHOD(CallbackInfo, holder) {
125+
static PHP_METHOD(FunctionCallbackInfo, holder) {
125126
zval rv;
126127
zval *tmp;
127128

@@ -133,7 +134,7 @@ static PHP_METHOD(CallbackInfo, holder) {
133134
ZVAL_COPY(return_value, tmp);
134135
}
135136

136-
static PHP_METHOD(CallbackInfo, getReturnValue) {
137+
static PHP_METHOD(FunctionCallbackInfo, getReturnValue) {
137138
zval rv;
138139
zval *tmp;
139140

@@ -224,11 +225,11 @@ ZEND_END_ARG_INFO()
224225

225226

226227
static const zend_function_entry php_v8_function_callback_info_methods[] = {
227-
PHP_V8_ME(CallbackInfo, this, ZEND_ACC_PUBLIC)
228-
PHP_V8_ME(CallbackInfo, holder, ZEND_ACC_PUBLIC)
229-
PHP_V8_ME(CallbackInfo, getIsolate, ZEND_ACC_PUBLIC)
230-
PHP_V8_ME(CallbackInfo, getContext, ZEND_ACC_PUBLIC)
231-
PHP_V8_ME(CallbackInfo, getReturnValue, ZEND_ACC_PUBLIC)
228+
PHP_V8_ME(FunctionCallbackInfo, getIsolate, ZEND_ACC_PUBLIC)
229+
PHP_V8_ME(FunctionCallbackInfo, getContext, ZEND_ACC_PUBLIC)
230+
PHP_V8_ME(FunctionCallbackInfo, this, ZEND_ACC_PUBLIC)
231+
PHP_V8_ME(FunctionCallbackInfo, holder, ZEND_ACC_PUBLIC)
232+
PHP_V8_ME(FunctionCallbackInfo, getReturnValue, ZEND_ACC_PUBLIC)
232233
PHP_V8_ME(FunctionCallbackInfo, length, ZEND_ACC_PUBLIC)
233234
PHP_V8_ME(FunctionCallbackInfo, arguments, ZEND_ACC_PUBLIC)
234235
PHP_V8_ME(FunctionCallbackInfo, newTarget, ZEND_ACC_PUBLIC)
@@ -241,6 +242,7 @@ PHP_MINIT_FUNCTION(php_v8_function_callback_info) {
241242

242243
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "FunctionCallbackInfo", php_v8_function_callback_info_methods);
243244
this_ce = zend_register_internal_class(&ce);
245+
zend_class_implements(this_ce, 1, php_v8_callback_info_interface_class_entry);
244246

245247
zend_declare_property_null(this_ce, ZEND_STRL("isolate"), ZEND_ACC_PRIVATE);
246248
zend_declare_property_null(this_ce, ZEND_STRL("context"), ZEND_ACC_PRIVATE);

src/php_v8_property_callback_info.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "php_v8_property_callback_info.h"
1818
#include "php_v8_return_value.h"
19+
#include "php_v8_callback_info_interface.h"
1920
#include "php_v8_value.h"
2021
#include "php_v8.h"
2122

@@ -186,10 +187,10 @@ ZEND_END_ARG_INFO()
186187

187188

188189
static const zend_function_entry php_v8_property_callback_info_methods[] = {
189-
PHP_V8_ME(PropertyCallbackInfo, this, ZEND_ACC_PUBLIC)
190-
PHP_V8_ME(PropertyCallbackInfo, holder, ZEND_ACC_PUBLIC)
191190
PHP_V8_ME(PropertyCallbackInfo, getIsolate, ZEND_ACC_PUBLIC)
192191
PHP_V8_ME(PropertyCallbackInfo, getContext, ZEND_ACC_PUBLIC)
192+
PHP_V8_ME(PropertyCallbackInfo, this, ZEND_ACC_PUBLIC)
193+
PHP_V8_ME(PropertyCallbackInfo, holder, ZEND_ACC_PUBLIC)
193194
PHP_V8_ME(PropertyCallbackInfo, getReturnValue, ZEND_ACC_PUBLIC)
194195
PHP_V8_ME(PropertyCallbackInfo, shouldThrowOnError, ZEND_ACC_PUBLIC)
195196
PHP_FE_END
@@ -199,6 +200,7 @@ PHP_MINIT_FUNCTION (php_v8_property_callback_info) {
199200
zend_class_entry ce;
200201
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyCallbackInfo", php_v8_property_callback_info_methods);
201202
this_ce = zend_register_internal_class(&ce);
203+
zend_class_implements(this_ce, 1, php_v8_callback_info_interface_class_entry);
202204

203205
zend_declare_property_null(this_ce, ZEND_STRL("isolate"), ZEND_ACC_PRIVATE);
204206
zend_declare_property_null(this_ce, ZEND_STRL("context"), ZEND_ACC_PRIVATE);

stubs/src/CallbackInfoInterface.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* This file is part of the pinepain/php-v8 PHP extension.
5+
*
6+
* Copyright (c) 2015-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace V8;
17+
18+
interface CallbackInfoInterface
19+
{
20+
/**
21+
* @return Isolate
22+
*/
23+
public function getIsolate(): Isolate;
24+
25+
/**
26+
* @return Context
27+
*/
28+
public function getContext(): Context;
29+
30+
/**
31+
* Returns the receiver. This corresponds to the "this" value.
32+
*
33+
* @return ObjectValue
34+
*/
35+
public function this(): ObjectValue;
36+
37+
/**
38+
* If the callback was created without a Signature, this is the same
39+
* value as This(). If there is a signature, and the signature didn't match
40+
* This() but one of its hidden prototypes, this will be the respective
41+
* hidden prototype.
42+
*
43+
* Note that this is not the prototype of This() on which the accessor
44+
* referencing this callback was found (which in V8 internally is often
45+
* referred to as holder [sic]).
46+
*
47+
* @return ObjectValue
48+
*/
49+
public function holder(): ObjectValue;
50+
51+
/**
52+
* The ReturnValue for the call
53+
*
54+
* @return ReturnValue
55+
*/
56+
public function getReturnValue(): ReturnValue;
57+
}

stubs/src/FunctionCallbackInfo.php

+5-18
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,35 @@
2525
class FunctionCallbackInfo
2626
{
2727
/**
28-
* @return Isolate
28+
* {@inheritdoc}
2929
*/
3030
public function getIsolate(): Isolate
3131
{
3232
}
3333

3434
/**
35-
* @return Context
35+
* {@inheritdoc}
3636
*/
3737
public function getContext(): Context
3838
{
3939
}
4040

4141
/**
42-
* Returns the receiver. This corresponds to the "this" value.
43-
*
44-
* @return ObjectValue
42+
* {@inheritdoc}
4543
*/
4644
public function this(): ObjectValue
4745
{
4846
}
4947

5048
/**
51-
* If the callback was created without a Signature, this is the same
52-
* value as This(). If there is a signature, and the signature didn't match
53-
* This() but one of its hidden prototypes, this will be the respective
54-
* hidden prototype.
55-
*
56-
* Note that this is not the prototype of This() on which the accessor
57-
* referencing this callback was found (which in V8 internally is often
58-
* referred to as holder [sic]).
59-
*
60-
* @return ObjectValue
49+
* {@inheritdoc}
6150
*/
6251
public function holder(): ObjectValue
6352
{
6453
}
6554

6655
/**
67-
* The ReturnValue for the call
68-
*
69-
* @return ReturnValue
56+
* {@inheritdoc}
7057
*/
7158
public function getReturnValue(): ReturnValue
7259
{

stubs/src/PropertyCallbackInfo.php

+7-19
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,43 @@
1515

1616
namespace V8;
1717

18+
1819
/**
1920
* The information passed to a property callback about the context
2021
* of the property access.
2122
*/
22-
class PropertyCallbackInfo
23+
class PropertyCallbackInfo implements CallbackInfoInterface
2324
{
2425
/**
25-
* @return Isolate
26+
* {@inheritdoc}
2627
*/
2728
public function getIsolate(): Isolate
2829
{
2930
}
3031

3132
/**
32-
* @return Context
33+
* {@inheritdoc}
3334
*/
3435
public function getContext(): Context
3536
{
3637
}
3738

3839
/**
39-
* Returns the receiver. This corresponds to the "this" value.
40-
*
41-
* @return ObjectValue
40+
* {@inheritdoc}
4241
*/
4342
public function this(): ObjectValue
4443
{
4544
}
4645

4746
/**
48-
* If the callback was created without a Signature, this is the same
49-
* value as This(). If there is a signature, and the signature didn't match
50-
* This() but one of its hidden prototypes, this will be the respective
51-
* hidden prototype.
52-
*
53-
* Note that this is not the prototype of This() on which the accessor
54-
* referencing this callback was found (which in V8 internally is often
55-
* referred to as holder [sic]).
56-
*
57-
* @return ObjectValue
47+
* {@inheritdoc}
5848
*/
5949
public function holder(): ObjectValue
6050
{
6151
}
6252

6353
/**
64-
* The ReturnValue for the call
65-
*
66-
* @return ReturnValue
54+
* {@inheritdoc}
6755
*/
6856
public function getReturnValue(): ReturnValue
6957
{

0 commit comments

Comments
 (0)