Example #1
0
 public virtual bool Set(string key, double[] buffer, int ofs, int count)
 {
     if (buffer == null)
     {
         return(this.Set(key, NSJSValue.Null(this.VirtualMachine)));
     }
     return(this.Set(key, (name) =>
     {
         if (ofs < 0 || ofs >= buffer.Length)
         {
             throw new ArgumentOutOfRangeException("The value of ofs is less than 0 or greater than or equal to the buffer length");
         }
         if (count > buffer.Length)
         {
             throw new ArgumentOutOfRangeException("The value of count is outside the buffer range");
         }
         if ((ofs + count) > buffer.Length)
         {
             throw new ArgumentOutOfRangeException("ofs and count the value overflow buffer range");
         }
         fixed(double *ch = &buffer[ofs])
         {
             return this.Set(key, ch, count);
         }
     }));
 }
Example #2
0
        public static NSJSValue Parse(NSJSVirtualMachine machine, string json)
        {
            if (machine == null)
            {
                throw new ArgumentNullException("machine");
            }
            IntPtr isolate = machine.Isolate;

            if (isolate == NULL)
            {
                throw new InvalidOperationException("machine");
            }
            if (string.IsNullOrEmpty(json))
            {
                return(NSJSValue.Null(machine));
            }
            IntPtr handle = NULL;
            int    count;

            byte[] cch = NSJSString.GetUTF8StringBuffer(json, out count);
            fixed(byte *p = cch)
            {
                handle = nsjs_localvalue_json_parse(isolate, p, count);
            }

            if (handle == NULL)
            {
                throw new ArgumentOutOfRangeException("json");
            }
            return(NSJSValueBuilder.From(handle, machine));
        }
Example #3
0
        private TResult InternalCall <TResult>(string name, IEnumerable <NSJSValue> args, Func <List <IntPtr>, TResult> d)
        {
            if (d == null)
            {
                throw new ArgumentNullException("d");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length <= 0)
            {
                throw new ArgumentException("name");
            }
            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);
                    }
                    argc.Add(i.Handle);
                }
            }
            return(d(argc));
        }
Example #4
0
 public static NSJSValue NullMerge(NSJSVirtualMachine machine, NSJSValue value)
 {
     if (value == null)
     {
         return(NSJSValue.Null(machine));
     }
     return(value);
 }
Example #5
0
 public virtual bool Set(string key, NSJSValue value)
 {
     if (value == null)
     {
         return(this.Set(key, NSJSValue.Null(this.VirtualMachine)));
     }
     return(this.Set(key, (name) => nsjs_localvalue_object_property_set(this.Isolate, this.Handle, name, value.Handle)));
 }
Example #6
0
 public virtual bool Set(string key, double *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_float64array(this.Isolate, this.Handle, name, value, (uint)count);
     }));
 }
Example #7
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);
         }
     }));
 }
Example #8
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));
        }
Example #9
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);
         }
     }));
 }
Example #10
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));
        }
Example #11
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));
        }
Example #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));
        }