Пример #1
0
 /// <summary>
 /// Implements the binary `in` operator.
 /// </summary>
 public static bool @in(Environment env, BoxedValue l, BoxedValue r)
 {
     if (!r.IsObject)
     {
         return env.RaiseTypeError<bool>("Right operand is not a object");
     }
     uint index = 0;
     if (TypeConverter.TryToIndex(l, out index))
     {
         return r.Object.Has(index);
     }
     string name = TypeConverter.ToString(l);
     return r.Object.Has(name);
 }
Пример #2
0
 /// <summary>
 /// Implements the binary `instanceof` operator.
 /// </summary>
 public static bool instanceOf(Environment env, BoxedValue l, BoxedValue r)
 {
     if (!r.IsFunction)
     {
         return env.RaiseTypeError<bool>("Right operand is not a function");
     }
     if (!l.IsObject)
     {
         return false;
     }
     return r.Func.HasInstance(l.Object);
 }
Пример #3
0
 public static ScriptObject ToObject(Environment env, object o)
 {
     return env.RaiseTypeError<ScriptObject>("Can't convert Null or CLR to Object");
 }
Пример #4
0
        public static ScriptObject ToObject(Environment env, BoxedValue v)
        {
            switch (v.Tag)
            {
                case TypeTags.Object:
                case TypeTags.Function:
                    return v.Object;

                case TypeTags.SuffixString:
                    return env.NewString(v.Clr.ToString());

                case TypeTags.String:
                    return env.NewString(v.String);

                case TypeTags.Bool:
                    return env.NewBoolean(v.Bool);

                case TypeTags.Clr:
                case TypeTags.Undefined:
                    return env.RaiseTypeError<ScriptObject>("Can't convert Undefined, Null or CLR to Object");

                default:
                    return env.NewNumber(v.Number);
            }
        }
Пример #5
0
 public static ScriptObject ToObject(Environment env, Undefined undef)
 {
     return env.RaiseTypeError<ScriptObject>("Can't convert Undefined to Object");
 }