Exemplo n.º 1
0
        private object InvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            NSJSObject global    = this.Value as NSJSObject;
            Exception  exception = null;
            object     result    = default(object);

            do
            {
                if (global == null)
                {
                    exception = new InvalidOperationException("The current call is missing an instance of the object");
                    break;
                }
                else
                {
                    NSJSVirtualMachine machine  = global.VirtualMachine;
                    NSJSFunction       function = global.Get(binder.Name) as NSJSFunction;
                    result = InternalInvokeTarget(function, args, binder.ReturnType, ref exception);
                }
                if (exception != null)
                {
                    throw exception;
                }
            } while (false);
            return(result);
        }
Exemplo n.º 2
0
        private object InternalInvokeTarget(NSJSFunction function, DynamicMetaObject[] args, Type returnType, ref Exception exception)
        {
            object results = null;

            do
            {
                if (function == null)
                {
                    exception = new InvalidOperationException("The called method is not defined correctly");
                    break;
                }
                if (returnType == null)
                {
                    returnType = typeof(object);
                }
                NSJSVirtualMachine machine = GetVirtualMachine(this.Value);
                IList <NSJSValue>  s       = new List <NSJSValue>();
                for (int i = 0; i < args.Length; i++)
                {
                    DynamicMetaObject mo = args[i];
                    s.Add(this.ToValue(machine, mo.Value));
                }
                results = this.Convert(returnType, function.Call(s));
            } while (false);
            return(results);
        }
Exemplo n.º 3
0
        protected static internal NSJSFunction GetFrameworkFunction(NSJSVirtualMachine machine, string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }
            NSJSFunction function = null;

            lock (machine)
            {
                function = machine.GetData <NSJSFunction>(key);
                if (function == null)
                {
                    NSJSObject o = machine.Global;
                    function = o.Get(key) as NSJSFunction;
                    if (function == null)
                    {
                        throw new InvalidProgramException("Framework system internal function appears to be deleted");
                    }
                    function.CrossThreading = true;
                    machine.SetData(key, function);
                }
            }
            return(function);
        }
Exemplo n.º 4
0
 public static bool InstanceOf(NSJSValue instance, NSJSFunction constructor)
 {
     if (instance == null || constructor == null)
     {
         return(false);
     }
     return(nsjs_localvalue_instanceof(instance, (NSJSValue)constructor));
 }
Exemplo n.º 5
0
 public static IntPtr GetCookie(Delegate d)
 {
     if (d == null)
     {
         throw new ArgumentNullException("d");
     }
     return(NSJSFunction.DelegateToFunctionPtr(d));
 }
Exemplo n.º 6
0
 public void Add(NSJSFunctionCallback callback)
 {
     if (callback == null)
     {
         this.Add(NSJSValue.Null(this.VirtualMachine));
         return;
     }
     this.Add(NSJSFunction.New(this.VirtualMachine, callback));
 }
Exemplo n.º 7
0
 public void SetReturnValue(NSJSFunctionCallback2 callback)
 {
     if (callback == null)
     {
         this.SetReturnValue(NSJSValue.Null(this.VirtualMachine));
         return;
     }
     this.SetReturnValue(NSJSFunction.New(This.VirtualMachine, callback));
 }
Exemplo n.º 8
0
        public virtual NSJSValue RemoveAt(int index)
        {
            if (index < 0 || index >= this.Length)
            {
                throw new ArgumentOutOfRangeException("value");
            }
            NSJSFunction splice = (NSJSFunction)base.Get("splice");

            return(splice.Call(NSJSInt32.New(this.VirtualMachine, index)));
        }
Exemplo n.º 9
0
        public static T Infer <T>()
        {
            IntPtr address = NSJSFunction.Infer();

            if (address == NULL)
            {
                return(default(T));
            }
            return(FunctionPtrToDelegate <T>(address));
        }
Exemplo n.º 10
0
        public static NSJSFunction New(NSJSVirtualMachine machine, NSJSFunctionCallback2 value)
        {
            IntPtr address = NULL;

            if (value != null)
            {
                address = NSJSFunction.DelegateToFunctionPtr(value);
            }
            return(InternalNew(machine, address));
        }
Exemplo n.º 11
0
        private void InternalJoin(Delegate callback, object state)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            IntPtr ptr = MarshalAs.ObjectToIUnknown(state);

            nsjs_virtualmachine_join(this.Handle, NSJSFunction.DelegateToFunctionPtr(callback), ptr);
        }
Exemplo n.º 12
0
        public virtual NSJSObject GetPropertyDescriptor(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }
            NSJSFunction function = this.GetFrameworkFunction(RUNTIME_GETPROPERTYDESCRIPTOR_PROPERTYKEY);

            return(function.Call(new NSJSValue[] { this, NSJSString.New(this.VirtualMachine, key) }) as NSJSObject);
        }
