forked from mirrors/0ad
Normalize module-path
Modules indipendant of the path, should only be evaluated once.
This commit is contained in:
@@ -58,7 +58,8 @@ namespace
|
||||
[[nodiscard]] JSObject* CompileModule(const ScriptRequest& rq, ModuleLoader::RegistryType& registry,
|
||||
const VfsPath& filePath)
|
||||
{
|
||||
const auto insertResult = registry.try_emplace(filePath, rq, filePath);
|
||||
const VfsPath normalizedPath{filePath.fileSystemPath().lexically_normal().generic_string()};
|
||||
const auto insertResult = registry.try_emplace(normalizedPath, rq, normalizedPath);
|
||||
return std::get<1>(*std::get<0>(insertResult)).m_ModuleObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,4 +97,21 @@ public:
|
||||
TS_ASSERT_THROWS(script.GetModuleLoader().LoadModule(rq, "nonexistent.js"),
|
||||
const std::runtime_error&);
|
||||
}
|
||||
|
||||
void test_EvaluateOnce()
|
||||
{
|
||||
ScriptInterface script{"Test", "Test", g_ScriptContext};
|
||||
const ScriptRequest rq{script};
|
||||
|
||||
{
|
||||
TestLogger logger;
|
||||
script.GetModuleLoader().LoadModule(rq, "blabbermouth.js");
|
||||
TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "blah blah blah");
|
||||
}
|
||||
{
|
||||
TestLogger logger;
|
||||
script.GetModuleLoader().LoadModule(rq, "include/../blabbermouth.js");
|
||||
TS_ASSERT_STR_NOT_CONTAINS(logger.GetOutput(), "blah blah blah");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user