Exemple #1
0
        public JsCallFunction(JsFunctionConstructor constructor)
        {
            if (constructor != null)
                Prototype = new JsObject() { Prototype = constructor.Prototype };

            Prototype.DefineOwnProperty("length", new ValueDescriptor(Prototype, "length", constructor.Global.NumberClass.New(1)) { Writable = false });
        }
Exemple #2
0
        public NativeMethodOverload(ICollection<MethodInfo> methods , JsObject prototype, IGlobal global)
            : base(prototype)
        {
            if (global == null)
                throw new ArgumentNullException("global");
            m_marshaller = global.Marshaller;

            foreach (MethodInfo info in methods)
            {
                Name = info.Name;
                break;
            }

            foreach (var method in methods)
            {
                if (method.IsGenericMethodDefinition)
                    m_generics.AddLast(method);
                else if (! method.ContainsGenericParameters)
                    m_methods.AddLast(method);
            }

            m_overloads = new NativeOverloadImpl<MethodInfo, JsMethodImpl>(
                m_marshaller,
                new NativeOverloadImpl<MethodInfo, JsMethodImpl>.GetMembersDelegate(this.GetMembers),
                new NativeOverloadImpl<MethodInfo, JsMethodImpl>.WrapMmemberDelegate(this.WrapMember)
            );
        }
        public override void InitPrototype(IGlobal global)
        {
            Prototype = new JsObject() { Prototype = global.FunctionClass.Prototype };
            Prototype.DefineOwnProperty("constructor", this, PropertyAttributes.DontEnum);

            #region Methods
            Prototype.DefineOwnProperty("toString", global.FunctionClass.New<JsArray>(ToStringImpl), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("toLocaleString", global.FunctionClass.New<JsArray>(ToLocaleStringImpl), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("concat", global.FunctionClass.New<JsObject>(Concat), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("join", global.FunctionClass.New<JsObject>(Join, 1), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("pop", global.FunctionClass.New<JsObject>(Pop), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("push", global.FunctionClass.New<JsObject>(Push, 1), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("reverse", global.FunctionClass.New<JsObject>(Reverse), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("shift", global.FunctionClass.New<JsObject>(Shift), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("slice", global.FunctionClass.New<JsObject>(Slice, 2), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("sort", global.FunctionClass.New<JsObject>(Sort), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("splice", global.FunctionClass.New<JsObject>(Splice, 2), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("unshift", global.FunctionClass.New<JsObject>(UnShift, 1), PropertyAttributes.DontEnum);

            #region ES5
            Prototype.DefineOwnProperty("indexOf", global.FunctionClass.New<JsObject>(IndexOfImpl, 1), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("lastIndexOf", global.FunctionClass.New<JsObject>(LastIndexOfImpl, 1), PropertyAttributes.DontEnum);
            #endregion

            #endregion
        }
            // 15.2.2.1
            public static object Constructor(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                // TODO: This looks wrong. It looks like this should be returning
                // a JsObject that has the value set to the parameter. Chrome returns
                // 'object' for typeof(new Object(7)) and typeof(Object(7)).

                if (arguments.Length > 0)
                {
                    var argument = arguments[0];

                    var global = runtime.Global;

                    switch (argument.GetJsType())
                    {
                        case JsType.String: return global.CreateObject(argument, global.StringClass);
                        case JsType.Number: return global.CreateObject((double)argument, global.NumberClass);
                        case JsType.Boolean: return global.CreateObject(argument, global.BooleanClass);
                        default: return argument;
                    }
                }

                var obj = runtime.Global.CreateObject(callee.Prototype);

                obj.DefineProperty(
                    Id.constructor,
                    callee,
                    PropertyAttributes.DontEnum
                );

                return obj;
            }
            public static object Constructor(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                var target = (JsObject)@this;

                if (target == runtime.Global.GlobalScope)
                    target = runtime.Global.CreateObject(callee.Prototype);

                string pattern = null;
                string options = null;

                if (arguments.Length > 0)
                {
                    pattern = JsValue.ToString(arguments[0]);
                    if (arguments.Length > 1)
                        options = JsValue.ToString(arguments[1]);
                }

                var manager = new RegexManager(pattern, options);

                target.SetClass(JsNames.ClassRegexp);
                target.IsClr = false;
                target.Value = manager;
                target.SetProperty(Id.source, pattern);
                target.SetProperty(Id.lastIndex, (double)0);
                target.SetProperty(Id.global, BooleanBoxes.Box(manager.IsGlobal));

                return target;
            }
Exemple #6
0
 /// <summary>
 /// Init new function object with a specified prototype
 /// </summary>
 /// <param name="prototype">prototype for this object</param>
 public JsFunction(JsObject prototype)
     : base(prototype)
 {
     Arguments = new List<string>();
     Statement = new EmptyStatement();
     DefineOwnProperty(PROTOTYPE, JsNull.Instance, PropertyAttributes.DontEnum);
 }
Exemple #7
0
 /// <summary>
 /// 15.4.4.4
 /// </summary>
 /// <param name="target"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public JsInstance Concat(JsObject target, JsInstance[] parameters)
 {
     if (target is JsArray)
         return ((JsArray)target).concat(Global, parameters);
     JsArray array = Global.ArrayClass.New();
     List<JsInstance> items = new List<JsInstance>();
     items.Add(target);
     items.AddRange(parameters);
     int n = 0;
     while (items.Count > 0) {
         JsInstance e = items[0];
         items.RemoveAt(0);
         if (Global.ArrayClass.HasInstance(e as JsObject)) {
             for (int k = 0; k < ((JsObject)e).Length; k++) {
                 string p = k.ToString();
                 JsInstance result = null;
                 if (((JsObject)e).TryGetProperty(p, out result))
                     array.put(n, result);
                 n++;
             }
         }
         else {
             array.put(n, e);
             n++;
         }
     }
     return array;
 }
            public static object Exec(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                var target = (JsObject)@this;
                var manager = (RegexManager)target.Value;

                return (object)manager.Exec(runtime, JsValue.ToString(arguments[0])) ?? JsNull.Instance;
            }
 public MarshalAccessorProperty(int index, JsObject getter, JsObject setter, PropertyAttributes attributes)
 {
     Index = index;
     Getter = getter;
     Setter = setter;
     Attributes = attributes;
 }
Exemple #10
0
            public static object DecodeURIComponent(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                if (arguments.Length < 1 || JsValue.IsUndefined(arguments[0]))
                    return String.Empty;

                return Uri.UnescapeDataString(JsValue.ToString(arguments[0]).Replace("+", " "));
            }
Exemple #11
0
 public void ShouldHandleDictionaryObjects() {
     var dic = new JsObject();
     dic["prop1"] = new JsNumber(1, JsNull.Instance);
     Assert.IsTrue(dic.HasProperty(new JsString("prop1", JsNull.Instance)));
     Assert.IsTrue(dic.HasProperty("prop1"));
     Assert.AreEqual(1, dic["prop1"].ToNumber());
 }
Exemple #12
0
 public JsObject CreateError(JsObject constructor, string message)
 {
     return constructor.Construct(
         _runtime,
         new[] { (object)message }
     );
 }
            public static object Call(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                if (!JsValue.IsFunction(@this))
                    throw new JsException(JsErrorType.TypeError, "The target of call() must be a function");

                object target;
                if (arguments.Length >= 1 && !JsValue.IsNullOrUndefined(arguments[0]))
                    target = arguments[0];
                else
                    target = runtime.GlobalScope;

                object[] argumentsCopy;

                if (arguments.Length >= 2 && !JsValue.IsNull(arguments[1]))
                {
                    argumentsCopy = new object[arguments.Length - 1];
                    Array.Copy(arguments, 1, argumentsCopy, 0, argumentsCopy.Length);
                }
                else
                {
                    argumentsCopy = JsValue.EmptyArray;
                }

                // Executes the statements in 'that' and use _this as the target of the call
                return ((JsObject)@this).Execute(runtime, target, argumentsCopy);
            }
            public static object Apply(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                if (!JsValue.IsFunction(@this))
                    throw new ArgumentException("The target of call() must be a function");

                object target;

                if (arguments.Length >= 1 && !JsValue.IsNullOrUndefined(arguments[0]))
                    target = arguments[0];
                else
                    target = runtime.Global.GlobalScope;

                object[] argumentsCopy;

                if (arguments.Length >= 2)
                {
                    var shim = new ArrayShim(arguments[1]);

                    argumentsCopy = new object[shim.Length];

                    foreach (var item in shim)
                    {
                        argumentsCopy[item.Key] = item.Value;
                    }
                }
                else
                {
                    argumentsCopy = JsValue.EmptyArray;
                }

                // Executes the statements in 'that' and use _this as the target of the call
                return ((JsObject)@this).Execute(runtime, target, argumentsCopy);
            }
Exemple #15
0
        public PropertyAccessor(JsObject getter, JsObject setter)
        {
            if (getter == null)
                throw new ArgumentNullException("getter");

            Getter = getter;
            Setter = setter;
        }
Exemple #16
0
 public void DefineAccessor(int index, JsObject getter, JsObject setter, PropertyAttributes attributes)
 {
     EnsurePropertyStore();
     PropertyStore.DefineProperty(
         index,
         new PropertyAccessor(getter, setter),
         attributes
     );
 }
        public DictionaryPropertyStore(JsObject owner)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

            Owner = owner;
            _global = Owner.Global;
            Schema = _global.RootSchema;
        }
 public void DefineProperty(JsObject @object)
 {
     @object.DefineAccessor(
         Index,
         Getter,
         Setter,
         Attributes
     );
 }
        public override void InitPrototype(IGlobal global)
        {
            Prototype = new JsObject() { Prototype = global.FunctionClass.Prototype };

            Prototype.DefineOwnProperty("constructor", this, PropertyAttributes.DontEnum);

            Prototype.DefineOwnProperty("toString", global.FunctionClass.New<JsDictionaryObject>(ToString2), PropertyAttributes.DontEnum);
            Prototype.DefineOwnProperty("toLocaleString", global.FunctionClass.New<JsDictionaryObject>(ToString2), PropertyAttributes.DontEnum);
        }
            // 15.2.3.2
            public static object GetPrototypeOf(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                var @object = arguments[0] as JsObject;
                if (@object == null)
                    throw new JsException(JsErrorType.TypeError);

                var constructor = @object.GetProperty(Id.constructor) as JsObject;
                if (constructor != null)
                    return constructor.GetProperty(Id.prototype);

                return JsNull.Instance;
            }
            // 15.5.4.6
            public static object Concat(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                var sb = new StringBuilder();

                sb.Append(JsValue.ToString(@this));

                for (int i = 0; i < arguments.Length; i++)
                {
                    sb.Append(JsValue.ToString(arguments[i]));
                }

                return sb.ToString();
            }
Exemple #22
0
        public JsObject CreateNakedFunction(string name, JsFunction @delegate, int argumentCount, JsObject prototype, bool isClr)
        {
            // Prototype is set to the created object from the CreateFunction
            // above; prototype here is "Result(9)"
            //   11. Set the prototype property of F to Result(9). This property is given attributes as specified in section 15.3.5.2.

            var result = CreateObject(null, prototype, new JsDelegate(name, @delegate, argumentCount));

            result.SetClass(JsNames.ClassFunction);
            result.IsClr = isClr;

            return result;
        }
		private void ReplicateToFunction(string tableName, JsObject cols)
		{
			if (tableName == null)
				throw new ArgumentException("tableName parameter is mandatory");
			if (cols == null)
				throw new ArgumentException("cols parameter is mandatory");

			var itemToReplicates = scriptResult.Data.GetOrAdd(tableName);
			itemToReplicates.Add(new ItemToReplicate
			{
				DocumentId = docId,
				Columns = ToRavenJObject(cols)
			});
		}
            public static object Constructor(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                var target = (JsObject)@this;
                if (target == runtime.Global.GlobalScope)
                    return BooleanBoxes.Box(arguments.Length > 0 && JsValue.ToBoolean(arguments[0]));

                // e.g., var foo = new Boolean(true);
                if (arguments.Length > 0)
                    target.Value = JsValue.ToBoolean(arguments[0]);
                else
                    target.Value = false;

                return @this;
            }
Exemple #25
0
 public NativeMethod(JsMethodImpl impl, MethodInfo nativeMethod , JsObject prototype)
     : base(prototype)
 {
     if (impl == null)
         throw new ArgumentNullException("impl");
     m_nativeMethod = nativeMethod;
     m_impl = impl;
     if (nativeMethod != null)
     {
         Name = nativeMethod.Name;
         foreach (var item in nativeMethod.GetParameters())
             Arguments.Add(item.Name);
     }
 }
Exemple #26
0
        public ExecutionVisitor(Options options)
        {
            this.methodInvoker = new CachedMethodInvoker(this);
            this.propertyGetter = new CachedReflectionPropertyGetter(methodInvoker);
            this.constructorInvoker = new CachedConstructorInvoker(methodInvoker);
            this.typeResolver = new CachedTypeResolver();
            this.fieldGetter = new CachedReflectionFieldGetter(methodInvoker);

            GlobalScope = new JsObject();
            Global = new JsGlobal(this, options);
            GlobalScope.Prototype = Global as JsDictionaryObject;
            EnterScope(GlobalScope);
            CallStack = new Stack<string>();
        }
Exemple #27
0
        public JsRegExp(string pattern, bool g, bool i, bool m, JsObject prototype)
            : base(prototype) {
            options = RegexOptions.ECMAScript;

            if (m) {
                options |= RegexOptions.Multiline;
            }

            if (i) {
                options |= RegexOptions.IgnoreCase;
            }

            this.pattern = pattern;
        }
            public static object Min(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                if (arguments.Length == 0)
                    return DoubleBoxes.PositiveInfinity;

                var result = JsValue.ToNumber(arguments[0]);

                foreach (var argument in arguments)
                {
                    result = Math.Min(JsValue.ToNumber(argument), result);
                }

                return result;
            }
            public static object Constructor(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
            {
                var target = (JsObject)@this;
                if (target == runtime.Global.GlobalScope)
                    target = runtime.Global.CreateObject(callee.Prototype);

                target.SetClass(callee.Delegate.Name);
                target.IsClr = false;

                if (arguments.Length > 0)
                    target.SetProperty(Id.message, arguments[0]);

                return target;
            }
Exemple #30
0
        public JsInstance MaxImpl(JsObject target, JsInstance[] parameters)
        {
            if (parameters.Length == 0) {
                return Global.NumberClass["NEGATIVE_INFINITY"];
            }

            var result = parameters[0].ToNumber();

            foreach (var p in parameters)
            {
                result = Math.Max(p.ToNumber(), result);
            }

            return Global.NumberClass.New(result);
        }
Exemple #31
0
 public JsDate(JsObject prototype)
     : base(prototype)
 {
     this.value = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
 }
Exemple #32
0
 public JsDate(double value, JsObject prototype)
     : this(JsDateConstructor.CreateDateTime(value), prototype)
 {
 }
Exemple #33
0
 public JsRegExp(string pattern, JsObject prototype)
     : this(pattern, false, false, false, prototype)
 {
 }
 public JsObject New(JsObject prototype)
 {
     return(new JsObject(prototype));
 }
Exemple #35
0
 public ClrImplDefinition(Func <T, JsInstance> impl, int length, JsObject prototype)
     : this(false, prototype)
 {
     this.impl   = (Delegate)impl;
     this.length = length;
 }
Exemple #36
0
 public ClrImplDefinition(Func <T, JsInstance> impl, JsObject prototype)
     : this(impl, -1, prototype)
 {
 }
Exemple #37
0
 private ClrImplDefinition(bool hasParameters, JsObject prototype)
     : base(prototype)
 {
     this.hasParameters = hasParameters;
 }
Exemple #38
0
 public JsBoolean(bool boolean, JsObject prototype)
     : base(prototype)
 {
     this.value = boolean;
 }
        /// <summary>
        /// 15.4.4.12
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance Splice(JsObject target, JsInstance[] parameters)
        {
            JsArray array             = Global.ArrayClass.New();
            int     relativeStart     = Convert.ToInt32(parameters[0].ToNumber());
            int     actualStart       = relativeStart < 0 ? Math.Max(target.Length + relativeStart, 0) : Math.Min(relativeStart, target.Length);
            int     actualDeleteCount = Math.Min(Math.Max(Convert.ToInt32(parameters[1].ToNumber()), 0), target.Length - actualStart);
            int     len = target.Length;

            for (int k = 0; k < actualDeleteCount; k++)
            {
                string     from   = (relativeStart + k).ToString();
                JsInstance result = null;
                if (target.TryGetProperty(from, out result))
                {
                    array.put(k, result);
                }
            }

            List <JsInstance> items = new List <JsInstance>();

            items.AddRange(parameters);
            items.RemoveAt(0);
            items.RemoveAt(0);

            // use non-distructional copy, determine direction
            if (items.Count < actualDeleteCount)
            {
                for (int k = actualStart; k < len - actualDeleteCount; k++)
                {
                    JsInstance result = null;
                    string     from   = (k + actualDeleteCount).ToString();
                    string     to     = (k + items.Count).ToString();
                    if (target.TryGetProperty(from, out result))
                    {
                        target[to] = result;
                    }
                    else
                    {
                        target.Delete(to);
                    }
                }

                for (int k = target.Length; k > len - actualDeleteCount + items.Count; k--)
                {
                    target.Delete((k - 1).ToString());
                }

                target.Length = len - actualDeleteCount + items.Count;
            }
            else
            {
                for (int k = len - actualDeleteCount; k > actualStart; k--)
                {
                    JsInstance result = null;
                    string     from   = (k + actualDeleteCount - 1).ToString();
                    string     to     = (k + items.Count - 1).ToString();
                    if (target.TryGetProperty(from, out result))
                    {
                        target[to] = result;
                    }
                    else
                    {
                        target.Delete(to);
                    }
                }
            }
            for (int k = 0; k < items.Count; k++)
            {
                target[k.ToString()] = items[k];
            }

            return(array);
        }
 JsInstance GetLengthImpl(JsObject that)
 {
     return(Global.NumberClass.New(that.Length));
 }
 public JsObjectConstructor(IGlobal global, JsObject prototype, JsObject rootPrototype)
     : base(global)
 {
     Name = "Object";
     DefineOwnProperty(PROTOTYPE, rootPrototype, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly);
 }
Exemple #42
0
 public ClrFunction(Delegate d, JsObject prototype)
     : base(prototype)
 {
     Delegate   = d;
     Parameters = d.Method.GetParameters();
 }
Exemple #43
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);
        }
Exemple #44
0
 private JsInstance GetLengthImpl(JsObject that)
 {
     return((JsInstance)this.Global.NumberClass.New((double)that.Length));
 }
Exemple #45
0
 public JsObject(object value, JsObject prototype)
     : base(prototype)
 {
     this.value = value;
 }
Exemple #46
0
 public JsString(string str, JsObject prototype)
     : base(prototype)
 {
     value = str;
 }
 public JsDate New(DateTime value, JsObject prototype)
 {
     return(new JsDate(value, prototype));
 }
 public JsObject New(object value, JsObject prototype)
 {
     return(new JsObject(value, prototype));
 }
Exemple #49
0
        public JsInstance Splice(JsObject target, JsInstance[] parameters)
        {
            JsArray jsArray = this.Global.ArrayClass.New();
            int     int32   = Convert.ToInt32(parameters[0].ToNumber());
            int     num1    = int32 < 0 ? Math.Max(target.Length + int32, 0) : Math.Min(int32, target.Length);
            int     num2    = Math.Min(Math.Max(Convert.ToInt32(parameters[1].ToNumber()), 0), target.Length - num1);
            int     length1 = target.Length;
            int     num3;

            for (int i = 0; i < num2; ++i)
            {
                num3 = int32 + i;
                string     index  = num3.ToString();
                JsInstance result = (JsInstance)null;
                if (target.TryGetProperty(index, out result))
                {
                    jsArray.put(i, result);
                }
            }
            List <JsInstance> jsInstanceList = new List <JsInstance>();

            jsInstanceList.AddRange((IEnumerable <JsInstance>)parameters);
            jsInstanceList.RemoveAt(0);
            jsInstanceList.RemoveAt(0);
            if (jsInstanceList.Count < num2)
            {
                for (int index1 = num1; index1 < length1 - num2; ++index1)
                {
                    JsInstance result = (JsInstance)null;
                    num3 = index1 + num2;
                    string index2 = num3.ToString();
                    num3 = index1 + jsInstanceList.Count;
                    string index3 = num3.ToString();
                    if (target.TryGetProperty(index2, out result))
                    {
                        target[index3] = result;
                    }
                    else
                    {
                        target.Delete(index3);
                    }
                }
                for (int length2 = target.Length; length2 > length1 - num2 + jsInstanceList.Count; --length2)
                {
                    JsObject jsObject = target;
                    num3 = length2 - 1;
                    string index = num3.ToString();
                    jsObject.Delete(index);
                }
                target.Length = length1 - num2 + jsInstanceList.Count;
            }
            else
            {
                for (int index1 = length1 - num2; index1 > num1; --index1)
                {
                    JsInstance result = (JsInstance)null;
                    num3 = index1 + num2 - 1;
                    string index2 = num3.ToString();
                    num3 = index1 + jsInstanceList.Count - 1;
                    string index3 = num3.ToString();
                    if (target.TryGetProperty(index2, out result))
                    {
                        target[index3] = result;
                    }
                    else
                    {
                        target.Delete(index3);
                    }
                }
            }
            for (int index = 0; index < jsInstanceList.Count; ++index)
            {
                target[index.ToString()] = jsInstanceList[index];
            }
            return((JsInstance)jsArray);
        }
 public JsFunctionConstructor(IGlobal global, JsObject prototype)
     : base(global, prototype)
 {
     Name = "Function";
     DefineOwnProperty(PROTOTYPE, prototype, PropertyAttributes.DontEnum | PropertyAttributes.DontDelete | PropertyAttributes.ReadOnly);
 }
 public JsFunctionWrapper(Func <JsInstance[], JsInstance> d, JsObject prototype)
     : base(prototype)
 {
     Delegate = d;
 }
Exemple #52
0
 public ClrImplDefinition(Delegates.Func <T, JsInstance[], JsInstance> impl, int length, JsObject prototype)
     : this(true, prototype)
 {
     this.impl   = impl;
     this.length = length;
 }
Exemple #53
0
 public JsString(JsObject prototype)
     : base(prototype)
 {
     value = String.Empty;
 }
Exemple #54
0
 public JsArray(JsObject prototype)
     : base(prototype)
 {
 }
Exemple #55
0
 public JsRegExp(JsObject prototype)
     : base(prototype)
 {
 }
Exemple #56
0
 private JsArray(SortedList <int, JsInstance> data, int len, JsObject prototype)
     : base(prototype)
 {
     m_data = data;
     length = len;
 }
Exemple #57
0
 public JsDate(DateTime date, JsObject prototype)
     : base(prototype)
 {
     this.value = date;
 }
 public JsObject(JsFunction constructor)
 {
     Prototype = new JsObject(constructor.Prototype);
 }
Exemple #59
0
 public JsBoolean(JsObject prototype)
     : this(false, prototype)
 {
     this.value = false;
 }
Exemple #60
0
        public JsGlobal(ExecutionVisitor visitor, Options options)
            : base(JsNull.Instance)
        {
            this.Options = options;
            this.Visitor = visitor;

            this["null"] = JsNull.Instance;
            JsObject objectProrotype = new JsObject(JsNull.Instance);

            JsFunction functionPrototype = new JsFunctionWrapper(
                delegate(JsInstance[] arguments) {
                return(JsUndefined.Instance);
            },
                objectProrotype
                );

            Marshaller = new Marshaller(this);

            #region Global Classes
            this["Function"] = FunctionClass = new JsFunctionConstructor(this, functionPrototype);
            this["Object"]   = ObjectClass = new JsObjectConstructor(this, functionPrototype, objectProrotype);
            ObjectClass.InitPrototype(this);


            this["Array"]   = ArrayClass = new JsArrayConstructor(this);
            this["Boolean"] = BooleanClass = new JsBooleanConstructor(this);
            this["Date"]    = DateClass = new JsDateConstructor(this);

            this["Error"]          = ErrorClass = new JsErrorConstructor(this, "Error");
            this["EvalError"]      = EvalErrorClass = new JsErrorConstructor(this, "EvalError");
            this["RangeError"]     = RangeErrorClass = new JsErrorConstructor(this, "RangeError");
            this["ReferenceError"] = ReferenceErrorClass = new JsErrorConstructor(this, "ReferenceError");
            this["SyntaxError"]    = SyntaxErrorClass = new JsErrorConstructor(this, "SyntaxError");
            this["TypeError"]      = TypeErrorClass = new JsErrorConstructor(this, "TypeError");
            this["URIError"]       = URIErrorClass = new JsErrorConstructor(this, "URIError");

            this["Number"] = NumberClass = new JsNumberConstructor(this);
            this["RegExp"] = RegExpClass = new JsRegExpConstructor(this);
            this["String"] = StringClass = new JsStringConstructor(this);
            this["Math"]   = MathClass = new JsMathConstructor(this);

            // 15.1 prototype of the global object varies on the implementation
            //this.Prototype = ObjectClass.PrototypeProperty;
            #endregion


            foreach (JsInstance c in this.GetValues())
            {
                if (c is JsConstructor)
                {
                    ((JsConstructor)c).InitPrototype(this);
                }
            }

            #region Global Properties
            this["NaN"]        = NumberClass["NaN"];               // 15.1.1.1
            this["Infinity"]   = NumberClass["POSITIVE_INFINITY"]; // // 15.1.1.2
            this["undefined"]  = JsUndefined.Instance;             // 15.1.1.3
            this[JsScope.THIS] = this;
            #endregion

            #region Global Functions
            // every embed function should have a prototype FunctionClass.PrototypeProperty - 15.
            this["eval"]               = new JsFunctionWrapper(Eval, FunctionClass.PrototypeProperty);       // 15.1.2.1
            this["parseInt"]           = new JsFunctionWrapper(ParseInt, FunctionClass.PrototypeProperty);   // 15.1.2.2
            this["parseFloat"]         = new JsFunctionWrapper(ParseFloat, FunctionClass.PrototypeProperty); // 15.1.2.3
            this["isNaN"]              = new JsFunctionWrapper(IsNaN, FunctionClass.PrototypeProperty);
            this["isFinite"]           = new JsFunctionWrapper(isFinite, FunctionClass.PrototypeProperty);
            this["decodeURI"]          = new JsFunctionWrapper(DecodeURI, FunctionClass.PrototypeProperty);
            this["encodeURI"]          = new JsFunctionWrapper(EncodeURI, FunctionClass.PrototypeProperty);
            this["decodeURIComponent"] = new JsFunctionWrapper(DecodeURIComponent, FunctionClass.PrototypeProperty);
            this["encodeURIComponent"] = new JsFunctionWrapper(EncodeURIComponent, FunctionClass.PrototypeProperty);
            #endregion

            Marshaller.InitTypes();
        }