Пример #1
0
        /// <summary>
        /// Implements the binary `==` operator.
        /// </summary>
        public static bool eq(BoxedValue l, BoxedValue r)
        {
            if (Operators.same(l, r))
            {
                return(true);
            }

            if (l.IsNull && r.IsUndefined ||
                l.IsUndefined && r.IsNull)
            {
                return(true);
            }

            if (l.IsNumber && r.IsString)
            {
                return(l.Number == TypeConverter.ToNumber(r));
            }

            if (l.IsString && r.IsNumber)
            {
                return(TypeConverter.ToNumber(l) == r.Number);
            }

            if (l.Tag == TypeTags.Bool)
            {
                var newL = BoxedValue.Box(TypeConverter.ToNumber(l));
                return(Operators.eq(newL, r));
            }

            if (r.Tag == TypeTags.Bool)
            {
                var newR = BoxedValue.Box(TypeConverter.ToNumber(r));
                return(Operators.eq(l, newR));
            }

            if (l.Tag >= TypeTags.Object)
            {
                if (r.Tag == TypeTags.SuffixString || r.Tag == TypeTags.String || r.IsNumber)
                {
                    var newL = TypeConverter.ToPrimitive(l.Object, DefaultValueHint.None);
                    return(Operators.eq(newL, r));
                }

                return(false);
            }

            if (r.Tag >= TypeTags.Object)
            {
                if (l.Tag == TypeTags.SuffixString || l.Tag == TypeTags.String || l.IsNumber)
                {
                    var newR = TypeConverter.ToPrimitive(r.Object, DefaultValueHint.None);
                    return(Operators.eq(l, newR));
                }

                return(false);
            }

            return(false);
        }
Пример #2
0
 /// <summary>
 /// Implements the binary `!==` operator.
 /// </summary>
 public static bool notSame(BoxedValue l, BoxedValue r)
 {
     return(!Operators.same(l, r));
 }