Skip to content

Commit

Permalink
[unity] merge bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieyang committed Sep 30, 2022
1 parent c1819d0 commit 1e7867d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
7 changes: 2 additions & 5 deletions unity/general/Src/UnitTest/EvalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,32 +200,29 @@ public void ESModuleImportCircular()
var loader = new TxtLoader();
loader.AddMockFileContent("module1.mjs", @"
import module2 from './module2.mjs';
CS.System.Console.WriteLine('module1 loading');
const CS = require('csharp')
function callMe(msg)
{
module2.callMe('module 2');
CS.System.Console.WriteLine('callMe called', msg);
}
class M1
{
constructor()
{
CS.System.Console.WriteLine('M1');
}
}
export default { callMe, M1 };
");
loader.AddMockFileContent("module2.mjs", @"
import module1 from './module1.mjs';
CS.System.Console.WriteLine('module2 loading');
const CS = require('csharp')
function callMe(msg)
{
new module1.M1();
CS.System.Console.WriteLine('callMe called', msg);
}
Expand Down
2 changes: 0 additions & 2 deletions unity/general/Src/UnitTest/JSTypeTest/TypedValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public static long PropertyLong

public static bool IsPropertyLongEquals(long l)
{
System.Console.WriteLine(PropertyLong);
System.Console.WriteLine(l);
return PropertyLong == l;
}

Expand Down
7 changes: 6 additions & 1 deletion unity/general/vs2013/Puerts.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
# Visual Studio Version 16
VisualStudioVersion = 16.0.32630.194
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Puerts.Core", "Puerts.Core.csproj", "{7FF5AB8C-EBAA-2482-749F-1E59E0531B86}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Puerts.Helloworld", "Puerts.Helloworld.csproj", "{72C36DF1-DED9-6B87-2751-F7A893A63C0F}"
Expand Down Expand Up @@ -92,4 +94,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D70E5B15-6CE7-430E-A97E-7B972EA3F0FD}
EndGlobalSection
EndGlobal
4 changes: 2 additions & 2 deletions unity/native_src/Src/JSEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ namespace puerts
Iter->second.Reset();
}
#if !WITH_QUICKJS
for (auto Iter = ModuleCacheMap.begin(); Iter != ModuleCacheMap.end(); ++Iter)
for (auto Iter = PathToModuleMap.begin(); Iter != PathToModuleMap.end(); ++Iter)
{
Iter->second.Reset();
}
#endif
ModuleCacheMap.clear();
PathToModuleMap.clear();
}
{
std::lock_guard<std::mutex> guard(JSFunctionsMutex);
Expand Down
14 changes: 10 additions & 4 deletions unity/native_src/Src/JSEngine_Eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 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 <algorithm>
#include "JSEngine.h"
#if WITH_QUICKJS
#include "quickjs-msvc.h"
Expand Down Expand Up @@ -81,7 +82,7 @@ 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->ScriptId());
const auto referIter = JsEngine->ScriptIdToPathMap.find(Referrer->GetIdentityHash());
if (referIter != JsEngine->ScriptIdToPathMap.end())
{
std::string referPath_std = referIter->second;
Expand All @@ -98,7 +99,7 @@ namespace puerts {
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<v8::Module>();
}
Expand Down Expand Up @@ -126,6 +127,7 @@ namespace puerts {
}

JsEngine->PathToModuleMap[Specifier_std] = v8::UniquePersistent<v8::Module>(Isolate, Module);
JsEngine->ScriptIdToPathMap[Module->GetIdentityHash()] = Specifier_std;
return Module;
}
v8::MaybeLocal<v8::Module> ResolveModule(
Expand All @@ -143,7 +145,7 @@ namespace puerts {
v8::Isolate* Isolate = Context->GetIsolate();
auto* JsEngine = FV8Utils::IsolateData<JSEngine>(Isolate);

auto iter = JsEngine->ScriptIdToPathMap.find(Module->6());
auto iter = JsEngine->ScriptIdToPathMap.find(Module->GetIdentityHash());
if (iter != JsEngine->ScriptIdToPathMap.end())
{
meta->CreateDataProperty(
Expand Down Expand Up @@ -171,7 +173,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;
Expand Down Expand Up @@ -228,6 +230,10 @@ namespace puerts {

if (Module.IsEmpty())
{
if (TryCatch.HasCaught())
{
LastExceptionInfo = FV8Utils::ExceptionToString(Isolate, TryCatch);
}
return false;
}

Expand Down

0 comments on commit 1e7867d

Please sign in to comment.