Changeset View
Changeset View
Standalone View
Standalone View
source/scriptinterface/ScriptConversions.cpp
Show All 15 Lines | |||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "ScriptConversions.h" | #include "ScriptConversions.h" | ||||
#include "graphics/Entity.h" | #include "graphics/Entity.h" | ||||
#include "maths/Vector2D.h" | #include "maths/Vector2D.h" | ||||
#include "ps/utf16string.h" | |||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#include "ps/CStrIntern.h" | |||||
#include "ps/utf16string.h" | |||||
#define FAIL(msg) STMT(JS_ReportError(cx, msg); return false) | #define FAIL(msg) STMT(JS_ReportError(cx, msg); return false) | ||||
// Implicit type conversions often hide bugs, so warn about them | // Implicit type conversions often hide bugs, so warn about them | ||||
#define WARN_IF_NOT(c, v) STMT(if (!(c)) { JS_ReportWarning(cx, "Script value conversion check failed: %s (got type %s)", #c, InformalValueTypeName(v)); }) | #define WARN_IF_NOT(c, v) STMT(if (!(c)) { JS_ReportWarning(cx, "Script value conversion check failed: %s (got type %s)", #c, InformalValueTypeName(v)); }) | ||||
// TODO: SpiderMonkey: Follow upstream progresses about JS_InformalValueTypeName in the API | // TODO: SpiderMonkey: Follow upstream progresses about JS_InformalValueTypeName in the API | ||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1285917 | // https://bugzilla.mozilla.org/show_bug.cgi?id=1285917 | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | template<> bool ScriptInterface::FromJSVal<CStr8>(JSContext* cx, JS::HandleValue v, CStr8& out) | ||||
return ScriptInterface::FromJSVal(cx, v, static_cast<std::string&>(out)); | return ScriptInterface::FromJSVal(cx, v, static_cast<std::string&>(out)); | ||||
} | } | ||||
template<> bool ScriptInterface::FromJSVal<CStrW>(JSContext* cx, JS::HandleValue v, CStrW& out) | template<> bool ScriptInterface::FromJSVal<CStrW>(JSContext* cx, JS::HandleValue v, CStrW& out) | ||||
{ | { | ||||
return ScriptInterface::FromJSVal(cx, v, static_cast<std::wstring&>(out)); | return ScriptInterface::FromJSVal(cx, v, static_cast<std::wstring&>(out)); | ||||
} | } | ||||
template<> bool ScriptInterface::FromJSVal<CStrIntern>(JSContext* cx, JS::HandleValue v, CStrIntern& out) | |||||
{ | |||||
CStrW value; | |||||
if (!FromJSVal(cx, v, value)) | |||||
return false; | |||||
out = CStrIntern(value.ToUTF8()); | |||||
elexis: It seems wrong to assume that UTF8 would be a format that this function should be concerned… | |||||
return true; | |||||
} | |||||
template<> bool ScriptInterface::FromJSVal<Entity>(JSContext* cx, JS::HandleValue v, Entity& out) | template<> bool ScriptInterface::FromJSVal<Entity>(JSContext* cx, JS::HandleValue v, Entity& out) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
if (!v.isObject()) | if (!v.isObject()) | ||||
FAIL("Argument must be an object"); | FAIL("Argument must be an object"); | ||||
JS::RootedObject obj(cx, &v.toObject()); | JS::RootedObject obj(cx, &v.toObject()); | ||||
JS::RootedValue templateName(cx); | JS::RootedValue templateName(cx); | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | template<> void ScriptInterface::ToJSVal<CStrW>(JSContext* cx, JS::MutableHandleValue ret, const CStrW& val) | ||||
ToJSVal(cx, ret, static_cast<const std::wstring&>(val)); | ToJSVal(cx, ret, static_cast<const std::wstring&>(val)); | ||||
} | } | ||||
template<> void ScriptInterface::ToJSVal<CStr8>(JSContext* cx, JS::MutableHandleValue ret, const CStr8& val) | template<> void ScriptInterface::ToJSVal<CStr8>(JSContext* cx, JS::MutableHandleValue ret, const CStr8& val) | ||||
{ | { | ||||
ToJSVal(cx, ret, static_cast<const std::string&>(val)); | ToJSVal(cx, ret, static_cast<const std::string&>(val)); | ||||
} | } | ||||
template<> void ScriptInterface::ToJSVal<CStrIntern>(JSContext* cx, JS::MutableHandleValue ret, const CStrIntern& val) | |||||
{ | |||||
ToJSVal(cx, ret, val.string()); | |||||
} | |||||
//////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////// | ||||
// Compound types | // Compound types | ||||
// Instantiate various vector types: | // Instantiate various vector types: | ||||
JSVAL_VECTOR(int) | JSVAL_VECTOR(int) | ||||
JSVAL_VECTOR(u32) | JSVAL_VECTOR(u32) | ||||
JSVAL_VECTOR(u16) | JSVAL_VECTOR(u16) | ||||
JSVAL_VECTOR(std::string) | JSVAL_VECTOR(std::string) | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
It seems wrong to assume that UTF8 would be a format that this function should be concerned about.
However if we use FromJSVal<CStr> here, then it will fail if the fontname contains an ä specified in JS.