示例#1
0
 public virtual bool Set(string key, short *value, int count)
 {
     if (value == null)
     {
         return(this.Set(key, NSJSValue.Null(this.VirtualMachine)));
     }
     return(this.Set(key, (name) =>
     {
         if (value == null && count != 0)
         {
             throw new ArgumentOutOfRangeException("Parameter count is greater than 0 o'clock, buffer not null is not allowed");
         }
         return nsjs_localvalue_object_property_set_int16array(this.Isolate, this.Handle, name, value, (uint)count);
     }));
 }
示例#2
0
 public virtual bool Set(string key, double[] value)
 {
     if (value == null)
     {
         return(this.Set(key, NSJSValue.Null(this.VirtualMachine)));
     }
     return(this.Set(key, (name) =>
     {
         if (value == null || value.Length <= 0)
         {
             return nsjs_localvalue_object_property_set_float64array(this.Isolate, this.Handle, name, null, 0);
         }
         fixed(double *p = value)
         {
             return nsjs_localvalue_object_property_set_float64array(this.Isolate, this.Handle, name, p, (uint)value.Length);
         }
     }));
 }
示例#3
0
        public static NSJSValue NewValue(NSJSVirtualMachine machine, string value)
        {
            if (machine == null)
            {
                throw new ArgumentNullException("machine");
            }
            IntPtr isolate = machine.Isolate;

            if (isolate == NULL)
            {
                throw new InvalidOperationException("machine");
            }
            if (value == null)
            {
                return(NSJSValue.Null(machine));
            }
            return(New(machine, value));
        }
示例#4
0
        public static string Stringify(NSJSValue value)
        {
            if (value == null)
            {
                return(null);
            }
            int    len   = 0;
            IntPtr chunk = nsjs_localvalue_json_stringify(value.Isolate, value.Handle, ref len);

            if (chunk == NULL)
            {
                return(null);
            }
            string result = chunk != NULL ? new string((sbyte *)chunk.ToPointer()) : null;

            NSJSMemoryManagement.Free(chunk);
            return(result);
        }
示例#5
0
 public virtual bool Set(string key, string value)
 {
     if (value == null)
     {
         return(this.Set(key, NSJSValue.Null(this.VirtualMachine)));
     }
     return(this.Set(key, (name) =>
     {
         if (value == null)
         {
             return nsjs_localvalue_object_property_set_string(this.Isolate, this.Handle, name, null, 0);
         }
         int count;
         byte[] cch = NSJSString.GetUTF8StringBuffer(value, out count);
         fixed(byte *s = cch)
         {
             return nsjs_localvalue_object_property_set_string(this.Isolate, this.Handle, name, s, count);
         }
     }));
 }
示例#6
0
        protected internal static NSJSValue ConvertValue(NSJSVirtualMachine machine, object obj)
        {
            if (machine == null)
            {
                return(default(NSJSValue));
            }
            if (obj == null || obj == DBNull.Value)
            {
                return(NSJSValue.Null(machine));
            }
            if (obj is NSJSValue)
            {
                return(unchecked ((NSJSValue)obj));
            }
            NSJSValue value = ValueAuxiliary.As(obj, machine);

            if (value != null && !value.IsNullOrUndfined)
            {
                return(value);
            }
            return(SimpleAgent.ToObject(machine, obj));
        }
示例#7
0
        private TResult Call <TResult>(IEnumerable <NSJSValue> args, Func <List <IntPtr>, TResult> d)
        {
            if (d == null)
            {
                throw new ArgumentNullException("d");
            }
            List <IntPtr> argc = new List <IntPtr>(256);

            if (args != null)
            {
                foreach (NSJSValue value in args)
                {
                    NSJSValue i = value;
                    if (i == null)
                    {
                        i = NSJSValue.Null(this.VirtualMachine);
                    }
                    argc.Add(i.Handle);
                }
            }
            return(d(argc));
        }
示例#8
0
        public virtual object GetValue(Type type, string key)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (key.Length <= 0)
            {
                throw new ArgumentException("key");
            }
            NSJSObject owner = this.Value as NSJSObject;
            NSJSValue  value = null;

            if (owner != null)
            {
                value = owner.Get(key);
            }
            return(this.GetValue(type, value));
        }
示例#9
0
        public virtual NSJSValue Callvir(string name, IEnumerable <NSJSValue> args, out NSJSException exception)
        {
            NSJSException exception_info = null;
            NSJSValue     result         = this.InternalCall(name, args, (List <IntPtr> argc) =>
            {
                fixed(byte *key = NSJSString.GetUTF8StringBuffer(name))
                {
                    fixed(IntPtr * argv = argc.ToArray())
                    {
                        IntPtr handle  = nsjs_virtualmachine_callvir(this.Handle, key, argc.Count, argv, ref *this.exception);
                        exception_info = NSJSException.From(this, this.exception);
                        if (handle == NULL)
                        {
                            return(null);
                        }
                        return(NSJSValueBuilder.From(handle, this));
                    }
                }
            });

            exception = exception_info;
            return(result);
        }
