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

Commit 3baa168

Browse files
committed
Use enum class for callback index in bucket
1 parent 22d62c8 commit 3baa168

9 files changed

+52
-44
lines changed

src/php_v8_callbacks.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace phpv8 {
8989
}
9090
}
9191

92-
phpv8::Callback *CallbacksBucket::get(size_t index) {
92+
phpv8::Callback *CallbacksBucket::get(Index index) {
9393
auto it = callbacks.find(index);
9494

9595
if (it != callbacks.end()) {
@@ -99,7 +99,7 @@ namespace phpv8 {
9999
return NULL;
100100
}
101101

102-
void CallbacksBucket::add(size_t index, zend_fcall_info fci, zend_fcall_info_cache fci_cache) {
102+
void CallbacksBucket::add(Index index, zend_fcall_info fci, zend_fcall_info_cache fci_cache) {
103103
callbacks[index] = std::make_shared<Callback>(fci, fci_cache);
104104
}
105105

@@ -235,7 +235,7 @@ static inline void php_v8_callback_set_retval_from_callback_info(v8::ReturnValue
235235
}
236236

237237

238-
void php_v8_callback_call_from_bucket_with_zargs(size_t index, v8::Local<v8::Value> data, zval *args, zval *retval) {
238+
void php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index index, v8::Local<v8::Value> data, zval *args, zval *retval) {
239239
phpv8::CallbacksBucket *bucket;
240240

241241
if (data.IsEmpty() || !data->IsExternal()) {
@@ -275,7 +275,7 @@ void php_v8_callback_call_from_bucket_with_zargs(size_t index, v8::Local<v8::Val
275275
}
276276

277277
template<class T, class M>
278-
void php_v8_callback_call_from_bucket_with_zargs(size_t index, const T &info, M rv, zval *args) {
278+
void php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index index, const T &info, M rv, zval *args) {
279279
zval callback_info;
280280
php_v8_return_value_t *php_v8_return_value;
281281
// Wrap callback info
@@ -304,7 +304,7 @@ void php_v8_callback_function(const v8::FunctionCallbackInfo<v8::Value> &info) {
304304
/* Build the parameter array */
305305
array_init_size(&args, 1);
306306

307-
php_v8_callback_call_from_bucket_with_zargs(0, info, info.GetReturnValue(), &args);
307+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Callback, info, info.GetReturnValue(), &args);
308308

309309
zval_ptr_dtor(&args);
310310
}
@@ -322,7 +322,7 @@ void php_v8_callback_accessor_name_getter(v8::Local<v8::Name> property, const v8
322322
php_v8_get_or_create_value(&property_name, property, php_v8_isolate);
323323
add_index_zval(&args, 0, &property_name);
324324

325-
php_v8_callback_call_from_bucket_with_zargs(0, info, info.GetReturnValue(), &args);
325+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Getter, info, info.GetReturnValue(), &args);
326326

327327
zval_ptr_dtor(&args);
328328
}
@@ -344,7 +344,7 @@ void php_v8_callback_accessor_name_setter(v8::Local<v8::Name> property, v8::Loca
344344
add_index_zval(&args, 0, &property_name);
345345
add_index_zval(&args, 1, &property_value);
346346

347-
php_v8_callback_call_from_bucket_with_zargs(1, info, info.GetReturnValue(), &args);
347+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Setter, info, info.GetReturnValue(), &args);
348348

349349
zval_ptr_dtor(&args);
350350
}
@@ -363,7 +363,7 @@ void php_v8_callback_generic_named_property_getter(v8::Local<v8::Name> property,
363363
php_v8_get_or_create_value(&property_name, property, php_v8_isolate);
364364
add_index_zval(&args, 0, &property_name);
365365

366-
php_v8_callback_call_from_bucket_with_zargs(0, info, info.GetReturnValue(), &args);
366+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Getter, info, info.GetReturnValue(), &args);
367367

368368
zval_ptr_dtor(&args);
369369
}
@@ -385,7 +385,7 @@ void php_v8_callback_generic_named_property_setter(v8::Local<v8::Name> property,
385385
add_index_zval(&args, 0, &property_name);
386386
add_index_zval(&args, 1, &property_value);
387387

388-
php_v8_callback_call_from_bucket_with_zargs(1, info, info.GetReturnValue(), &args);
388+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Setter, info, info.GetReturnValue(), &args);
389389

390390
zval_ptr_dtor(&args);
391391
}
@@ -403,7 +403,7 @@ void php_v8_callback_generic_named_property_query(v8::Local<v8::Name> property,
403403
php_v8_get_or_create_value(&property_name, property, php_v8_isolate);
404404
add_index_zval(&args, 0, &property_name);
405405

406-
php_v8_callback_call_from_bucket_with_zargs(2, info, info.GetReturnValue(), &args);
406+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Query, info, info.GetReturnValue(), &args);
407407

408408
zval_ptr_dtor(&args);
409409
}
@@ -421,7 +421,7 @@ void php_v8_callback_generic_named_property_deleter(v8::Local<v8::Name> property
421421
php_v8_get_or_create_value(&property_name, property, php_v8_isolate);
422422
add_index_zval(&args, 0, &property_name);
423423

424-
php_v8_callback_call_from_bucket_with_zargs(3, info, info.GetReturnValue(), &args);
424+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Deleter, info, info.GetReturnValue(), &args);
425425

426426
zval_ptr_dtor(&args);
427427
}
@@ -434,7 +434,7 @@ void php_v8_callback_generic_named_property_enumerator(const v8::PropertyCallbac
434434
/* Build the parameter array */
435435
array_init_size(&args, 1);
436436

437-
php_v8_callback_call_from_bucket_with_zargs(4, info, info.GetReturnValue(), &args);
437+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Enumerator, info, info.GetReturnValue(), &args);
438438

