123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using System;
- using System.Reflection;
- using Jint.Native;
- using Jint.Runtime.CallStack;
- using Jint.Runtime.References;
- namespace Jint.Runtime
- {
- internal static class ExceptionHelper
- {
- public static T ThrowSyntaxError<T>(Engine engine, string message = null)
- {
- ThrowSyntaxError(engine, message);
- return default;
- }
- public static void ThrowSyntaxError(Engine engine, string message = null)
- {
- throw new JavaScriptException(engine.SyntaxError, message);
- }
- public static T ThrowArgumentException<T>(string message = null)
- {
- ThrowArgumentException(message);
- return default;
- }
- public static void ThrowArgumentException(string message = null)
- {
- ThrowArgumentException(message, null);
- }
- public static void ThrowArgumentException(string message, string paramName)
- {
- throw new ArgumentException(message, paramName);
- }
- public static void ThrowReferenceError(Engine engine, Reference reference)
- {
- ThrowReferenceError(engine, reference?.GetReferencedName()?.ToString());
- }
- public static void ThrowReferenceError(Engine engine, string name)
- {
- var message = name != null ? name + " is not defined" : null;
- throw new JavaScriptException(engine.ReferenceError, message);
- }
- public static T ThrowTypeErrorNoEngine<T>(string message = null, Exception exception = null)
- {
- throw new TypeErrorException(message);
- }
- public static T ThrowReferenceError<T>(Engine engine, string message = null)
- {
- throw new JavaScriptException(engine.ReferenceError, message);
- }
- public static T ThrowTypeError<T>(Engine engine, string message = null, Exception exception = null)
- {
- ThrowTypeError(engine, message, exception);
- return default;
- }
- public static void ThrowTypeError(Engine engine, string message = null, Exception exception = null)
- {
- throw new JavaScriptException(engine.TypeError, message, exception);
- }
- public static T ThrowRangeError<T>(Engine engine, string message = null)
- {
- throw new JavaScriptException(engine.RangeError, message);
- }
- public static void ThrowRangeError(Engine engine, string message = null)
- {
- throw new JavaScriptException(engine.RangeError, message);
- }
- public static void ThrowUriError(Engine engine)
- {
- throw new JavaScriptException(engine.UriError);
- }
- public static void ThrowNotImplementedException(string message = null)
- {
- throw new NotImplementedException(message);
- }
- public static T ThrowNotImplementedException<T>()
- {
- throw new NotImplementedException();
- }
- public static T ThrowArgumentOutOfRangeException<T>()
- {
- throw new ArgumentOutOfRangeException();
- }
- public static T ThrowArgumentOutOfRangeException<T>(string paramName, string message)
- {
- throw new ArgumentOutOfRangeException(paramName, message);
- }
- public static void ThrowArgumentOutOfRangeException(string paramName, string message)
- {
- throw new ArgumentOutOfRangeException(paramName, message);
- }
- public static void ThrowTimeoutException()
- {
- throw new TimeoutException();
- }
- public static void ThrowStatementsCountOverflowException()
- {
- throw new StatementsCountOverflowException();
- }
- public static void ThrowArgumentOutOfRangeException()
- {
- throw new ArgumentOutOfRangeException();
- }
- public static T ThrowNotSupportedException<T>(string message = null)
- {
- throw new NotSupportedException(message);
- }
- public static void ThrowNotSupportedException(string message = null)
- {
- throw new NotSupportedException(message);
- }
- public static void ThrowInvalidOperationException(string message = null)
- {
- throw new InvalidOperationException(message);
- }
- public static void ThrowJavaScriptException(Engine engine, JsValue value, Completion result)
- {
- throw new JavaScriptException(value).SetCallstack(engine, result.Location);
- }
- public static void ThrowRecursionDepthOverflowException(JintCallStack currentStack, string currentExpressionReference)
- {
- throw new RecursionDepthOverflowException(currentStack, currentExpressionReference);
- }
- public static void ThrowArgumentNullException(string paramName)
- {
- throw new ArgumentNullException(paramName);
- }
- public static T ThrowArgumentNullException<T>(string paramName)
- {
- throw new ArgumentNullException(paramName);
- }
- public static void ThrowMeaningfulException(Engine engine, TargetInvocationException exception)
- {
- var meaningfulException = exception.InnerException ?? exception;
- var handler = engine.Options._ClrExceptionsHandler;
- if (handler != null && handler(meaningfulException))
- ThrowError(engine, meaningfulException.Message);
- throw meaningfulException;
- }
- public static void ThrowError(Engine engine, string message)
- {
- throw new JavaScriptException(engine.Error, message);
- }
- public static void ThrowPlatformNotSupportedException(string message)
- {
- throw new PlatformNotSupportedException(message);
- }
- public static void ThrowMemoryLimitExceededException(string message)
- {
- throw new MemoryLimitExceededException(message);
- }
- }
- }
|