5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) 2003, Cesar Lopez Nataren
8 // (C) 2005, Novell Inc. (http://novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Reflection.Emit;
35 namespace Microsoft.JScript {
37 public class StrictEquality : BinaryOp {
39 internal StrictEquality (AST parent, AST left, AST right, JSToken op, Location location)
40 : base (parent, left, right, op, location)
44 public static bool JScriptStrictEquals (object v1, object v2)
46 IConvertible ic1 = v1 as IConvertible;
47 IConvertible ic2 = v2 as IConvertible;
49 TypeCode tc1 = Convert.GetTypeCode (v1, ic1);
50 TypeCode tc2 = Convert.GetTypeCode (v2, ic2);
52 bool both_numbers = Convert.IsNumberTypeCode (tc1) && Convert.IsNumberTypeCode (tc2);
53 if (tc1 != tc2 && !both_numbers)
61 case TypeCode.Boolean:
62 return ic1.ToBoolean (null) == ic2.ToBoolean (null);
65 return ic1.ToString (null) == ic2.ToString (null);
68 if (v1 is ScriptFunction && v2 is ScriptFunction)
69 return v1 == v2 || v1.Equals (v2);
76 if (Convert.IsFloatTypeCode (tc1))
77 num1 = ic1.ToDouble (null);
79 num1 = (double) ic1.ToInt64 (null);
82 if (Convert.IsFloatTypeCode (tc2))
83 num2 = ic2.ToDouble (null);
85 num2 = (double) ic2.ToInt64 (null);
89 Console.WriteLine ("StrictEquality, tc1 = {0}, tc2 = {1}", tc1, tc2);
92 throw new NotImplementedException ();
95 internal override bool Resolve (Environment env)
99 r &= left.Resolve (env);
101 r &= right.Resolve (env);
105 internal override bool Resolve (Environment env, bool no_effect)
107 this.no_effect = no_effect;
108 return Resolve (env);
111 internal override void Emit (EmitContext ec)
115 CodeGenerator.EmitBox (ec.ig, left);
119 CodeGenerator.EmitBox (ec.ig, right);
121 ec.ig.Emit (OpCodes.Call, typeof (StrictEquality).GetMethod ("JScriptStrictEquals"));