refactor path interface:

- use wrapper class instead of std::wstring (reduces mixing of
strings/paths; allows safe+easy join via operator/ and convenient
case-insensitive comparison via operator==, avoids NativePathFromString,
similar to boost::filesystem)
- NativePath -> OsPath
- add hash and To/FromJSVal for Path
- add TS_ASSERT_PATH_EQUALS
- replace _wfopen_s with sys_OpenFile
- remove obsolete SortFiles/Directories

This was SVN commit r9107.
This commit is contained in:
janwas
2011-03-23 13:36:20 +00:00
parent e39fb7d0de
commit dcd192cb60
147 changed files with 948 additions and 1003 deletions
@@ -120,6 +120,15 @@ template<> bool ScriptInterface::FromJSVal<std::wstring>(JSContext* cx, jsval v,
return true;
}
template<> bool ScriptInterface::FromJSVal<Path>(JSContext* cx, jsval v, Path& out)
{
std::wstring string;
if(!FromJSVal(cx, v, string))
return false;
out = string;
return true;
}
template<> bool ScriptInterface::FromJSVal<std::string>(JSContext* cx, jsval v, std::string& out)
{
WARN_IF_NOT(JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v), v); // allow implicit number conversions
@@ -242,6 +251,11 @@ template<> jsval ScriptInterface::ToJSVal<std::wstring>(JSContext* cx, const std
return JSVAL_VOID;
}
template<> jsval ScriptInterface::ToJSVal<Path>(JSContext* cx, const Path& val)
{
return ToJSVal(cx, val.string());
}
template<> jsval ScriptInterface::ToJSVal<std::string>(JSContext* cx, const std::string& val)
{
JSString* str = JS_NewStringCopyN(cx, val.c_str(), val.length());
+7 -7
View File
@@ -768,9 +768,9 @@ bool ScriptInterface::FreezeObject(jsval obj, bool deep)
return JS_FreezeObject(m->m_cx, JSVAL_TO_OBJECT(obj)) ? true : false;
}
bool ScriptInterface::LoadScript(const std::wstring& filename, const std::wstring& code)
bool ScriptInterface::LoadScript(const VfsPath& filename, const std::wstring& code)
{
std::string fnAscii(filename.begin(), filename.end());
std::string fnAscii = utf8_from_wstring(filename.string());
// Compile the code in strict mode, to encourage better coding practices and
// to possibly help SpiderMonkey with optimisations
@@ -792,7 +792,7 @@ bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path)
{
if (!VfsFileExists(g_VFS, path))
{
LOGERROR(L"File '%ls' does not exist", path.c_str());
LOGERROR(L"File '%ls' does not exist", path.string().c_str());
return false;
}
@@ -802,14 +802,14 @@ bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path)
if (ret != PSRETURN_OK)
{
LOGERROR(L"Failed to load file '%ls': %hs", path.c_str(), GetErrorString(ret));
LOGERROR(L"Failed to load file '%ls': %hs", path.string().c_str(), GetErrorString(ret));
return false;
}
std::string content(file.GetBuffer(), file.GetBuffer() + file.GetBufferSize());
std::wstring code = wstring_from_utf8(content);
std::string fnAscii(path.begin(), path.end());
std::string fnAscii = utf8_from_wstring(path.string());
// Compile the code in strict mode, to encourage better coding practices and
// to possibly help SpiderMonkey with optimisations
@@ -877,7 +877,7 @@ CScriptValRooted ScriptInterface::ReadJSONFile(const VfsPath& path)
{
if (!VfsFileExists(g_VFS, path))
{
LOGERROR(L"File '%ls' does not exist", path.c_str());
LOGERROR(L"File '%ls' does not exist", path.string().c_str());
return CScriptValRooted();
}
@@ -887,7 +887,7 @@ CScriptValRooted ScriptInterface::ReadJSONFile(const VfsPath& path)
if (ret != PSRETURN_OK)
{
LOGERROR(L"Failed to load file '%ls': %hs", path.c_str(), GetErrorString(ret));
LOGERROR(L"Failed to load file '%ls': %hs", path.string().c_str(), GetErrorString(ret));
return CScriptValRooted();
}
+1 -1
View File
@@ -235,7 +235,7 @@ public:
* @param code JS code to execute
* @return true on successful compilation and execution; false otherwise
*/
bool LoadScript(const std::wstring& filename, const std::wstring& code);
bool LoadScript(const VfsPath& filename, const std::wstring& code);
/**
* Load and execute the given script in the global scope.