0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 14:48:40 +00:00

toJSON: use zend_hash_find_ptr_lc instead of ZEND_HASH_FOREACH_STR_KEY_PTR

This commit is contained in:
Christiano Becker 2023-02-22 16:13:13 -03:00
parent 9cb0400f90
commit 34d944a9f5

View File

@ -1016,23 +1016,23 @@ static v8::MaybeLocal<v8::Object> v8js_wrap_object(v8::Isolate *isolate, zend_cl
} }
if (has_json_serializable) { if (has_json_serializable) {
void *ptr; zend_string *jsonserialize_str = zend_string_init
zend_string *key; ("jsonSerialize", sizeof("jsonSerialize") - 1, 0);
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, ptr) { zend_function *jsonserialize_method_ptr = reinterpret_cast<zend_function *>
zend_function *method_ptr = reinterpret_cast<zend_function *>(ptr); (zend_hash_find_ptr_lc(&ce->function_table, jsonserialize_str));
if (strcmp(ZSTR_VAL(method_ptr->common.function_name), "jsonSerialize") == 0) { if (jsonserialize_method_ptr &&
v8::Local<v8::String> method_name = V8JS_SYM("toJSON"); jsonserialize_method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) {
v8::Local<v8::FunctionTemplate> ft; v8::Local<v8::String> method_name = V8JS_SYM("toJSON");
v8::Local<v8::FunctionTemplate> ft;
ft = v8::FunctionTemplate::New(isolate, v8js_php_callback, ft = v8::FunctionTemplate::New(isolate, v8js_php_callback,
v8::External::New((isolate), method_ptr)); v8::External::New((isolate), jsonserialize_method_ptr));
v8js_function_tmpl_t *persistent_ft = &ctx->method_tmpls[std::make_pair(ce, method_ptr)]; v8js_function_tmpl_t *persistent_ft = &ctx->method_tmpls[std::make_pair(ce, jsonserialize_method_ptr)];
persistent_ft->Reset(isolate, ft); persistent_ft->Reset(isolate, ft);
newobj.ToLocalChecked()->CreateDataProperty(v8_context, method_name, ft->GetFunction(v8_context).ToLocalChecked()); newobj.ToLocalChecked()->CreateDataProperty(v8_context, method_name, ft->GetFunction(v8_context).ToLocalChecked());
} }
} ZEND_HASH_FOREACH_END();
} }
if (ce == zend_ce_closure && !newobj.IsEmpty()) { if (ce == zend_ce_closure && !newobj.IsEmpty()) {