439439
zval_ptr_dtor(&args);
440440
}
@@ -453,7 +453,7 @@ void php_v8_callback_indexed_property_getter(uint32_t index, const v8::PropertyC
453453
ZVAL_LONG(&property_name, index);
454454
add_index_zval(&args, 0, &property_name);
455455

456-
php_v8_callback_call_from_bucket_with_zargs(0, info, info.GetReturnValue(), &args);
456+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Getter, info, info.GetReturnValue(), &args);
457457

458458
zval_ptr_dtor(&args);
459459
}
@@ -475,7 +475,7 @@ void php_v8_callback_indexed_property_setter(uint32_t index, v8::Local<v8::Value
475475
add_index_zval(&args, 0, &property_name);
476476
add_index_zval(&args, 1, &property_value);
477477

478-
php_v8_callback_call_from_bucket_with_zargs(1, info, info.GetReturnValue(), &args);
478+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Setter, info, info.GetReturnValue(), &args);
479479

480480
zval_ptr_dtor(&args);
481481
}
@@ -492,7 +492,7 @@ void php_v8_callback_indexed_property_query(uint32_t index, const v8::PropertyCa
492492
ZVAL_LONG(&property_name, index);
493493
add_index_zval(&args, 0, &property_name);
494494

495-
php_v8_callback_call_from_bucket_with_zargs(2, info, info.GetReturnValue(), &args);
495+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Query, info, info.GetReturnValue(), &args);
496496

497497
zval_ptr_dtor(&args);
498498
}
@@ -509,7 +509,7 @@ void php_v8_callback_indexed_property_deleter(uint32_t index, const v8::Property
509509
ZVAL_LONG(&property_name, index);
510510
add_index_zval(&args, 0, &property_name);
511511

512-
php_v8_callback_call_from_bucket_with_zargs(3, info, info.GetReturnValue(), &args);
512+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Deleter, info, info.GetReturnValue(), &args);
513513

