Skip to content

Commit

Permalink
1.2.x 버전 빌드 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
jihoons94 committed Nov 10, 2022
1 parent 23ffd60 commit 4f6eed0
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 313 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/unity_build_plugins.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: unity build plugins
name: build unity plugins

on:
workflow_dispatch:
Expand Down Expand Up @@ -33,6 +33,7 @@ jobs:
unzip -q NDK
- name: Build
run: |
ls ~/android-ndk-r21b
cd unity/native_src
chmod 777 make_android.sh
ANDROID_NDK=~/android-ndk-r21b ./make_android.sh
Expand Down Expand Up @@ -257,4 +258,5 @@ jobs:
uses: actions/upload-artifact@v2
with:
path: ./unity/Assets/Plugins/**/*
name: Unity_Plugins_V8
name: Unity_Plugins_V8

4 changes: 0 additions & 4 deletions unity/native_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ if ( WIN32 AND NOT CYGWIN )
target_compile_definitions (puerts PRIVATE BUILDING_V8_SHARED)
endif ()

if ( NOT CMAKE_BUILD_TYPE MATCHES "Release" )
target_compile_definitions (puerts PRIVATE PUERTS_DEBUG)
endif ()

include(${PROJECT_SOURCE_DIR}/cmake/${JS_ENGINE}/CMakeLists.txt)

if ( MSYS OR WIN32 )
Expand Down
71 changes: 36 additions & 35 deletions unity/native_src/Inc/JSEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
#include "JSFunction.h"
#include "V8InspectorImpl.h"

#if PUERTS_UT
# if PLATFORM_WINDOWS
# define PUERTS_EXPORT_FOR_UT __declspec(dllexport)
# else
# define PUERTS_EXPORT_FOR_UT __attribute__ ((visibility("default")))
# endif
#else
# define PUERTS_EXPORT_FOR_UT
#endif

#if WITH_NODEJS
#pragma warning(push, 0)
#include "node.h"
Expand Down Expand Up @@ -55,8 +65,6 @@

typedef char* (*CSharpModuleResolveCallback)(const char* identifer, int32_t jsEnvIdx);

typedef void (*CSharpPushJSFunctionArgumentsCallback)(v8::Isolate* Isolate, int32_t jsEnvIdx, puerts::JSFunction* NativeFuncPtr);

typedef void(*CSharpFunctionCallback)(v8::Isolate* Isolate, const v8::FunctionCallbackInfo<v8::Value>& Info, void* Self, int ParamLen, int64_t UserData);

typedef void* (*CSharpConstructorCallback)(v8::Isolate* Isolate, const v8::FunctionCallbackInfo<v8::Value>& Info, int ParamLen, int64_t UserData);
Expand Down Expand Up @@ -105,55 +113,52 @@ class JSEngine
private:
void JSEngineWithNode();
void JSEngineWithoutNode(void* external_quickjs_runtime, void* external_quickjs_context);
#if !WITH_QUICKJS
static void HostInitializeImportMetaObject(v8::Local<v8::Context> context, v8::Local<v8::Module> module, v8::Local<v8::Object> meta);
#endif
public:
JSEngine(void* external_quickjs_runtime, void* external_quickjs_context);
PUERTS_EXPORT_FOR_UT JSEngine(void* external_quickjs_runtime, void* external_quickjs_context);

~JSEngine();
PUERTS_EXPORT_FOR_UT ~JSEngine();

void SetGlobalFunction(const char *Name, CSharpFunctionCallback Callback, int64_t Data);
PUERTS_EXPORT_FOR_UT void SetGlobalFunction(const char *Name, CSharpFunctionCallback Callback, int64_t Data);

bool ExecuteModule(const char* Path, const char* Exportee);
bool Eval(const char *Code, const char* Path);
PUERTS_EXPORT_FOR_UT bool ExecuteModule(const char* Path, const char* Exportee);

PUERTS_EXPORT_FOR_UT bool Eval(const char *Code, const char* Path);

int RegisterClass(const char *FullName, int BaseTypeId, CSharpConstructorCallback Constructor, CSharpDestructorCallback Destructor, int64_t Data, int Size);
PUERTS_EXPORT_FOR_UT int RegisterClass(const char *FullName, int BaseTypeId, CSharpConstructorCallback Constructor, CSharpDestructorCallback Destructor, int64_t Data, int Size);

bool RegisterFunction(int ClassID, const char *Name, bool IsStatic, CSharpFunctionCallback Callback, int64_t Data);
PUERTS_EXPORT_FOR_UT bool RegisterFunction(int ClassID, const char *Name, bool IsStatic, CSharpFunctionCallback Callback, int64_t Data);

