public static object JScriptExceptionValue(object e, VsaEngine engine)
        {
            if (engine == null)
            {
                engine = new VsaEngine(true);
                engine.InitVsaEngine("JS7://Microsoft.JScript.Vsa.VsaEngine", new DefaultVsaSite());
            }
            ErrorConstructor originalError = engine.Globals.globalObject.originalError;

            if (e is JScriptException)
            {
                object obj2 = ((JScriptException)e).value;
                if ((!(obj2 is Exception) && !(obj2 is Microsoft.JScript.Missing)) && ((((JScriptException)e).Number & 0xffff) == 0x139e))
                {
                    return(obj2);
                }
                return(originalError.Construct((Exception)e));
            }
            if (e is StackOverflowException)
            {
                return(originalError.Construct(new JScriptException(JSError.OutOfStack)));
            }
            if (e is OutOfMemoryException)
            {
                return(originalError.Construct(new JScriptException(JSError.OutOfMemory)));
            }
            return(originalError.Construct(e));
        }
示例#2
0
        public static Object JScriptExceptionValue(Object e, VsaEngine engine)
        {
            if (engine == null)
            {
                engine = new VsaEngine(true);
                engine.InitVsaEngine("JS7://Microsoft.JScript.Vsa.VsaEngine", new DefaultVsaSite());
            }
            ErrorConstructor originalError = engine.Globals.globalObject.originalError;

            if (e is JScriptException)
            {
                Object value = ((JScriptException)e).value;
                if (value is Exception || value is Missing || (((JScriptException)e).Number & 0xFFFF) != (int)JSError.UncaughtException)
                {
                    return(originalError.Construct((Exception)e));
                }
                return(value); //The exception wraps a non-exception value
            }
            else if (e is StackOverflowException)
            {
                return(originalError.Construct(new JScriptException(JSError.OutOfStack)));
            }
            else if (e is OutOfMemoryException)
            {
                return(originalError.Construct(new JScriptException(JSError.OutOfMemory)));
            }
            return(originalError.Construct(e));
        }
        private VsaEngine CreateAndInitEngine(CompilerParameters options, string[] sourceFiles, string outputFile, TextWriter output)
        {
            VsaEngine engine = new VsaEngine(true);
            VsaSite   site   = new VsaSite(output);

            engine.InitVsaEngine("JSCodeGenerator://Microsoft.JScript.Vsa.VsaEngine", site);

            // Ensure that all options are valid; throw a CmdLineException otherwise
            this.ValidateOptions(options, engine);

            // Set options on the engine (equivalent of cmdline args in out-of-proc scenario)
            engine.GenerateDebugInfo = options.IncludeDebugInformation;
            engine.SetOption("referenceLoaderAPI", "LoadFile");
            engine.SetOption("fast", true);
            engine.SetOption("print", false);
            engine.SetOption("VersionSafe", false);
            engine.SetOption("output", options.OutputAssembly);
            if (options.GenerateExecutable)
            {
                engine.SetOption("PEFileKind", PEFileKinds.ConsoleApplication);
            }
            else
            {
                engine.SetOption("PEFileKind", PEFileKinds.Dll);
            }
            site.treatWarningsAsErrors = options.TreatWarningsAsErrors;
            engine.SetOption("warnaserror", options.TreatWarningsAsErrors);
            site.warningLevel = options.WarningLevel;
            engine.SetOption("WarningLevel", options.WarningLevel);
            bool stdLibAdded = false;

            foreach (string assemblyName in options.ReferencedAssemblies)
            {
                if (String.Compare(Path.GetFileName(assemblyName), "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    stdLibAdded = true;
                }
                this.AddAssemblyReference(engine, assemblyName);
            }
            if (!stdLibAdded)
            {
                this.AddAssemblyReference(engine, "mscorlib.dll");
            }

            // Parse any additional compiler options
            StringCollection compilerOptions = this.SplitCmdLineArguments(options.CompilerOptions);

            this.ParseCompilerOptions(engine, compilerOptions, output, options.GenerateExecutable);

            // Add the source files to the engine (as IVsaCodeItems)
            for (int j = 0; j < sourceFiles.Length; j++)
            {
                this.AddSourceFile(engine, sourceFiles[j]);
            }

            return(engine);
        }
示例#4
0
        private VsaEngine CreateAndInitEngine(CompilerParameters options, string[] sourceFiles, string outputFile, TextWriter output)
        {
            VsaEngine engine = new VsaEngine(true);
            VsaSite   site   = new VsaSite(output);

            engine.InitVsaEngine("JSCodeGenerator://Microsoft.JScript.Vsa.VsaEngine", site);
            this.ValidateOptions(options, engine);
            engine.GenerateDebugInfo = options.IncludeDebugInformation;
            engine.SetOption("referenceLoaderAPI", "LoadFile");
            engine.SetOption("fast", true);
            engine.SetOption("print", false);
            engine.SetOption("VersionSafe", false);
            engine.SetOption("output", options.OutputAssembly);
            if (options.GenerateExecutable)
            {
                engine.SetOption("PEFileKind", PEFileKinds.ConsoleApplication);
            }
            else
            {
                engine.SetOption("PEFileKind", PEFileKinds.Dll);
            }
            site.treatWarningsAsErrors = options.TreatWarningsAsErrors;
            engine.SetOption("warnaserror", options.TreatWarningsAsErrors);
            site.warningLevel = options.WarningLevel;
            engine.SetOption("WarningLevel", options.WarningLevel);
            if ((options.Win32Resource != null) && (options.Win32Resource.Length > 0))
            {
                engine.SetOption("win32resource", options.Win32Resource);
            }
            bool flag = false;

            foreach (string str in options.ReferencedAssemblies)
            {
                if (string.Compare(Path.GetFileName(str), "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    flag = true;
                }
                this.AddAssemblyReference(engine, str);
            }
            if (!flag)
            {
                this.AddAssemblyReference(engine, "mscorlib.dll");
            }
            StringCollection args = this.SplitCmdLineArguments(options.CompilerOptions);

            this.ParseCompilerOptions(engine, args, output, options.GenerateExecutable);
            for (int i = 0; i < sourceFiles.Length; i++)
            {
                this.AddSourceFile(engine, sourceFiles[i]);
            }
            return(engine);
        }
示例#5
0
文件: mjs.cs 项目: pmq20/mono_forked
        //
        // Entry point
        //
        private static void Main(string [] args)
        {
            if (args.Length < 1)
            {
                Usage();
                Environment.Exit(0);
            }
            MainDriver(args);
            VsaEngine engine = new VsaEngine();

            engine.InitVsaEngine("mjs:com.mono-project", new MonoEngineSite());

            foreach (string asm in references)
            {
                IVsaReferenceItem item = (IVsaReferenceItem)engine.Items.CreateItem(asm, VsaItemType.Reference, VsaItemFlag.None);
                item.AssemblyName = asm;
            }

            string asm_name = String.Empty;

            foreach (Assembly assembly in assemblies)
            {
                asm_name = assembly.GetName().FullName;
                IVsaReferenceItem item = (IVsaReferenceItem)engine.Items.CreateItem(asm_name, VsaItemType.Reference, VsaItemFlag.None);
                item.AssemblyName = asm_name;
            }

            foreach (string file in files)
            {
                IVsaCodeItem item = (IVsaCodeItem)engine.Items.CreateItem(file, VsaItemType.Code, VsaItemFlag.None);
                item.SourceText = GetCodeFromFile(file);
            }
            engine.SetOption("debug", want_debugging_support);
            engine.SetOption("link_path", link_paths);
            engine.SetOption("first_source", first_source);
            engine.SetOption("assemblies", assemblies);
            engine.SetOption("out", output_file);
            if (warning_level != -1)
            {
                engine.SetOption("WarningLevel", warning_level);
            }
            engine.Compile();
        }