//
using System;
+using System.Diagnostics;
+using System.Globalization;
namespace Microsoft.JScript {
public sealed class Plus : BinaryOp {
public Plus ()
- : base (null, null, JSToken.Plus)
+ : base (null, null, null, JSToken.Plus, null)
{
}
- public object EvaluatePlus (object v1, object v2)
+ [DebuggerStepThroughAttribute]
+ [DebuggerHiddenAttribute]
+ public object EvaluatePlus (object v1, object v2)
{
- IConvertible ic1 = v1 as IConvertible;
- IConvertible ic2 = v2 as IConvertible;
-
- TypeCode tc1 = Convert.GetTypeCode (v1, ic1);
- TypeCode tc2 = Convert.GetTypeCode (v2, ic2);
-
- switch (tc1) {
- case TypeCode.Double:
- switch (tc2) {
- case TypeCode.Boolean:
- case TypeCode.Double:
- return ic1.ToDouble (null) + ic2.ToDouble (null);
-
- case TypeCode.String:
- return ic1.ToString (null) + ic2.ToString (null);
- }
- break;
-
- case TypeCode.String:
- switch (tc2) {
- case TypeCode.Boolean:
- return ic1.ToString (null) + Convert.ToString (ic2.ToBoolean (null));
-
- case TypeCode.Double:
- case TypeCode.String:
- return ic1.ToString (null) + ic2.ToString (null);
- }
- break;
-
- case TypeCode.Boolean:
- switch (tc2) {
- case TypeCode.Double:
- return ic1.ToDouble (null) + ic2.ToDouble (null);
-
- case TypeCode.String:
- return Convert.ToString (ic1.ToBoolean (null)) + ic2.ToString (null);
-
- case TypeCode.Boolean:
- return ic1.ToInt32 (null) + ic2.ToInt32 (null);
- }
- break;
- default:
- return EvaluatePlus (v2, v1);
- }
- throw new NotImplementedException ();
+ object val1 = Convert.ToPrimitive (v1, null);
+ object val2 = Convert.ToPrimitive (v2, null);
+ if (Convert.IsString (val1) || Convert.IsString (val2))
+ return Convert.ToString (val1) + Convert.ToString (val2);
+ else
+ return Convert.ToNumber (val1) + Convert.ToNumber (val2);
}
public static object DoOp (object v1, object v2)
throw new NotImplementedException ();
}
- internal override bool Resolve (IdentificationTable context)
+ internal override bool Resolve (Environment env)
{
throw new NotImplementedException ();
}
- internal override bool Resolve (IdentificationTable context, bool no_effect)
+ internal override bool Resolve (Environment env, bool no_effect)
{
throw new NotImplementedException ();
}