514514
zval_ptr_dtor(&args);
515515
}
@@ -522,7 +522,7 @@ void php_v8_callback_indexed_property_enumerator(const v8::PropertyCallbackInfo<
522522
/* Build the parameter array */
523523
array_init_size(&args, 1);
524524

525-
php_v8_callback_call_from_bucket_with_zargs(4, info, info.GetReturnValue(), &args);
525+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Enumerator, info, info.GetReturnValue(), &args);
526526

527527
zval_ptr_dtor(&args);
528528
}
@@ -556,7 +556,7 @@ bool php_v8_callback_access_check(v8::Local<v8::Context> accessing_context, v8::
556556
add_index_zval(&args, 0, &context_zv);
557557
add_index_zval(&args, 1, &accessed_object_zv);
558558

559-
php_v8_callback_call_from_bucket_with_zargs(0, data, &args, &retval);
559+
php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Callback, data, &args, &retval);
560560

561561
if (Z_TYPE(retval) == IS_TRUE) {
562562
security_retval = true;

src/php_v8_callbacks.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,18 @@ namespace phpv8 {
9292

9393
class CallbacksBucket {
9494
public:
95-
phpv8::Callback *get(size_t index);
95+
enum class Index {
96+
Callback = 0,
97+
Getter = 0,
98+
Setter = 1,
99+
Query = 2,
100+
Deleter = 3,
101+
Enumerator = 4,
102+
};
103+
phpv8::Callback *get(Index index);
96104
void reset(CallbacksBucket *bucket);
97105

98-
void add(size_t index, zend_fcall_info fci, zend_fcall_info_cache fci_cache);
106+
void add(Index index, zend_fcall_info fci, zend_fcall_info_cache fci_cache);
99107
int getGcCount();
100108

101109
void collectGcZvals(zval *& zv);
@@ -109,7 +117,7 @@ namespace phpv8 {
109117
}
110118

111119
private:
112-
std::map<size_t, std::shared_ptr<Callback>> callbacks;
120+
std::map<Index, std::shared_ptr<Callback>> callbacks;
113121
};
114122

115123

src/php_v8_function.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static PHP_METHOD(V8Function, __construct) {
328328
phpv8::CallbacksBucket *bucket = php_v8_value->persistent_data->bucket("callback");
329329
data = v8::External::New(isolate, bucket);
330330

331-
bucket->add(0, fci, fci_cache);
331+
bucket->add(phpv8::CallbacksBucket::Index::Getter, fci, fci_cache);
332332

333333
callback = php_v8_callback_function;
334334
}

src/php_v8_function_template.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static PHP_METHOD(V8FunctionTemplate, __construct) {
155155
phpv8::CallbacksBucket *bucket= php_v8_function_template->persistent_data->bucket("callback");
156156
data = v8::External::New(isolate, bucket);
157157

158-
bucket->add(0, fci, fci_cache);
158+
bucket->add(phpv8::CallbacksBucket::Index::Callback, fci, fci_cache);
159159

160160
callback = php_v8_callback_function;
161161
}
@@ -237,7 +237,7 @@ static PHP_METHOD(V8FunctionTemplate, SetCallHandler) {
237237
PHP_V8_ENTER_STORED_ISOLATE(php_v8_function_template);
238238

239239
phpv8::CallbacksBucket *bucket= php_v8_function_template->persistent_data->bucket("callback");
240-
bucket->add(0, fci, fci_cache);
240+
bucket->add(phpv8::CallbacksBucket::Index::Callback, fci, fci_cache);
241241

242242
v8::Local<v8::FunctionTemplate> local_template = php_v8_function_template_get_local(php_v8_function_template);
243243

src/php_v8_indexed_property_handler_configuration.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,26 @@ static PHP_METHOD (V8IndexedPropertyHandlerConfiguration, __construct) {
9696

9797
PHP_V8_INDEXED_PROPERTY_HANDLER_FETCH_INTO(getThis(), php_v8_handlers);
9898

99-
php_v8_handlers->bucket->add(0, fci_getter, fci_cache_getter);
99+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Getter, fci_getter, fci_cache_getter);
100100
php_v8_handlers->getter = php_v8_callback_indexed_property_getter;
101101

102102
if (fci_setter.size) {
103-
php_v8_handlers->bucket->add(1, fci_setter, fci_cache_setter);
103+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Setter, fci_setter, fci_cache_setter);
104104
php_v8_handlers->setter = php_v8_callback_indexed_property_setter;
105105
}
106106

107107
if (fci_query.size) {
108-
php_v8_handlers->bucket->add(2, fci_query, fci_cache_query);
108+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Query, fci_query, fci_cache_query);
109109
php_v8_handlers->query = php_v8_callback_indexed_property_query;
110110
}
111111

112112
if (fci_deleter.size) {
113-
php_v8_handlers->bucket->add(3, fci_deleter, fci_cache_deleter);
113+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Deleter, fci_deleter, fci_cache_deleter);
114114
php_v8_handlers->deleter = php_v8_callback_indexed_property_deleter;
115115
}
116116

