예제 #1
0
        public void VBScriptEngine_ErrorHandling_NestedScriptError()
        {
            var innerEngine = new JScriptEngine("inner", WindowsScriptEngineFlags.EnableDebugging);

            engine.AddHostObject("engine", innerEngine);

            TestUtil.AssertException <ScriptEngineException>(() =>
            {
                try
                {
                    engine.Execute("engine.Execute(\"foo = {}; foo();\")");
                }
                catch (ScriptEngineException exception)
                {
                    TestUtil.AssertValidException(engine, exception);
                    Assert.IsNotNull(exception.InnerException);

                    var hostException = exception.InnerException;
                    Assert.IsInstanceOfType(hostException, typeof(TargetInvocationException));
                    TestUtil.AssertValidException(hostException);
                    Assert.IsNotNull(hostException.InnerException);

                    var nestedException = hostException.InnerException as ScriptEngineException;
                    Assert.IsNotNull(nestedException);
                    TestUtil.AssertValidException(innerEngine, nestedException);
                    Assert.IsNull(nestedException.InnerException);

                    Assert.AreEqual(hostException.Message, exception.Message);
                    throw;
                }
            });
        }
예제 #2
0
        public void VBScriptEngine_ErrorHandling_HostException()
        {
            engine.AddHostObject("host", new HostFunctions());

            TestUtil.AssertException <ScriptEngineException>(() =>
            {
                try
                {
                    engine.Evaluate("host.newObj(0)");
                }
                catch (ScriptEngineException exception)
                {
                    TestUtil.AssertValidException(engine, exception);
                    Assert.IsNotNull(exception.InnerException);

                    var hostException = exception.InnerException;
                    Assert.IsInstanceOfType(hostException, typeof(RuntimeBinderException));
                    TestUtil.AssertValidException(hostException);
                    Assert.IsNull(hostException.InnerException);

                    Assert.AreEqual(hostException.Message, exception.Message);
                    throw;
                }
            });
        }
예제 #3
0
 public void VBScriptEngine_ErrorHandling_ScriptError()
 {
     TestUtil.AssertException <ScriptEngineException>(() =>
     {
         try
         {
             engine.Execute("foo = {}; foo();");
         }
         catch (ScriptEngineException exception)
         {
             TestUtil.AssertValidException(engine, exception);
             Assert.IsNull(exception.InnerException);
             throw;
         }
     });
 }
 public void JScriptEngine_ErrorHandling_ThrowNonError()
 {
     TestUtil.AssertException <ScriptEngineException>(() =>
     {
         try
         {
             engine.Execute("(function () { throw 123; })()");
         }
         catch (ScriptEngineException exception)
         {
             TestUtil.AssertValidException(engine, exception);
             Assert.IsNull(exception.InnerException);
             Assert.IsTrue(exception.ErrorDetails.Contains(" -> throw 123"));
             throw;
         }
     });
 }
 public void JScriptEngine_ErrorHandling_SyntaxError()
 {
     TestUtil.AssertException <ScriptEngineException>(() =>
     {
         try
         {
             engine.Execute("function foo() { int c; }");
         }
         catch (ScriptEngineException exception)
         {
             TestUtil.AssertValidException(engine, exception);
             Assert.IsNull(exception.InnerException);
             Assert.IsTrue(exception.Message.StartsWith("Expected", StringComparison.Ordinal));
             throw;
         }
     });
 }
예제 #6
0
        public void VBScriptEngine_ErrorHandling_IgnoredHostException()
        {
            engine.AddHostObject("host", new HostFunctions());

            TestUtil.AssertException <ScriptEngineException>(() =>
            {
                try
                {
                    engine.Execute("on error resume next : host.newObj(null) : on error goto 0 : foo = \"foo\" : foo()");
                }
                catch (ScriptEngineException exception)
                {
                    TestUtil.AssertValidException(engine, exception);
                    Assert.IsNull(exception.InnerException);
                    throw;
                }
            });
        }
        public void JScriptEngine_ErrorHandling_IgnoredHostException()
        {
            engine.AddHostObject("host", new HostFunctions());

            TestUtil.AssertException <ScriptEngineException>(() =>
            {
                try
                {
                    engine.Execute("try { host.newObj(null); } catch(ex) {} foo = {}; foo();");
                }
                catch (ScriptEngineException exception)
                {
                    TestUtil.AssertValidException(engine, exception);
                    Assert.IsNull(exception.InnerException);
                    throw;
                }
            });
        }
        public void JScriptEngine_ErrorHandling_NestedHostException()
        {
            var innerEngine = new JScriptEngine("inner", WindowsScriptEngineFlags.EnableDebugging);

            innerEngine.AddHostObject("host", new HostFunctions());
            engine.AddHostObject("engine", innerEngine);

            TestUtil.AssertException <ScriptEngineException>(() =>
            {
                try
                {
                    engine.Execute("engine.Evaluate('host.newObj(0)')");
                }
                catch (ScriptEngineException exception)
                {
                    TestUtil.AssertValidException(engine, exception);
                    Assert.IsNotNull(exception.InnerException);

                    var hostException = exception.InnerException;
                    Assert.IsInstanceOfType(hostException, typeof(TargetInvocationException));
                    TestUtil.AssertValidException(hostException);
                    Assert.IsNotNull(hostException.InnerException);

                    var nestedException = hostException.InnerException as ScriptEngineException;
                    Assert.IsNotNull(nestedException);
                    TestUtil.AssertValidException(innerEngine, nestedException);
                    Assert.IsNotNull(nestedException.InnerException);

                    var nestedHostException = nestedException.InnerException;
                    Assert.IsInstanceOfType(nestedHostException, typeof(RuntimeBinderException));
                    TestUtil.AssertValidException(nestedHostException);
                    Assert.IsNull(nestedHostException.InnerException);

                    Assert.AreEqual(nestedHostException.Message, nestedException.Message);
                    Assert.AreEqual(hostException.Message, exception.Message);
                    throw;
                }
            });
        }