From 4f6eed0ad9f5f36891e39f1b5483ed82ef20a69b Mon Sep 17 00:00:00 2001 From: "jh.Kim" Date: Thu, 10 Nov 2022 15:04:56 +0900 Subject: [PATCH] =?UTF-8?q?1.2.x=20=EB=B2=84=EC=A0=84=20=EB=B9=8C=EB=93=9C?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/unity_build_plugins.yml | 6 +- unity/native_src/CMakeLists.txt | 4 - unity/native_src/Inc/JSEngine.h | 71 +++++++------ unity/native_src/Inc/JSFunction.h | 2 +- unity/native_src/Inc/V8Utils.h | 2 +- unity/native_src/Src/JSEngine.cpp | 32 ++---- unity/native_src/Src/JSEngine_Eval.cpp | 124 +++------------------- unity/native_src/Src/JSFunction.cpp | 23 ++-- unity/native_src/Src/Puerts.cpp | 74 ++++--------- unity/native_src/cmake/nodejs/backend.rc | 2 +- unity/native_src/cmake/v8/backend.rc | 3 +- unity/native_src/make_android.sh | 12 +-- unity/native_src/make_ios.sh | 12 +-- unity/native_src/make_linux64.sh | 10 +- unity/native_src/make_osx.sh | 32 ++++-- unity/native_src/make_win32.bat | 13 +-- unity/native_src/make_win64.bat | 13 +-- unity/native_src/make_win64_test.bat | 12 --- 18 files changed, 134 insertions(+), 313 deletions(-) delete mode 100644 unity/native_src/make_win64_test.bat diff --git a/.github/workflows/unity_build_plugins.yml b/.github/workflows/unity_build_plugins.yml index 18b8ce4ab0..875e208619 100644 --- a/.github/workflows/unity_build_plugins.yml +++ b/.github/workflows/unity_build_plugins.yml @@ -1,4 +1,4 @@ -name: unity build plugins +name: build unity plugins on: workflow_dispatch: @@ -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 @@ -257,4 +258,5 @@ jobs: uses: actions/upload-artifact@v2 with: path: ./unity/Assets/Plugins/**/* - name: Unity_Plugins_V8 \ No newline at end of file + name: Unity_Plugins_V8 + \ No newline at end of file diff --git a/unity/native_src/CMakeLists.txt b/unity/native_src/CMakeLists.txt index 0d1b3d06c6..b4bf0a018e 100644 --- a/unity/native_src/CMakeLists.txt +++ b/unity/native_src/CMakeLists.txt @@ -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 ) diff --git a/unity/native_src/Inc/JSEngine.h b/unity/native_src/Inc/JSEngine.h index cdea17c82a..e2a2bc5984 100644 --- a/unity/native_src/Inc/JSEngine.h +++ b/unity/native_src/Inc/JSEngine.h @@ -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" @@ -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& Info, void* Self, int ParamLen, int64_t UserData); typedef void* (*CSharpConstructorCallback)(v8::Isolate* Isolate, const v8::FunctionCallbackInfo& Info, int ParamLen, int64_t UserData); @@ -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 context, v8::Local module, v8::Local 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 GetClassConstructor(int ClassID); + PUERTS_EXPORT_FOR_UT v8::Local GetClassConstructor(int ClassID); - v8::Local FindOrAddObject(v8::Isolate* Isolate, v8::Local Context, int ClassID, void *Ptr); + PUERTS_EXPORT_FOR_UT v8::Local FindOrAddObject(v8::Isolate* Isolate, v8::Local Context, int ClassID, void *Ptr); - void BindObject(FLifeCycleInfo* LifeCycleInfo, void* Ptr, v8::Local JSObject); + PUERTS_EXPORT_FOR_UT void BindObject(FLifeCycleInfo* LifeCycleInfo, void* Ptr, v8::Local 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 InContext, v8::Local InFunction); + PUERTS_EXPORT_FOR_UT JSFunction* CreateJSFunction(v8::Isolate* InIsolate, v8::Local InContext, v8::Local InFunction); - void ReleaseJSFunction(JSFunction* InFunction); + PUERTS_EXPORT_FOR_UT void ReleaseJSFunction(JSFunction* InFunction); - JSObject* CreateJSObject(v8::Isolate* InIsolate, v8::Local InContext, v8::Local InObject); + PUERTS_EXPORT_FOR_UT JSObject* CreateJSObject(v8::Isolate* InIsolate, v8::Local InContext, v8::Local 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; @@ -163,7 +168,7 @@ class JSEngine v8::UniquePersistent JsPromiseRejectCallback; - V8_INLINE static JSEngine * Get(v8::Isolate* Isolate) + PUERTS_EXPORT_FOR_UT V8_INLINE static JSEngine * Get(v8::Isolate* Isolate) { return FV8Utils::IsolateData(Isolate); } @@ -171,15 +176,11 @@ class JSEngine int32_t Idx; CSharpModuleResolveCallback ModuleResolver; - CSharpPushJSFunctionArgumentsCallback GetJSArgumentsCallback; - #if defined(WITH_QUICKJS) - std::map PathToModuleMap; + std::map ModuleCacheMap; #else - std::map> PathToModuleMap; + std::map> ModuleCacheMap; #endif - - std::map ScriptIdToPathMap; private: #if defined(WITH_NODEJS) uv_loop_t* NodeUVLoop; @@ -218,7 +219,7 @@ class JSEngine V8Inspector* Inspector; -public: +private: v8::Local ToTemplate(v8::Isolate* Isolate, bool IsStatic, CSharpFunctionCallback Callback, int64_t Data); }; } diff --git a/unity/native_src/Inc/JSFunction.h b/unity/native_src/Inc/JSFunction.h index 08d95973b2..2e0d170f7a 100644 --- a/unity/native_src/Inc/JSFunction.h +++ b/unity/native_src/Inc/JSFunction.h @@ -73,7 +73,7 @@ class JSFunction ~JSFunction(); - bool Invoke(int argumentsLength, bool HasResult); + bool Invoke(bool HasResult); std::vector Arguments; diff --git a/unity/native_src/Inc/V8Utils.h b/unity/native_src/Inc/V8Utils.h index 426901841c..29b6ffd38e 100644 --- a/unity/native_src/Inc/V8Utils.h +++ b/unity/native_src/Inc/V8Utils.h @@ -17,7 +17,7 @@ namespace puerts { -const intptr_t OBJECT_MAGIC = 0xFA0E5D68; // a random value +const intptr_t OBJECT_MAGIC = 0xFA0E5D68; enum JsValueType { diff --git a/unity/native_src/Src/JSEngine.cpp b/unity/native_src/Src/JSEngine.cpp index 3fc90ef7fb..90297ae656 100644 --- a/unity/native_src/Src/JSEngine.cpp +++ b/unity/native_src/Src/JSEngine.cpp @@ -16,7 +16,7 @@ namespace puerts v8::Local NewArrayBuffer(v8::Isolate* Isolate, void *Ptr, size_t Size) { v8::Local Ab = v8::ArrayBuffer::New(Isolate, Size); - void* Buff = Ab->GetBackingStore()->Data(); + void* Buff = Ab->GetContents().Data(); ::memcpy(Buff, Ptr, Size); return Ab; } @@ -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(Flags.size())); + // PLog(puerts::Log, "[PuertsDLL][JSEngineWithNode]GPlatform done"); NodeUVLoop = new uv_loop_t; const int Ret = uv_loop_init(NodeUVLoop); @@ -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); -#if !WITH_QUICKJS - MainIsolate->SetHostInitializeImportMetaObjectCallback(&JSEngine::HostInitializeImportMetaObject); -#endif - Global->Set(Context, FV8Utils::V8String(MainIsolate, "__tgjsSetPromiseRejectCallback"), v8::FunctionTemplate::New(MainIsolate, &SetPromiseRejectCallback)->GetFunction(Context).ToLocalChecked()).Check(); JSObjectIdMap.Reset(MainIsolate, v8::Map::New(MainIsolate)); @@ -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(Flags.size())); +#endif v8::StartupData SnapshotBlob; SnapshotBlob.data = (const char *)SnapshotBlobCode; @@ -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); - Global->Set(Context, FV8Utils::V8String(Isolate, "__tgjsSetPromiseRejectCallback"), v8::FunctionTemplate::New(Isolate, &SetPromiseRejectCallback)->GetFunction(Context).ToLocalChecked()).Check(); - } + Isolate->SetPromiseRejectCallback(&PromiseRejectCallback); + Global->Set(Context, FV8Utils::V8String(Isolate, "__tgjsSetPromiseRejectCallback"), v8::FunctionTemplate::New(Isolate, &SetPromiseRejectCallback)->GetFunction(Context).ToLocalChecked()).Check(); JSObjectIdMap.Reset(Isolate, v8::Map::New(Isolate)); } @@ -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 guard(JSFunctionsMutex); diff --git a/unity/native_src/Src/JSEngine_Eval.cpp b/unity/native_src/Src/JSEngine_Eval.cpp index a3e0dafd33..f074a40c7d 100644 --- a/unity/native_src/Src/JSEngine_Eval.cpp +++ b/unity/native_src/Src/JSEngine_Eval.cpp @@ -4,75 +4,19 @@ * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may be subject to their corresponding license terms. * This file is subject to the terms and conditions defined in file 'LICENSE', which is part of this source code package. */ -#include #include "JSEngine.h" #if WITH_QUICKJS #include "quickjs-msvc.h" #endif namespace puerts { - bool IsAbsolutePath(const std::string& path) { -#if defined(_WIN32) || defined(_WIN64) - // This is an incorrect approximation, but should - // work for all our test-running cases. - return path.find(':') != std::string::npos; -#else - return path[0] == '/'; -#endif - } - bool IsRelativePath(const std::string& path) { - if (path[0] == '.') { - if (path.length() == 1 || path[1] == '/') return true; - if (path[1] == '.') { - if (path.length() == 2 || path[2] == '/') return true; - } - } - return false; - } - - // Returns the directory part of path, without the trailing '/'. - std::string DirName(const std::string& path) { - size_t last_slash = path.find_last_of('/'); - printf("%s %d\n", path.c_str(), (int)last_slash); - if (last_slash == std::string::npos) return "."; - return path.substr(0, last_slash); - } - - // Resolves path to an absolute path if necessary, and does some - // normalization (eliding references to the current directory - // and replacing backslashes with slashes). - std::string NormalizePath(const std::string& path, - const std::string& from_path) { - std::string absolute_path; - if (IsRelativePath(path)) { - absolute_path = DirName(from_path) + '/' + path; - } else { - absolute_path = path; - } - std::replace(absolute_path.begin(), absolute_path.end(), '\\', '/'); - std::vector segments; - std::istringstream segment_stream(absolute_path); - std::string segment; - while (std::getline(segment_stream, segment, '/')) { - if (segment == "..") { - segments.pop_back(); - } else if (segment != ".") { - segments.push_back(segment); - } - } - // Join path segments. - std::ostringstream os; - std::copy(segments.begin(), segments.end() - 1, - std::ostream_iterator(os, "/")); - os << *segments.rbegin(); - return os.str(); - } + std::string CjsModulePrepend("export default globalThis.require('"); + std::string CjsModuleAppend("');"); #if !WITH_QUICKJS - v8::MaybeLocal _ResolveModule( + v8::MaybeLocal ResolveModule( v8::Local Context, v8::Local Specifier, - v8::Local Referrer, - bool& isFromCache + v8::Local Referrer ) { v8::Isolate* Isolate = Context->GetIsolate(); @@ -82,24 +26,16 @@ namespace puerts { std::string Specifier_std(*Specifier_utf8, Specifier_utf8.length()); size_t Specifier_length = Specifier_std.length(); - const auto referIter = JsEngine->ScriptIdToPathMap.find(Referrer->GetIdentityHash()); - if (referIter != JsEngine->ScriptIdToPathMap.end()) - { - std::string referPath_std = referIter->second; - Specifier_std = NormalizePath(Specifier_std, referPath_std); - } - - const auto cacheIter = JsEngine->PathToModuleMap.find(Specifier_std); - if (cacheIter != JsEngine->PathToModuleMap.end())//create and link + auto Iter = JsEngine->ModuleCacheMap.find(Specifier_std); + if (Iter != JsEngine->ModuleCacheMap.end())//create and link { - isFromCache = true; - return v8::Local::New(Isolate, cacheIter->second); + return v8::Local::New(Isolate, Iter->second); } v8::Local Module; const char* Code = JsEngine->ModuleResolver(Specifier_std.c_str(), JsEngine->Idx); if (Code == nullptr) { - std::string ErrorMessage = std::string("module not found ") + Specifier_std; + std::string ErrorMessage = std::string("module not found") + Specifier_std; Isolate->ThrowException(v8::Exception::Error(FV8Utils::V8String(Isolate, ErrorMessage.c_str()))); return v8::MaybeLocal(); } @@ -126,35 +62,9 @@ namespace puerts { return v8::MaybeLocal(); } - JsEngine->PathToModuleMap[Specifier_std] = v8::UniquePersistent(Isolate, Module); - JsEngine->ScriptIdToPathMap[Module->GetIdentityHash()] = Specifier_std; + JsEngine->ModuleCacheMap[Specifier_std] = v8::UniquePersistent(Isolate, Module); return Module; } - v8::MaybeLocal ResolveModule( - v8::Local Context, - v8::Local Specifier, - v8::Local Referrer - ) - { - bool isFromCache = false; - return _ResolveModule(Context, Specifier, Referrer, isFromCache); - } - - void JSEngine::HostInitializeImportMetaObject(v8::Local Context, v8::Local Module, v8::Local meta) - { - v8::Isolate* Isolate = Context->GetIsolate(); - auto* JsEngine = FV8Utils::IsolateData(Isolate); - - auto iter = JsEngine->ScriptIdToPathMap.find(Module->GetIdentityHash()); - if (iter != JsEngine->ScriptIdToPathMap.end()) - { - meta->CreateDataProperty( - Context, - FV8Utils::V8String(Context->GetIsolate(), "url"), - FV8Utils::V8String(Context->GetIsolate(), ("puer:" + iter->second).c_str()) - ).ToChecked(); - } - } #else JSModuleDef* js_module_loader(JSContext* ctx, const char *name, void *opaque) { JSRuntime *rt = JS_GetRuntime(ctx); @@ -164,8 +74,8 @@ namespace puerts { std::string name_std(name); size_t name_length = name_std.length(); - auto Iter = JsEngine->PathToModuleMap.find(name_std); - if (Iter != JsEngine->PathToModuleMap.end())//create and link + auto Iter = JsEngine->ModuleCacheMap.find(name_std); + if (Iter != JsEngine->ModuleCacheMap.end())//create and link { return Iter->second; } @@ -173,7 +83,7 @@ namespace puerts { const char* Code = JsEngine->ModuleResolver(name_std.c_str(), JsEngine->Idx); if (Code == nullptr) { - std::string ErrorMessage = std::string("module not found ") + name_std; + std::string ErrorMessage = std::string("module not found") + name_std; JSValue ex = JS_NewStringLen(ctx, ErrorMessage.c_str(), ErrorMessage.length()); JS_Throw(ctx, ex); return nullptr; @@ -186,11 +96,7 @@ namespace puerts { auto module_ = (JSModuleDef *) JS_VALUE_GET_PTR(func_val); - auto obj = JS_GetImportMeta(ctx, module_); - JS_SetProperty(ctx, obj, JS_NewAtom(ctx, "url"), JS_NewString(ctx, ("puer:" + name_std).c_str())); - JS_FreeValue(ctx, obj); - - JsEngine->PathToModuleMap[name_std] = module_; + JsEngine->ModuleCacheMap[name_std] = module_; return module_; } @@ -230,10 +136,6 @@ namespace puerts { if (Module.IsEmpty()) { - if (TryCatch.HasCaught()) - { - LastExceptionInfo = FV8Utils::ExceptionToString(Isolate, TryCatch); - } return false; } diff --git a/unity/native_src/Src/JSFunction.cpp b/unity/native_src/Src/JSFunction.cpp index 22fdf8995f..a1106278e1 100644 --- a/unity/native_src/Src/JSFunction.cpp +++ b/unity/native_src/Src/JSFunction.cpp @@ -81,7 +81,12 @@ namespace puerts } } - bool JSFunction::Invoke(int argumentsLength, bool HasResult) + /*void JSFunction::SetResult(v8::MaybeLocal maybeValue) + { + + }*/ + + bool JSFunction::Invoke(bool HasResult) { v8::Isolate* Isolate = ResultInfo.Isolate; v8::Isolate::Scope IsolateScope(Isolate); @@ -89,20 +94,14 @@ namespace puerts v8::Local Context = ResultInfo.Context.Get(Isolate); v8::Context::Scope ContextScope(Context); - Arguments.clear(); - JSEngine* JsEngine = FV8Utils::IsolateData(Isolate); - if (argumentsLength > 0) + std::vector< v8::Local> V8Args; + for (int i = 0; i < Arguments.size(); ++i) { - JsEngine->GetJSArgumentsCallback(Isolate, JsEngine->Idx, this); + V8Args.push_back(ToV8(Isolate, Context, Arguments[i])); } - + Arguments.clear(); v8::TryCatch TryCatch(Isolate); - v8::Local *args = (v8::Local *)alloca(sizeof(v8::Local) * Arguments.size()); - for (int i = 0; i < Arguments.size(); i++) - { - args[i] = ToV8(Isolate, Context, Arguments[i]); - } - auto maybeValue = GFunction.Get(Isolate)->Call(Context, Context->Global(), static_cast(Arguments.size()), args); + auto maybeValue = GFunction.Get(Isolate)->Call(Context, Context->Global(), static_cast(V8Args.size()), V8Args.data()); if (TryCatch.HasCaught()) { diff --git a/unity/native_src/Src/Puerts.cpp b/unity/native_src/Src/Puerts.cpp index bc937b8a0e..95d84e27b3 100644 --- a/unity/native_src/Src/Puerts.cpp +++ b/unity/native_src/Src/Puerts.cpp @@ -8,7 +8,7 @@ #include #include "V8Utils.h" -#define API_LEVEL 16 +#define LIB_VERSION 15 using puerts::JSEngine; using puerts::FValue; @@ -22,14 +22,9 @@ using puerts::JsValueType; extern "C" { #endif -// deprecated, delete in 1.4 plz V8_EXPORT int GetLibVersion() { - return API_LEVEL; -} -V8_EXPORT int GetApiLevel() -{ - return API_LEVEL; + return LIB_VERSION; } V8_EXPORT int GetLibBackend() @@ -77,12 +72,6 @@ V8_EXPORT void SetModuleResolver(v8::Isolate *Isolate, CSharpModuleResolveCallba JsEngine->ModuleResolver = Resolver; JsEngine->Idx = Idx; } -V8_EXPORT void SetPushJSFunctionArgumentsCallback(v8::Isolate *Isolate, CSharpPushJSFunctionArgumentsCallback Callback, int32_t Idx) -{ - auto JsEngine = FV8Utils::IsolateData(Isolate); - JsEngine->GetJSArgumentsCallback = Callback; - JsEngine->Idx = Idx; -} V8_EXPORT FResultInfo * ExecuteModule(v8::Isolate *Isolate, const char* Path, const char* Exportee) { @@ -363,15 +352,15 @@ V8_EXPORT const char* GetArrayBufferFromValue(v8::Isolate* Isolate, v8::Value *V { v8::ArrayBufferView * BuffView = v8::ArrayBufferView::Cast(Value); *Length = static_cast(BuffView->ByteLength()); - auto ABS = BuffView->Buffer()->GetBackingStore(); - return static_cast(ABS->Data()) + BuffView->ByteOffset(); + auto ABC = BuffView->Buffer()->GetContents(); + return static_cast(ABC.Data()) + BuffView->ByteOffset(); } else if (Value->IsArrayBuffer()) { auto Ab = v8::ArrayBuffer::Cast(Value); - auto ABS = Ab->GetBackingStore(); - *Length = static_cast(ABS->ByteLength()); - return static_cast(ABS->Data()); + auto ABC = Ab->GetContents(); + *Length = static_cast(ABC.ByteLength()); + return static_cast(ABC.Data()); } else { @@ -569,17 +558,6 @@ V8_EXPORT void ReturnFunction(v8::Isolate* Isolate, const v8::FunctionCallbackIn Info.GetReturnValue().Set(Function->GFunction.Get(Isolate)); } -V8_EXPORT void ReturnCSharpFunctionCallback(v8::Isolate* Isolate, const v8::FunctionCallbackInfo& Info, CSharpFunctionCallback Callback, int64_t Data) -{ - auto JsEngine = FV8Utils::IsolateData(Isolate); - v8::Isolate::Scope IsolateScope(Isolate); - v8::HandleScope HandleScope(Isolate); - v8::Local Context = JsEngine->ResultInfo.Context.Get(Isolate); - v8::Context::Scope ContextScope(Context); - - Info.GetReturnValue().Set(JsEngine->ToTemplate(Isolate, false, Callback, Data)->GetFunction(Context).ToLocalChecked()); -} - V8_EXPORT void ReturnJSObject(v8::Isolate* Isolate, const v8::FunctionCallbackInfo& Info, puerts::JSObject *Object) { Info.GetReturnValue().Set(Object->GObject.Get(Isolate)); @@ -593,7 +571,6 @@ V8_EXPORT void PushNullForJSFunction(JSFunction *Function) { FValue Value; Value.Type = puerts::NullOrUndefined; - // Function->PushArgument(Value); Function->Arguments.push_back(std::move(Value)); } @@ -602,7 +579,6 @@ V8_EXPORT void PushDateForJSFunction(JSFunction *Function, double DateValue) FValue Value; Value.Type = puerts::Date; Value.Number = DateValue; - // Function->PushArgument(Value); Function->Arguments.push_back(std::move(Value)); } @@ -611,7 +587,6 @@ V8_EXPORT void PushBooleanForJSFunction(JSFunction *Function, int B) FValue Value; Value.Type = puerts::Boolean; Value.Boolean = B; - // Function->PushArgument(Value); Function->Arguments.push_back(std::move(Value)); } @@ -620,7 +595,6 @@ V8_EXPORT void PushBigIntForJSFunction(JSFunction *Function, int64_t V) FValue Value; Value.Type = puerts::BigInt; Value.BigInt = V; - // Function->PushArgument(Value); Function->Arguments.push_back(std::move(Value)); } @@ -634,7 +608,6 @@ V8_EXPORT void PushArrayBufferForJSFunction(JSFunction *Function, unsigned char FValue Value; Value.Type = puerts::ArrayBuffer; Value.ArrayBuffer.Reset(Isolate, puerts::NewArrayBuffer(Isolate, Bytes, Length)); - // Function->PushArgument(Value); Function->Arguments.push_back(std::move(Value)); } @@ -643,7 +616,6 @@ V8_EXPORT void PushStringForJSFunction(JSFunction *Function, const char* S) FValue Value; Value.Type = puerts::String; Value.Str = S; - // Function->PushArgument(Value); Function->Arguments.push_back(std::move(Value)); } @@ -652,7 +624,6 @@ V8_EXPORT void PushNumberForJSFunction(JSFunction *Function, double D) FValue Value; Value.Type = puerts::Number; Value.Number = D; - // Function->PushArgument(Value); Function->Arguments.push_back(std::move(Value)); } @@ -662,31 +633,28 @@ V8_EXPORT void PushObjectForJSFunction(JSFunction *Function, int ClassID, void* Value.Type = puerts::NativeObject; Value.ObjectInfo.ClassID = ClassID; Value.ObjectInfo.ObjectPtr = Ptr; - // Function->PushArgument(Value); Function->Arguments.push_back(std::move(Value)); } V8_EXPORT void PushJSFunctionForJSFunction(JSFunction *F, JSFunction *V) { - FValue Value; - Value.Type = puerts::Function; - Value.FunctionPtr = V; - // F->PushArgument(Value); + FValue Value; + Value.Type = puerts::Function; + Value.FunctionPtr = V; F->Arguments.push_back(std::move(Value)); } V8_EXPORT void PushJSObjectForJSFunction(JSFunction *F, puerts::JSObject *V) { - FValue Value; - Value.Type = puerts::JsObject; - Value.JSObjectPtr = V; - // F->PushArgument(Value); - F->Arguments.push_back(std::move(Value)); + FValue Value; + Value.Type = puerts::JsObject; + Value.JSObjectPtr = V; + F->Arguments.push_back(std::move(Value)); } -V8_EXPORT FResultInfo *InvokeJSFunction(JSFunction *Function, int argumentsLength, int HasResult) +V8_EXPORT FResultInfo *InvokeJSFunction(JSFunction *Function, int HasResult) { - if (Function->Invoke(argumentsLength, HasResult)) + if (Function->Invoke(HasResult)) { return &(Function->ResultInfo); } @@ -807,15 +775,15 @@ V8_EXPORT const char *GetArrayBufferFromResult(FResultInfo *ResultInfo, int *Len { v8::Local BuffView = Value.As(); *Length = static_cast(BuffView->ByteLength()); - auto ABS = BuffView->Buffer()->GetBackingStore(); - return static_cast(ABS->Data()) + BuffView->ByteOffset(); + auto ABC = BuffView->Buffer()->GetContents(); + return static_cast(ABC.Data()) + BuffView->ByteOffset(); } else if (Value->IsArrayBuffer()) { auto Ab = v8::Local ::Cast(Value); - auto ABS = Ab->GetBackingStore(); - *Length = static_cast(ABS->ByteLength()); - return static_cast(ABS->Data()); + auto ABC = Ab->GetContents(); + *Length = static_cast(ABC.ByteLength()); + return static_cast(ABC.Data()); } else { diff --git a/unity/native_src/cmake/nodejs/backend.rc b/unity/native_src/cmake/nodejs/backend.rc index 854eef1ef2..78ba3b954b 100644 --- a/unity/native_src/cmake/nodejs/backend.rc +++ b/unity/native_src/cmake/nodejs/backend.rc @@ -1,4 +1,4 @@ BACKEND_ARTIFACT_NAME=nodejs_bin -BACKEND_ARTIFACT_WORKFLOW=build_nodejs.yml +BACKEND_ARTIFACT_WORKFLOW=build_14.yml BACKEND_ARTIFACT_REPO=puerts/backend-nodejs BACKEND_URL=https://github.com/puerts/backend-nodejs/releases/download/NodeJS_0425/nodejs_bin_14.16.1.tgz \ No newline at end of file diff --git a/unity/native_src/cmake/v8/backend.rc b/unity/native_src/cmake/v8/backend.rc index 870706dae9..47d76bf9c8 100644 --- a/unity/native_src/cmake/v8/backend.rc +++ b/unity/native_src/cmake/v8/backend.rc @@ -1,3 +1,4 @@ BACKEND_ARTIFACT_NAME=v8_bin BACKEND_ARTIFACT_WORKFLOW=build_8.4.yml -BACKEND_ARTIFACT_REPO=puerts/backend-v8 \ No newline at end of file +BACKEND_ARTIFACT_REPO=puerts/backend-v8 +BACKEND_URL=https://github.com/puerts/backend-v8/releases/download/V8_8.4.371.19_20220705/v8_bin_8.4.371.19.tgz \ No newline at end of file diff --git a/unity/native_src/make_android.sh b/unity/native_src/make_android.sh index 8a8b975eff..c4b3317321 100755 --- a/unity/native_src/make_android.sh +++ b/unity/native_src/make_android.sh @@ -4,12 +4,6 @@ then ENGINE="v8" fi -CONFIG=$2 -if [ "$2" == "" ] -then - CONFIG="Release" -fi - if [ -n "$ANDROID_NDK" ]; then export NDK=${ANDROID_NDK} elif [ -n "$ANDROID_NDK_HOME" ]; then @@ -27,9 +21,9 @@ function build() { API=$1 ABI=$2 TOOLCHAIN_ANME=$3 - BUILD_PATH=build.${ENGINE}.Android.${ABI} - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DJS_ENGINE=${ENGINE} -DCMAKE_BUILD_TYPE=${CONFIG} -DANDROID_ABI=${ABI} -H. -B${BUILD_PATH} -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=${API} -DANDROID_TOOLCHAIN=clang -DANDROID_TOOLCHAIN_NAME=${TOOLCHAIN_ANME} - cmake --build ${BUILD_PATH} --config ${CONFIG} + BUILD_PATH=build.$ENGINE.Android.${ABI} + cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DJS_ENGINE=$ENGINE -DANDROID_ABI=${ABI} -H. -B${BUILD_PATH} -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=${API} -DANDROID_TOOLCHAIN=clang -DANDROID_TOOLCHAIN_NAME=${TOOLCHAIN_ANME} + cmake --build ${BUILD_PATH} --config Release mkdir -p ../Assets/Plugins/Android/libs/${ABI}/ cp ${BUILD_PATH}/libpuerts.so ../Assets/Plugins/Android/libs/${ABI}/libpuerts.so } diff --git a/unity/native_src/make_ios.sh b/unity/native_src/make_ios.sh index f61c253a75..ebfbfa2cca 100755 --- a/unity/native_src/make_ios.sh +++ b/unity/native_src/make_ios.sh @@ -4,17 +4,11 @@ then ENGINE="v8" fi -CONFIG=$2 -if [ "$2" == "" ] -then - CONFIG="Release" -fi - mkdir -p build_ios_$ENGINE && cd build_ios_$ENGINE -cmake -DJS_ENGINE=$ENGINE -DCMAKE_BUILD_TYPE=$CONFIG -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64 -GXcode ../ +cmake -DJS_ENGINE=$ENGINE -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64 -GXcode ../ cd .. -cmake --build build_ios_$ENGINE --config $CONFIG +cmake --build build_ios_$ENGINE --config Release mkdir -p ../Assets/Plugins/iOS/ -cp build_ios_$ENGINE/$CONFIG-iphoneos/libpuerts.a ../Assets/Plugins/iOS/ +cp build_ios_$ENGINE/Release-iphoneos/libpuerts.a ../Assets/Plugins/iOS/ cp $ENGINE/Lib/iOS/arm64/*.a ../Assets/Plugins/iOS/ diff --git a/unity/native_src/make_linux64.sh b/unity/native_src/make_linux64.sh index 2a1cff2950..509941c1a6 100755 --- a/unity/native_src/make_linux64.sh +++ b/unity/native_src/make_linux64.sh @@ -4,15 +4,9 @@ then ENGINE="v8" fi -CONFIG=$2 -if [ "$2" == "" ] -then - CONFIG="Release" -fi - mkdir -p build_linux64_$ENGINE && cd build_linux64_$ENGINE -cmake -DJS_ENGINE=$ENGINE -DCMAKE_BUILD_TYPE=$CONFIG ../ +cmake -DJS_ENGINE=$ENGINE ../ cd .. -cmake --build build_linux64_$ENGINE --config $CONFIG +cmake --build build_linux64_$ENGINE --config Release mkdir -p ../Assets/Plugins/x86_64/ cp build_linux64_$ENGINE/libpuerts.so ../Assets/Plugins/x86_64/libpuerts.so \ No newline at end of file diff --git a/unity/native_src/make_osx.sh b/unity/native_src/make_osx.sh index b45f9bd450..ea918e24fa 100755 --- a/unity/native_src/make_osx.sh +++ b/unity/native_src/make_osx.sh @@ -4,19 +4,31 @@ then ENGINE="v8" fi -CONFIG=$2 -if [ "$2" == "" ] -then - CONFIG="Release" -fi - mkdir -p build_osx_$ENGINE && cd build_osx_$ENGINE -cmake -DJS_ENGINE=$ENGINE -DCMAKE_BUILD_TYPE=$CONFIG -GXcode ../ +cmake -DJS_ENGINE=$ENGINE -GXcode ../ cd .. -cmake --build build_osx_$ENGINE --config $CONFIG -cmake --install build_osx_$ENGINE --config $CONFIG --prefix "$(pwd)/build_osx_$ENGINE" +cmake --build build_osx_$ENGINE --config Release +cmake --install build_osx_$ENGINE --prefix "$(pwd)/build_osx_$ENGINE" mv build_osx_$ENGINE/bin/libpuerts.dylib build_osx_$ENGINE/bin/puerts.bundle cp -r $ENGINE/Lib/macOS/*.dylib build_osx_$ENGINE/bin/ mkdir -p ../Assets/Plugins/macOS -cp -r build_osx_$ENGINE/bin/* ../Assets/Plugins/macOS/ \ No newline at end of file +cp -r build_osx_$ENGINE/bin/* ../Assets/Plugins/macOS/ + + +# mkdir -p build_osx && cd build_osx +# if [ "$1" == "-ut" ] +# then +# cmake -DFOR_UT=ON ../ +# cd .. +# cmake --build build_osx --config Debug +# cp -r build_osx/libpuerts.dylib ../general/Bin/ +# else +# cmake -GXcode ../ +# cd .. +# cmake --build build_osx --config Release +# cmake --install build_osx --prefix "$(pwd)/build_osx" +# mv build_osx/bin/libpuerts.dylib build_osx/bin/libpuerts.bundle +# mkdir -p ../Assets/Plugins/macOS +# cp -r build_osx/bin/* ../Assets/Plugins/macOS/ +# fi \ No newline at end of file diff --git a/unity/native_src/make_win32.bat b/unity/native_src/make_win32.bat index cc31c41aca..77e5db7859 100644 --- a/unity/native_src/make_win32.bat +++ b/unity/native_src/make_win32.bat @@ -2,18 +2,11 @@ set ENGINE=%1 if "%ENGINE%"=="" ( set ENGINE=v8 ) -set CONFIG=%2 -if "%CONFIG%"=="" ( - set CONFIG=Release -) -if "%CONFIG%"=="Debug" ( - set CONFIG=RelWithDebInfo -) mkdir build32_%ENGINE% & pushd build32_%ENGINE% -cmake -DJS_ENGINE=%ENGINE% -DCMAKE_BUILD_TYPE=%CONFIG% -G "Visual Studio 16 2019" -A Win32 .. +cmake -DJS_ENGINE=%ENGINE% -G "Visual Studio 16 2019" -A Win32 .. popd -cmake --build build32_%ENGINE% --config %CONFIG% +cmake --build build32_%ENGINE% --config Release md ..\Assets\Plugins\x86 -copy build32_%ENGINE%\%CONFIG%\puerts.dll ..\Assets\Plugins\x86 +copy build32_%ENGINE%\Release\puerts.dll ..\Assets\Plugins\x86 xcopy %ENGINE%\Lib\Win32\*.dll ..\Assets\Plugins\x86 /C \ No newline at end of file diff --git a/unity/native_src/make_win64.bat b/unity/native_src/make_win64.bat index b1fdd93958..14980657f2 100644 --- a/unity/native_src/make_win64.bat +++ b/unity/native_src/make_win64.bat @@ -2,18 +2,11 @@ set ENGINE=%1 if "%ENGINE%"=="" ( set ENGINE=v8 ) -set CONFIG=%2 -if "%CONFIG%"=="" ( - set CONFIG=Release -) -if "%CONFIG%"=="Debug" ( - set CONFIG=RelWithDebInfo -) mkdir build64_%ENGINE% & pushd build64_%ENGINE% -cmake -DJS_ENGINE=%ENGINE% -DCMAKE_BUILD_TYPE=%CONFIG% -G "Visual Studio 16 2019" -A x64 .. +cmake -DJS_ENGINE=%ENGINE% -G "Visual Studio 16 2019" -A x64 .. popd -cmake --build build64_%ENGINE% --config %CONFIG% +cmake --build build64_%ENGINE% --config Release md ..\Assets\Plugins\x86_64 -copy build64_%ENGINE%\%CONFIG%\puerts.dll ..\Assets\Plugins\x86_64 +copy build64_%ENGINE%\Release\puerts.dll ..\Assets\Plugins\x86_64 xcopy %ENGINE%\Lib\Win64\*.dll ..\Assets\Plugins\x86_64 /C \ No newline at end of file diff --git a/unity/native_src/make_win64_test.bat b/unity/native_src/make_win64_test.bat deleted file mode 100644 index 1c2d4354b8..0000000000 --- a/unity/native_src/make_win64_test.bat +++ /dev/null @@ -1,12 +0,0 @@ -set ENGINE=%1 -if "%ENGINE%"=="" ( - set ENGINE=v8 -) - -mkdir build64_%ENGINE%_test & pushd build64_%ENGINE%_test -cmake -DJS_ENGINE=%ENGINE% -G "Visual Studio 16 2019" -A x64 .. -popd -cmake --build build64_%ENGINE%_test --config RelWithDebInfo -md ..\Assets\Plugins\x86_64 -copy build64_%ENGINE%_test\RelWithDebInfo\puerts.dll ..\general\Bin\ -xcopy %ENGINE%\Lib\Win64\*.dll ..\general\Bin\ \ No newline at end of file