예제 #1
0
        public static string GetDefaultFormatStackTrace(NSJSException exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            StringBuilder contents = new StringBuilder();

            contents.AppendLine(string.Format("{0} {1}({2}:{3})", exception.Message, exception.ResourceName, exception.LineNumber, exception.StartColumn));
            contents.AppendFormat("    ErrorLevel: {0}\r\n", exception.ErrorLevel);
            contents.AppendFormat("    StartColumn: {0}\r\n", exception.StartColumn);
            contents.AppendFormat("    StartPosition: {0}\r\n", exception.StartPosition);
            contents.AppendFormat("    EndColumn: {0}\r\n", exception.EndColumn);
            contents.AppendFormat("    EndPosition: {0}\r\n", exception.EndPosition);
            contents.AppendFormat("    LineNumber: {0}\r\n", exception.LineNumber);
            contents.AppendFormat("    ResourceColumnOffset: {0}\r\n", exception.ResourceColumnOffset);
            contents.AppendFormat("    ResourceLineOffset: {0}\r\n", exception.ResourceLineOffset);
            contents.AppendFormat("    IsSharedCrossOrigin: {0}\r\n", exception.IsSharedCrossOrigin);
            contents.AppendFormat("    ResourceName: {0}\r\n", exception.ResourceName);
            contents.AppendFormat("    ScriptId: {0}\r\n", exception.ScriptId);
            contents.AppendFormat("    ScriptResourceName: {0}\r\n", exception.ScriptResourceName);
            contents.AppendFormat("    SourceLine: {0}\r\n", exception.SourceLine);
            contents.AppendFormat("    SourceMapUrl: {0}\r\n", exception.SourceMapUrl);
            contents.AppendLine("-----------------------------------------------------");
            contents.AppendFormat("JavaScript StackTrace\r\n{0}\r\n", exception.JavaScriptStackTrace);
            contents.AppendLine("-----------------------------------------------------");
            contents.AppendLine(".NET StackTrace\r\n" + (exception.StackTrace ?? new StackTrace(1).ToString()));
            return(contents.ToString());
        }
예제 #2
0
        public virtual string Eval(string expression, out NSJSException exception)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            if (string.IsNullOrEmpty(expression))
            {
                throw new ArgumentException("expression");
            }
            NSJSException exception_info = null;
            string        result         = null;

            this.Executing(() =>
            {
                byte[] ch     = NSJSString.GetUTF8StringBuffer(expression);
                fixed(byte *s = ch)
                {
                    sbyte *p       = nsjs_virtualmachine_eval(this.Handle, s, ref *this.exception);
                    exception_info = NSJSException.From(this, this.exception);
                    result         = p != null ? new string(p) : null;
                    NSJSMemoryManagement.Free(p);
                    return(result);
                }
            });
            exception = exception_info;
            return(result);
        }
예제 #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
        public virtual string Run(string source, string alias, out NSJSException exception)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            NSJSException exception_info = null;
            string        result         = null;

            try
            {
                lock (this)
                {
                    RunContext context = new RunContext();
                    if (this.runings.TryGetValue(source, out context))
                    {
                        result         = context.result;
                        exception_info = context.exception;
                        return(result);
                    }
                }
                result = this.Executing((() =>
                {
                    byte[] alias_buffer = null;
                    if (alias != null)
                    {
                        alias_buffer = NSJSString.GetUTF8StringBuffer(alias);
                    }
                    byte[] source_buffer = NSJSString.GetUTF8StringBuffer(source);
                    fixed(byte *pstr_source = source_buffer)
                    {
                        fixed(byte *pstr_alias = alias_buffer)
                        {
                            sbyte *pstr_result = nsjs_virtualmachine_run(this.Handle,
                                                                         pstr_source, pstr_alias, ref *this.exception);
                            string result_str = pstr_result != null ? new string(pstr_result) : null;
                            NSJSMemoryManagement.Free(pstr_result);
                            exception_info = NSJSException.From(this, this.exception);
                            return(result_str);
                        }
                    }
                }));
                lock (this)
                {
                    RunContext context = new RunContext()
                    {
                        exception = exception_info,
                        result    = result,
                        alias     = alias,
                        source    = source
                    };
                    this.runings.Add(source, context);
                }
                return(result);
            }
            finally
            {
                exception = exception_info;
            }
        }
예제 #5
0
        public virtual string Run(string expression, out NSJSException exception)
        {
            string result = Run(expression, null, out exception);

            exception?.Raise();
            return(result);
        }
예제 #6
0
 public NSJSUnhandledExceptionEventArgs(NSJSException exception)
 {
     if (exception == null)
     {
         throw new ArgumentNullException("exception");
     }
     this.Exception = exception;
 }
예제 #7
0
 public virtual void Assert(NSJSFunctionCallbackInfo arguments, bool condition, string message, string detailMessage)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     NSJSException.Throw(arguments.VirtualMachine, string.Format("assert failed\r\n{0}\r\n{1}", message, detailMessage));
     Assert(condition, message, detailMessage);
 }
예제 #8
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);
        }
예제 #9
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));
 }
