1
0
forked from mirrors/0ad

Some const for scriptinterface.

Reviewed By: Itms
Differential Revision: https://code.wildfiregames.com/D155
This was SVN commit r19339.
This commit is contained in:
leper
2017-03-24 18:47:03 +00:00
parent 9cf84c6800
commit 3648ba448d
2 changed files with 57 additions and 58 deletions
+24 -25
View File
@@ -312,7 +312,7 @@ bool Math_random(JSContext* cx, uint UNUSED(argc), jsval* vp)
{
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
double r;
if(!ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->MathRandom(r))
if (!ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->MathRandom(r))
return false;
rec.rval().setNumber(r);
@@ -434,9 +434,9 @@ ScriptInterface::CxPrivate* ScriptInterface::GetScriptInterfaceAndCBData(JSConte
return pCxPrivate;
}
JS::Value ScriptInterface::GetCachedValue(CACHED_VAL valueIdentifier)
JS::Value ScriptInterface::GetCachedValue(CACHED_VAL valueIdentifier) const
{
std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue>::iterator it = m->m_ScriptValCache.find(valueIdentifier);
std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue>::const_iterator it = m->m_ScriptValCache.find(valueIdentifier);
ENSURE(it != m->m_ScriptValCache.end());
return it->second.get();
}
@@ -509,7 +509,7 @@ shared_ptr<ScriptRuntime> ScriptInterface::GetRuntime() const
return m->m_runtime;
}
void ScriptInterface::CallConstructor(JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out)
void ScriptInterface::CallConstructor(JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out) const
{
JSAutoRequest rq(m->m_cx);
if (!ctor.isObject())
@@ -668,12 +668,12 @@ bool ScriptInterface::SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleV
return true;
}
bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleValue out)
bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const
{
return GetProperty_(obj, name, out);
}
bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleObject out)
bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleObject out) const
{
JSContext* cx = GetContext();
JSAutoRequest rq(cx);
@@ -690,12 +690,12 @@ bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, JS::Mut
return true;
}
bool ScriptInterface::GetPropertyInt(JS::HandleValue obj, int name, JS::MutableHandleValue out)
bool ScriptInterface::GetPropertyInt(JS::HandleValue obj, int name, JS::MutableHandleValue out) const
{
return GetPropertyInt_(obj, name, out);
}
bool ScriptInterface::GetProperty_(JS::HandleValue obj, const char* name, JS::MutableHandleValue out)
bool ScriptInterface::GetProperty_(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const
{
JSAutoRequest rq(m->m_cx);
if (!obj.isObject())
@@ -707,7 +707,7 @@ bool ScriptInterface::GetProperty_(JS::HandleValue obj, const char* name, JS::Mu
return true;
}
bool ScriptInterface::GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue out)
bool ScriptInterface::GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue out) const
{
JSAutoRequest rq(m->m_cx);
JS::RootedId nameId(m->m_cx, INT_TO_JSID(name));
@@ -720,7 +720,7 @@ bool ScriptInterface::GetPropertyInt_(JS::HandleValue obj, int name, JS::Mutable
return true;
}
bool ScriptInterface::HasProperty(JS::HandleValue obj, const char* name)
bool ScriptInterface::HasProperty(JS::HandleValue obj, const char* name) const
{
// TODO: proper errorhandling
JSAutoRequest rq(m->m_cx);
@@ -734,7 +734,7 @@ bool ScriptInterface::HasProperty(JS::HandleValue obj, const char* name)
return found;
}
bool ScriptInterface::EnumeratePropertyNamesWithPrefix(JS::HandleValue objVal, const char* prefix, std::vector<std::string>& out)
bool ScriptInterface::EnumeratePropertyNamesWithPrefix(JS::HandleValue objVal, const char* prefix, std::vector<std::string>& out) const
{
JSAutoRequest rq(m->m_cx);
@@ -811,7 +811,7 @@ bool ScriptInterface::SetPrototype(JS::HandleValue objVal, JS::HandleValue proto
return JS_SetPrototype(m->m_cx, obj, proto);
}
bool ScriptInterface::FreezeObject(JS::HandleValue objVal, bool deep)
bool ScriptInterface::FreezeObject(JS::HandleValue objVal, bool deep) const
{
JSAutoRequest rq(m->m_cx);
if (!objVal.isObject())
@@ -825,9 +825,8 @@ bool ScriptInterface::FreezeObject(JS::HandleValue objVal, bool deep)
return JS_FreezeObject(m->m_cx, obj);
}
bool ScriptInterface::LoadScript(const VfsPath& filename, const std::string& code)
bool ScriptInterface::LoadScript(const VfsPath& filename, const std::string& code) const
{
JSAutoRequest rq(m->m_cx);
JS::RootedObject global(m->m_cx, m->m_glob);
utf16string codeUtf16(code.begin(), code.end());
@@ -855,7 +854,7 @@ shared_ptr<ScriptRuntime> ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntim
return shared_ptr<ScriptRuntime>(new ScriptRuntime(parentRuntime, runtimeSize, heapGrowthBytesGCTrigger));
}
bool ScriptInterface::LoadGlobalScript(const VfsPath& filename, const std::wstring& code)
bool ScriptInterface::LoadGlobalScript(const VfsPath& filename, const std::wstring& code) const
{
JSAutoRequest rq(m->m_cx);
JS::RootedObject global(m->m_cx, m->m_glob);
@@ -872,7 +871,7 @@ bool ScriptInterface::LoadGlobalScript(const VfsPath& filename, const std::wstri
reinterpret_cast<const char16_t*>(codeUtf16.c_str()), (uint)(codeUtf16.length()), &rval);
}
bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path)
bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path) const
{
JSAutoRequest rq(m->m_cx);
JS::RootedObject global(m->m_cx, m->m_glob);
@@ -907,14 +906,14 @@ bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path)
reinterpret_cast<const char16_t*>(codeUtf16.c_str()), (uint)(codeUtf16.length()), &rval);
}
bool ScriptInterface::Eval(const char* code)
bool ScriptInterface::Eval(const char* code) const
{
JSAutoRequest rq(m->m_cx);
JS::RootedValue rval(m->m_cx);
return Eval_(code, &rval);
}
bool ScriptInterface::Eval_(const char* code, JS::MutableHandleValue rval)
bool ScriptInterface::Eval_(const char* code, JS::MutableHandleValue rval) const
{
JSAutoRequest rq(m->m_cx);
JS::RootedObject global(m->m_cx, m->m_glob);
@@ -925,7 +924,7 @@ bool ScriptInterface::Eval_(const char* code, JS::MutableHandleValue rval)
return JS::Evaluate(m->m_cx, global, opts, reinterpret_cast<const char16_t*>(codeUtf16.c_str()), (uint)codeUtf16.length(), rval);
}
bool ScriptInterface::Eval_(const wchar_t* code, JS::MutableHandleValue rval)
bool ScriptInterface::Eval_(const wchar_t* code, JS::MutableHandleValue rval) const
{
JSAutoRequest rq(m->m_cx);
JS::RootedObject global(m->m_cx, m->m_glob);
@@ -936,7 +935,7 @@ bool ScriptInterface::Eval_(const wchar_t* code, JS::MutableHandleValue rval)
return JS::Evaluate(m->m_cx, global, opts, reinterpret_cast<const char16_t*>(codeUtf16.c_str()), (uint)codeUtf16.length(), rval);
}
bool ScriptInterface::ParseJSON(const std::string& string_utf8, JS::MutableHandleValue out)
bool ScriptInterface::ParseJSON(const std::string& string_utf8, JS::MutableHandleValue out) const
{
JSAutoRequest rq(m->m_cx);
std::wstring attrsW = wstring_from_utf8(string_utf8);
@@ -968,7 +967,7 @@ bool ScriptInterface::ParseJSON(const std::string& string_utf8, JS::MutableHandl
return false;
}
void ScriptInterface::ReadJSONFile(const VfsPath& path, JS::MutableHandleValue out)
void ScriptInterface::ReadJSONFile(const VfsPath& path, JS::MutableHandleValue out) const
{
if (!VfsFileExists(path))
{
@@ -1009,7 +1008,7 @@ struct Stringifier
// TODO: It's not quite clear why JS_Stringify needs JS::MutableHandleValue. |obj| should not get modified.
// It probably has historical reasons and could be changed by SpiderMonkey in the future.
std::string ScriptInterface::StringifyJSON(JS::MutableHandleValue obj, bool indent)
std::string ScriptInterface::StringifyJSON(JS::MutableHandleValue obj, bool indent) const
{
JSAutoRequest rq(m->m_cx);
Stringifier str;
@@ -1025,7 +1024,7 @@ std::string ScriptInterface::StringifyJSON(JS::MutableHandleValue obj, bool inde
}
std::string ScriptInterface::ToString(JS::MutableHandleValue obj, bool pretty)
std::string ScriptInterface::ToString(JS::MutableHandleValue obj, bool pretty) const
{
JSAutoRequest rq(m->m_cx);
@@ -1062,7 +1061,7 @@ std::string ScriptInterface::ToString(JS::MutableHandleValue obj, bool pretty)
return utf8_from_wstring(source);
}
void ScriptInterface::ReportError(const char* msg)
void ScriptInterface::ReportError(const char* msg) const
{
JSAutoRequest rq(m->m_cx);
// JS_ReportError by itself doesn't seem to set a JS-style exception, and so
@@ -1136,7 +1135,7 @@ shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClo
return shared_ptr<StructuredClone>();
}
shared_ptr<StructuredClone> ret (new StructuredClone);
shared_ptr<StructuredClone> ret(new StructuredClone);
ret->m_Data = data;
ret->m_Size = nbytes;
return ret;