示例#1
0
        public virtual NSJSValue Call(IEnumerable <NSJSValue> args, out NSJSException exception)
        {
            NSJSObject owner = this.m_This;

            if (owner == null)
            {
                throw new InvalidOperationException("this");
            }
            NSJSException exception_info = null;
            NSJSValue     result         = this.Call(args, (argc) =>
            {
                NSJSVirtualMachine machine = this.VirtualMachine;
                fixed(IntPtr * argv        = argc.ToArray())
                {
                    IntPtr handle = nsjs_localvalue_object_property_call(machine.Isolate,
                                                                         owner.Handle,
                                                                         this.Handle,
                                                                         argc.Count, argv,
                                                                         ref *machine.exception);
                    exception_info = NSJSException.From(machine, machine.exception);
                    if (handle == NULL)
                    {
                        return(null);
                    }
                    return(NSJSValueBuilder.From(handle, this.VirtualMachine));
                }
            });

            exception = exception_info;
            return(result);
        }
示例#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));
        }
示例#3
0
 public virtual NSJSValue[] GetParameters()
 {
     lock (this)
     {
         if (this.m_Parameters == null)
         {
             int count = nsjs_argument_get_length(this.Handle);
             if (count < 0)
             {
                 count = 0;
             }
             this.m_Parameters = new NSJSValue[count];
             NSJSVirtualMachine machine = this.VirtualMachine;
             for (int i = 0; i < count; i++)
             {
                 IntPtr localValue = nsjs_argument_get_solt(this.Handle, i);
                 if (localValue == NULL)
                 {
                     continue;
                 }
                 this.m_Parameters[i] = NSJSValueBuilder.From(localValue, machine);
             }
         }
         return(this.m_Parameters);
     }
 }
示例#4
0
        public virtual NSJSValue Get(string key)
        {
            IntPtr p = this.GetPropertyAndReturnHandle(key);

            if (p == null)
            {
                return(null);
            }
            return(NSJSValueBuilder.From(p, this, this.VirtualMachine));
        }
示例#5
0
        public NSJSValue GetReturnValue()
        {
            if (this.Handle == NULL)
            {
                throw new ArgumentNullException("this");
            }
            IntPtr handle = nsjs_argument_returnvalue_get(this.Handle);

            if (handle == NULL)
            {
                throw new InvalidOperationException();
            }
            return(NSJSValueBuilder.From(handle, this.VirtualMachine));
        }
示例#6
0
        protected virtual NSJSValue GetInternalField(int solt)
        {
            if (solt < 0 || solt >= GetInternalFieldCount())
            {
                throw new ArgumentOutOfRangeException("The solt location of the access exceeds the specified range");
            }
            IntPtr handle = nsjs_localvalue_object_internalfield_get(this.Handle, solt);

            if (handle == NULL)
            {
                throw new InvalidOperationException();
            }
            return(NSJSValueBuilder.From(this.Handle, this, this.VirtualMachine));
        }
示例#7
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);
        }
示例#8
0
 public virtual NSJSValue this[int index]
 {
     get
     {
         IntPtr handle = nsjs_localvalue_array_indexget(this.Handle, (uint)index);
         if (handle == null)
         {
             throw new ArgumentOutOfRangeException("index");
         }
         return(NSJSValueBuilder.From(handle, this.VirtualMachine));
     }
     set
     {
         if (value == null)
         {
             value = NSJSValue.Null(this.VirtualMachine);
         }
         if (value.Handle == NULL)
         {
             throw new ArgumentException("value");
         }
         nsjs_localvalue_array_indexset(this.Handle, (uint)index, value.Handle);
     }
 }