Skip to content

Commit fef17d3

Browse files
committed
只有13版本及以上的v8才打开PUERTS_LAZYLOAD
1 parent 79dfd7e commit fef17d3

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

‎unity/native/papi-v8/include/CppObjectMapper.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ class FCppObjectMapper final : public ICppObjectMapper
9494

9595
v8::Local<v8::FunctionTemplate> GetTemplateOfClass(v8::Isolate* Isolate, const ScriptClassDefinition* ClassDefinition);
9696

97-
#ifdef PUERTS_LAZYLOAD
97+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
9898
void WrapFunctionWithStaticLazyInterceptor(v8::Isolate* Isolate, v8::Local<v8::Context> Context,
9999
v8::Local<v8::Function> Func, const ScriptClassDefinition* ClassDefinition);
100-
#endif // PUERTS_LAZYLOAD
100+
#endif // defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
101101

102102
private:
103103
std::unordered_map<void*, FObjectCacheNode, PointerHash, PointerEqual> CDataCache;
@@ -107,10 +107,10 @@ class FCppObjectMapper final : public ICppObjectMapper
107107
v8::UniquePersistent<v8::FunctionTemplate> PointerTemplate;
108108

109109
std::vector<PesapiCallbackData*> FunctionDatas;
110-
#ifdef PUERTS_LAZYLOAD
110+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
111111
std::vector<void*> InterceptorDatas;
112112
std::unordered_set<const void*, PointerHash, PointerEqual> StaticLazyWrappedTypes;
113-
#endif // PUERTS_LAZYLOAD
113+
#endif // defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
114114
v8::Global<v8::Symbol> PrivateKey;
115115

116116
std::shared_ptr<int> Ref = std::make_shared<int>(0);

