Skip to content

Commit 2cc68b4

Browse files
Merge pull request #5 from puerts/dev
重构
2 parents 3981435 + f020865 commit 2cc68b4

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

include/CppObjectMapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ struct CppObjectMapper
121121

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

124-
JSValue CreateClassByID(const void* typeId);
124+
JSValue FindOrCreateClassByID(const void* typeId);
125125

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

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

132-
JSValue CreateClass(const puerts::JSClassDefinition* ClassDefinition);
132+
JSValue FindOrCreateClass(const puerts::JSClassDefinition* ClassDefinition);
133133

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

source/CppObjectMapper.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ JSValue CppObjectMapper::PushNativeObject(const void* TypeId, void* ObjectPtr, b
152152
{
153153
ClassDefinition = &PtrClassDef;
154154
}
155-
JSValue ctor = CreateClass(ClassDefinition);
155+
JSValue ctor = FindOrCreateClass(ClassDefinition);
156156
JSValue proto = JS_GetProperty(ctx, ctor, JS_ATOM_prototype);
157157
JSValue obj = JS_NewObjectProtoClass(ctx, proto, classId);
158158
JS_FreeValue(ctx, proto);
@@ -224,7 +224,7 @@ void CppObjectMapper::InitProperty(puerts::JSPropertyInfo* PropInfo, JSValue Obj
224224
JS_FreeValue(ctx, setter);
225225
}
226226

227-
JSValue CppObjectMapper::CreateClass(const puerts::JSClassDefinition* ClassDefinition)
227+
JSValue CppObjectMapper::FindOrCreateClass(const puerts::JSClassDefinition* ClassDefinition)
228228
{
229229
auto it = TypeIdToFunctionMap.find(ClassDefinition->TypeId);
230230
if (it == TypeIdToFunctionMap.end())
@@ -312,7 +312,7 @@ JSValue CppObjectMapper::CreateClass(const puerts::JSClassDefinition* ClassDefin
312312
{
313313
if (auto SuperDefinition = puerts::FindClassByID(ClassDefinition->SuperTypeId))
314314
{
315-
JSValue super_func = CreateClass(SuperDefinition);
315+
JSValue super_func = FindOrCreateClass(SuperDefinition);
316316
JSValue parent_proto = JS_GetProperty(ctx, super_func, JS_ATOM_prototype);
317317
JS_SetPrototype(ctx, proto, parent_proto);
318318
JS_FreeValue(ctx, parent_proto);
@@ -326,14 +326,14 @@ JSValue CppObjectMapper::CreateClass(const puerts::JSClassDefinition* ClassDefin
326326
return it->second;
327327
}
328328

329-
JSValue CppObjectMapper::CreateClassByID(const void* typeId)
329+
JSValue CppObjectMapper::FindOrCreateClassByID(const void* typeId)
330330
{
331331
auto clsDef = puerts::LoadClassByID(typeId);
332332
if (!clsDef)
333333
{
334334
return JS_UNDEFINED;
335335
}
336-
return CreateClass(clsDef);
336+
return FindOrCreateClass(clsDef);
337337
}
338338

339339
void CppObjectMapper::Initialize(JSContext* ctx_)

source/PapiQuickjsImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pesapi_value pesapi_create_class(pesapi_env env, const void* type_id)
196196
{
197197
auto ctx = qjsContextFromPesapiEnv(env);
198198
auto ret = allocValueInCurrentScope(ctx);
199-
*ret = pesapi::qjsimpl::CppObjectMapper::Get(ctx)->CreateClassByID(type_id);
199+
*ret = pesapi::qjsimpl::CppObjectMapper::Get(ctx)->FindOrCreateClassByID(type_id);
200200
JS_DupValue(ctx, *ret);
201201
return pesapiValueFromQjsValue(ret);
202202
}

0 commit comments

Comments
 (0)