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); }
public static bool Set(NSJSObject obj, object value) { if (obj == null) { return(false); } NSJSVirtualMachine machine = obj.VirtualMachine; ConcurrentDictionary <int, object> dd = GetTable(machine); lock (dd) { int key = GetObjectIdentity(obj); if (dd.ContainsKey(key)) { dd[key] = value; } else { key = GetObjectIdentity(dd); dd.TryAdd(key, value); obj.Set(RUNTIME_OBJECTID_PROPERTYKEY, key); } return(true); } }
public static bool Release(NSJSObject obj) { if (obj == null) { return(false); } object value; return(Release(obj, out value)); }
public override IEnumerable <string> GetDynamicMemberNames() { NSJSObject owner = this.Value as NSJSObject; if (owner == null) { return(new string[0]); } return(owner.GetPropertyNames()); }
public static bool Release(NSJSObject obj, out object value) { if (obj == null) { value = null; return(false); } NSJSVirtualMachine machine = obj.VirtualMachine; ConcurrentDictionary <int, object> dd = GetTable(machine); int key = GetObjectIdentity(obj); return(dd.TryRemove(key, out value)); }
public static bool Contains(NSJSObject obj) { if (obj == null) { return(false); } ConcurrentDictionary <int, object> d = GetTable(obj.VirtualMachine); if (d == null) { return(false); } return(d.ContainsKey(GetObjectIdentity(obj))); }
protected static int GetObjectIdentity(NSJSObject obj) { if (obj == null) { return(0); } IntPtr handle = obj.GetPropertyAndReturnHandle(RUNTIME_OBJECTID_PROPERTYKEY); if (handle == null) { return(0); } return(new NSJSInt32(handle, obj.VirtualMachine).Value); }
public static TValue Get <TValue>(NSJSObject obj) { if (obj == null) { return(default(TValue)); } object result = Get(obj); if (result == null || !typeof(TValue).IsInstanceOfType(result)) { return(default(TValue)); } return((TValue)result); }
public virtual bool Extension(string key, NSJSValue value) { if (key == null) { throw new ArgumentNullException("The extension parameter key is not allowed to be null"); } if (key.Length <= 0) { throw new ArgumentNullException("The extension parameter key is not allowed to be empty"); } NSJSObject global = this.Global; return(global.Set(key, value)); }
public static bool Release <TValue>(NSJSObject obj, out TValue value) { if (obj == null) { value = default(TValue); return(false); } object result; bool success = Release(obj, out result); if (!success) { result = default(TValue); } value = (TValue)result; return(success); }
public static object Get(NSJSObject obj) { if (obj == null) { return(null); } NSJSVirtualMachine machine = obj.VirtualMachine; ConcurrentDictionary <int, object> dd = GetTable(machine); int key = GetObjectIdentity(obj); object value; if (dd.TryGetValue(key, out value)) { return(value); } return(default(object)); }
public virtual void SetValue(Type type, string key, object value) { if (type == null) { throw new ArgumentNullException("type"); } if (key == null) { throw new ArgumentNullException("key"); } if (key.Length <= 0) { throw new ArgumentException("key"); } NSJSObject owner = this.Value as NSJSObject; if (owner != null) { NSJSVirtualMachine machine = owner.VirtualMachine; owner.Set(key, this.ToValue(machine, value)); } }
public virtual object GetValue(Type type, string key) { if (type == null) { throw new ArgumentNullException("type"); } if (key == null) { throw new ArgumentNullException("key"); } if (key.Length <= 0) { throw new ArgumentException("key"); } NSJSObject owner = this.Value as NSJSObject; NSJSValue value = null; if (owner != null) { value = owner.Get(key); } return(this.GetValue(type, value)); }
public static NSJSValue From(IntPtr handle, NSJSObject owner, NSJSVirtualMachine machine) { if (machine == null) { return(null); } if (handle == NULL) { return(null); } NSJSDataType datatype = nsjs_localvalue_get_typeid(handle); if (!((datatype & NSJSDataType.kUndefined) > 0 || (datatype & NSJSDataType.kNull) > 0)) { if ((datatype & NSJSDataType.kString) > 0) { return(new NSJSString(handle, machine)); } else if ((datatype & NSJSDataType.kInt32) > 0) { return(new NSJSInt32(handle, machine)); } else if ((datatype & NSJSDataType.kUInt32) > 0) { return(new NSJSUInt32(handle, machine)); } else if ((datatype & NSJSDataType.kBoolean) > 0) { return(new NSJSBoolean(handle, machine)); } else if ((datatype & NSJSDataType.kDouble) > 0) { return(new NSJSDouble(handle, machine)); } else if ((datatype & NSJSDataType.kFunction) > 0) { return(new NSJSFunction(handle, owner, machine)); } else if ((datatype & NSJSDataType.kInt64) > 0) { return(new NSJSInt64(handle, machine)); } else if ((datatype & NSJSDataType.kDateTime) > 0) { return(new NSJSDateTime(handle, machine)); } else if ((datatype & NSJSDataType.kArray) > 0) { return(new NSJSArray(handle, machine)); } else if ((datatype & NSJSDataType.kInt8Array) > 0) { return(new NSJSInt8Array(handle, machine)); } else if ((datatype & NSJSDataType.kUInt8Array) > 0) { return(new NSJSUInt8Array(handle, machine)); } else if ((datatype & NSJSDataType.kInt16Array) > 0) { return(new NSJSInt16Array(handle, machine)); } else if ((datatype & NSJSDataType.kUInt16Array) > 0) { return(new NSJSUInt16Array(handle, machine)); } else if ((datatype & NSJSDataType.kInt32Array) > 0) { return(new NSJSInt32Array(handle, machine)); } else if ((datatype & NSJSDataType.kUInt32Array) > 0) { return(new NSJSUInt32Array(handle, machine)); } else if ((datatype & NSJSDataType.kFloat32Array) > 0) { return(new NSJSFloat32Array(handle, machine)); } else if ((datatype & NSJSDataType.kFloat64Array) > 0) { return(new NSJSFloat64Array(handle, machine)); } else if ((datatype & NSJSDataType.kObject) > 0) { return(new NSJSObject(handle, machine)); } } return(new NSJSValue(handle, datatype, machine)); }