‎unity/native/papi-v8/source/CppObjectMapper.cpp‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void FCppObjectMapper::findClassByName(const v8::FunctionCallbackInfo<v8::Value>
4343
if (ClassDef)
4444
{
4545
auto Func = GetTemplateOfClass(Isolate, ClassDef)->GetFunction(Context).ToLocalChecked();
46-
#ifdef PUERTS_LAZYLOAD
46+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
4747
WrapFunctionWithStaticLazyInterceptor(Isolate, Context, Func, ClassDef);
4848
#endif
4949
Info.GetReturnValue().Set(Func);
@@ -64,7 +64,7 @@ v8::MaybeLocal<v8::Function> FCppObjectMapper::LoadTypeById(v8::Local<v8::Contex
6464
}
6565
auto Template = GetTemplateOfClass(Context->GetIsolate(), ClassDef);
6666
auto MaybeFunc = Template->GetFunction(Context);
67-
#ifdef PUERTS_LAZYLOAD
67+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
6868
if (!MaybeFunc.IsEmpty())
6969
{
7070
WrapFunctionWithStaticLazyInterceptor(Context->GetIsolate(), Context, MaybeFunc.ToLocalChecked(), ClassDef);
@@ -253,7 +253,7 @@ static void PesapiSetterWrap(const v8::FunctionCallbackInfo<v8::Value>& Info)
253253
PropertyInfo->Setter(&v8impl::g_pesapi_ffi, (pesapi_callback_info)(&Info));
254254
}
255255

256-
#ifdef PUERTS_LAZYLOAD
256+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
257257
static thread_local bool LazyStaticMemberCaching = false;
258258

259259
struct LazyInterceptorData
@@ -359,9 +359,9 @@ static v8::Intercepted LazyStaticFunctionInterceptorGetter(
359359
}
360360

361361
static thread_local bool LazyMemberCaching = false;
362-
#endif // PUERTS_LAZYLOAD
362+
#endif // defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
363363

364-
#ifdef PUERTS_LAZYLOAD
364+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
365365
// Check if any ancestor class in the inheritance chain has a static variable (Variables) with the given name
366366
static bool SuperHasStaticVariable(ScriptClassRegistry* Registry, const ScriptClassDefinition* ClassDefinition, const char* Name)
367367
{
@@ -445,9 +445,9 @@ static bool SuperHasProperty(ScriptClassRegistry* Registry, const ScriptClassDef
445445
}
446446
return false;
447447
}
448-
#endif // PUERTS_LAZYLOAD
448+
#endif // defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
449449

450-
#ifdef PUERTS_LAZYLOAD
450+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
451451
// Search for a method by name in the given ClassDefinition's Methods, create the v8::Function,
452452
// cache it on proto, and return it. If not found, recurse into the parent ClassDefinition
453453
// (via SuperTypeId) and proto's prototype. Returns empty Maybe if no match in the entire chain.
@@ -718,7 +718,7 @@ static v8::Intercepted LazyPrototypeMemberGetter(
718718

719719
return v8::Intercepted::kNo;
720720
}
721-
#endif // PUERTS_LAZYLOAD
721+
#endif // defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
722722

723723
v8::Local<v8::FunctionTemplate> FCppObjectMapper::GetTemplateOfClass(v8::Isolate* Isolate, const ScriptClassDefinition* ClassDefinition)
724724
{
@@ -729,7 +729,7 @@ v8::Local<v8::FunctionTemplate> FCppObjectMapper::GetTemplateOfClass(v8::Isolate
729729
Isolate, CDataNew, v8::External::New(Isolate, &(const_cast<ScriptClassDefinition*>(ClassDefinition)->Data)));
730730
Template->InstanceTemplate()->SetInternalFieldCount(4);
731731

732-
#ifdef PUERTS_LAZYLOAD
732+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
733733
// InstanceTemplate, PrototypeTemplate
734734
auto InterceptorData = new LazyInterceptorData{ClassDefinition, Registry};
735735
InterceptorDatas.push_back(InterceptorData);
@@ -742,14 +742,14 @@ v8::Local<v8::FunctionTemplate> FCppObjectMapper::GetTemplateOfClass(v8::Isolate
742742
LazyPrototypeMemberGetter, nullptr, nullptr, nullptr, nullptr,
743743
v8::External::New(Isolate, InterceptorData),
744744
v8::PropertyHandlerFlags::kNonMasking));
745-
#endif // PUERTS_LAZYLOAD
745+
#endif // defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
746746

747747
// Methods
748748
{
749749
ScriptFunctionInfo* FunctionInfo = ClassDefinition->Methods;
750750
while (FunctionInfo && FunctionInfo->Name && FunctionInfo->Callback)
751751
{
752-
#ifdef PUERTS_LAZYLOAD
752+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
753753
if (ClassDefinition->SuperTypeId && SuperHasMethod(Registry, ClassDefinition, FunctionInfo->Name))
754754
#endif
755755
{
@@ -780,7 +780,7 @@ v8::Local<v8::FunctionTemplate> FCppObjectMapper::GetTemplateOfClass(v8::Isolate
780780
ScriptPropertyInfo* PropertyInfo = ClassDefinition->Properties;
781781
while (PropertyInfo && PropertyInfo->Name)
782782
{
783-
#ifdef PUERTS_LAZYLOAD
783+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
784784
if (ClassDefinition->SuperTypeId && SuperHasProperty(Registry, ClassDefinition, PropertyInfo->Name))
785785
#endif
786786
{
@@ -806,7 +806,7 @@ v8::Local<v8::FunctionTemplate> FCppObjectMapper::GetTemplateOfClass(v8::Isolate
806806
ScriptPropertyInfo* PropertyInfo = ClassDefinition->Variables;
807807
while (PropertyInfo && PropertyInfo->Name)
808808
{
809-
#ifdef PUERTS_LAZYLOAD
809+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
810810
// Directly register if: has setter (writable), or parent has same-named static variable (override)
811811
bool DirectRegister = PropertyInfo->Setter
812812
|| (ClassDefinition->SuperTypeId && SuperHasStaticVariable(Registry, ClassDefinition, PropertyInfo->Name));
@@ -835,7 +835,7 @@ v8::Local<v8::FunctionTemplate> FCppObjectMapper::GetTemplateOfClass(v8::Isolate
835835
ScriptFunctionInfo* FunctionInfo = ClassDefinition->Functions;
836836
while (FunctionInfo && FunctionInfo->Name && FunctionInfo->Callback)
837837
{
838-
#ifdef PUERTS_LAZYLOAD
838+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
839839
if (ClassDefinition->SuperTypeId && SuperHasStaticMethod(Registry, ClassDefinition, FunctionInfo->Name))
840840
#endif
841841
{
@@ -879,7 +879,7 @@ v8::Local<v8::FunctionTemplate> FCppObjectMapper::GetTemplateOfClass(v8::Isolate
879879
}
880880
}
881881

882-
#ifdef PUERTS_LAZYLOAD
882+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
883883
void FCppObjectMapper::WrapFunctionWithStaticLazyInterceptor(v8::Isolate* Isolate, v8::Local<v8::Context> Context,
884884
v8::Local<v8::Function> Func, const ScriptClassDefinition* ClassDefinition)
885885
{
@@ -905,7 +905,7 @@ void FCppObjectMapper::WrapFunctionWithStaticLazyInterceptor(v8::Isolate* Isolat
905905

906906
StaticLazyWrappedTypes.insert(ClassDefinition->TypeId);
907907
}
908-
#endif // PUERTS_LAZYLOAD
908+
#endif // defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
909909

910910
static void CDataGarbageCollectedWithFree(const v8::WeakCallbackInfo<ScriptClassDefinition>& Data)
911911
{
@@ -1041,14 +1041,14 @@ void FCppObjectMapper::UnInitialize(v8::Isolate* InIsolate)
10411041
delete CallbackData;
10421042
}
10431043
FunctionDatas.clear();
1044-
#ifdef PUERTS_LAZYLOAD
1044+
#if defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
10451045
for (auto* Data : InterceptorDatas)
10461046
{
10471047
delete static_cast<LazyInterceptorData*>(Data);
10481048
}
10491049
InterceptorDatas.clear();
10501050
StaticLazyWrappedTypes.clear();
1051-
#endif // PUERTS_LAZYLOAD
1051+
#endif // defined(PUERTS_LAZYLOAD) && V8_MAJOR_VERSION >= 13
10521052
CDataCache.clear();
10531053
TypeIdToTemplateMap.clear();
10541054
PrivateKey.Reset();

0 commit comments

Comments
 (0)