コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #4
0
 public static bool InstanceOf(NSJSValue instance, NSJSFunction constructor)
 {
     if (instance == null || constructor == null)
     {
         return(false);
     }
     return(nsjs_localvalue_instanceof(instance, (NSJSValue)constructor));
 }
コード例 #5
0
 public static IntPtr GetCookie(Delegate d)
 {
     if (d == null)
     {
         throw new ArgumentNullException("d");
     }
     return(NSJSFunction.DelegateToFunctionPtr(d));
 }
コード例 #6
0
ファイル: NSJSArray.cs プロジェクト: liulilittle/nsjs
 public void Add(NSJSFunctionCallback callback)
 {
     if (callback == null)
     {
         this.Add(NSJSValue.Null(this.VirtualMachine));
         return;
     }
     this.Add(NSJSFunction.New(this.VirtualMachine, callback));
 }
コード例 #7
0
 public void SetReturnValue(NSJSFunctionCallback2 callback)
 {
     if (callback == null)
     {
         this.SetReturnValue(NSJSValue.Null(this.VirtualMachine));
         return;
     }
     this.SetReturnValue(NSJSFunction.New(This.VirtualMachine, callback));
 }
コード例 #8
0
ファイル: NSJSArray.cs プロジェクト: liulilittle/nsjs
        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)));
        }
コード例 #9
0
        public static T Infer <T>()
        {
            IntPtr address = NSJSFunction.Infer();

            if (address == NULL)
            {
                return(default(T));
            }
            return(FunctionPtrToDelegate <T>(address));
        }
コード例 #10
0
        public static NSJSFunction New(NSJSVirtualMachine machine, NSJSFunctionCallback2 value)
        {
            IntPtr address = NULL;

            if (value != null)
            {
                address = NSJSFunction.DelegateToFunctionPtr(value);
            }
            return(InternalNew(machine, address));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #14
0
ファイル: NSJSArray.cs プロジェクト: liulilittle/nsjs
        public virtual void Add(NSJSValue value)
        {
            if (value == null)
            {
                value = NSJSValue.Null(this.VirtualMachine);
            }
            NSJSFunction push = (NSJSFunction)base.Get("push");

            push.Call(value);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
     });
 }
コード例 #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");
                }
            }
コード例 #20
0
ファイル: NSJSArray.cs プロジェクト: liulilittle/nsjs
        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);
        }
コード例 #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);
        }
コード例 #22
0
        public virtual IEnumerable <string> GetPropertyNames()
        {
            NSJSFunction function = this.GetFrameworkFunction(RUNTIME_GETPROPERTYNAMES_PROPERTYKEY);

            return(ArrayAuxiliary.ToStringList(function.Call(this)));
        }
コード例 #23
0
ファイル: NSJSArray.cs プロジェクト: liulilittle/nsjs
        public virtual NSJSValue Clear()
        {
            NSJSFunction splice = (NSJSFunction)base.Get("splice");

            return(splice.Call(NSJSInt32.New(this.VirtualMachine, 0), NSJSInt32.New(this.VirtualMachine, this.Length)));
        }
コード例 #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)));
 }
コード例 #25
0
 protected internal virtual NSJSFunction GetFrameworkFunction(string key)
 {
     return(NSJSFunction.GetFrameworkFunction(this.VirtualMachine, key));
 }
コード例 #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))));
 }