Esempio n. 1
0
        public void print_exception(IScriptLogger logger, LogLevel logLevel, string title)
        {
            var ex = JSApi.JS_GetException(this);

            if (logger != null)
            {
                var err_fileName   = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_fileName);
                var err_lineNumber = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_lineNumber);
                var err_message    = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_message);
                var err_stack      = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_stack);

                var fileName   = err_fileName.IsNullish() ? "native" : GetString(err_fileName);
                var lineNumber = err_lineNumber.IsNullish() ? null : GetString(err_lineNumber);
                var message    = GetString(err_message);
                var stack      = GetString(err_stack);

                if (string.IsNullOrEmpty(lineNumber))
                {
                    if (string.IsNullOrEmpty(stack))
                    {
                        logger.Write(logLevel, "[{0}] {1} {2}",
                                     fileName, title, message);
                    }
                    else
                    {
                        logger.Write(logLevel, "[{0}] {1} {2}\nJavascript stack:\n{3}",
                                     fileName, title, message, stack);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(stack))
                    {
                        logger.Write(logLevel, "[{0}:{1}] {2} {3}",
                                     fileName, lineNumber, title, message);
                    }
                    else
                    {
                        logger.Write(logLevel, "[{0}:{1}] {2} {3}\nJavascript stack:\n{4}",
                                     fileName, lineNumber, title, message, stack);
                    }
                }

                JSApi.JS_FreeValue(this, err_fileName);
                JSApi.JS_FreeValue(this, err_lineNumber);
                JSApi.JS_FreeValue(this, err_message);
                JSApi.JS_FreeValue(this, err_stack);
            }

            JSApi.JS_FreeValue(this, ex);
        }
Esempio n. 2
0
        public bool CheckFuncProperty(ScriptContext context, string name)
        {
            if (context == null)
            {
                return(false);
            }

            var ctx        = (JSContext)context;
            var val_Update = JSApi.JS_GetProperty(ctx, this, context.GetAtom("Update"));
            var res        = JSApi.JS_IsFunction(context, val_Update) == 1;

            JSApi.JS_FreeValue(ctx, val_Update);
            return(res);
        }
Esempio n. 3
0
        // 在外部已确定存在异常
        public string GetExceptionString()
        {
            var ex             = JSApi.JS_GetException(this);
            var err_fileName   = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_fileName);
            var err_lineNumber = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_lineNumber);
            var err_message    = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_message);
            var err_stack      = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_stack);

            var fileName   = this.GetString(err_fileName);
            var lineNumber = this.GetString(err_lineNumber);
            var message    = this.GetString(err_message);
            var stack      = this.GetString(err_stack);

            var exceptionString = string.Format("[JS] {0}:{1} {2}\n{3}", fileName, lineNumber, message, stack);

            JSApi.JS_FreeValue(this, err_fileName);
            JSApi.JS_FreeValue(this, err_lineNumber);
            JSApi.JS_FreeValue(this, err_message);
            JSApi.JS_FreeValue(this, err_stack);
            JSApi.JS_FreeValue(this, ex);

            return(exceptionString);
        }