private void exitEverything(JSValue[] arguments)
 {
     Properties.Settings.Default.remember = Program.remember;
     Properties.Settings.Default.password = Program.pass;
     Properties.Settings.Default.email = Program.email;
     Application.Current.Shutdown();
 }
Esempio n. 2
0
        protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope propertyScope)
        {
            if (key.ToString() == "getSystem")
            {
                var f = new Func<string, ISystem>(s => getSystem(s));
                return Marshal(f);
            }

            var methodInfo = _instance.GetType().GetMethod(key.ToString(), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            if (methodInfo != null)
            {
                var del = methodInfo.CreateDelegate(Expression.GetDelegateType(

                        (from parameter in methodInfo.GetParameters() select parameter.ParameterType)
                        .Concat(new[] { methodInfo.ReturnType })
                        .ToArray()), _instance);

                return Marshal(del);
            }

            methodInfo = _instance.GetType().GetMethod(key.ToString(), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
            if (methodInfo != null)
            {
                var del = methodInfo.CreateDelegate(Expression.GetDelegateType(

                        (from parameter in methodInfo.GetParameters() select parameter.ParameterType)
                        .Concat(new[] { methodInfo.ReturnType })
                        .ToArray()));

                return Marshal(del);
            }

            return base.GetProperty(key, forWrite, propertyScope);
        }
Esempio n. 3
0
 public JSCallbackEventArgs(WebView webView, string objectName, string callbackName, JSValue[] args)
 {
     this.webView = webView;
     this.objectName = objectName;
     this.callbackName = callbackName;
     this.args = args;
 }
Esempio n. 4
0
 public void SetMappedJSValue(JSValue ijsobject, IJSCBridgeCache mapper)
 {
     _MappedJSValue = ijsobject;
     JSObject mapped = ((JSObject)_MappedJSValue);
     mapped.Bind("Execute", false, (o, e) => ExecuteCommand(e, mapper));
     mapped.Bind("CanExecute", false, (o, e) => CanExecuteCommand(e, mapper));
 }
Esempio n. 5
0
 public JSArray(IEnumerable<IJSCSGlue> values, IEnumerable collection, Type ElementType)
 {
     JSValue = new JSValue(values.Select(v => v.JSValue).ToArray());
     Items = new List<IJSCSGlue>(values);
     CValue = collection;
     IndividualType = ElementType;
 }
Esempio n. 6
0
        public void EmptyEquality()
        {
            var undef_v = JSValue.NewUndefined (context);
            var null_v = JSValue.NewNull (context);
            var number_v = new JSValue (context, 0);
            var bool_v = new JSValue (context, false);
            var string_v = new JSValue (context, "");

            Assert.IsTrue (undef_v.IsEqual (undef_v));
            Assert.IsTrue (undef_v.IsStrictEqual (undef_v));
            Assert.IsTrue (undef_v.IsEqual (null_v));
            Assert.IsFalse (undef_v.IsStrictEqual (null_v));
            Assert.IsFalse (undef_v.IsEqual (number_v));
            Assert.IsFalse (undef_v.IsStrictEqual (number_v));
            Assert.IsFalse (undef_v.IsEqual (bool_v));
            Assert.IsFalse (undef_v.IsStrictEqual (bool_v));
            Assert.IsFalse (undef_v.IsEqual (string_v));
            Assert.IsFalse (undef_v.IsStrictEqual (string_v));

            Assert.IsFalse (string_v.IsEqual (undef_v));
            Assert.IsFalse (string_v.IsStrictEqual (undef_v));
            Assert.IsFalse (string_v.IsEqual (null_v));
            Assert.IsFalse (string_v.IsStrictEqual (null_v));
            Assert.IsTrue (string_v.IsEqual (number_v));
            Assert.IsFalse (string_v.IsStrictEqual (number_v));
            Assert.IsTrue (string_v.IsEqual (bool_v));
            Assert.IsFalse (string_v.IsStrictEqual (bool_v));
            Assert.IsTrue (string_v.IsEqual (string_v));
            Assert.IsTrue (string_v.IsStrictEqual (string_v));
        }
Esempio n. 7
0
		public MarkdownService()
		{
			_ctx = new JSContext(_vm);
			var script = System.IO.File.ReadAllText("Markdown/marked.js", System.Text.Encoding.UTF8);
			_ctx.EvaluateScript(script);
			_val = _ctx[new NSString("marked")];
		}
Esempio n. 8
0
 private JSValue Fib_1 (JSFunction function, JSObject @this, JSValue [] args)
 {
     return args[0].NumberValue <= 1 ? new JSValue (@this.Context, 1) : new JSValue (@this.Context,
         Fib_1 (function, @this, new [] { new JSValue (@this.Context, args[0].NumberValue - 1) }).NumberValue +
         Fib_1 (function, @this, new [] { new JSValue (@this.Context, args[0].NumberValue - 2) }).NumberValue
     );
 }
        public object GetSimpleValue(JSValue ijsvalue, Type iTargetType=null)
        {
            if (ijsvalue.IsString)
                return (string)ijsvalue;

            if (ijsvalue.IsBoolean)
                return (bool)ijsvalue;

            object res =null;

            if (ijsvalue.IsNumber)
            {
                if (ijsvalue.IsInteger)
                    res = (int)ijsvalue;
                else if (ijsvalue.IsDouble)
                    res = (double)ijsvalue;

                if (iTargetType == null)
                    return res;
                else
                    return Convert.ChangeType(res, iTargetType);
            }

            var resdate =  GetDate(ijsvalue);
            if (resdate.HasValue)
                return resdate.Value;

            return null;
        }
Esempio n. 10
0
        public override void OnCallback(string name, JSValue[] args)
        {
            base.OnCallback(name, args);

            if (name.Equals("MainMenuClick"))
            {
                var uiView = UIManager.GetByType(UIType.Main);
                UIManager.SetView(uiView);
            }
        }
Esempio n. 11
0
        public void UpdateCSharpProperty(string PropertyName, IJSCBridgeCache converter, JSValue newValue )
        {
            PropertyInfo propertyInfo = CValue.GetType().GetProperty(PropertyName, BindingFlags.Public | BindingFlags.Instance);
            if (!propertyInfo.CanWrite)
                return;

            var type = propertyInfo.PropertyType.GetUnderlyingNullableType() ?? propertyInfo.PropertyType;
            IJSCSGlue glue = converter.GetCachedOrCreateBasic(newValue, type);
            _Attributes[PropertyName] = glue;
            propertyInfo.SetValue(CValue, glue.CValue, null);
        }
Esempio n. 12
0
        // Returns a wrapper JSValue array from a const jsarray* instance. Ownership remains
        // with the original instance.
        internal static JSValue[] getArray( IntPtr instance )
        {
            uint size = awe_jsarray_get_size( instance );
            JSValue[] temp = new JSValue[ size ];
            for ( uint i = 0; i < size; i++ )
            {
                temp[ i ] = new JSValue( awe_jsarray_get_element( instance, i ) );
            }

            return temp;
        }
Esempio n. 13
0
        internal static IntPtr CreateArray( JSValue[] vals )
        {
            IntPtr[] temp = new IntPtr[ vals.Length ];
            int count = 0;
            foreach ( JSValue i in vals )
            {
                temp[ count ] = i.Instance;
                count++;
            }

            return awe_jsarray_create( temp, (uint)vals.Length );
        }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the SongDisplayController class.
 /// </summary>
 /// <param name="control">The web view that is controlled by this instance. Its IsProcessCreated property must be true.</param>
 /// <param name="features">The desired feature level.</param>
 public SongDisplayController(IWebView control, FeatureLevel features = FeatureLevel.None)
 {
     this.control = control;
     this.features = features;
     this.control.ConsoleMessage += (obj, target) =>
     {
         System.Windows.MessageBox.Show("SongDisplayController encountered JS error in " + target.Source + " (line " +  target.LineNumber + "): " + target.Message);
     };
     // FIXME: sometimes throws exception saying that "bridge" object already exists
     bridge = this.control.CreateGlobalJavascriptObject("bridge");
     bridge.BindAsync("callbackLoaded", (sender, args) => OnSongLoaded());
     bridge["featureLevel"] = new JSValue(JsonConvert.SerializeObject(features));
 }
Esempio n. 15
0
 private static object ToObject(JSValue e)
 {
     if (e.IsArray) return null;
     if (e.IsBoolean) return (bool)e;
     if (e.IsDouble) return (double)e;
     if (e.IsInteger) return (int)e;
     if (e.IsNull) return null;
     if (e.IsNumber) return (decimal)e;
     if (e.IsObject) return null;
     if (e.IsString) return (string)e;
     if (e.IsUndefined) return null;
     return null;
 }
Esempio n. 16
0
        public JSCommand(IJSOBuilder builder,  ICommand  icValue)
        {
            _Command = icValue;
       
            bool canexecute = true;
            try
            {
                canexecute = _Command.CanExecute(null);
            }
            catch { }
 
            JSObject res =  builder.CreateJSO();
            res["CanExecuteValue"] = new JSValue(canexecute);
            res["CanExecuteCount"] = new JSValue(_Count);
            JSValue = res;       
        }
Esempio n. 17
0
        public void OnRequestBuddies(object sender, JavascriptMethodEventArgs e)
        {
            JSValue[] buddyList = new JSValue[Client.AllPlayers.Count];

            int i = 0;
            foreach (var x in Client.AllPlayers)
            {
                JSObject buddy = new JSObject();
                buddy["name"] = new JSValue(x.Value.Username);
                buddy["summonerId"] = new JSValue(x.Key.Replace("sum", ""));
                buddy["isMutualFriend"] = new JSValue(true);
                buddyList[i++] = buddy;
            }

            e.Result = new JSValue(buddyList);
        }
Esempio n. 18
0
        public void Boolean()
        {
            var a = new JSValue (context, false);
            var b = new JSValue (context, true);

            Assert.IsTrue (a.IsBoolean);
            Assert.IsTrue (b.IsBoolean);

            Assert.AreEqual (false, a.BooleanValue);
            Assert.AreEqual (true, b.BooleanValue);

            Assert.AreEqual (0.0, a.NumberValue);
            Assert.AreEqual (1.0, b.NumberValue);

            Assert.AreEqual ("false", a.StringValue);
            Assert.AreEqual ("true", b.StringValue);

            Assert.AreEqual (JSType.Boolean, a.JSType);
            Assert.AreEqual (JSType.Boolean, b.JSType);
        }
 private void zlo_Remember(JSValue[] arguments)
 {
     Program.remember = true;
     string email = Program.email;
     string pass = Program.pass;
     if (email != null && pass != null)
     {
         try
         {
             zloAPI.Battlefield3.ZLO_AuthClient(email, pass);
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
             Console.WriteLine("Login failed! Please try again.");
         }
         finally
         {
         }
         Console.WriteLine("Loggedin - " + arguments[0].ToString());
     }
 }
        private DateTime? GetDate(JSValue iJSValue)
        {
            if (!iJSValue.IsObject)
                return null;

            JSObject ob = iJSValue;

            if (ob == null)
                return null;

            JSObject ko = _IWebView.ExecuteJavascriptWithResult("ko");
            if ((bool)ko.Invoke("isDate", iJSValue) == false)
                return null;

            int year = (int)ob.Invoke("getFullYear", null);
            int month = (int)ob.Invoke("getMonth", null) + 1;
            int day = (int)ob.Invoke("getDate", null);
            int hour = (int)ob.Invoke("getHours",null);
            int minute = (int)ob.Invoke("getMinutes",null);
            int second = (int)ob.Invoke("getSeconds",null);
            int millisecond = (int)ob.Invoke("getMilliseconds",null);

            return new DateTime(year, month, day, hour, minute, second, millisecond);
        }
Esempio n. 21
0
 public GeneratorResult(JSValue value, bool done)
 {
     _value = value;
     _done = done;
 }
Esempio n. 22
0
        public void String()
        {
            var a = new JSValue (context, "Hello World");
            var b = new JSValue (context, JSString.New ("Hello World"));

            Assert.IsTrue (a.IsString);
            Assert.IsTrue (b.IsString);

            Assert.IsTrue (a.IsEqual (b));
            Assert.IsTrue (a.IsStrictEqual (b));
            Assert.AreEqual (a.StringValue, b.StringValue);

            Assert.AreEqual (JSType.String, a.JSType);
            Assert.AreEqual (JSType.String, b.JSType);

            a = new JSValue (context, "Hello World");
            b = new JSValue (context, JSString.New ("Not the same"));

            Assert.IsFalse (a.IsEqual (b));
            Assert.IsFalse (a.IsStrictEqual (b));
        }
Esempio n. 23
0
        internal static bool Check(JSValue first, JSValue second, bool lessOrEqual)
        {
            switch (first._valueType)
            {
            case JSValueType.Boolean:
            case JSValueType.Integer:
            {
                switch (second._valueType)
                {
                case JSValueType.Boolean:
                case JSValueType.Integer:
                {
                    return(first._iValue > second._iValue);
                }

                case JSValueType.Double:
                {
                    if (double.IsNaN(second._dValue))
                    {
                        return(lessOrEqual);                // Костыль. Для его устранения нужно делать полноценную реализацию оператора MoreOrEqual.
                    }
                    else
                    {
                        return(first._iValue > second._dValue);
                    }
                }

                case JSValueType.String:
                {
                    var    index = 0;
                    double td    = 0;
                    if (Tools.ParseNumber(second._oValue.ToString(), ref index, out td) && (index == (second._oValue.ToString()).Length))
                    {
                        return(first._iValue > td);
                    }
                    else
                    {
                        return(lessOrEqual);
                    }
                }

                case JSValueType.Date:
                case JSValueType.Object:
                {
                    second = second.ToPrimitiveValue_Value_String();
                    if (second._valueType == JSValueType.Integer)
                    {
                        goto case JSValueType.Integer;
                    }
                    if (second._valueType == JSValueType.Boolean)
                    {
                        goto case JSValueType.Integer;
                    }
                    if (second._valueType == JSValueType.Double)
                    {
                        goto case JSValueType.Double;
                    }
                    if (second._valueType == JSValueType.String)
                    {
                        goto case JSValueType.String;
                    }
                    if (second._valueType >= JSValueType.Object)                 // null
                    {
                        return(first._iValue > 0);
                    }
                    throw new NotImplementedException();
                }

                default:
                    return(lessOrEqual);
                }
            }

            case JSValueType.Double:
            {
                if (double.IsNaN(first._dValue))
                {
                    return(lessOrEqual);        // Костыль. Для его устранения нужно делать полноценную реализацию оператора MoreOrEqual.
                }
                else
                {
                    switch (second._valueType)
                    {
                    case JSValueType.Boolean:
                    case JSValueType.Integer:
                    {
                        return(first._dValue > second._iValue);
                    }

                    case JSValueType.Double:
                    {
                        if (double.IsNaN(first._dValue) || double.IsNaN(second._dValue))
                        {
                            return(lessOrEqual);                // Костыль. Для его устранения нужно делать полноценную реализацию оператора MoreOrEqual.
                        }
                        else
                        {
                            return(first._dValue > second._dValue);
                        }
                    }

                    case JSValueType.String:
                    {
                        var    index = 0;
                        double td    = 0;
                        if (Tools.ParseNumber(second._oValue.ToString(), ref index, out td) && (index == (second._oValue.ToString()).Length))
                        {
                            return(first._dValue > td);
                        }
                        else
                        {
                            return(lessOrEqual);
                        }
                    }

                    case JSValueType.Undefined:
                    case JSValueType.NotExistsInObject:
                    {
                        return(lessOrEqual);
                    }

                    case JSValueType.Date:
                    case JSValueType.Object:
                    {
                        second = second.ToPrimitiveValue_Value_String();
                        if (second._valueType == JSValueType.Integer)
                        {
                            goto case JSValueType.Integer;
                        }
                        if (second._valueType == JSValueType.Boolean)
                        {
                            goto case JSValueType.Integer;
                        }
                        if (second._valueType == JSValueType.Double)
                        {
                            goto case JSValueType.Double;
                        }
                        if (second._valueType == JSValueType.String)
                        {
                            goto case JSValueType.String;
                        }
                        if (second._valueType >= JSValueType.Object)                 // null
                        {
                            return(first._dValue > 0);
                        }
                        throw new NotImplementedException();
                    }

                    default:
                        return(lessOrEqual);
                    }
                }
            }

            case JSValueType.String:
            {
                string left = first._oValue.ToString();
                switch (second._valueType)
                {
                case JSValueType.Boolean:
                case JSValueType.Integer:
                {
                    double d = 0;
                    int    i = 0;
                    if (Tools.ParseNumber(left, ref i, out d) && (i == left.Length))
                    {
                        return(d > second._iValue);
                    }
                    else
                    {
                        return(lessOrEqual);
                    }
                }

                case JSValueType.Double:
                {
                    double d = 0;
                    int    i = 0;
                    if (Tools.ParseNumber(left, ref i, out d) && (i == left.Length))
                    {
                        return(d > second._dValue);
                    }
                    else
                    {
                        return(lessOrEqual);
                    }
                }

                case JSValueType.String:
                {
                    return(string.CompareOrdinal(left, second._oValue.ToString()) > 0);
                }

                case JSValueType.Function:
                case JSValueType.Object:
                {
                    second = second.ToPrimitiveValue_Value_String();
                    switch (second._valueType)
                    {
                    case JSValueType.Integer:
                    case JSValueType.Boolean:
                    {
                        double t = 0.0;
                        int    i = 0;
                        if (Tools.ParseNumber(left, ref i, out t) && (i == left.Length))
                        {
                            return(t > second._iValue);
                        }
                        else
                        {
                            goto case JSValueType.String;
                        }
                    }

                    case JSValueType.Double:
                    {
                        double t = 0.0;
                        int    i = 0;
                        if (Tools.ParseNumber(left, ref i, out t) && (i == left.Length))
                        {
                            return(t > second._dValue);
                        }
                        else
                        {
                            goto case JSValueType.String;
                        }
                    }

                    case JSValueType.String:
                    {
                        return(string.CompareOrdinal(left, second._oValue.ToString()) > 0);
                    }

                    case JSValueType.Object:
                    {
                        double t = 0.0;
                        int    i = 0;
                        if (Tools.ParseNumber(left, ref i, out t) && (i == left.Length))
                        {
                            return(t > 0);
                        }
                        else
                        {
                            return(lessOrEqual);
                        }
                    }

                    default: throw new NotImplementedException();
                    }
                }

                default:
                    return(lessOrEqual);
                }
            }

            case JSValueType.Function:
            case JSValueType.Date:
            case JSValueType.Object:
            {
                first = first.ToPrimitiveValue_Value_String();
                if (first._valueType == JSValueType.Integer)
                {
                    goto case JSValueType.Integer;
                }
                if (first._valueType == JSValueType.Boolean)
                {
                    goto case JSValueType.Integer;
                }
                if (first._valueType == JSValueType.Double)
                {
                    goto case JSValueType.Double;
                }
                if (first._valueType == JSValueType.String)
                {
                    goto case JSValueType.String;
                }
                if (first._valueType >= JSValueType.Object) // null
                {
                    first._iValue = 0;                      // такое делать можно, поскольку тип не меняется
                    goto case JSValueType.Integer;
                }
                throw new NotImplementedException();
            }

            default:
                return(lessOrEqual);
            }
        }
Esempio n. 24
0
 private static void addCategoryData(JSValue[] categoryName, JSValue[] browserValue)
 {
     MySqlConnection con = new MySqlConnection(connectionString);
       string dbCommand = String.Empty;
       MySqlCommand comm = new MySqlCommand(dbCommand, con);
       con.Open();
       for(int i = 0; i < categoryName.Length; i++)
       {
     dbCommand = "INSERT INTO categories (categoryName, browserValue) VALUES ('" + (string)categoryName[i] + "', '" +
     (string)browserValue[i] + "')";
     comm.CommandText = dbCommand;
     comm.ExecuteNonQuery();
       }
       con.Close();
 }
Esempio n. 25
0
        public void Number()
        {
            var a = new JSValue (context, 10);
            var b = new JSValue (context, 10.0);
            var c = new JSValue (context, 10.0f);
            var d = new JSValue (context, 0);
            var e = new JSValue (context, -200);

            Assert.IsTrue (a.IsNumber);
            Assert.IsTrue (b.IsNumber);
            Assert.IsTrue (c.IsNumber);
            Assert.IsTrue (d.IsNumber);
            Assert.IsTrue (e.IsNumber);

            Assert.AreEqual (10.0, a.NumberValue);
            Assert.AreEqual (10.0, b.NumberValue);
            Assert.AreEqual (10.0, c.NumberValue);
            Assert.AreEqual (0, d.NumberValue);
            Assert.AreEqual (-200, e.NumberValue);

            Assert.AreEqual (false, d.BooleanValue);
            Assert.AreEqual (true, e.BooleanValue);

            Assert.AreEqual ("-200", e.StringValue);

            Assert.AreEqual (JSType.Number, a.JSType);
            Assert.AreEqual (JSType.Number, b.JSType);
            Assert.AreEqual (JSType.Number, c.JSType);
            Assert.AreEqual (JSType.Number, d.JSType);
            Assert.AreEqual (JSType.Number, e.JSType);
        }
Esempio n. 26
0
 public static bool js_get_classvalue(JSContext ctx, JSValue val, out Delegate o)
 {
     return(js_get_delegate_unsafe(ctx, val, out o));
 }
Esempio n. 27
0
 public override void Assign(JSValue value)
 {
     throw new InvalidOperationException();
 }
Esempio n. 28
0
 // return type id, 不可重复注册
 public int RegisterType(Type type, JSValue proto)
 {
     _pendingTypes.Add(type);
     return(_db.AddType(type, proto));
 }
Esempio n. 29
0
 public Constant(JSValue value)
     : base(null, null, false)
 {
     this.value = value;
 }
Esempio n. 30
0
        public void PrimitiveTypeShouldBeWrappedAsClass()
        {
            var wrappedObject = JSValue.Wrap(1);

            Assert.AreEqual(JSValueType.Object, wrappedObject.ValueType);
        }
Esempio n. 31
0
        public void PrimitiveTypeShouldBeMarshaledAsPrimitive()
        {
            var wrappedObject = JSValue.Marshal(1);

            Assert.AreEqual(JSValueType.Integer, wrappedObject.ValueType);
        }
Esempio n. 32
0
        private bool evalAsConst(CodeBlock body, Expression[] arguments, Context initiator, out JSValue result)
        {
            if (body._lines.Length == 0)
            {
                result = notExists;
            }
            else if (body._lines.Length == 1)
            {
                var ret = body._lines[0] as Return;
                if (ret != null)
                {
                    if (ret.Value != null)
                    {
                        if (ret.Value.ContextIndependent)
                        {
                            result = ret.Value.Evaluate(null);
                        }
                        else
                        {
                            result = null;
                            return(false);
                        }
                    }
                    else
                    {
                        result = notExists;
                    }
                }
                else
                {
                    result = null;
                    return(false);
                }
            }
            else
            {
                result = null;
                return(false);
            }

            for (int i = 0; i < arguments.Length; i++)
            {
                if (!arguments[i].Evaluate(initiator).Defined)
                {
                    if (_functionDefinition.parameters.Length > i && _functionDefinition.parameters[i].initializer != null)
                    {
                        _functionDefinition.parameters[i].initializer.Evaluate(_initialContext);
                    }
                }
            }

            return(true);
        }
Esempio n. 33
0
        private void initParametersFast(Expression[] arguments, Core.Context initiator, Context internalContext)
        {
            JSValue a0 = null,
                    a1 = null,
                    a2 = null,
                    a3 = null,
                    a4 = null,
                    a5 = null,
                    a6 = null,
                    a7 = null; // Вместо кучи, выделяем память на стеке

            var argumentsCount = arguments.Length;

            if (_functionDefinition.parameters.Length != argumentsCount)
            {
                throw new ArgumentException("Invalid arguments count");
            }
            if (argumentsCount > 8)
            {
                throw new ArgumentException("To many arguments");
            }
            if (argumentsCount == 0)
            {
                return;
            }

            /*
             * Да, от этого кода можно вздрогнуть, но по ряду причин лучше сделать не получится.
             * Такая она цена оптимизации
             */

            /*
             * Эти два блока нельзя смешивать. Текущие значения параметров могут быть использованы для расчёта новых.
             * Поэтому заменять значения можно только после полного расчёта новых значений
             */

            a0 = Tools.EvalExpressionSafe(initiator, arguments[0]);
            if (argumentsCount > 1)
            {
                a1 = Tools.EvalExpressionSafe(initiator, arguments[1]);
                if (argumentsCount > 2)
                {
                    a2 = Tools.EvalExpressionSafe(initiator, arguments[2]);
                    if (argumentsCount > 3)
                    {
                        a3 = Tools.EvalExpressionSafe(initiator, arguments[3]);
                        if (argumentsCount > 4)
                        {
                            a4 = Tools.EvalExpressionSafe(initiator, arguments[4]);
                            if (argumentsCount > 5)
                            {
                                a5 = Tools.EvalExpressionSafe(initiator, arguments[5]);
                                if (argumentsCount > 6)
                                {
                                    a6 = Tools.EvalExpressionSafe(initiator, arguments[6]);
                                    if (argumentsCount > 7)
                                    {
                                        a7 = Tools.EvalExpressionSafe(initiator, arguments[7]);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            setParamValue(0, a0, internalContext);
            if (argumentsCount > 1)
            {
                setParamValue(1, a1, internalContext);
                if (argumentsCount > 2)
                {
                    setParamValue(2, a2, internalContext);
                    if (argumentsCount > 3)
                    {
                        setParamValue(3, a3, internalContext);
                        if (argumentsCount > 4)
                        {
                            setParamValue(4, a4, internalContext);
                            if (argumentsCount > 5)
                            {
                                setParamValue(5, a5, internalContext);
                                if (argumentsCount > 6)
                                {
                                    setParamValue(6, a6, internalContext);
                                    if (argumentsCount > 7)
                                    {
                                        setParamValue(7, a7, internalContext);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 34
0
        private JSValue fastInvoke(JSValue targetObject, Expression[] arguments, Context initiator)
        {
#if DEBUG && !(PORTABLE || NETCORE)
            if (_functionDefinition.trace)
            {
                System.Console.WriteLine("DEBUG: Run \"" + _functionDefinition.Reference.Name + "\"");
            }
#endif
            var body = _functionDefinition._body;
            targetObject = correctTargetObject(targetObject, body._strict);
            if (_functionDefinition.recursionDepth > _functionDefinition.parametersStored) // рекурсивный вызов.
            {
                storeParameters();
                _functionDefinition.parametersStored++;
            }

            JSValue   res      = null;
            Arguments args     = null;
            bool      tailCall = false;
            for (;;)
            {
                var internalContext = new Context(_initialContext, false, this);

                if (_functionDefinition.kind == FunctionKind.Arrow)
                {
                    internalContext._thisBind = _initialContext._thisBind;
                }
                else
                {
                    internalContext._thisBind = targetObject;
                }

                if (tailCall)
                {
                    initParameters(args, internalContext);
                }
                else
                {
                    initParametersFast(arguments, initiator, internalContext);
                }

                // Эта строка обязательно должна находиться после инициализации параметров
                _functionDefinition.recursionDepth++;

                if (this._functionDefinition.reference._descriptor != null && _functionDefinition.reference._descriptor.cacheRes == null)
                {
                    _functionDefinition.reference._descriptor.cacheContext = internalContext._parent;
                    _functionDefinition.reference._descriptor.cacheRes     = this;
                }

                internalContext._strict |= body._strict;
                internalContext.Activate();

                try
                {
                    res = evaluateBody(internalContext);
                    if (internalContext._executionMode == ExecutionMode.TailRecursion)
                    {
                        tailCall = true;
                        args     = internalContext._executionInfo as Arguments;
                    }
                    else
                    {
                        tailCall = false;
                    }
                }
                finally
                {
#if DEBUG && !(PORTABLE || NETCORE)
                    if (_functionDefinition.trace)
                    {
                        System.Console.WriteLine("DEBUG: Exit \"" + _functionDefinition.Reference.Name + "\"");
                    }
#endif
                    _functionDefinition.recursionDepth--;
                    if (_functionDefinition.parametersStored > _functionDefinition.recursionDepth)
                    {
                        _functionDefinition.parametersStored--;
                    }
                    exit(internalContext);
                }
                if (!tailCall)
                {
                    break;
                }
                targetObject = correctTargetObject(internalContext._objectSource, body._strict);
            }
            return(res);
        }
Esempio n. 35
0
        internal protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope)
        {
            if (memberScope < PropertyScope.Super && key._valueType != JSValueType.Symbol)
            {
                var     name = key.ToString();
                JSValue res  = null;
                if (childs != null && childs.TryGetValue(name, out res))
                {
                    return(res);
                }
                string reqname   = Namespace + "." + name;
                var    selection = types.StartedWith(reqname).GetEnumerator();

                Type        resultType = null;
                List <Type> ut         = null;

                while (selection.MoveNext())
                {
                    if (selection.Current.Value.FullName.Length > reqname.Length &&
                        selection.Current.Value.FullName[reqname.Length] == '`')
                    {
                        string fn = selection.Current.Value.FullName;
                        for (var i = fn.Length - 1; i > reqname.Length; i--)
                        {
                            if (!Tools.IsDigit(fn[i]))
                            {
                                fn = null;
                                break;
                            }
                        }

                        if (fn != null)
                        {
                            if (resultType == null)
                            {
                                resultType = selection.Current.Value;
                            }
                            else
                            {
                                if (ut == null)
                                {
                                    ut = new List <Type> {
                                        resultType
                                    }
                                }
                                ;

                                ut.Add(selection.Current.Value);
                            }
                        }
                    }
                    else if (selection.Current.Value.Name != name)
                    {
                        break;
                    }
                    else
                    {
                        resultType = selection.Current.Value;
                    }
                }

                if (ut != null)
                {
                    res = Proxy.GetGenericTypeSelector(ut);

                    if (childs == null)
                    {
                        childs = new BinaryTree <JSValue>();
                    }

                    childs[name] = res;
                    return(res);
                }

                if (resultType != null)
                {
                    return(Context.CurrentGlobalContext.GetConstructor(resultType));
                }

                selection = types.StartedWith(reqname).GetEnumerator();
                if (selection.MoveNext() && selection.Current.Key[reqname.Length] == '.')
                {
                    res = new NamespaceProvider(reqname);

                    if (childs == null)
                    {
                        childs = new BinaryTree <JSValue>();
                    }

                    childs.Add(name, res);
                    return(res);
                }
            }

            return(undefined);
        }
Esempio n. 36
0
    public void SetBodyBGColor(string bgColor)
    {
        JSValue result = ExecuteJavaScriptWithResult("var elems = document.getElementsByTagName(\"body\"); if(elems.length > 0){elems[0].style.backgroundColor=\"" + bgColor + "\";}");

        Debug.Log("SetBodyBGColor ExecuteJavaScriptWithResult: " + result.ToString());
    }
Esempio n. 37
0
        public static bool js_get_primitive_array(JSContext ctx, JSValue val, out byte[] o)
        {
            var isArray = JSApi.JS_IsArray(ctx, val);

            if (isArray == 1)
            {
                var lengthVal = JSApi.JS_GetProperty(ctx, val, JSApi.JS_ATOM_length);
                if (JSApi.JS_IsException(lengthVal))
                {
                    o = null;
                    return(js_script_error(ctx));
                }
                int length;
                JSApi.JS_ToInt32(ctx, out length, lengthVal);
                JSApi.JS_FreeValue(ctx, lengthVal);
                o = new byte[length];
                for (var i = 0U; i < length; i++)
                {
                    var  eVal = JSApi.JS_GetPropertyUint32(ctx, val, i);
                    byte e;
                    if (js_get_primitive(ctx, eVal, out e))
                    {
                        o[i] = e;
                        JSApi.JS_FreeValue(ctx, eVal);
                    }
                    else
                    {
                        o = null;
                        JSApi.JS_FreeValue(ctx, eVal);
                        return(false);
                    }
                }
                return(true);
            }

            // check ArrayBuffer
            size_t psize;
            var    pbuf = JSApi.JS_GetArrayBuffer(ctx, out psize, val);

            if (pbuf != IntPtr.Zero)
            {
                o = new byte[psize];
                Marshal.Copy(pbuf, o, 0, psize);
                return(true);
            }

            // check TypedArray
            var asBuffer = JSApi.JS_GetProperty(ctx, val, ScriptEngine.GetContext(ctx).GetAtom("buffer"));

            if (asBuffer.IsObject())
            {
                pbuf = JSApi.JS_GetArrayBuffer(ctx, out psize, asBuffer);
                JSApi.JS_FreeValue(ctx, asBuffer);

                if (pbuf != IntPtr.Zero)
                {
                    o = new byte[psize];
                    Marshal.Copy(pbuf, o, 0, psize);
                    return(true);
                }
            }
            else
            {
                JSApi.JS_FreeValue(ctx, asBuffer);
            }

            if (isArray == -1)
            {
                o = null;
                return(false);
            }
            return(js_get_classvalue <byte[]>(ctx, val, out o));
        }
Esempio n. 38
0
        internal static void Impl(JSValue resultContainer, JSValue first, JSValue second)
        {
            switch (first._valueType)
            {
            case JSValueType.Boolean:
            case JSValueType.Integer:
            {
                if (second._valueType >= JSValueType.Object)
                {
                    second = second.ToPrimitiveValue_Value_String();
                }
                switch (second._valueType)
                {
                case JSValueType.Integer:
                case JSValueType.Boolean:
                {
                    long tl = (long)first._iValue + second._iValue;
                    if ((int)tl == tl)
                    {
                        resultContainer._valueType = JSValueType.Integer;
                        resultContainer._iValue    = (int)tl;
                    }
                    else
                    {
                        resultContainer._valueType = JSValueType.Double;
                        resultContainer._dValue    = tl;
                    }
                    return;
                }

                case JSValueType.Double:
                {
                    resultContainer._valueType = JSValueType.Double;
                    resultContainer._dValue    = first._iValue + second._dValue;
                    return;
                }

                case JSValueType.String:
                {
                    resultContainer._oValue    = new RopeString((first._valueType == JSValueType.Boolean ? (first._iValue != 0 ? "true" : "false") : first._iValue.ToString(CultureInfo.InvariantCulture)), second._oValue);
                    resultContainer._valueType = JSValueType.String;
                    return;
                }

                case JSValueType.NotExists:
                case JSValueType.NotExistsInObject:
                case JSValueType.Undefined:
                {
                    resultContainer._dValue    = double.NaN;
                    resultContainer._valueType = JSValueType.Double;
                    return;
                }

                case JSValueType.Object:             // x+null
                {
                    resultContainer._iValue    = first._iValue;
                    resultContainer._valueType = JSValueType.Integer;
                    return;
                }
                }
                break;
            }

            case JSValueType.Double:
            {
                if (second._valueType >= JSValueType.Object)
                {
                    second = second.ToPrimitiveValue_Value_String();
                }
                switch (second._valueType)
                {
                case JSValueType.Integer:
                case JSValueType.Boolean:
                {
                    resultContainer._valueType = JSValueType.Double;
                    resultContainer._dValue    = first._dValue + second._iValue;
                    return;
                }

                case JSValueType.Double:
                {
                    resultContainer._valueType = JSValueType.Double;
                    resultContainer._dValue    = first._dValue + second._dValue;
                    return;
                }

                case JSValueType.String:
                {
                    resultContainer._oValue    = new RopeString(Tools.DoubleToString(first._dValue), second._oValue);
                    resultContainer._valueType = JSValueType.String;
                    return;
                }

                case JSValueType.Object:             // null
                {
                    resultContainer._dValue    = first._dValue;
                    resultContainer._valueType = JSValueType.Double;
                    return;
                }

                case JSValueType.NotExists:
                case JSValueType.NotExistsInObject:
                case JSValueType.Undefined:
                {
                    resultContainer._dValue    = double.NaN;
                    resultContainer._valueType = JSValueType.Double;
                    return;
                }
                }
                break;
            }

            case JSValueType.String:
            {
                object tstr = first._oValue;
                switch (second._valueType)
                {
                case JSValueType.String:
                {
                    tstr = new RopeString(tstr, second._oValue);
                    break;
                }

                case JSValueType.Boolean:
                {
                    tstr = new RopeString(tstr, second._iValue != 0 ? "true" : "false");
                    break;
                }

                case JSValueType.Integer:
                {
                    tstr = new RopeString(tstr, second._iValue.ToString(CultureInfo.InvariantCulture));
                    break;
                }

                case JSValueType.Double:
                {
                    tstr = new RopeString(tstr, Tools.DoubleToString(second._dValue));
                    break;
                }

                case JSValueType.Undefined:
                case JSValueType.NotExistsInObject:
                case JSValueType.NotExists:
                {
                    tstr = new RopeString(tstr, "undefined");
                    break;
                }

                case JSValueType.Object:
                case JSValueType.Function:
                {
                    tstr = new RopeString(tstr, second.ToPrimitiveValue_Value_String().BaseToString());
                    break;
                }

                case JSValueType.Date:
                {
                    tstr = new RopeString(tstr, second.ToPrimitiveValue_String_Value().BaseToString());
                    break;
                }
                }

                resultContainer._oValue    = tstr;
                resultContainer._valueType = JSValueType.String;
                return;
            }

            case JSValueType.Date:
            {
                first = first.ToPrimitiveValue_String_Value();
                Impl(resultContainer, first, second);
                return;
            }

            case JSValueType.NotExistsInObject:
            case JSValueType.NotExists:
            case JSValueType.Undefined:
            {
                if (second._valueType >= JSValueType.Object)
                {
                    second = second.ToPrimitiveValue_Value_String();
                }
                switch (second._valueType)
                {
                case JSValueType.String:
                {
                    resultContainer._valueType = JSValueType.String;
                    resultContainer._oValue    = new RopeString("undefined", second._oValue);
                    return;
                }

                case JSValueType.Double:
                case JSValueType.Boolean:
                case JSValueType.Integer:
                {
                    resultContainer._valueType = JSValueType.Double;
                    resultContainer._dValue    = double.NaN;
                    return;
                }

                case JSValueType.Object:             // undefined+null
                case JSValueType.NotExistsInObject:
                case JSValueType.NotExists:
                case JSValueType.Undefined:
                {
                    resultContainer._valueType = JSValueType.Double;
                    resultContainer._dValue    = double.NaN;
                    return;
                }
                }
                break;
            }

            case JSValueType.Function:
            case JSValueType.Object:
            {
                first = first.ToPrimitiveValue_Value_String();
                if (first._valueType == JSValueType.Integer || first._valueType == JSValueType.Boolean)
                {
                    goto case JSValueType.Integer;
                }
                if (first._valueType == JSValueType.Object)         // null
                {
                    if (second._valueType >= JSValueType.String)
                    {
                        second = second.ToPrimitiveValue_Value_String();
                    }
                    if (second._valueType == JSValueType.String)
                    {
                        resultContainer._oValue    = new RopeString("null", second._oValue);
                        resultContainer._valueType = JSValueType.String;
                        return;
                    }
                    first._iValue = 0;
                    goto case JSValueType.Integer;
                }

                if (first._valueType == JSValueType.Double)
                {
                    goto case JSValueType.Double;
                }
                if (first._valueType == JSValueType.String)
                {
                    goto case JSValueType.String;
                }
                break;
            }
            }
        }
Esempio n. 39
0
 public JSValue _new_commonjs_module(string module_id, JSValue exports_obj, bool loaded)
 {
     return(_new_commonjs_module(module_id, module_id, exports_obj, loaded));
 }
Esempio n. 40
0
 public override void Assign(JSValue value)
 {
     Console.WriteLine("Write value \"" + value + "\" with key \"" + _name + "\"");
 }
Esempio n. 41
0
 internal HtmlInputElement(JSValue underlyingJSValue) : base(underlyingJSValue)
 {
 }
Esempio n. 42
0
 public static bool js_rebind_this(JSContext ctx, JSValue this_obj, ref Vector2 o)
 {
     return(JSApi.jsb_set_float_2(this_obj, o.x, o.y) == 1);
 }
        public IJSCSGlue GetCachedOrCreateBasic(JSValue globalkey,Type iTargetType)
        {
            IJSCSGlue res = null;
            JSObject obj = globalkey;

            //Use local cache for objet not created in javascript session such as enum
            if ((obj != null) &&  ((res = GetCached(globalkey) ?? GetCachedLocal(globalkey)) != null) )
                    return res;

            object targetvalue = _JavascriptToCSharpMapper.GetSimpleValue(globalkey, iTargetType);
            if ((targetvalue == null) && (!globalkey.IsNull) && (!globalkey.IsUndefined))
                throw ExceptionHelper.Get(string.Format("Unable to convert javascript object: {0}", globalkey));

            return new JSBasicObject(globalkey, targetvalue);
        }
Esempio n. 44
0
 public void FreeValue(JSValue value)
 {
     _runtime.FreeValue(value);
 }
Esempio n. 45
0
 private static void addItemData(JSValue item)
 {
 }
Esempio n. 46
0
 private JSObject UnsafeCreateJSO()
 {
     JSObject res =new JSObject();
     res["_MappedId"] = new JSValue(_MapCount++);
     return res;
 }
Esempio n. 47
0
 public void ProtectUnprotect()
 {
     var a = new JSValue (context, 5);
     a.Protect ();
     a.Unprotect ();
 }
Esempio n. 48
0
 private unsafe static JSValue Hello2(JSContext ctx, JSValue thisArg, int argc, JSValue[] argv)
 {
     return(Hello(ctx, thisArg, argc, argv, 0, null));
 }
Esempio n. 49
0
 private JSValue UpdateObject(JSObject ires)
 {
     ires["_MappedId"] = new JSValue(_MapCount++);
     return(ires);
 }
Esempio n. 50
0
        public unsafe object EvalMain(byte[] source, string fileName, Type expectedReturnType)
        {
            var tagValue = ScriptRuntime.TryReadByteCodeTagValue(source);

            if (tagValue == ScriptRuntime.BYTECODE_ES6_MODULE_TAG)
            {
                throw new Exception("es6 module bytecode as main is unsupported");
            }

            object csValue        = null;
            var    dirname        = PathUtils.GetDirectoryName(fileName);
            var    filename_bytes = TextUtils.GetNullTerminatedBytes(fileName);
            var    filename_atom  = GetAtom(fileName);
            var    dirname_atom   = GetAtom(dirname);

            var exports_obj  = JSApi.JS_NewObject(_ctx);
            var require_obj  = JSApi.JS_DupValue(_ctx, _require);
            var module_obj   = _new_commonjs_module(".", exports_obj, false);
            var filename_obj = JSApi.JS_AtomToString(_ctx, filename_atom);
            var dirname_obj  = JSApi.JS_AtomToString(_ctx, dirname_atom);
            var require_argv = new JSValue[5] {
                exports_obj, require_obj, module_obj, filename_obj, dirname_obj
            };

            JSApi.JS_SetProperty(_ctx, require_obj, GetAtom("moduleId"), JSApi.JS_DupValue(_ctx, filename_obj));
            JSApi.JS_SetProperty(_ctx, require_obj, GetAtom("main"), JSApi.JS_DupValue(_ctx, module_obj));

            if (tagValue == ScriptRuntime.BYTECODE_COMMONJS_MODULE_TAG)
            {
                // bytecode
                fixed(byte *intput_ptr = source)
                {
                    var bytecodeFunc = JSApi.JS_ReadObject(_ctx, intput_ptr + sizeof(uint), source.Length - sizeof(uint), JSApi.JS_READ_OBJ_BYTECODE);

                    if (bytecodeFunc.tag == JSApi.JS_TAG_FUNCTION_BYTECODE)
                    {
                        var func_val = JSApi.JS_EvalFunction(_ctx, bytecodeFunc); // it's CallFree (bytecodeFunc)
                        if (JSApi.JS_IsFunction(_ctx, func_val) != 1)
                        {
                            JSApi.JS_FreeValue(_ctx, func_val);
                            FreeValues(require_argv);
                            throw new Exception("failed to eval bytecode module");
                        }

                        var rval = JSApi.JS_Call(_ctx, func_val, JSApi.JS_UNDEFINED);
                        JSApi.JS_FreeValue(_ctx, func_val);
                        if (rval.IsException())
                        {
                            _ctx.print_exception();
                            JSApi.JS_FreeValue(_ctx, rval);
                            FreeValues(require_argv);
                            throw new Exception("failed to eval bytecode module");
                        }

                        // success
                        Values.js_get_var(_ctx, rval, expectedReturnType, out csValue);
                        JSApi.JS_FreeValue(_ctx, rval);
                        JSApi.JS_SetProperty(_ctx, module_obj, GetAtom("loaded"), JSApi.JS_NewBool(_ctx, true));
                        FreeValues(require_argv);
                        return(csValue);
                    }

                    JSApi.JS_FreeValue(_ctx, bytecodeFunc);
                    FreeValues(require_argv);
                    throw new Exception("failed to eval bytecode module");
                }
            }
            else
            {
                // source
                var input_bytes = TextUtils.GetShebangNullTerminatedCommonJSBytes(source);
                fixed(byte *input_ptr = input_bytes)
                fixed(byte *resolved_id_ptr = filename_bytes)
                {
                    var input_len = (size_t)(input_bytes.Length - 1);
                    var func_val  = JSApi.JS_Eval(_ctx, input_ptr, input_len, resolved_id_ptr, JSEvalFlags.JS_EVAL_TYPE_GLOBAL | JSEvalFlags.JS_EVAL_FLAG_STRICT);

                    if (func_val.IsException())
                    {
                        FreeValues(require_argv);
                        _ctx.print_exception();
                        throw new Exception("failed to eval module");
                    }

                    if (JSApi.JS_IsFunction(_ctx, func_val) == 1)
                    {
                        var rval = JSApi.JS_Call(_ctx, func_val, JSApi.JS_UNDEFINED, require_argv.Length, require_argv);
                        if (rval.IsException())
                        {
                            JSApi.JS_FreeValue(_ctx, func_val);
                            FreeValues(require_argv);
                            _ctx.print_exception();
                            throw new Exception("failed to eval module");
                        }
                        Values.js_get_var(_ctx, rval, expectedReturnType, out csValue);
                        JSApi.JS_FreeValue(_ctx, rval);
                    }

                    JSApi.JS_FreeValue(_ctx, func_val);
                    JSApi.JS_SetProperty(_ctx, module_obj, GetAtom("loaded"), JSApi.JS_NewBool(_ctx, true));
                    FreeValues(require_argv);
                    return(csValue);
                }
            }
        }
Esempio n. 51
0
File: Program.cs Progetto: hiiru/lab
        private static List<CarListItem> parseList(JSValue innerHtml)
        {
            if (innerHtml == null) return null;
            string html = innerHtml.ToString();
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(html);
            List<CarListItem> retVal = new List<CarListItem>();
            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//li[@class='car']"))
            {
                var item = new CarListItem();
                item.Id = node.SelectSingleNode(".//input[@type='checkbox']").GetAttributeValue("value", 0);
                item.UrlImage = node.SelectSingleNode(".//img").GetAttributeValue("src", "");
                item.Title = node.SelectSingleNode(".//h3[@class='car-title show-both']/a").GetAttributeValue("title", "");
                item.Abstract = node.SelectSingleNode(".//p[@class='description']").InnerText;

                item.BuildYear = node.SelectSingleNode(".//li[@class='prop prop-date']").InnerText;
                item.Milage = node.SelectSingleNode(".//li[@class='prop prop-milage']").InnerText;
                item.Price = node.SelectSingleNode(".//li[@class='prop prop-price']").InnerText;
                retVal.Add(item);
            }
            return retVal;
        }
 public abstract bool ReloadModule(ScriptContext context, string resolved_id, JSValue module_obj, out JSValue exports_obj);
Esempio n. 53
0
        public async void GetLoginTokenAsync(JSValue parameters, IReactPromise <string> promise)
        {
            string result = await MsalAuthentication.CallLoginAPI(parameters);

            promise.Resolve(result);
        }
Esempio n. 54
0
 public override void Assign(JSValue value)
 {
     owner[index] = value;
 }
Esempio n. 55
0
 private JSValue UpdateObject(JSObject ires)
 {
     ires["_MappedId"] = new JSValue(_MapCount++);
     return ires;
 }
Esempio n. 56
0
        protected internal sealed override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope)
        {
            if (memberScope < PropertyScope.Super && key._valueType != JSValueType.Symbol)
            {
                if (key._valueType == JSValueType.String && "length".Equals(key._oValue))
                {
                    return(length);
                }
                bool    isIndex = false;
                int     index   = 0;
                JSValue tname   = key;
                if (tname._valueType >= JSValueType.Object)
                {
                    tname = tname.ToPrimitiveValue_String_Value();
                }
                switch (tname._valueType)
                {
                case JSValueType.Object:
                case JSValueType.Boolean:
                    break;

                case JSValueType.Integer:
                {
                    isIndex = tname._iValue >= 0;
                    index   = tname._iValue;
                    break;
                }

                case JSValueType.Double:
                {
                    isIndex = tname._dValue >= 0 && tname._dValue < uint.MaxValue && (long)tname._dValue == tname._dValue;
                    if (isIndex)
                    {
                        index = (int)(uint)tname._dValue;
                    }
                    break;
                }

                case JSValueType.String:
                {
                    var fc = tname._oValue.ToString()[0];
                    if ('0' <= fc && '9' >= fc)
                    {
                        var dindex = 0.0;
                        int si     = 0;
                        if (Tools.ParseNumber(tname._oValue.ToString(), ref si, out dindex) &&
                            (si == tname._oValue.ToString().Length) &&
                            dindex >= 0 &&
                            dindex < uint.MaxValue &&
                            (long)dindex == dindex)
                        {
                            isIndex = true;
                            index   = (int)(uint)dindex;
                        }
                    }
                    break;
                }
                }
                if (isIndex)
                {
                    if (index < 0)
                    {
                        ExceptionHelper.Throw(new RangeError("Invalid array index"));
                    }
                    if (index >= length._iValue)
                    {
                        return(undefined);
                    }
                    return(this[index]);
                }
            }
            return(base.GetProperty(key, forWrite, memberScope));
        }
Esempio n. 57
0
 public override bool StrictEqualsTo(JSValue value)
 {
     return(value.Type == JSValueType.Null);
 }
Esempio n. 58
0
        protected internal override void SetProperty(JSValue name, JSValue value, PropertyScope memberScope, bool strict)
        {
            if (name._valueType == JSValueType.String && "length".Equals(name._oValue))
            {
                return;
            }
            bool    isIndex = false;
            int     index   = 0;
            JSValue tname   = name;

            if (tname._valueType >= JSValueType.Object)
            {
                tname = tname.ToPrimitiveValue_String_Value();
            }
            switch (tname._valueType)
            {
            case JSValueType.Object:
            case JSValueType.Boolean:
                break;

            case JSValueType.Integer:
            {
                isIndex = tname._iValue >= 0;
                index   = tname._iValue;
                break;
            }

            case JSValueType.Double:
            {
                isIndex = tname._dValue >= 0 && tname._dValue < uint.MaxValue && (long)tname._dValue == tname._dValue;
                if (isIndex)
                {
                    index = (int)(uint)tname._dValue;
                }
                break;
            }

            case JSValueType.String:
            {
                var fc = tname._oValue.ToString()[0];
                if ('0' <= fc && '9' >= fc)
                {
                    var dindex = 0.0;
                    int si     = 0;
                    if (Tools.ParseNumber(tname._oValue.ToString(), ref si, out dindex) &&
                        (si == tname._oValue.ToString().Length) &&
                        dindex >= 0 &&
                        dindex < uint.MaxValue &&
                        (long)dindex == dindex)
                    {
                        isIndex = true;
                        index   = (int)(uint)dindex;
                    }
                }
                break;
            }
            }
            if (isIndex)
            {
                if (index < 0)
                {
                    ExceptionHelper.Throw(new RangeError("Invalid array index"));
                }
                if (index >= length._iValue)
                {
                    return;
                }
                this[index] = value;
                return;
            }
            base.SetProperty(name, value, strict);
        }
Esempio n. 59
0
File: API.cs Progetto: burnbaby/Dwar
 private static void addItems(JSValue itemData, MySqlCommand command)
 {
     if (!itemData.IsUndefined)
     {
         JSValue[] records = (JSValue[])itemData;
         foreach (JSValue[] record in records)
         {
             command.CommandText = "REPLACE INTO items (itemID, itemName, itemCategory, itemStrength, itemTime, itemCount, itemBid, itemBuyOut) VALUES(@itemID, @itemName, @itemCategory, @itemStrength, @itemTime, @itemCount, @itemBid, @itemBuyOut)";
             command.Parameters.AddWithValue("@itemID", (string)record[0]);
             command.Parameters.AddWithValue("@itemName", (string)record[1]);
             command.Parameters.AddWithValue("@itemCategory", (string)record[2]);
             command.Parameters.AddWithValue("@itemStrength", (string)record[3]);
             command.Parameters.AddWithValue("@itemTime", (string)record[4]);
             command.Parameters.AddWithValue("@itemCount", (string)record[5]);
             command.Parameters.AddWithValue("@itemBid", (string)record[6]);
             command.Parameters.AddWithValue("@itemBuyOut", (string)record[7]);
             command.ExecuteNonQuery();
             command.Parameters.Clear();
         }
     }
 }
Esempio n. 60
0
 public override bool ConvEqualsTo(JSValue value)
 {
     return(value.Type == JSValueType.Undefined || value.Type == JSValueType.Null);
 }