Ejemplo n.º 1
0
        public JsArguments(IGlobal global, JsFunction callee, JsInstance[] arguments)
            : base()
        {
			this.args = arguments;
            this.global = global;
            Prototype = global.ObjectClass.New();
            // Add the named parameters
            for (int i = 0; i < Math.Max(arguments.Length, callee.Arguments.Count); i++)
            {
                ValueDescriptor d = new ValueDescriptor(this, i < callee.Arguments.Count ? callee.Arguments[i] : i.ToString());

                d.Set(this, i < arguments.Length ? arguments[i] : JsUndefined.Instance);

                if (i < callee.Arguments.Count)
                    this.DefineOwnProperty(callee.Arguments[i], d);
                this.DefineOwnProperty(i.ToString(), d);
            }

            length = arguments.Length;
            calleeDescriptor = new ValueDescriptor(this, "callee");
            DefineOwnProperty("callee", calleeDescriptor);
            calleeDescriptor.Set(this, callee);
            DefineOwnProperty("length", new PropertyDescriptor<JsArguments>(global, this, "length", GetLength));
			DefineOwnProperty("array", new PropertyDescriptor<JsArguments>(global, this, "array", GetArray));
        }
Ejemplo n.º 2
0
        public JsArguments(IGlobal global, JsFunction callee, JsInstance[] arguments)
            : base(global.ObjectClass.New())
        {
            this.global = global;

            // Add the named parameters
            for (int i = 0; i < arguments.Length; i++)
            {
                this.DefineOwnProperty(
                    new ValueDescriptor(this, i.ToString(), arguments[i])
                {
                    Enumerable = false
                }
                    );
            }

            length = arguments.Length;

            calleeDescriptor = new ValueDescriptor(this, CALLEE, callee)
            {
                Enumerable = false
            };
            DefineOwnProperty(calleeDescriptor);

            DefineOwnProperty(new PropertyDescriptor <JsArguments>(global, this, "length", GetLength)
            {
                Enumerable = false
            });
        }
Ejemplo n.º 3
0
        public JsArguments(IGlobal global, JsFunction callee, JsInstance[] arguments)
            : base()
        {
            this.args   = arguments;
            this.global = global;
            Prototype   = global.ObjectClass.New();
            // Add the named parameters
            for (int i = 0; i < Math.Max(arguments.Length, callee.Arguments.Count); i++)
            {
                ValueDescriptor d = new ValueDescriptor(this, i < callee.Arguments.Count ? callee.Arguments[i] : i.ToString());

                d.Set(this, i < arguments.Length ? arguments[i] : JsUndefined.Instance);

                if (i < callee.Arguments.Count)
                {
                    this.DefineOwnProperty(callee.Arguments[i], d);
                }
                this.DefineOwnProperty(i.ToString(), d);
            }

            length           = arguments.Length;
            calleeDescriptor = new ValueDescriptor(this, "callee");
            DefineOwnProperty("callee", calleeDescriptor);
            calleeDescriptor.Set(this, callee);
            DefineOwnProperty("length", new PropertyDescriptor <JsArguments>(global, this, "length", GetLength));
            DefineOwnProperty("array", new PropertyDescriptor <JsArguments>(global, this, "array", GetArray));
        }
Ejemplo n.º 4
0
        public JsArguments(IGlobal global, JsFunction callee, JsInstance[] arguments)
            : base(global.ObjectClass.New())
        {
            this.global = global;
            // Add the named parameters
            for (int i = 0; i < Math.Max(arguments.Length, callee.Arguments.Count); i++)
            {
                ValueDescriptor d = new ValueDescriptor(this, i < callee.Arguments.Count ? callee.Arguments[i] : i.ToString())
                {
                    Attributes = PropertyAttributes.DontDelete
                };

                d.Set(this, i < arguments.Length ? arguments[i] : JsUndefined.Instance);

                this.DefineOwnProperty(i.ToString(), d);
            }

            length = arguments.Length;

            calleeDescriptor = new ValueDescriptor(this, CALLEE)
            {
                Attributes = PropertyAttributes.DontEnum
            };
            DefineOwnProperty(CALLEE, calleeDescriptor);
            calleeDescriptor.Set(this, callee);

            DefineOwnProperty("length", new PropertyDescriptor <JsArguments>(global, this, "length", GetLength)
            {
                Attributes = PropertyAttributes.DontEnum
            });
        }
Ejemplo n.º 5
0
        public override Descriptor Clone()
        {
            ValueDescriptor valueDescriptor = new ValueDescriptor(this.Owner, this.Name, this.value);

            valueDescriptor.Enumerable   = this.Enumerable;
            valueDescriptor.Configurable = this.Configurable;
            valueDescriptor.Writable     = this.Writable;
            return((Descriptor)valueDescriptor);
        }