117117
if (fci_enumerator.size) {
118-
php_v8_handlers->bucket->add(4, fci_enumerator, fci_cache_enumerator);
118+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Enumerator, fci_enumerator, fci_cache_enumerator);
119119
php_v8_handlers->enumerator = php_v8_callback_indexed_property_enumerator;
120120
}
121121

src/php_v8_named_property_handler_configuration.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,26 @@ static PHP_METHOD (V8NamedPropertyHandlerConfiguration, __construct) {
9696

9797
PHP_V8_NAMED_PROPERTY_HANDLER_FETCH_INTO(getThis(), php_v8_handlers);
9898

99-
php_v8_handlers->bucket->add(0, fci_getter, fci_cache_getter);
99+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Getter, fci_getter, fci_cache_getter);
100100
php_v8_handlers->getter = php_v8_callback_generic_named_property_getter;
101101

102102
if (fci_setter.size) {
103-
php_v8_handlers->bucket->add(1, fci_setter, fci_cache_setter);
103+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Setter, fci_setter, fci_cache_setter);
104104
php_v8_handlers->setter = php_v8_callback_generic_named_property_setter;
105105
}
106106

107107
if (fci_query.size) {
108-
php_v8_handlers->bucket->add(2, fci_query, fci_cache_query);
108+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Query, fci_query, fci_cache_query);
109109
php_v8_handlers->query = php_v8_callback_generic_named_property_query;
110110
}
111111

112112
if (fci_deleter.size) {
113-
php_v8_handlers->bucket->add(3, fci_deleter, fci_cache_deleter);
113+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Deleter, fci_deleter, fci_cache_deleter);
114114
php_v8_handlers->deleter = php_v8_callback_generic_named_property_deleter;
115115
}
116116

117117
if (fci_enumerator.size) {
118-
php_v8_handlers->bucket->add(4, fci_enumerator, fci_cache_enumerator);
118+
php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Enumerator, fci_enumerator, fci_cache_enumerator);
119119
php_v8_handlers->enumerator = php_v8_callback_generic_named_property_enumerator;
120120
}
121121

