Exemple #1
0
        public override void Put(string name, BoxedValue value)
        {
            if (name == "length")
            {
                this.PutLength(TypeConverter.ToNumber(value));
                this.SetAttrs("length", DescriptorAttrs.DontEnum); //TODO: Shouldn't `PutLength` keep the `DontEnum` flag?
                return;
            }

            uint index;

            if (TypeConverter.TryToIndex(name, out index))  //TODO: I changed this to use TryToIndex, but that forgoes checking that `index.ToString() == name`, which may be necessary.
            {
                this.Put(index, value);
                return;
            }

            base.Put(name, value);
        }
Exemple #2
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            var item = this.Find(binder.Name);

            if (item.HasValue)
            {
                var box = item.Value;
                if (box.IsFunction)
                {
                    var func      = box.Func;
                    var boxedArgs = args.Select(a => BoxedValue.Box(a)).ToArray();
                    var ret       = func.Call(this, boxedArgs);
                    result = ret.UnboxObject();
                    return(true);
                }
            }

            result = null;
            return(false);
        }
Exemple #3
0
        public static BoxedValue Box(object value)
        {
            if (value is double)
            {
                return(Box((double)value));
            }
            if (value is int)
            {
                return(Box((int)value));
            }
            if (value is bool)
            {
                return(Box((bool)value));
            }
            if (value is string)
            {
                return(Box((string)value));
            }
            if (value is SuffixString)
            {
                return(Box((SuffixString)value));
            }
            if (value is FunctionObject)
            {
                return(Box((FunctionObject)value));
            }
            if (value is CommonObject)
            {
                return(Box((CommonObject)value));
            }
            if (value is Undefined)
            {
                return(Box((Undefined)value));
            }

            var box = new BoxedValue();

            box.Clr = value;
            box.Tag = TypeTags.Clr;
            return(box);
        }
Exemple #4
0
        /// <summary>
        /// Puts the <paramref name="value"/> at the specified <paramref name="index"/>.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="value">The value.</param>
        public override void Put(uint index, BoxedValue value)
        {
            var ii = (int)index;

            if (LinkIntact && ii < LinkMap.Length)
            {
                var link = LinkMap[ii];
                switch (link.Item1)
                {
                case ParameterStorageType.Private:
                    PrivateScope[link.Item2] = value;
                    break;

                case ParameterStorageType.Shared:
                    SharedScope[link.Item2] = value;
                    break;
                }
            }

            base.Put(index, value);
        }
Exemple #5
0
        public static BoxedValue JsBox(object o)
        {
            if (o is BoxedValue)
            {
                return((BoxedValue)o);
            }

            if (o == null)
            {
                return(Environment.BoxedNull);
            }

            var tag = TypeTag.OfType(o.GetType());

            switch (tag)
            {
            case TypeTags.Bool: return(BoxedValue.Box((bool)o));

            case TypeTags.Number: return(BoxedValue.Box((double)o));

            default: return(BoxedValue.Box(o, tag));
            }
        }
Exemple #6
0
        public static object ToClrObject(BoxedValue v)
        {
            switch (v.Tag)
            {
            case TypeTags.Undefined:
                return(null);

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

            case TypeTags.Object:
            case TypeTags.Function:
            case TypeTags.String:
            case TypeTags.Clr:
                return(v.Clr);

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

            default:
                return(v.Number);
            }
        }
Exemple #7
0
        //----------------------------------------------------------------------------

        public virtual void Put(uint index, BoxedValue value)
        {
            this.Put(index.ToString(), value);
        }
Exemple #8
0
 public static int ToInteger(BoxedValue b)
 {
     return(ToInteger(ToNumber(b)));
 }
Exemple #9
0
 public static ushort ToUInt16(BoxedValue b)
 {
     return((ushort)(uint)ToNumber(b));
 }
Exemple #10
0
 public static BoxedValue ToBoxedValue(bool b)
 {
     return(BoxedValue.Box(b));
 }
Exemple #11
0
 static Undefined()
 {
     instance = new Undefined();
     boxed    = BoxedValue.Box(instance, TypeTags.Undefined);
 }
Exemple #12
0
 public void Put(Undefined index, BoxedValue value)
 {
     this.Put("undefined", value);
 }
Exemple #13
0
 public static BoxedValue ToBoxedValue(FunctionObject f)
 {
     return(BoxedValue.Box(f));
 }
Exemple #14
0
 public static BoxedValue ToBoxedValue(CommonObject o)
 {
     return(BoxedValue.Box(o));
 }
Exemple #15
0
 public static BoxedValue ToBoxedValue(SuffixString s)
 {
     return(BoxedValue.Box(s));
 }
Exemple #16
0
 public static BoxedValue ToPrimitive(BoxedValue v)
 {
     return(ToPrimitive(v, DefaultValueHint.None));
 }
Exemple #17
0
 public static BoxedValue ToPrimitive(string s, DefaultValueHint hint)
 {
     return(BoxedValue.Box(s));
 }
Exemple #18
0
 public static BoxedValue ToPrimitive(double d, DefaultValueHint hint)
 {
     return(BoxedValue.Box(d));
 }
Exemple #19
0
 public static BoxedValue ToPrimitive(bool b, DefaultValueHint hint)
 {
     return(BoxedValue.Box(b));
 }
Exemple #20
0
 public void Put(string name, BoxedValue value, ushort attrs)
 {
     this.Put(name, value);
     this.SetAttrs(name, attrs);
 }
Exemple #21
0
 public void Put(bool index, BoxedValue value)
 {
     this.Put(TypeConverter.ToString(index), value);
 }
Exemple #22
0
 public override void Put(uint index, double value)
 {
     this.Put(index, BoxedValue.Box(value));
 }
Exemple #23
0
 public static BoxedValue ToBoxedValue(BoxedValue v)
 {
     return(v);
 }
Exemple #24
0
 public void Put(uint index, BoxedValue value)
 {
     this.storage[index] = value;
 }
Exemple #25
0
 public static BoxedValue ToBoxedValue(object c)
 {
     return(BoxedValue.Box(c));
 }
Exemple #26
0
 public static BoxedValue ToBoxedValue(double d)
 {
     return(BoxedValue.Box(d));
 }
Exemple #27
0
 public override void Put(uint index, object value, uint tag)
 {
     this.Put(index, BoxedValue.Box(value, tag));
 }
Exemple #28
0
 public static int ToInt32(BoxedValue b)
 {
     return((int)(uint)ToNumber(b));
 }
Exemple #29
0
 public bool TryGet(uint index, out BoxedValue value)
 {
     return(this.storage.TryGetValue(index, out value));
 }
Exemple #30
0
 public static uint ToUInt32(BoxedValue b)
 {
     return((uint)ToNumber(b));
 }