Exemplo n.º 13
0
        private static bool nsjs_localvalue_instanceof(NSJSValue instance, NSJSValue type)
        {
            if (instance == null || type == null)
            {
                return(false);
            }
            NSJSFunction __instanceof = instance.GetFrameworkFunction(RUNTIME_INSTANCEOF_PROPERTYKEY);

            return((__instanceof.Call(new NSJSValue[] { instance, type }) as NSJSInt32)?.Value == 1);
        }
Exemplo n.º 14
0
        public virtual void Add(NSJSValue value)
        {
            if (value == null)
            {
                value = NSJSValue.Null(this.VirtualMachine);
            }
            NSJSFunction push = (NSJSFunction)base.Get("push");

            push.Call(value);
        }
Exemplo n.º 15
0
        public virtual bool IsDefined(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(false);
            }
            NSJSFunction function = this.GetFrameworkFunction(RUNTIME_ISDEFINED_PROPERTYKEY);

            return((function.Call(new NSJSValue[] { this, NSJSString.New(this.VirtualMachine, key) }) as NSJSInt32)?.Value == 1);
        }
Exemplo n.º 16
0
        private void InternalJoin(Delegate callback, IntPtr state)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            IntPtr machine  = this.Handle;
            IntPtr function = NSJSFunction.DelegateToFunctionPtr(callback);

            nsjs_virtualmachine_join(machine, function, state);
        }
Exemplo n.º 17
0
        private object Invoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            Exception    exception = null;
            NSJSFunction function  = this.Value as NSJSFunction;
            object       result    = InternalInvokeTarget(function, args, binder.ReturnType, ref exception);

            if (exception != null)
            {
                throw exception;
            }
            return(result);
        }
Exemplo n.º 18
0
 public virtual void DefineProperty(string key, NSJSFunctionCallback get, NSJSFunctionCallback set)
 {
     this.InternalDefineProperty(key, (machine, function) =>
     {
         NSJSValue[] s = new NSJSValue[]
         {
             this,
             NSJSString.New(machine, key),
             get == null ? NSJSValue.Undefined(machine) : NSJSFunction.New(machine, get),
             set == null ? NSJSValue.Undefined(machine) : NSJSFunction.New(machine, set),
         };
         function.Call(s);
     });
 }
Exemplo n.º 19
0
            private ExtensionObjectTemplate(Delegate constructor)
            {
                IntPtr address = NULL;

                if (constructor != null)
                {
                    address = NSJSFunction.DelegateToFunctionPtr(constructor);
                }
                this.Handle = nsjs_virtualmachine_extension_object_template_new(address);
                if (this.Handle == NULL)
                {
                    throw new InvalidOperationException("Unable to create handle");
                }
            }
Exemplo n.º 20
0
        public virtual int IndexOf(NSJSValue value)
        {
            if (value == null)
            {
                return(-1);
            }
            NSJSFunction indexOf = (NSJSFunction)base.Get("indexOf");
            NSJSInt32    result  = indexOf.Call(value) as NSJSInt32;

            if (result == null)
            {
                return(-1);
            }
            return(result.Value);
        }
Exemplo n.º 21
0
        private void InternalDefineProperty(string key, Action <NSJSVirtualMachine, NSJSFunction> executing)
        {
            if (executing == null)
            {
                throw new ArgumentNullException("executing");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key is not allowed to be null");
            }
            if (key.Length <= 0)
            {
                throw new ArgumentNullException("key is not allowed to be empty");
            }
            NSJSFunction function = this.GetFrameworkFunction(RUNTIME_DEFINEPROPERTY_PROPERTYKEY);

            executing(this.VirtualMachine, function);
        }
Exemplo n.º 22
0
        public virtual IEnumerable <string> GetPropertyNames()
        {
            NSJSFunction function = this.GetFrameworkFunction(RUNTIME_GETPROPERTYNAMES_PROPERTYKEY);

            return(ArrayAuxiliary.ToStringList(function.Call(this)));
        }
Exemplo n.º 23
0
        public virtual NSJSValue Clear()
        {
            NSJSFunction splice = (NSJSFunction)base.Get("splice");

            return(splice.Call(NSJSInt32.New(this.VirtualMachine, 0), NSJSInt32.New(this.VirtualMachine, this.Length)));
        }
Exemplo n.º 24
0
 private bool InternalSet(string name, Delegate value, PropertyAttribute attributes)
 {
     return(Handling <bool>(name, (s) => nsjs_virtualmachine_extension_object_template_set_function(this.Handle, s, NSJSFunction.DelegateToFunctionPtr(value), attributes)));
 }
Exemplo n.º 25
0
 protected internal virtual NSJSFunction GetFrameworkFunction(string key)
 {
     return(NSJSFunction.GetFrameworkFunction(this.VirtualMachine, key));
 }
Exemplo n.º 26
0
 private bool InternalSet(string key, Delegate value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     return(this.Set(key, (name) => nsjs_localvalue_object_property_set_function(this.Isolate, this.Handle, name, NSJSFunction.DelegateToFunctionPtr(value))));
 }