public static NSJSInt16Array New(NSJSVirtualMachine machine, short[] buffer, int ofs, int count) { fixed(short *p = &buffer[ofs]) { return(New(machine, p, count)); } }
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 virtual NSJSValue Call(IEnumerable <NSJSValue> args, out NSJSException exception) { NSJSObject owner = this.m_This; if (owner == null) { throw new InvalidOperationException("this"); } NSJSException exception_info = null; NSJSValue result = this.Call(args, (argc) => { NSJSVirtualMachine machine = this.VirtualMachine; fixed(IntPtr * argv = argc.ToArray()) { IntPtr handle = nsjs_localvalue_object_property_call(machine.Isolate, owner.Handle, this.Handle, argc.Count, argv, ref *machine.exception); exception_info = NSJSException.From(machine, machine.exception); if (handle == NULL) { return(null); } return(NSJSValueBuilder.From(handle, this.VirtualMachine)); } }); exception = exception_info; 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); }
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 NSJSString New(NSJSVirtualMachine machine, string value) { if (machine == null) { throw new ArgumentNullException("machine"); } IntPtr isolate = machine.Isolate; if (isolate == NULL) { throw new InvalidOperationException("machine"); } IntPtr handle = NULL; if (value == null) { handle = nsjs_localvalue_string_new(isolate, null, 0); } else { int count; byte[] cch = NSJSString.GetUTF8StringBuffer(value, out count); fixed(byte *p = cch) { handle = nsjs_localvalue_string_new(isolate, p, count); } } if (handle == NULL) { throw new InvalidOperationException("machine"); } return(new NSJSString(handle, machine)); }
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 void Throw(NSJSVirtualMachine machine, string message, NSJSErrorKind kind) { if (machine == null) { throw new ArgumentNullException("machine"); } if (message == null) { throw new ArgumentNullException("message"); } IntPtr isolate = machine.Isolate; if (isolate == NULL) { throw new InvalidOperationException("isolate"); } if (!Enum.IsDefined(typeof(NSJSErrorKind), kind)) { throw new NotSupportedException("kind"); } byte[] cch = NSJSString.GetUTF8StringBuffer(message); if (cch.Length <= 0) { cch = new byte[] { 0 }; } fixed(byte *s = cch) { nsjs_exception_throw_error(isolate, s, kind); } }
public static NSJSValue Parse(NSJSVirtualMachine machine, string json) { if (machine == null) { throw new ArgumentNullException("machine"); } IntPtr isolate = machine.Isolate; if (isolate == NULL) { throw new InvalidOperationException("machine"); } if (string.IsNullOrEmpty(json)) { return(NSJSValue.Null(machine)); } IntPtr handle = NULL; int count; byte[] cch = NSJSString.GetUTF8StringBuffer(json, out count); fixed(byte *p = cch) { handle = nsjs_localvalue_json_parse(isolate, p, count); } if (handle == NULL) { throw new ArgumentOutOfRangeException("json"); } return(NSJSValueBuilder.From(handle, machine)); }
public virtual NSJSValue[] GetParameters() { lock (this) { if (this.m_Parameters == null) { int count = nsjs_argument_get_length(this.Handle); if (count < 0) { count = 0; } this.m_Parameters = new NSJSValue[count]; NSJSVirtualMachine machine = this.VirtualMachine; for (int i = 0; i < count; i++) { IntPtr localValue = nsjs_argument_get_solt(this.Handle, i); if (localValue == NULL) { continue; } this.m_Parameters[i] = NSJSValueBuilder.From(localValue, machine); } } return(this.m_Parameters); } }
public static NSJSUInt32Array New(NSJSVirtualMachine machine, uint *buffer, int count) { if (machine == null) { throw new ArgumentNullException("machine"); } if (buffer == null && count > 0) { throw new ArgumentOutOfRangeException("Parameter count is greater than 0 o'clock, buffer not null is not allowed"); } IntPtr isolate = machine.Isolate; if (isolate == NULL) { throw new InvalidOperationException("machine"); } IntPtr handle = NULL; if (buffer == null) { handle = nsjs_localvalue_uint32array_new(isolate, null, 0); } else { handle = nsjs_localvalue_uint32array_new(isolate, buffer, (uint)count); } if (handle == NULL) { throw new InvalidOperationException("machine"); } return(new NSJSUInt32Array(handle, machine)); }
internal NSJSFunction(IntPtr handle, NSJSObject owner, NSJSVirtualMachine machine) : base(handle, NSJSDataType.kFunction, machine) { if (owner == null) { owner = machine.Global; } this.This = owner; }
public static NSJSUInt32Array New(NSJSVirtualMachine machine, uint[] buffer) { if (buffer == null) { throw new ArgumentNullException("buffer"); } return(New(machine, buffer, 0, buffer.Length)); }
public static NSJSValue UndefinedMerge(NSJSVirtualMachine machine, NSJSValue value) { if (value == null) { return(NSJSValue.Undefined(machine)); } return(value); }
public static NSJSValue NullMerge(NSJSVirtualMachine machine, NSJSValue value) { if (value == null) { return(NSJSValue.Null(machine)); } return(value); }
public static void ReleaseAll(NSJSVirtualMachine machine) { ConcurrentDictionary <int, object> dd; if (kvtables.TryRemove(machine, out dd)) { dd.Clear();; } }
public static NSJSFunction New(NSJSVirtualMachine machine, NSJSFunctionCallback2 value) { IntPtr address = NULL; if (value != null) { address = NSJSFunction.DelegateToFunctionPtr(value); } return(InternalNew(machine, address)); }
public static void Throw(NSJSException exception) { if (exception == null) { throw new ArgumentNullException("exception"); } NSJSVirtualMachine machine = exception.VirtualMachine; Throw(machine, exception.exception_message, NSJSErrorKind.kError); }
public static NSJSUInt32Array New(NSJSVirtualMachine machine, uint[] buffer, int ofs, int count) { if (buffer.Length == ofs) { return(New(machine, (uint *)null, count)); } fixed(uint *p = &buffer[ofs]) { return(New(machine, p, count)); } }
public static void Throw(NSJSVirtualMachine machine, Exception exception) { if (machine == null) { throw new ArgumentNullException("machine"); } if (exception == null) { throw new ArgumentNullException("exception"); } NSJSException.Throw(machine, Throwable.FormatMessage(exception)); }
public static NSJSInt8Array New(NSJSVirtualMachine machine, sbyte[] buffer, int ofs, int count) { if (buffer.Length == ofs) { return(New(machine, (sbyte *)null, count)); } fixed(sbyte *p = &buffer[ofs]) { return(New(machine, p, count)); } }
protected static NSJSObject New(NSJSVirtualMachine machine, int fieldcount) { if (machine == null) { throw new ArgumentNullException("machine"); } if (machine.Isolate == NULL) { throw new InvalidOperationException("machine"); } return(new NSJSObject(machine, fieldcount)); }
public static NSJSFloat64Array New(NSJSVirtualMachine machine, double[] buffer, int ofs, int count) { if (buffer.Length == ofs) { return(New(machine, (double *)null, count)); } fixed(double *p = &buffer[ofs]) { return(New(machine, p, count)); } }
internal static NSJSException From(NSJSVirtualMachine machine, NSJSStructural.NSJSExceptionInfo *exception) { if (exception == null || machine == null) { return(null); } if (!exception->NowIsWrong) { return(null); } exception->NowIsWrong = false; return(new NSJSException(machine, exception)); }
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)); }
protected internal void Raise() { NSJSVirtualMachine machine = this.VirtualMachine; machine.Abort(); if (machine.AutomaticallyPrintException) { this.PrintStackTrace(); } if (!machine.HasUnhandledExceptionHandler()) { throw this; } }
private static NSJSValue NewNullOrUndfined(NSJSVirtualMachine machine, bool undefined) { if (machine == null) { throw new InvalidOperationException("machine"); } IntPtr isolate = machine.Isolate; if (isolate == NULL) { throw new InvalidOperationException("machine"); } return(undefined ? machine.Undefined() : machine.Null()); }
public static bool Close(NSJSVirtualMachine machine) { TimerScheduler scheduler = null; if (machine == null) { return(false); } if (!schedulers.TryRemove(machine, out scheduler)) { return(false); } scheduler.Dispose(); return(true); }
public object MarshalNativeToManaged(IntPtr pNativeData) { if (pNativeData == NULL) { return(null); } if (this.kind == MarshalAsKind.kStateObject) { return(MarshalAs.IUnknownToObject(pNativeData)); } if (this.kind == MarshalAsKind.kVirtualMachine) { return(NSJSVirtualMachine.From(pNativeData)); } return(null); }
private static TimerScheduler GetScheduler(NSJSVirtualMachine machine) { if (machine == null) { throw new ArgumentNullException("machine"); } if (machine.IsDisposed) { throw new ObjectDisposedException("machine"); } return(schedulers.GetOrAdd(machine, (key) => { TimerScheduler scheduler = new TimerScheduler(); machine.Disposed += (sender, e) => Close(machine); return scheduler; })); }