コード例 #1
0
ファイル: TypeConverter.cs プロジェクト: rockyjvec/SpaceJS
        /// <summary>
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-9.8
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static string ToString(JsValue o)
        {
            if (o._type == Types.Object && o is IPrimitiveInstance)
            {
                var p = o as IPrimitiveInstance;
                return(ToString(ToPrimitive(p.PrimitiveValue, Types.String)));
            }

            switch (o._type)
            {
            case Types.String:
                return(o.AsStringWithoutTypeCheck());

            case Types.Boolean:
                return(((JsBoolean)o)._value ? "true" : "false");

            case Types.Number:
                return(ToString(((JsNumber)o)._value));

            case Types.Symbol:
                return(o.AsSymbol());

            case Types.Undefined:
                return(Undefined.Text);

            case Types.Null:
                return(Null.Text);

            default:
                return(ToString(ToPrimitive(o, Types.String)));
            }
        }