Skip to content

Commit

Permalink
Merge pull request #5 from puerts/dev
Browse files Browse the repository at this point in the history
重构
  • Loading branch information
chexiongsheng authored Feb 26, 2025
2 parents 3981435 + f020865 commit 2cc68b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/CppObjectMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ struct CppObjectMapper

JSValue CreateFunction(pesapi_callback Callback, void* Data, pesapi_function_finalize Finalize);

JSValue CreateClassByID(const void* typeId);
JSValue FindOrCreateClassByID(const void* typeId);

static JSValue CreateError(JSContext* ctx, const char* message);

JSValue MakeMethod(pesapi_callback Callback, void* Data);
void InitMethod(puerts::JSFunctionInfo* FuncInfo, JSValue Obj);
void InitProperty(puerts::JSPropertyInfo* PropInfo, JSValue Obj);

JSValue CreateClass(const puerts::JSClassDefinition* ClassDefinition);
JSValue FindOrCreateClass(const puerts::JSClassDefinition* ClassDefinition);

void BindAndAddToCache(const puerts::JSClassDefinition* typeInfo, const void* ptr, JSValue value, bool callFinalize);

Expand Down
10 changes: 5 additions & 5 deletions source/CppObjectMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ JSValue CppObjectMapper::PushNativeObject(const void* TypeId, void* ObjectPtr, b
{
ClassDefinition = &PtrClassDef;
}
JSValue ctor = CreateClass(ClassDefinition);
JSValue ctor = FindOrCreateClass(ClassDefinition);
JSValue proto = JS_GetProperty(ctx, ctor, JS_ATOM_prototype);
JSValue obj = JS_NewObjectProtoClass(ctx, proto, classId);
JS_FreeValue(ctx, proto);
Expand Down Expand Up @@ -224,7 +224,7 @@ void CppObjectMapper::InitProperty(puerts::JSPropertyInfo* PropInfo, JSValue Obj
JS_FreeValue(ctx, setter);
}

JSValue CppObjectMapper::CreateClass(const puerts::JSClassDefinition* ClassDefinition)
JSValue CppObjectMapper::FindOrCreateClass(const puerts::JSClassDefinition* ClassDefinition)
{
auto it = TypeIdToFunctionMap.find(ClassDefinition->TypeId);
if (it == TypeIdToFunctionMap.end())
Expand Down Expand Up @@ -312,7 +312,7 @@ JSValue CppObjectMapper::CreateClass(const puerts::JSClassDefinition* ClassDefin
{
if (auto SuperDefinition = puerts::FindClassByID(ClassDefinition->SuperTypeId))
{
JSValue super_func = CreateClass(SuperDefinition);
JSValue super_func = FindOrCreateClass(SuperDefinition);
JSValue parent_proto = JS_GetProperty(ctx, super_func, JS_ATOM_prototype);
JS_SetPrototype(ctx, proto, parent_proto);
JS_FreeValue(ctx, parent_proto);
Expand All @@ -326,14 +326,14 @@ JSValue CppObjectMapper::CreateClass(const puerts::JSClassDefinition* ClassDefin
return it->second;
}

JSValue CppObjectMapper::CreateClassByID(const void* typeId)
JSValue CppObjectMapper::FindOrCreateClassByID(const void* typeId)
{
auto clsDef = puerts::LoadClassByID(typeId);
if (!clsDef)
{
return JS_UNDEFINED;
}
return CreateClass(clsDef);
return FindOrCreateClass(clsDef);
}

void CppObjectMapper::Initialize(JSContext* ctx_)
Expand Down
2 changes: 1 addition & 1 deletion source/PapiQuickjsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pesapi_value pesapi_create_class(pesapi_env env, const void* type_id)
{
auto ctx = qjsContextFromPesapiEnv(env);
auto ret = allocValueInCurrentScope(ctx);
*ret = pesapi::qjsimpl::CppObjectMapper::Get(ctx)->CreateClassByID(type_id);
*ret = pesapi::qjsimpl::CppObjectMapper::Get(ctx)->FindOrCreateClassByID(type_id);
JS_DupValue(ctx, *ret);
return pesapiValueFromQjsValue(ret);
}
Expand Down

0 comments on commit 2cc68b4

Please sign in to comment.