示例#10
0
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            NSJSValue y = obj as NSJSValue;
            NSJSValue x = this;

            if (x == null && y != null)
            {
                return(false);
            }
            if (x != null && y == null)
            {
                return(false);
            }
            if (x.IsNullOrUndfined && y.IsNullOrUndfined)
            {
                return(true);
            }
            return(nsjs_localvalue_equals(x.Handle, y.Handle));
        }
示例#11
0
 protected virtual T Executing <T>(Func <T> d)
 {
     if (d == null)
     {
         throw new ArgumentNullException("d");
     }
     lock (this)
     {
         if (!this.initialize)
         {
             this.initialize = true;
             this.InitializationLibrary();
             nsjs_virtualmachine_initialize(this.Handle);
             nsjs_virtualmachine_set_data(this.Handle, 0, (IntPtr)this.cookie);
             this.undefined = new NSJSValue(nsjs_localvalue_null(this.Isolate), NSJSDataType.kUndefined, this);
             this.nullable  = new NSJSValue(nsjs_localvalue_null(this.Isolate), NSJSDataType.kNull, this);
             this.nullable.CrossThreading  = true;
             this.undefined.CrossThreading = true;
             this.InitializationFramework();
         }
     }
     return(d());
 }
示例#12
0
        public virtual NSJSValue Call(IEnumerable <string> args, out NSJSException exception)
        {
            IList <NSJSValue>  argv    = new List <NSJSValue>();
            NSJSVirtualMachine machine = this.VirtualMachine;

            foreach (string s in args)
            {
                NSJSValue value = null;
                if (s == null)
                {
                    value = NSJSValue.Null(machine);
                }
                else
                {
                    value = NSJSString.New(machine, s);
                }
                if (value == null)
                {
                    continue;
                }
                argv.Add(value);
            }
            return(this.Call(argv, out exception));
        }
示例#13
0
 protected virtual object Convert(Type type, NSJSValue value)
 {
     return(ConvertValue(type, value));
 }
示例#14
0
 public static NSJSFunction Cast(NSJSValue value, NSJSObject owner)
 {
     return(Cast(value, (handle, machine) => new NSJSFunction(value.Handle, owner, value.VirtualMachine)));
 }
示例#15
0
 public static NSJSFunction Cast(NSJSValue value)
 {
     return(Cast(value, default(NSJSObject)));
 }
示例#16
0
 public static NSJSDateTime Cast(NSJSValue value)
 {
     return Cast(value, (handle, machine) => new NSJSDateTime(value.Handle, value.VirtualMachine));
 }
示例#17
0
 public static NSJSInt64 Cast(NSJSValue value)
 {
     return(Cast(value, (handle, machine) => new NSJSInt64(value.Handle, value.VirtualMachine)));
 }
示例#18
0
 public static new NSJSUInt32Array Cast(NSJSValue value)
 {
     return(Cast(value, (handle, machine) => new NSJSUInt32Array(value.Handle, value.VirtualMachine)));
 }
示例#19
0
 protected virtual object GetValue(Type type, NSJSValue value)
 {
     return(FetchValue(type, value));
 }
示例#20
0
        protected static internal object ConvertValue(Type type, NSJSValue value)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            object o = FetchValue(type, value);

            if (type == typeof(int))
            {
                o = (o == null ? 0 : Converter.ToInt32(o));
            }
            else if (type == typeof(uint))
            {
                o = (o == null ? 0u : Converter.ToUInt32(o));
            }
            else if (type == typeof(short))
            {
                o = (o == null ? (short)0 : Converter.ToInt16(o));
            }
            else if (type == typeof(ushort))
            {
                o = (o == null ? (ushort)0 : Converter.ToUInt16(o));
            }
            else if (type == typeof(sbyte))
            {
                o = (o == null ? (sbyte)0 : Converter.ToSByte(o));
            }
            else if (type == typeof(byte))
            {
                o = (o == null ? (byte)0 : Converter.ToByte(o));
            }
            else if (type == typeof(long))
            {
                o = (o == null ? 0L : Converter.ToInt64(o));
            }
            else if (type == typeof(ulong))
            {
                o = (o == null ? 0ul : Converter.ToUInt64(o));
            }
            else if (type == typeof(float))
            {
                o = (o == null ? 0f : Converter.ToSingle(o));
            }
            else if (type == typeof(double))
            {
                o = (o == null ? 0d : Converter.ToDouble(o));
            }
            else if (type == typeof(decimal))
            {
                o = (o == null ? 0m : Converter.ToDecimal(o));
            }
            else if (type == typeof(char))
            {
                o = (o == null ? '\0' : Converter.ToChar(o));
            }
            else if (type == typeof(DateTime))
            {
                long ticks = 0;
                if (o is long)
                {
                    ticks = (long)o;
                }
                else if (o != null)
                {
                    ticks = Converter.ToInt64(o);
                }
                o = NSJSDateTime.LocalDateToDateTime(ticks);
            }
            else if (type == typeof(string))
            {
                if (o == null)
                {
                    o = null;
                }
                else if (!(o is string))
                {
                    o = o.ToString();
                }
            }
            else if (typeof(NSJSValue).IsAssignableFrom(type))
            {
                return(type.IsInstanceOfType(value) ? value : null);
            }
            return(o);
        }
示例#21
0
 public static NSJSObject Cast(NSJSValue value)
 {
     return(Cast(value, (handle, machine) => new NSJSObject(handle, machine)));
 }