コード例 #1
0
 public static NSJSInt16Array New(NSJSVirtualMachine machine, short[] buffer, int ofs, int count)
 {
     fixed(short *p = &buffer[ofs])
     {
         return(New(machine, p, count));
     }
 }
コード例 #2
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);
        }
コード例 #3
0
        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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: NSJSString.cs プロジェクト: liulilittle/nsjs
        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));
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
ファイル: NSJSJson.cs プロジェクト: liulilittle/nsjs
        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));
        }
コード例 #10
0
 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);
     }
 }
コード例 #11
0
ファイル: NSJSUInt32Array.cs プロジェクト: liulilittle/nsjs
        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));
        }
コード例 #12
0
 internal NSJSFunction(IntPtr handle, NSJSObject owner, NSJSVirtualMachine machine) : base(handle, NSJSDataType.kFunction, machine)
 {
     if (owner == null)
     {
         owner = machine.Global;
     }
     this.This = owner;
 }
コード例 #13
0
ファイル: NSJSUInt32Array.cs プロジェクト: liulilittle/nsjs
 public static NSJSUInt32Array New(NSJSVirtualMachine machine, uint[] buffer)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     return(New(machine, buffer, 0, buffer.Length));
 }
コード例 #14
0
 public static NSJSValue UndefinedMerge(NSJSVirtualMachine machine, NSJSValue value)
 {
     if (value == null)
     {
         return(NSJSValue.Undefined(machine));
     }
     return(value);
 }
コード例 #15
0
 public static NSJSValue NullMerge(NSJSVirtualMachine machine, NSJSValue value)
 {
     if (value == null)
     {
         return(NSJSValue.Null(machine));
     }
     return(value);
 }
コード例 #16
0
        public static void ReleaseAll(NSJSVirtualMachine machine)
        {
            ConcurrentDictionary <int, object> dd;

            if (kvtables.TryRemove(machine, out dd))
            {
                dd.Clear();;
            }
        }
コード例 #17
0
        public static NSJSFunction New(NSJSVirtualMachine machine, NSJSFunctionCallback2 value)
        {
            IntPtr address = NULL;

            if (value != null)
            {
                address = NSJSFunction.DelegateToFunctionPtr(value);
            }
            return(InternalNew(machine, address));
        }
コード例 #18
0
        public static void Throw(NSJSException exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            NSJSVirtualMachine machine = exception.VirtualMachine;

            Throw(machine, exception.exception_message, NSJSErrorKind.kError);
        }
コード例 #19
0
ファイル: NSJSUInt32Array.cs プロジェクト: liulilittle/nsjs
        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));
            }
        }
コード例 #20
0
 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));
 }
コード例 #21
0
        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));
            }
        }
コード例 #22
0
 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));
 }
コード例 #23
0
ファイル: NSJSFloat64Array.cs プロジェクト: liulilittle/nsjs
        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));
            }
        }
コード例 #24
0
 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));
 }
コード例 #25
0
        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));
        }
コード例 #26
0
        protected internal void Raise()
        {
            NSJSVirtualMachine machine = this.VirtualMachine;

            machine.Abort();
            if (machine.AutomaticallyPrintException)
            {
                this.PrintStackTrace();
            }
            if (!machine.HasUnhandledExceptionHandler())
            {
                throw this;
            }
        }
コード例 #27
0
        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());
        }
コード例 #28
0
        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);
        }
コード例 #29
0
 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);
 }
コード例 #30
0
 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;
     }));
 }