internal static string Uneval(Context cx, Scriptable scope, object value)
{
if (value == null)
{
return "null";
}
if (value == Undefined.instance)
{
return "undefined";
}
if (value is CharSequence)
{
string escaped = EscapeString(value.ToString());
StringBuilder sb = new StringBuilder(escaped.Length + 2);
sb.Append('\"');
sb.Append(escaped);
sb.Append('\"');
return sb.ToString();
}
if (value is Number)
{
double d = System.Convert.ToDouble(((Number)value));
if (d == 0 && 1 / d < 0)
{
return "-0";
}
return ToString(d);
}
if (value is bool)
{
return ToString(value);
}
if (value is Scriptable)
{
Scriptable obj = (Scriptable)value;
// Wrapped Java objects won't have "toSource" and will report
// errors for get()s of nonexistent name, so use has() first
if (ScriptableObject.HasProperty(obj, "toSource"))
{
object v = ScriptableObject.GetProperty(obj, "toSource");
if (v is Function)
{
Function f = (Function)v;
return ToString(f.Call(cx, scope, obj, emptyArgs));
}
}
return ToString(value);
}
WarnAboutNonJSObject(value);
return value.ToString();
}