src/php_v8_object.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,11 @@ static PHP_METHOD(V8Object, SetAccessor) {
463463
phpv8::CallbacksBucket *bucket = php_v8_value->persistent_data->bucket("accessor_", local_name->IsSymbol(), name);
464464
data = v8::External::New(isolate, bucket);
465465

466-
bucket->add(0, getter_fci, getter_fci_cache);
466+
bucket->add(phpv8::CallbacksBucket::Index::Getter, getter_fci, getter_fci_cache);
467467
getter = php_v8_callback_accessor_name_getter;
468468

469469
if (setter_fci.size) {
470-
bucket->add(1, setter_fci, setter_fci_cache);
470+
bucket->add(phpv8::CallbacksBucket::Index::Setter, setter_fci, setter_fci_cache);
471471
setter = php_v8_callback_accessor_name_setter;
472472
}
473473

@@ -587,11 +587,11 @@ static PHP_METHOD(V8Object, SetNativeDataProperty) {
587587
phpv8::CallbacksBucket *bucket = php_v8_value->persistent_data->bucket("native_data_property_", local_name->IsSymbol(), name);
588588
data = v8::External::New(isolate, bucket);
589589

590-
bucket->add(0, getter_fci, getter_fci_cache);
590+
bucket->add(phpv8::CallbacksBucket::Index::Getter, getter_fci, getter_fci_cache);
591591
getter = php_v8_callback_accessor_name_getter;
592592

593593
if (setter_fci.size) {
594-
bucket->add(1, setter_fci, setter_fci_cache);
594+
bucket->add(phpv8::CallbacksBucket::Index::Setter, setter_fci, setter_fci_cache);
595595
setter = php_v8_callback_accessor_name_setter;
596596
}
597597

src/php_v8_object_template.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ static PHP_METHOD(V8ObjectTemplate, SetAccessor) {
253253
local_name->IsSymbol(), name);
254254
data = v8::External::New(isolate, bucket);
255255

256-
bucket->add(0, getter_fci, getter_fci_cache);
256+
bucket->add(phpv8::CallbacksBucket::Index::Getter, getter_fci, getter_fci_cache);
257257
getter = php_v8_callback_accessor_name_getter;
258258

259259
if (setter_fci.size) {
260-
bucket->add(1, setter_fci, setter_fci_cache);
260+
bucket->add(phpv8::CallbacksBucket::Index::Setter, setter_fci, setter_fci_cache);
261261
setter = php_v8_callback_accessor_name_setter;
262262
}
263263

@@ -353,7 +353,7 @@ static PHP_METHOD(V8ObjectTemplate, SetCallAsFunctionHandler) {
353353
phpv8::CallbacksBucket *bucket = php_v8_object_template->persistent_data->bucket("callback");
354354
data = v8::External::New(isolate, bucket);
355355

356-
bucket->add(0, fci, fci_cache);
356+
bucket->add(phpv8::CallbacksBucket::Index::Callback, fci, fci_cache);
357357

358358
callback = php_v8_callback_function;
359359
}
@@ -391,7 +391,7 @@ static PHP_METHOD(V8ObjectTemplate, SetAccessCheckCallback) {
391391
PHP_V8_ENTER_STORED_ISOLATE(php_v8_object_template);
392392

393393
phpv8::CallbacksBucket *bucket = php_v8_object_template->persistent_data->bucket("access_check");
394-
bucket->add(0, fci_callback, fci_cache_callback);
394+
bucket->add(phpv8::CallbacksBucket::Index::Callback, fci_callback, fci_cache_callback);
395395

396396
v8::Local<v8::ObjectTemplate> local_template = php_v8_object_template_get_local(php_v8_object_template);
397397

src/php_v8_template.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ void php_v8_template_SetNativeDataProperty(v8::Isolate *isolate, v8::Local<T> lo
250250
phpv8::CallbacksBucket *bucket = php_v8_template->persistent_data->bucket("native_data_property_", local_name->IsSymbol(), name);
251251
data = v8::External::New(isolate, bucket);
252252

253-
bucket->add(0, getter_fci, getter_fci_cache);
253+
bucket->add(phpv8::CallbacksBucket::Index::Getter, getter_fci, getter_fci_cache);
254254
getter = php_v8_callback_accessor_name_getter;
255255

256256
if (setter_fci.size) {
257-
bucket->add(1, setter_fci, setter_fci_cache);
257+
bucket->add(phpv8::CallbacksBucket::Index::Setter, setter_fci, setter_fci_cache);
258258
setter = php_v8_callback_accessor_name_setter;
259259
}
260260

0 commit comments

Comments
 (0)