bool RegisterProperty(int ClassID, const char *Name, bool IsStatic, CSharpFunctionCallback Getter, int64_t GetterData, CSharpFunctionCallback Setter, int64_t SetterData, bool DontDelete);
PUERTS_EXPORT_FOR_UT bool RegisterProperty(int ClassID, const char *Name, bool IsStatic, CSharpFunctionCallback Getter, int64_t GetterData, CSharpFunctionCallback Setter, int64_t SetterData, bool DontDelete);

v8::Local<v8::Value> GetClassConstructor(int ClassID);
PUERTS_EXPORT_FOR_UT v8::Local<v8::Value> GetClassConstructor(int ClassID);

v8::Local<v8::Value> FindOrAddObject(v8::Isolate* Isolate, v8::Local<v8::Context> Context, int ClassID, void *Ptr);
PUERTS_EXPORT_FOR_UT v8::Local<v8::Value> FindOrAddObject(v8::Isolate* Isolate, v8::Local<v8::Context> Context, int ClassID, void *Ptr);

void BindObject(FLifeCycleInfo* LifeCycleInfo, void* Ptr, v8::Local<v8::Object> JSObject);
PUERTS_EXPORT_FOR_UT void BindObject(FLifeCycleInfo* LifeCycleInfo, void* Ptr, v8::Local<v8::Object> JSObject);

void UnBindObject(FLifeCycleInfo* LifeCycleInfo, void* Ptr);
PUERTS_EXPORT_FOR_UT void UnBindObject(FLifeCycleInfo* LifeCycleInfo, void* Ptr);

std::string LastExceptionInfo;

CSharpDestructorCallback GeneralDestructor;

void LowMemoryNotification();
PUERTS_EXPORT_FOR_UT void LowMemoryNotification();

JSFunction* CreateJSFunction(v8::Isolate* InIsolate, v8::Local<v8::Context> InContext, v8::Local<v8::Function> InFunction);
PUERTS_EXPORT_FOR_UT JSFunction* CreateJSFunction(v8::Isolate* InIsolate, v8::Local<v8::Context> InContext, v8::Local<v8::Function> InFunction);

void ReleaseJSFunction(JSFunction* InFunction);
PUERTS_EXPORT_FOR_UT void ReleaseJSFunction(JSFunction* InFunction);

JSObject* CreateJSObject(v8::Isolate* InIsolate, v8::Local<v8::Context> InContext, v8::Local<v8::Object> InObject);
PUERTS_EXPORT_FOR_UT JSObject* CreateJSObject(v8::Isolate* InIsolate, v8::Local<v8::Context> InContext, v8::Local<v8::Object> InObject);

void ReleaseJSObject(JSObject* InObject);
PUERTS_EXPORT_FOR_UT void ReleaseJSObject(JSObject* InObject);

void CreateInspector(int32_t Port);
PUERTS_EXPORT_FOR_UT void CreateInspector(int32_t Port);

void DestroyInspector();
PUERTS_EXPORT_FOR_UT void DestroyInspector();

bool InspectorTick();
PUERTS_EXPORT_FOR_UT bool InspectorTick();

void LogicTick();
PUERTS_EXPORT_FOR_UT void LogicTick();

v8::Isolate* MainIsolate;

Expand All @@ -163,23 +168,19 @@ class JSEngine

v8::UniquePersistent<v8::Function> JsPromiseRejectCallback;

V8_INLINE static JSEngine * Get(v8::Isolate* Isolate)
PUERTS_EXPORT_FOR_UT V8_INLINE static JSEngine * Get(v8::Isolate* Isolate)
{
return FV8Utils::IsolateData<JSEngine>(Isolate);
}

int32_t Idx;

CSharpModuleResolveCallback ModuleResolver;
CSharpPushJSFunctionArgumentsCallback GetJSArgumentsCallback;

#if defined(WITH_QUICKJS)
std::map<std::string, JSModuleDef*> PathToModuleMap;
std::map<std::string, JSModuleDef*> ModuleCacheMap;
#else
std::map<std::string, v8::UniquePersistent<v8::Module>> PathToModuleMap;
std::map<std::string, v8::UniquePersistent<v8::Module>> ModuleCacheMap;
#endif

std::map<int, std::string> ScriptIdToPathMap;
private:
#if defined(WITH_NODEJS)
uv_loop_t* NodeUVLoop;
Expand Down Expand Up @@ -218,7 +219,7 @@ class JSEngine

V8Inspector* Inspector;

public:
private:
v8::Local<v8::FunctionTemplate> ToTemplate(v8::Isolate* Isolate, bool IsStatic, CSharpFunctionCallback Callback, int64_t Data);
};
}
2 changes: 1 addition & 1 deletion unity/native_src/Inc/JSFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class JSFunction

~JSFunction();

bool Invoke(int argumentsLength, bool HasResult);
bool Invoke(bool HasResult);

std::vector<FValue> Arguments;

