Beispiel #1
0
 public BoxedValue Call(CommonObject @this, BoxedValue[] args)
 {
     return
         (MetaData
          .GetDelegate <Func <FunctionObject, CommonObject, BoxedValue[], BoxedValue> >(this)
          .Invoke(this, @this, args));
 }
Beispiel #2
0
 public CommonObject(Environment env, CommonObject prototype)
 {
     this.Env            = env;
     this.Prototype      = prototype;
     this.PropertySchema = env.Maps.Base;
     this.Properties     = new Descriptor[env.Maps.Base.IndexMap.Count];
 }
Beispiel #3
0
 public CommonObject(Environment env, Schema map, CommonObject prototype)
 {
     this.Env            = env;
     this.Prototype      = prototype;
     this.PropertySchema = map;
     this.Properties     = new Descriptor[map.IndexMap.Count];
 }
Beispiel #4
0
        public CommonObject NewInstance()
        {
            CommonObject o = Env.NewObject();

            o.Prototype = InstancePrototype;
            return(o);
        }
Beispiel #5
0
 public BoxedValue Call <T0, T1, T2, T3>(CommonObject @this, T0 a0, T1 a1, T2 a2, T3 a3)
 {
     return
         (MetaData
          .GetDelegate <Func <FunctionObject, CommonObject, T0, T1, T2, T3, BoxedValue> >(this)
          .Invoke(this, @this, a0, a1, a2, a3));
 }
Beispiel #6
0
 public BoxedValue Call <T0>(CommonObject @this, T0 a0)
 {
     return
         (MetaData
          .GetDelegate <Func <FunctionObject, CommonObject, T0, BoxedValue> >(this)
          .Invoke(this, @this, a0));
 }
Beispiel #7
0
 internal CommonObject(Environment env)
 {
     this.Env            = env;
     this.Prototype      = null;
     this.PropertySchema = null;
     this.Properties     = null;
 }
Beispiel #8
0
        public static string ToString(CommonObject o)
        {
            var s = o as StringObject;

            return(s != null
                ? s.Value.Value.String
                : ToString(o.DefaultValue(DefaultValueHint.String)));
        }
Beispiel #9
0
        public static BoxedValue Box(CommonObject value)
        {
            var box = new BoxedValue();

            box.Clr = value;
            box.Tag = TypeTags.Object;
            return(box);
        }
Beispiel #10
0
        public static double ToNumber(CommonObject o)
        {
            var n = o as NumberObject;

            return(n != null
                ? n.Value.Value.Number
                : ToNumber(o.DefaultValue(DefaultValueHint.Number)));
        }
Beispiel #11
0
        public T RaiseError <T>(CommonObject prototype, string message)
        {
            ErrorObject error = new ErrorObject(this)
            {
                Prototype = prototype
            };

            error.Put("message", message);
            throw new UserError(BoxedValue.Box((CommonObject)error), 0, 0);
        }
Beispiel #12
0
        public FunctionObject NewFunction(ulong id, int args, BoxedValue[] closureScope, FSharpList <Tuple <int, CommonObject> > dynamicScope)
        {
            FunctionObject func  = new FunctionObject(this, id, closureScope, dynamicScope);
            CommonObject   proto = this.NewPrototype();

            proto.Put("constructor", func, 2);
            func.Put("prototype", proto, 4);
            func.Put("length", (double)args, 7);
            return(func);
        }
Beispiel #13
0
        public bool Has(CommonObject index)
        {
            string s      = TypeConverter.ToString(index);
            uint   parsed = 0;

            if (TypeConverter.TryToIndex(s, out parsed))
            {
                return(this.Has(parsed));
            }
            return(this.Has(s));
        }
Beispiel #14
0
        public BoxedValue PickReturnObject(BoxedValue r, CommonObject o)
        {
            switch (r.Tag)
            {
            case TypeTags.Function: return(BoxedValue.Box(r.Func));

            case TypeTags.Object: return(BoxedValue.Box(r.Object));

            default: return(BoxedValue.Box(o));
            }
        }
