当前位置: 首页>>代码示例>>C#>>正文


C# Native.JsInstance类代码示例

本文整理汇总了C#中Jint.Native.JsInstance的典型用法代码示例。如果您正苦于以下问题:C# JsInstance类的具体用法?C# JsInstance怎么用?C# JsInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsInstance类属于Jint.Native命名空间,在下文中一共展示了JsInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Concat

 /// <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;
 }
开发者ID:cosh,项目名称:Jint,代码行数:34,代码来源:JsArrayConstructor.cs

示例2: get

 public JsInstance get(JsInstance that, JsInstance index)
 {
     JsIndexerGetter getter = m_getOverload.ResolveOverload(new JsInstance[] { index }, null);
     if (getter == null)
         throw new JintException("No matching overload found");
     return getter(that, index);
 }
开发者ID:cosh,项目名称:Jint,代码行数:7,代码来源:NativeIndexer.cs

示例3: Execute

        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (that == null)
            {
                JsArray array = Global.ArrayClass.New();

                for (int i = 0; i < parameters.Length; i++)
                {
                    array[i.ToString()] = parameters[i];
                }

                visitor.Return(array);
            }
            else
            {
                // When called as part of a new expression, it is a constructor: it initialises the newly created object.
                for (int i = 0; i < parameters.Length; i++)
                {
                    that[i.ToString()] = parameters[i];
                }

                visitor.Return(that);
            }

            return that;
        }
开发者ID:Fedorm,项目名称:core-master,代码行数:26,代码来源:JsArrayConstructor.cs

示例4: Execute

        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            JsFunction function = that as JsFunction;

            if (function == null) {
                throw new ArgumentException("the target of call() must be a function");
            }
            JsDictionaryObject _this;
            JsInstance[] _parameters;
            if (parameters.Length >= 1)
                _this = parameters[0] as JsDictionaryObject;
            else
                _this = visitor.Global as JsDictionaryObject;

            if (parameters.Length >= 2 && parameters[1] != JsNull.Instance) {
                JsObject arguments = parameters[1] as JsObject;
                if (arguments == null)
                    throw new JsException(visitor.Global.TypeErrorClass.New("second argument must be an array"));
                _parameters = new JsInstance[arguments.Length];
                for (int i = 0; i < arguments.Length; i++) {
                    _parameters[i] = arguments[i.ToString()];
                }
            }
            else {
                _parameters = JsInstance.EMPTY;
            }

            // Executes the statements in 'that' and use _this as the target of the call
            visitor.ExecuteFunction(function, _this, _parameters);
            return visitor.Result;
            //visitor.CallFunction(function, _this, _parameters);

            //return visitor.Result;
        }
开发者ID:nate-yocom,项目名称:jint,代码行数:34,代码来源:JsApplyFunction.cs

示例5: ToStringImpl

        /// <summary>
        /// 15.4.4.2
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance ToStringImpl(JsArray target, JsInstance[] parameters)
        {
            JsArray result = Global.ArrayClass.New();

            for (int i = 0; i < target.Length; i++)
            {
                var obj = (JsDictionaryObject)target[i.ToString()];
                if (ExecutionVisitor.IsNullOrUndefined(obj)) {
                    result[i.ToString()] = Global.StringClass.New();
                }
                else
                {
                    var function = obj["toString"] as JsFunction;
                    if (function != null) {
                        Global.Visitor.ExecuteFunction(function, obj, parameters);
                        result[i.ToString()] = Global.Visitor.Returned;
                    }
                    else
                    {
                        result[i.ToString()] = Global.StringClass.New();
                    }
                }
            }

            return Global.StringClass.New(result.ToString());

        }
开发者ID:Fedorm,项目名称:core-master,代码行数:33,代码来源:JsArrayConstructor.cs

示例6: Execute

        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (that == null)
            {
                // 15.5.1 - When String is called as a function rather than as a constructor, it performs a type conversion.
                if (parameters.Length > 0)
                {
                    return visitor.Return(Global.StringClass.New(parameters[0].ToString()));
                }
                else
                {
                    return visitor.Return(Global.StringClass.New(String.Empty));
                }
            }
            else
            {
                // 15.5.2 - When String is called as part of a new expression, it is a constructor: it initialises the newly created object.
                if (parameters.Length > 0)
                {
                    that.Value = parameters[0].ToString();
                }
                else
                {
                    that.Value = String.Empty;
                }

                return visitor.Return(that);
            }
        }
开发者ID:pusp,项目名称:o2platform,代码行数:29,代码来源:JsStringConstructor.cs

示例7: Execute

        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (that == null)
            {
                // 15.7.1 - When Number is called as a function rather than as a constructor, it performs a type conversion.
                if (parameters.Length > 0)
                {
                    return visitor.Return(new JsNumber(parameters[0].ToNumber()));
                }
                else
                {
                    return visitor.Return(new JsNumber(0));
                }
            }
            else
            {
                // 15.7.2 - When Number is called as part of a new expression, it is a constructor: it initialises the newly created object.
                if (parameters.Length > 0)
                {
                    that.Value = parameters[0].ToNumber();
                }
                else
                {
                    that.Value = 0;
                }

                visitor.Return(that);
            }

            return that;
        }
开发者ID:pusp,项目名称:o2platform,代码行数:31,代码来源:JsNumberConstructor.cs

示例8: Set

 public override void Set(JsDictionaryObject that, JsInstance value)
 {
     if (SetFunction == null)
         throw new JsException(global.TypeErrorClass.New());
     //JsDictionaryObject that = global.Visitor.CallTarget;
     global.Visitor.ExecuteFunction(SetFunction, that, new JsInstance[] { value });
 }
开发者ID:pusp,项目名称:o2platform,代码行数:7,代码来源:PropertyDescriptor.cs