Ejemplo n.º 6
0
        public JsObject New(JsFunction constructor, JsObject Prototype)
        {
            JsObject        jsObject1       = new JsObject(Prototype);
            JsObject        jsObject2       = jsObject1;
            ValueDescriptor valueDescriptor = new ValueDescriptor((JsDictionaryObject)jsObject1, JsFunction.CONSTRUCTOR, (JsInstance)constructor);

            valueDescriptor.Enumerable = false;
            jsObject2.DefineOwnProperty((Descriptor)valueDescriptor);
            return(jsObject1);
        }
Ejemplo n.º 7
0
        public void DefineOwnProperty(
            string key,
            JsInstance value,
            PropertyAttributes propertyAttributes)
        {
            ValueDescriptor valueDescriptor = new ValueDescriptor(this, key, value);

            valueDescriptor.Writable   = (propertyAttributes & PropertyAttributes.ReadOnly) == PropertyAttributes.None;
            valueDescriptor.Enumerable = (propertyAttributes & PropertyAttributes.DontEnum) == PropertyAttributes.None;
            this.DefineOwnProperty((Descriptor)valueDescriptor);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 8.10.5
        /// </summary>
        /// <param name="global"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        internal static Descriptor ToPropertyDesciptor(IGlobal global, JsDictionaryObject owner, string name, JsInstance jsInstance) {
            if (jsInstance.Class != JsInstance.CLASS_OBJECT) {
                throw new JsException(global.TypeErrorClass.New("The target object has to be an instance of an object"));
            }

            JsObject obj = (JsObject)jsInstance;
            if ((obj.HasProperty("value") || obj.HasProperty("writable")) && (obj.HasProperty("set") || obj.HasProperty("get"))) {
                throw new JsException(global.TypeErrorClass.New("The property cannot be both writable and have get/set accessors or cannot have both a value and an accessor defined"));
            }

            Descriptor desc;
            JsInstance result = null;

            if (obj.HasProperty("value")) {
                desc = new ValueDescriptor(owner, name, obj["value"]);
            }
            else {
                desc = new PropertyDescriptor(global, owner, name);
            }

            if (obj.TryGetProperty("enumerable", out result)) {
                desc.Enumerable = result.ToBoolean();
            }

            if (obj.TryGetProperty("configurable", out result)) {
                desc.Configurable = result.ToBoolean();
            }

            if (obj.TryGetProperty("writable", out result)) {
                desc.Writable = result.ToBoolean();
            }

            if (obj.TryGetProperty("get", out result)) {
                if (!(result is JsFunction))
                    throw new JsException(global.TypeErrorClass.New("The getter has to be a function"));

                ((PropertyDescriptor)desc).GetFunction = (JsFunction)result;
            }

            if (obj.TryGetProperty("set", out result)) {
                if (!(result is JsFunction))
                    throw new JsException(global.TypeErrorClass.New("The setter has to be a function"));

                ((PropertyDescriptor)desc).SetFunction = (JsFunction)result;
            }

            return desc;
        }
Ejemplo n.º 9
0
        public JsArguments(IGlobal global, JsFunction callee, JsInstance[] arguments)
            : base(global.ObjectClass.New())
        {            
            this.global = global;

            // Add the named parameters            
            for (int i = 0; i < arguments.Length ; i++)
                this.DefineOwnProperty(
                    new ValueDescriptor(this, i.ToString(), arguments[i]) { Enumerable = false }
                );

            length = arguments.Length;

            calleeDescriptor = new ValueDescriptor(this, CALLEE, callee) { Enumerable = false };
            DefineOwnProperty(calleeDescriptor);

            DefineOwnProperty(new PropertyDescriptor<JsArguments>(global, this, "length", GetLength) { Enumerable = false });
        }
Ejemplo n.º 10
0
        public JsArguments(IGlobal global, JsFunction callee, JsInstance[] arguments)
            : base(global.ObjectClass.New())
        {
            this.global = global;
            // Add the named parameters
            for (int i = 0; i < Math.Max(arguments.Length, callee.Arguments.Count); i++) {
                ValueDescriptor d = new ValueDescriptor(this, i < callee.Arguments.Count ? callee.Arguments[i] : i.ToString()) { Attributes = PropertyAttributes.DontDelete };

                d.Set(this, i < arguments.Length ? arguments[i] : JsUndefined.Instance);

                this.DefineOwnProperty(i.ToString(), d);
            }

            length = arguments.Length;

            calleeDescriptor = new ValueDescriptor(this, CALLEE) { Attributes = PropertyAttributes.DontEnum };
            DefineOwnProperty(CALLEE, calleeDescriptor);
            calleeDescriptor.Set(this, callee);

            DefineOwnProperty("length", new PropertyDescriptor<JsArguments>(global, this, "length", GetLength) { Attributes = PropertyAttributes.DontEnum });
        }