Beispiel #15
0
        public bool Delete(CommonObject index)
        {
            string name   = TypeConverter.ToString(index);
            uint   parsed = 0;

            if (TypeConverter.TryToIndex(name, out parsed))
            {
                return(this.Delete(parsed));
            }
            return(this.Delete(name));
        }
Beispiel #16
0
        public BoxedValue Get(CommonObject index)
        {
            string s      = TypeConverter.ToString(index);
            uint   parsed = 0;

            if (TypeConverter.TryToIndex(s, out parsed))
            {
                return(this.Get(parsed));
            }
            return(this.Get(s));
        }
Beispiel #17
0
        public static BoxedValue GetValue(CommonObject o)
        {
            var vo = o as ValueObject;

            if (vo == null)
            {
                return(o.Env.RaiseTypeError <BoxedValue>("Cannot read the value of a non-value object."));
            }

            return(vo.Value.Value);
        }
Beispiel #18
0
        public static BoxedValue Box(CommonObject value)
        {
            if (value == null)
            {
                return(Environment.BoxedNull);
            }

            var box = new BoxedValue();

            box.Clr = value;
            box.Tag = TypeTags.Object;
            return(box);
        }
Beispiel #19
0
        public void Put(CommonObject index, object value, uint tag)
        {
            string s      = TypeConverter.ToString(index);
            uint   parsed = 0;

            if (TypeConverter.TryToIndex(s, out parsed))
            {
                this.Put(parsed, value, tag);
            }
            else
            {
                this.Put(s, value, tag);
            }
        }
Beispiel #20
0
        private static Descriptor Find(CommonObject @this, string name)
        {
            while (@this != null)
            {
                int index;
                if (@this.PropertySchema.IndexMap.TryGetValue(name, out index))
                {
                    return(@this.Properties[index]);
                }

                @this = @this.Prototype;
            }

            return(new Descriptor());
        }
Beispiel #21
0
        public bool HasInstance(CommonObject v)
        {
            var o = Get("prototype");

            if (!o.IsObject)
            {
                return(Env.RaiseTypeError <bool>("prototype property is not an object"));
            }

            v = (v != null) ? v.Prototype : null;

            while (v != null)
            {
                if (Object.ReferenceEquals(o.Object, v))
                {
                    return(true);
                }

                v = v.Prototype;
            }

            return(false);
        }
Beispiel #22
0
 public static BoxedValue ToBoxedValue(CommonObject o)
 {
     return(BoxedValue.Box(o));
 }
Beispiel #23
0
 public void Put(string name, CommonObject value, ushort attrs)
 {
     this.Put(name, value);
     this.SetAttrs(name, attrs);
 }
Beispiel #24
0
 public void Put(uint index, CommonObject value)
 {
     this.Put(index, value, TypeTags.Object);
 }
Beispiel #25
0
 public void Put(string name, CommonObject value)
 {
     this.Put(name, value, TypeTags.Object);
 }
Beispiel #26
0
 public static CommonObject ToObject(Environment env, CommonObject o)
 {
     return(o);
 }
Beispiel #27
0
 public static bool ToBoolean(CommonObject o)
 {
     return(true);
 }
Beispiel #28
0
 public static BoxedValue ToPrimitive(CommonObject o, DefaultValueHint hint)
 {
     return(o.DefaultValue(hint));
 }
Beispiel #29
0
        private Tuple <uint, HashSet <string> > collectProperties(uint length, HashSet <string> set, CommonObject current)
        {
            if (current != null)
            {
                var array = current as ArrayObject;
                if (array != null)
                {
                    length = length < array.Length ? array.Length : length;
                }

                foreach (var pair in current.PropertySchema.IndexMap)
                {
                    var descriptor = current.Properties[pair.Value];
                    if (descriptor.HasValue && descriptor.IsEnumerable)
                    {
                        set.Add(pair.Key);
                    }
                }

                return(collectProperties(length, set, current.Prototype));
            }
            else
            {
                return(Tuple.Create(length, set));
            }
        }
Beispiel #30
0
 public static object ToClrObject(CommonObject o)
 {
     return(o);
 }