示例9: ExecImpl

 public JsInstance ExecImpl(JsRegExp regexp, JsInstance[] parameters)
 {
     string S = parameters[0].ToString();
     int length = S.Length;
     int lastIndex = (int)regexp["lastIndex"].ToNumber();
     int i = lastIndex;
     if (regexp["global"].ToBoolean())
         i = 0;
     if (i < 0 || i > length)
     {
         lastIndex = 0;
         return JsNull.Instance;
     }
     Match r = ((Regex)regexp.Value).Match(S, i);
     if (!r.Success)
     {
         lastIndex = 0;
         return JsNull.Instance;
     }
     int e = r.Index + r.Length;
     if (regexp["global"].ToBoolean())
         lastIndex = e;
     int n = r.Groups.Count;
     JsArray result = Global.ArrayClass.New();
     result["index"] = Global.NumberClass.New(r.Index);
     result["input"] = Global.StringClass.New(S);
     result["length"] = Global.NumberClass.New(n + 1);
     result[Global.NumberClass.New(0)] = Global.StringClass.New(r.Value);
     for (i = 1; i > 0 && i < n; i++)
     {
         result[Global.NumberClass.New(i)] = Global.StringClass.New(r.Groups[i].Value);
     }
     return result;
 }
开发者ID:pusp,项目名称:o2platform,代码行数:34,代码来源:JsRegExpConstructor.cs

示例10: Execute

        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            JsFunction function = that as JsFunction;

            if (function == null)
            {
                throw new ArgumentException("the target of call() must be a function");
            }

            JsDictionaryObject _this;
            JsInstance[] _parameters;
            if (parameters.Length >= 1 && parameters[0] != JsUndefined.Instance && parameters[0] != JsNull.Instance)
                _this = parameters[0] as JsDictionaryObject;
            else
                _this = visitor.Global as JsDictionaryObject;

            if (parameters.Length >= 2 && parameters[1] != JsNull.Instance)
            {
                _parameters = new JsInstance[parameters.Length - 1];
                for (int i = 1; i < parameters.Length; i++)
                {
                    _parameters[i - 1] = parameters[i];
                }
            }
            else
            {
                _parameters = JsInstance.EMPTY;
            }
            // Executes the statements in 'that' and use _this as the target of the call
            visitor.ExecuteFunction(function, _this, _parameters);
            return visitor.Result;
            //visitor.CallFunction(function, _this, _parameters);

            //return visitor.Result;
        }
开发者ID:pusp,项目名称:o2platform,代码行数:35,代码来源:JsCallFunction.cs

示例11: JsException

 public JsException(JsInstance value)
     : base(value.ToString())
 {
     Value = value;
     //if (value is JsDictionaryObject)
     //    ((JsDictionaryObject)value)["jintException"] = new JsClr(this);
 }
开发者ID:Fedorm,项目名称:core-master,代码行数:7,代码来源:JsException.cs

示例12: JsArguments

        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));
        }
开发者ID:Fedorm,项目名称:core-master,代码行数:25,代码来源:JsArguments.cs

示例13: ExecImpl

        public JsInstance ExecImpl(JsRegExp regexp, JsInstance[] parameters)
        {
            JsArray A = Global.ArrayClass.New();
            string input = parameters[0].ToString();
            A["input"] = Global.StringClass.New(input);

            int i = 0;
            var lastIndex = regexp.IsGlobal ? regexp["lastIndex"].ToNumber() : 0;
            MatchCollection matches = Regex.Matches(input.Substring((int)lastIndex), regexp.Pattern, regexp.Options);
            if (matches.Count > 0) {
                // A[Global.NumberClass.New(i++)] = Global.StringClass.New(matches[0].Value);
                A["index"] = Global.NumberClass.New(matches[0].Index);

                if(regexp.IsGlobal)
                {
                    regexp["lastIndex"] = Global.NumberClass.New(lastIndex + matches[0].Index + matches[0].Value.Length);
                }

                foreach (Group g in matches[0].Groups) {
                    A[Global.NumberClass.New(i++)] = Global.StringClass.New(g.Value);
                }

                return A;
            }
            else
            {
                return JsNull.Instance;
            }
        }
开发者ID:nate-yocom,项目名称:jint,代码行数:29,代码来源:JsRegExpConstructor.cs

示例14: ExecImpl

        public JsInstance ExecImpl(JsRegExp regexp, JsInstance[] parameters)
        {
            JsArray A = Global.ArrayClass.New();
            string input = parameters[0].ToString();
            A["input"] = Global.StringClass.New(input);

            int i = 0;
            MatchCollection matches = Regex.Matches(input, regexp.Pattern, regexp.Options);
            if (matches.Count > 0) {
                if (regexp.IsGlobal) {
                    foreach (Match m in matches) {
                        A[Global.NumberClass.New(i++)] = Global.StringClass.New(m.Value);
                    }
                }
                else {
                    foreach (Group g in matches[0].Groups) {
                        A[Global.NumberClass.New(i++)] = Global.StringClass.New(g.Value);
                    }
                }

                A["index"] = Global.NumberClass.New(matches[0].Index);
            }

            return A;
        }
开发者ID:cosh,项目名称:Jint,代码行数:25,代码来源:JsRegExpConstructor.cs

示例15: Construct

        public override JsObject Construct(JsInstance[] parameters, Type[] genericArgs, IJintVisitor visitor) {
            JsArray array = New();

            for (int i = 0; i < parameters.Length; i++)
                array.put(i, parameters[i]); // fast versin since it avoids a type conversion

            return array;
        }
开发者ID:robashton,项目名称:ravendb,代码行数:8,代码来源:JsArrayConstructor.cs


注:本文中的Jint.Native.JsInstance类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。