예제 #10
0
 public virtual void Throw(NSJSFunctionCallbackInfo arguments, NSJSValue exception)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     if (exception == null)
     {
         throw new ArgumentNullException("exception");
     }
     NSJSException.Throw(exception);
 }
예제 #11
0
 public virtual string Run(FileInfo path, out NSJSException exception)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     if (!path.Exists)
     {
         throw new FileNotFoundException("path");
     }
     byte[] source = File.ReadAllBytes(path.FullName);
     return(Run(FileAuxiliary.GetEncoding(source).GetString(source), path.FullName, out exception));
 }
예제 #12
0
        public virtual string Call(string name, IEnumerable <NSJSValue> args, out NSJSException exception)
        {
            NSJSException exception_info = null;
            string        result         = null;

            this.InternalCall(name, args, (List <IntPtr> argc) =>
            {
                fixed(byte *key = NSJSString.GetUTF8StringBuffer(name))
                {
                    fixed(IntPtr * argv = argc.ToArray())
                    {
                        sbyte *chunk   = nsjs_virtualmachine_call(this.Handle, key, argc.Count, argv, ref *this.exception);
                        exception_info = NSJSException.From(this, this.exception);
                        result         = chunk != null ? new string(chunk) : null;
                        NSJSMemoryManagement.Free(chunk);
                        return(result);
                    }
                }
            });
            exception = exception_info;
            return(result);
        }
예제 #13
0
        public virtual NSJSValue Callvir(string name, IEnumerable <NSJSValue> args, out NSJSException exception)
        {
            NSJSException exception_info = null;
            NSJSValue     result         = this.InternalCall(name, args, (List <IntPtr> argc) =>
            {
                fixed(byte *key = NSJSString.GetUTF8StringBuffer(name))
                {
                    fixed(IntPtr * argv = argc.ToArray())
                    {
                        IntPtr handle  = nsjs_virtualmachine_callvir(this.Handle, key, argc.Count, argv, ref *this.exception);
                        exception_info = NSJSException.From(this, this.exception);
                        if (handle == NULL)
                        {
                            return(null);
                        }
                        return(NSJSValueBuilder.From(handle, this));
                    }
                }
            });

            exception = exception_info;
            return(result);
        }
예제 #14
0
        public virtual NSJSValue Call(IEnumerable <string> args, out NSJSException exception)
        {
            IList <NSJSValue>  argv    = new List <NSJSValue>();
            NSJSVirtualMachine machine = this.VirtualMachine;

            foreach (string s in args)
            {
                NSJSValue value = null;
                if (s == null)
                {
                    value = NSJSValue.Null(machine);
                }
                else
                {
                    value = NSJSString.New(machine, s);
                }
                if (value == null)
                {
                    continue;
                }
                argv.Add(value);
            }
            return(this.Call(argv, out exception));
        }
예제 #15
0
 public virtual NSJSValue Call(string[] args, out NSJSException exception)
 {
     return(this.Call((IEnumerable <string>)args, out exception));
 }
예제 #16
0
        public virtual string Call(string name, IEnumerable <string> args, out NSJSException exception)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length <= 0)
            {
                throw new ArgumentException("name");
            }
            NSJSException exception_info = null;
            string        result         = null;

            this.Executing <string>(() =>
            {
                IList <GCHandle?> cookies = new List <GCHandle?>(256);
                IList <IntPtr> arguments  = new List <IntPtr>(256);
                cookies.Add(GCHandle.Alloc(NSJSString.GetUTF8StringBuffer(name), GCHandleType.Pinned));
                int argc = 0;
                if (args != null)
                {
                    foreach (string s in args)
                    {
                        byte[] ch = null;
                        if (s != null)
                        {
                            ch = NSJSString.GetUTF8StringBuffer(s);
                        }
                        if (s == null || ch.Length <= 0)
                        {
                            cookies.Add(null);
                            arguments.Add(NULL);
                        }
                        else
                        {
                            GCHandle cookie = GCHandle.Alloc(ch, GCHandleType.Pinned);
                            cookies.Add(cookie);
                            arguments.Add(cookie.AddrOfPinnedObject());
                        }
                        argc++;
                    }
                }
                void **argv = null;
                if (argc > 0)
                {
                    void **ppv = stackalloc void *[argc];
                    for (int i = 0; i < argc; i++)
                    {
                        ppv[i] = arguments[i].ToPointer();
                    }
                    argv = ppv;
                }
                IntPtr chunk   = nsjs_virtualmachine_call2(this.Handle, cookies[0].Value.AddrOfPinnedObject().ToPointer(), argc, argv, ref *this.exception);
                exception_info = NSJSException.From(this, this.exception);
                result         = chunk != NULL ? new string((sbyte *)chunk.ToPointer()) : null;
                foreach (GCHandle?cookie in cookies)
                {
                    if (cookie == null)
                    {
                        continue;
                    }
                    cookie.Value.Free();
                }
                return(result);
            });
            exception = exception_info;
            return(result);
        }
예제 #17
0
 public virtual string Call(string name, NSJSValue[] args, out NSJSException exception)
 {
     return(this.Call(name, (IEnumerable <NSJSValue>)args, out exception));
 }