Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/scriptinterface/ScriptConversions.cpp
Show All 22 Lines | |||||
#include "maths/Vector2D.h" | #include "maths/Vector2D.h" | ||||
#include "ps/utf16string.h" | #include "ps/utf16string.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#define FAIL(msg) STMT(LOGERROR(msg); return false) | #define FAIL(msg) STMT(LOGERROR(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(rq.cx, "Script value conversion check failed: %s (got type %s)", #c, InformalValueTypeName(v)); }) | #define WARN_IF_NOT(c, v) STMT(if (!(c)) { JS_ReportWarningUTF8(rq.cx, "Script value conversion check failed: %s (got type %s)", #c, JS::InformalValueTypeName(v)); }) | ||||
// TODO: SpiderMonkey: Follow upstream progresses about JS_InformalValueTypeName in the API | |||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1285917 | |||||
static const char* InformalValueTypeName(const JS::Value& v) | |||||
{ | |||||
if (v.isObject()) | |||||
return "object"; | |||||
if (v.isString()) | |||||
return "string"; | |||||
if (v.isSymbol()) | |||||
return "symbol"; | |||||
if (v.isNumber()) | |||||
return "number"; | |||||
if (v.isBoolean()) | |||||
return "boolean"; | |||||
if (v.isNull()) | |||||
return "null"; | |||||
if (v.isUndefined()) | |||||
return "undefined"; | |||||
return "value"; | |||||
} | |||||
template<> bool ScriptInterface::FromJSVal<bool>(const ScriptRequest& rq, JS::HandleValue v, bool& out) | template<> bool ScriptInterface::FromJSVal<bool>(const ScriptRequest& rq, JS::HandleValue v, bool& out) | ||||
{ | { | ||||
WARN_IF_NOT(v.isBoolean(), v); | WARN_IF_NOT(v.isBoolean(), v); | ||||
out = JS::ToBoolean(v); | out = JS::ToBoolean(v); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 303 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator