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); }
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); }
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); }
public static bool InstanceOf(NSJSValue instance, NSJSFunction constructor) { if (instance == null || constructor == null) { return(false); } return(nsjs_localvalue_instanceof(instance, (NSJSValue)constructor)); }
public static IntPtr GetCookie(Delegate d) { if (d == null) { throw new ArgumentNullException("d"); } return(NSJSFunction.DelegateToFunctionPtr(d)); }
public void Add(NSJSFunctionCallback callback) { if (callback == null) { this.Add(NSJSValue.Null(this.VirtualMachine)); return; } this.Add(NSJSFunction.New(this.VirtualMachine, callback)); }
public void SetReturnValue(NSJSFunctionCallback2 callback) { if (callback == null) { this.SetReturnValue(NSJSValue.Null(this.VirtualMachine)); return; } this.SetReturnValue(NSJSFunction.New(This.VirtualMachine, callback)); }
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))); }
public static T Infer <T>() { IntPtr address = NSJSFunction.Infer(); if (address == NULL) { return(default(T)); } return(FunctionPtrToDelegate <T>(address)); }
public static NSJSFunction New(NSJSVirtualMachine machine, NSJSFunctionCallback2 value) { IntPtr address = NULL; if (value != null) { address = NSJSFunction.DelegateToFunctionPtr(value); } return(InternalNew(machine, address)); }
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); }
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); }
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); }
public virtual void Add(NSJSValue value) { if (value == null) { value = NSJSValue.Null(this.VirtualMachine); } NSJSFunction push = (NSJSFunction)base.Get("push"); push.Call(value); }
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); }
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); }
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); }
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); }); }
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"); } }
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); }
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); }
public virtual IEnumerable <string> GetPropertyNames() { NSJSFunction function = this.GetFrameworkFunction(RUNTIME_GETPROPERTYNAMES_PROPERTYKEY); return(ArrayAuxiliary.ToStringList(function.Call(this))); }
public virtual NSJSValue Clear() { NSJSFunction splice = (NSJSFunction)base.Get("splice"); return(splice.Call(NSJSInt32.New(this.VirtualMachine, 0), NSJSInt32.New(this.VirtualMachine, this.Length))); }
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))); }
protected internal virtual NSJSFunction GetFrameworkFunction(string key) { return(NSJSFunction.GetFrameworkFunction(this.VirtualMachine, key)); }
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)))); }