Expand Down
2 changes: 1 addition & 1 deletion unity/native_src/Inc/V8Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace puerts
{
const intptr_t OBJECT_MAGIC = 0xFA0E5D68; // a random value
const intptr_t OBJECT_MAGIC = 0xFA0E5D68;

enum JsValueType
{
Expand Down
32 changes: 8 additions & 24 deletions unity/native_src/Src/JSEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace puerts
v8::Local<v8::ArrayBuffer> NewArrayBuffer(v8::Isolate* Isolate, void *Ptr, size_t Size)
{
v8::Local<v8::ArrayBuffer> Ab = v8::ArrayBuffer::New(Isolate, Size);
void* Buff = Ab->GetBackingStore()->Data();
void* Buff = Ab->GetContents().Data();
::memcpy(Buff, Ptr, Size);
return Ab;
}
Expand Down Expand Up @@ -74,11 +74,7 @@ namespace puerts
printf("InitializeNodeWithArgs failed\n");
}
}
std::string Flags = "";
#if PUERTS_DEBUG
Flags += "--expose-gc";
#endif
v8::V8::SetFlagsFromString(Flags.c_str(), static_cast<int>(Flags.size()));
// PLog(puerts::Log, "[PuertsDLL][JSEngineWithNode]GPlatform done");

NodeUVLoop = new uv_loop_t;
const int Ret = uv_loop_init(NodeUVLoop);
Expand Down Expand Up @@ -134,10 +130,6 @@ namespace puerts
Global->Set(Context, FV8Utils::V8String(MainIsolate, "__tgjsEvalScript"), v8::FunctionTemplate::New(MainIsolate, &EvalWithPath)->GetFunction(Context).ToLocalChecked()).Check();

MainIsolate->SetPromiseRejectCallback(&PromiseRejectCallback<JSEngine>);
#if !WITH_QUICKJS
MainIsolate->SetHostInitializeImportMetaObjectCallback(&JSEngine::HostInitializeImportMetaObject);
#endif

Global->Set(Context, FV8Utils::V8String(MainIsolate, "__tgjsSetPromiseRejectCallback"), v8::FunctionTemplate::New(MainIsolate, &SetPromiseRejectCallback<JSEngine>)->GetFunction(Context).ToLocalChecked()).Check();

JSObjectIdMap.Reset(MainIsolate, v8::Map::New(MainIsolate));
Expand All @@ -156,15 +148,10 @@ namespace puerts
v8::V8::InitializePlatform(GPlatform.get());
v8::V8::Initialize();
}

std::string Flags = "";
#if PUERTS_DEBUG
Flags += "--expose-gc";
#endif
#if PLATFORM_IOS
Flags += "--jitless --no-expose-wasm";
#endif
std::string Flags = "--jitless --no-expose-wasm";
v8::V8::SetFlagsFromString(Flags.c_str(), static_cast<int>(Flags.size()));
#endif

v8::StartupData SnapshotBlob;
SnapshotBlob.data = (const char *)SnapshotBlobCode;
Expand Down Expand Up @@ -197,11 +184,8 @@ namespace puerts

Global->Set(Context, FV8Utils::V8String(Isolate, "__tgjsEvalScript"), v8::FunctionTemplate::New(Isolate, &EvalWithPath)->GetFunction(Context).ToLocalChecked()).Check();

if (external_quickjs_runtime == nullptr)
{
Isolate->SetPromiseRejectCallback(&PromiseRejectCallback<JSEngine>);
Global->Set(Context, FV8Utils::V8String(Isolate, "__tgjsSetPromiseRejectCallback"), v8::FunctionTemplate::New(Isolate, &SetPromiseRejectCallback<JSEngine>)->GetFunction(Context).ToLocalChecked()).Check();
}
Isolate->SetPromiseRejectCallback(&PromiseRejectCallback<JSEngine>);
Global->Set(Context, FV8Utils::V8String(Isolate, "__tgjsSetPromiseRejectCallback"), v8::FunctionTemplate::New(Isolate, &SetPromiseRejectCallback<JSEngine>)->GetFunction(Context).ToLocalChecked()).Check();

JSObjectIdMap.Reset(Isolate, v8::Map::New(Isolate));
}
Expand Down Expand Up @@ -257,12 +241,12 @@ namespace puerts
Iter->second.Reset();
}
#if !WITH_QUICKJS
for (auto Iter = PathToModuleMap.begin(); Iter != PathToModuleMap.end(); ++Iter)
for (auto Iter = ModuleCacheMap.begin(); Iter != ModuleCacheMap.end(); ++Iter)
{
Iter->second.Reset();
}
#endif
PathToModuleMap.clear();
ModuleCacheMap.clear();
}
{
std::lock_guard<std::mutex> guard(JSFunctionsMutex);
Expand Down
Loading

0 comments on commit 4f6eed0

Please sign in to comment.