예제 #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
 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
        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
        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
        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
        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))));
 }