Ejemplo n.º 11
0
        public JsArguments(IGlobal global, JsFunction callee, JsInstance[] arguments)
            : base(global.ObjectClass.New())
        {
            this.global = global;
            for (int index = 0; index < arguments.Length; ++index)
            {
                ValueDescriptor valueDescriptor = new ValueDescriptor((JsDictionaryObject)this, index.ToString(), arguments[index]);
                valueDescriptor.Enumerable = false;
                this.DefineOwnProperty((Descriptor)valueDescriptor);
            }
            this.length = arguments.Length;
            ValueDescriptor valueDescriptor1 = new ValueDescriptor((JsDictionaryObject)this, nameof(callee), (JsInstance)callee);

            valueDescriptor1.Enumerable = false;
            this.calleeDescriptor       = valueDescriptor1;
            this.DefineOwnProperty((Descriptor)this.calleeDescriptor);
            PropertyDescriptor <JsArguments> propertyDescriptor = new PropertyDescriptor <JsArguments>(global, (JsDictionaryObject)this, nameof(length), new Func <JsArguments, JsInstance>(this.GetLength));

            propertyDescriptor.Enumerable = false;
            this.DefineOwnProperty((Descriptor)propertyDescriptor);
        }
 public JsDictionaryObject()
 {
     Extensible = true;
     DefineOwnProperty(PROTOTYPE, prototypeDescriptor = new ValueDescriptor(this, PROTOTYPE, JsUndefined.Instance), PropertyAttributes.DontEnum);
 }
Ejemplo n.º 13
0
 public void Visit(PropertyDeclarationExpression expression)
 {
     switch (expression.Mode)
     {
         case PropertyExpressionType.Data:
             expression.Expression.Accept(this);
             Result = new ValueDescriptor(CurrentScope, expression.Name, Result);
             break;
         case PropertyExpressionType.Get:
         case PropertyExpressionType.Set:
             JsFunction get = null, set = null;
             if (expression.GetExpression != null)
             {
                 expression.GetExpression.Accept(this);
                 get = (JsFunction)Result;
             }
             if (expression.SetExpression != null)
             {
                 expression.SetExpression.Accept(this);
                 set = (JsFunction)Result;
             }
             Result = new PropertyDescriptor(Global, CurrentScope, expression.Name) { GetFunction = get, SetFunction = set, Enumerable = true };
             break;
         default:
             break;
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// 8.10.5
        /// </summary>
        /// <param name="global"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        internal static Descriptor ToPropertyDesciptor(IGlobal global, JsDictionaryObject owner, string name, JsInstance jsInstance)
        {
            if (jsInstance.Class != JsInstance.CLASS_OBJECT)
            {
                throw new JsException(global.TypeErrorClass.New("The target object has to be an instance of an object"));
            }

            JsObject obj = (JsObject)jsInstance;

            if ((obj.HasProperty("value") || obj.HasProperty("writable")) && (obj.HasProperty("set") || obj.HasProperty("get")))
            {
                throw new JsException(global.TypeErrorClass.New("The property cannot be both writable and have get/set accessors or cannot have both a value and an accessor defined"));
            }

            Descriptor desc;
            JsInstance result = null;

            if (obj.HasProperty("value"))
            {
                desc = new ValueDescriptor(owner, name, obj["value"]);
            }
            else
            {
                desc = new PropertyDescriptor(global, owner, name);
            }

            if (obj.TryGetProperty("enumerable", out result))
            {
                desc.Enumerable = result.ToBoolean();
            }

            if (obj.TryGetProperty("configurable", out result))
            {
                desc.Configurable = result.ToBoolean();
            }

            if (obj.TryGetProperty("writable", out result))
            {
                desc.Writable = result.ToBoolean();
            }

            if (obj.TryGetProperty("get", out result))
            {
                if (!(result is JsFunction))
                {
                    throw new JsException(global.TypeErrorClass.New("The getter has to be a function"));
                }

                ((PropertyDescriptor)desc).GetFunction = (JsFunction)result;
            }

            if (obj.TryGetProperty("set", out result))
            {
                if (!(result is JsFunction))
                {
                    throw new JsException(global.TypeErrorClass.New("The setter has to be a function"));
                }

                ((PropertyDescriptor)desc).SetFunction = (JsFunction)result;
            }

            return(desc);
        }
Ejemplo n.º 15
0
        public void Visit(PropertyDeclarationExpression expression)
        {
            // previous result was the object in which we need to define a property
            var target = Result as JsDictionaryObject;

            switch (expression.Mode) {
                case PropertyExpressionType.Data:
                    expression.Expression.Accept(this);
                    Result = new ValueDescriptor(target, expression.Name, Result);
                    break;
                case PropertyExpressionType.Get:
                case PropertyExpressionType.Set:
                    JsFunction get = null, set = null;
                    if (expression.GetExpression != null) {
                        expression.GetExpression.Accept(this);
                        get = (JsFunction)Result;
                    }
                    if (expression.SetExpression != null) {
                        expression.SetExpression.Accept(this);
                        set = (JsFunction)Result;
                    }
                    Result = new PropertyDescriptor(Global, target, expression.Name) { GetFunction = get, SetFunction = set, Enumerable = true };
                    break;
                default:
                    break;
            }
        }