Inheritance: BaseVsaEngine, IEngine2, IRedirectOutput
 public static ArrayObject concat(object thisob, VsaEngine engine, params object[] args)
 {
     ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct();
     if (thisob is ArrayObject)
     {
         obj2.Concat((ArrayObject) thisob);
     }
     else
     {
         obj2.Concat(thisob);
     }
     for (int i = 0; i < args.Length; i++)
     {
         object obj3 = args[i];
         if (obj3 is ArrayObject)
         {
             obj2.Concat((ArrayObject) obj3);
         }
         else
         {
             obj2.Concat(obj3);
         }
     }
     return obj2;
 }
Example #2
0
        public ScriptEngine(WebClient client)
        {
            m_Client = client;

            m_AppDomain = AppDomain.CreateDomain("ScriptEngine");

            m_Site = new MyVsaSite(this);

            m_Engine             = new Microsoft.JScript.Vsa.VsaEngine(false);
            m_Engine.RootMoniker = "Cb://Web/Scripting";
            //m_Engine.Site = (IJSVsaSite) m_Site;
            m_Engine.InitNew();
            m_Engine.RootNamespace = GetType().Namespace;
            m_Engine.SetOption("AlwaysGenerateIL", false);
            m_Engine.SetOption("CLSCompliant", false);
            m_Engine.GenerateDebugInfo = true;
            m_Engine.SetOutputStream(new EmptyMessageReceiver());


            SetGlobalObject("Context", this);

            AddCodeBlock("__init",
                         @"
					function alert(msg) { Context.Alert(msg); }
					function confirm(msg) { return Context.Confirm(msg); }
					function setInterval(funcName, delay) { Context.SetInterval(funcName, delay); }
			"            );
        }
	// Constructor.
	public EngineInstance(VsaEngine engine)
			{
				// Initialize the local state.
				this.engine = engine;
				this.outStream = null;
				this.errorStream = null;
			}
 		public void OnEngineClosed ()
		{
			VsaEngine engine = new VsaEngine ();
			IVsaItems items;
			IVsaItem item;

			engine = new VsaEngine ();
			engine.RootMoniker = "com.foo://path/to/nowhere";
			engine.Site = new Site ();

			engine.InitNew ();
			items = engine.Items;
			engine.Close ();
		
			int size;

			try {
				size = items.Count;
			} catch (VsaException e) {
				Assert.AreEqual (VsaError.EngineClosed, e.ErrorCode, "#1");
			}

			try {
				item = items.CreateItem ("itemx", VsaItemType.Code, 
							 VsaItemFlag.Class);
			} catch (VsaException e) {
				Assert.AreEqual (VsaError.EngineClosed, e.ErrorCode, "#2");
			}
		}
Example #5
0
        public static object CallValue(object thisObj, object val, object [] arguments,
            bool construct, bool brackets, VsaEngine engine)
        {
            if (construct) {
                if (brackets) {
                }

                if (val is Closure)
                    return ((Closure) val).func.CreateInstance (arguments);
                else if (val is FunctionObject)
                    return ((FunctionObject) val).CreateInstance (arguments);
            } else if (brackets) {
                object first_arg = arguments.Length > 0 ? arguments [0] : null;
                return GetObjectProperty ((ScriptObject) Convert.ToObject (val, engine), Convert.ToString (first_arg));
            } else {
                if (val is Closure)
                    return ((Closure) val).func.Invoke (thisObj, arguments);
                else if (val is FunctionObject)
                    return ((FunctionObject) val).Invoke (thisObj, arguments);
                else if (val is RegExpObject) {
                    object first_arg = arguments.Length > 0 ? arguments [0] : null;
                    return RegExpPrototype.exec (val, first_arg);
                } else
                    return null;
            }

            Console.WriteLine ("CallValue: construct = {0}, brackets = {1}, this = {2}, val = {3} ({4}), arg[0] = {5}",
                construct, brackets, thisObj.GetType (), val, val.GetType (), arguments [0]);
            throw new NotImplementedException ();
        }
 private void AddDefinition(string def, Hashtable definitions, VsaEngine engine){
   int equalsIndex = def.IndexOf("=");
   string key;
   string strValue;
   object value = null;
   if (equalsIndex == -1){
     key = def.Trim();
     value = true;
   }else{
     key = def.Substring(0, equalsIndex).Trim();
     strValue = def.Substring(equalsIndex + 1).Trim();
     if (String.Compare(strValue, "true", StringComparison.OrdinalIgnoreCase) == 0)
       value = true;
     else if (String.Compare(strValue, "false", StringComparison.OrdinalIgnoreCase) == 0)
       value = false;
     else{
       try{
         value = Int32.Parse(strValue, CultureInfo.InvariantCulture);
       }catch{
         throw new CmdLineException(CmdLineError.InvalidDefinition, key, engine.ErrorCultureInfo);
       }
     }
   }
   if (key.Length == 0)
     throw new CmdLineException(CmdLineError.MissingDefineArgument, engine.ErrorCultureInfo);
   definitions[key] = value;
 }
 internal GlobalScope(GlobalScope parent, VsaEngine engine, bool isComponentScope) : base(parent)
 {
     this.componentScopes = null;
     this.recursive = false;
     this.isComponentScope = isComponentScope;
     if (parent == null)
     {
         this.globalObject = engine.Globals.globalObject;
         this.globalObjectTR = TypeReflector.GetTypeReflectorFor(Globals.TypeRefs.ToReferenceContext(this.globalObject.GetType()));
         base.fast = !(this.globalObject is LenientGlobalObject);
     }
     else
     {
         this.globalObject = null;
         this.globalObjectTR = null;
         base.fast = parent.fast;
         if (isComponentScope)
         {
             ((GlobalScope) base.parent).AddComponentScope(this);
         }
     }
     base.engine = engine;
     base.isKnownAtCompileTime = base.fast;
     this.evilScript = true;
     this.thisObject = this;
     this.typeReflector = TypeReflector.GetTypeReflectorFor(Globals.TypeRefs.ToReferenceContext(base.GetType()));
     if (isComponentScope)
     {
         engine.Scopes.Add(this);
     }
 }
Example #8
0
        public static ArrayObject concat(object thisObj, VsaEngine engine,
            params object [] args)
        {
            uint i = 0;
            ArrayObject result = new ArrayObject ();
            int arg_idx = -1;
            int arg_count = args.Length;

            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type (thisObj, typeof (ArrayObject));
            object cur_obj = thisObj;

            ArrayObject cur_ary;
            while (cur_obj != null) {
                if (cur_obj is ArrayObject) {
                    cur_ary = (ArrayObject) cur_obj;

                    uint n = (uint) cur_ary.length;
                    for (uint j = 0; j < n; j++, i++)
                        result.elems [i] = cur_ary.elems [j];
                } else
                    result.elems [i++] = cur_obj;

                arg_idx++;
                cur_obj = arg_idx < arg_count ? args [arg_idx] : null;
            }

            result.length = i;

            return result;
        }
 private void AddSourceFile(VsaEngine engine, string filename)
 {
     string name = "$SourceFile_" + this.codeItemCounter++;
     IJSVsaCodeItem item = (IJSVsaCodeItem) engine.Items.CreateItem(name, JSVsaItemType.Code, JSVsaItemFlag.None);
     item.SetOption("codebase", filename);
     item.SourceText = this.ReadFile(filename, engine);
 }
Example #10
0
 internal VsaItem(VsaEngine engine, string name, VsaItemType type, VsaItemFlag flag)
 {
     this.engine = engine;
     this.name = name;
     this.type = type;
     this.flag = flag;
 }
	// Perform a late binding call, with reversed arguments.
	public static Object CallValue2(Object val, Object thisob,
								    Object[] arguments, bool construct,
								    bool brackets, VsaEngine engine)
			{
				// TODO
				return null;
			}
 internal ScriptFunction Construct(object[] args, VsaEngine engine)
 {
     ScriptFunction function;
     StringBuilder builder = new StringBuilder("function anonymous(");
     int index = 0;
     int num2 = args.Length - 2;
     while (index < num2)
     {
         builder.Append(Microsoft.JScript.Convert.ToString(args[index]));
         builder.Append(", ");
         index++;
     }
     if (args.Length > 1)
     {
         builder.Append(Microsoft.JScript.Convert.ToString(args[args.Length - 2]));
     }
     builder.Append(") {\n");
     if (args.Length > 0)
     {
         builder.Append(Microsoft.JScript.Convert.ToString(args[args.Length - 1]));
     }
     builder.Append("\n}");
     Context context = new Context(new DocumentContext("anonymous", engine), builder.ToString());
     JSParser parser = new JSParser(context);
     engine.PushScriptObject(((IActivationObject) engine.ScriptObjectStackTop()).GetGlobalScope());
     try
     {
         function = (ScriptFunction) parser.ParseFunctionExpression().PartiallyEvaluate().Evaluate();
     }
     finally
     {
         engine.PopScriptObject();
     }
     return function;
 }
 internal FunctionObject(Type t, string name, string method_name, string[] formal_parameters, JSLocalField[] fields, bool must_save_stack_locals, bool hasArgumentsObject, string text, VsaEngine engine) : base(engine.Globals.globalObject.originalFunction.originalPrototype, name, formal_parameters.Length)
 {
     base.engine = engine;
     this.formal_parameters = formal_parameters;
     this.argumentsSlotNumber = 0;
     this.body = null;
     this.method = TypeReflector.GetTypeReflectorFor(Globals.TypeRefs.ToReferenceContext(t)).GetMethod(method_name, BindingFlags.Public | BindingFlags.Static);
     this.parameterInfos = this.method.GetParameters();
     if (!Microsoft.JScript.CustomAttribute.IsDefined(this.method, typeof(JSFunctionAttribute), false))
     {
         this.isMethod = true;
     }
     else
     {
         JSFunctionAttributeEnum attributeValue = ((JSFunctionAttribute) Microsoft.JScript.CustomAttribute.GetCustomAttributes(this.method, typeof(JSFunctionAttribute), false)[0]).attributeValue;
         this.isExpandoMethod = (attributeValue & JSFunctionAttributeEnum.IsExpandoMethod) != JSFunctionAttributeEnum.None;
     }
     this.funcContext = null;
     this.own_scope = null;
     this.fields = fields;
     this.must_save_stack_locals = must_save_stack_locals;
     this.hasArgumentsObject = hasArgumentsObject;
     this.text = text;
     this.attributes = MethodAttributes.Public;
     this.globals = engine.Globals;
     this.superConstructor = null;
     this.superConstructorCall = null;
     this.enclosing_scope = this.globals.ScopeStack.Peek();
     base.noExpando = false;
     this.clsCompliance = CLSComplianceSpec.NotAttributed;
 }
Example #14
0
 internal VsaItem(VsaEngine engine, string itemName, VsaItemType type, VsaItemFlag flag){ 
   this.engine = engine;
   this.type = type;
   this.name = itemName;
   this.flag = flag;
   this.codebase = null;
   this.isDirty = true;
 }
Example #15
0
 VsaEngine INeedEngine.GetEngine()
 {
     if (this.vsaEngine == null)
     {
         this.vsaEngine = VsaEngine.CreateEngineWithType(typeof(Playground.JSEvaluator.Evaluator).TypeHandle);
     }
     return this.vsaEngine;
 }
 internal VsaScriptScope(VsaEngine engine, string itemName, VsaScriptScope parent) 
   : base(engine, itemName, (VsaItemType)(int)VSAITEMTYPE2.SCRIPTSCOPE, VsaItemFlag.None){ 
   this.parent = parent;
   this.scope = null;
   this.items = new ArrayList(8);
   this.isCompiled = false;
   this.isClosed = false;
 }
 internal VsaScriptScope(VsaEngine engine, string itemName, VsaScriptScope parent) : base(engine, itemName, (JSVsaItemType) 0x13, JSVsaItemFlag.None)
 {
     this.parent = parent;
     this.scope = null;
     this.items = new ArrayList(8);
     this.isCompiled = false;
     this.isClosed = false;
 }
 internal WrappedNamespace(String name, VsaEngine engine, bool AddReferences)
   : base(null) {
   this.name = name;
   this.engine = engine;
   this.isKnownAtCompileTime = true;
   if (name.Length > 0 && AddReferences)
     engine.TryToAddImplicitAssemblyReference(name);
 }
Example #19
0
 internal VsaNamedItemScope(Object hostObject, ScriptObject parent, VsaEngine engine)
   : base(parent){
   this.namedItem = hostObject;
   if ((this.reflectObj = hostObject as IReflect) == null)
     this.reflectObj = hostObject.GetType();
   this.recursive = false;
   this.engine = engine;
 }
Example #20
0
 public static Object JScriptWith(Object withOb, VsaEngine engine){
   Object ob = Convert.ToObject(withOb, engine);
   if (ob == null)
     throw new JScriptException(JSError.ObjectExpected);
   Globals glob = engine.Globals;
   glob.ScopeStack.GuardedPush(new WithObject(glob.ScopeStack.Peek(), ob));
   return ob;
 }
 public static ArrayObject toArray(object thisob, VsaEngine engine)
 {
     if (!(thisob is VBArrayObject))
     {
         throw new JScriptException(JSError.VBArrayExpected);
     }
     return ((VBArrayObject) thisob).toArray(engine);
 }
 public static void JScriptPackage(string rootName, VsaEngine engine)
 {
     GlobalScope globalScope = ((IActivationObject) engine.ScriptObjectStackTop()).GetGlobalScope();
     if (globalScope.GetLocalField(rootName) == null)
     {
         FieldInfo info = globalScope.AddNewField(rootName, Namespace.GetNamespace(rootName, engine), FieldAttributes.Literal | FieldAttributes.Public);
     }
 }
      public VsaEngine engine; //This is only really useful for ScriptFunctions, IActivation objects and prototype objects. It lives here for the sake of simplicity.
      //Prototype objects do not need the scope stack, so in fast mode, all prototype objects can share a common engine.

      internal ScriptObject(ScriptObject parent){
        this.parent = parent;
        this.wrappedMemberCache = null;
        if (this.parent != null)
          this.engine = parent.engine;
        else
          this.engine = null;
      }
 internal LenientGlobalObject(VsaEngine engine)
 {
     this.engine = engine;
     this.Infinity = (double) 1.0 / (double) 0.0;
     this.NaN = (double) 1.0 / (double) 0.0;
     this.undefined = null;
     this.ActiveXObjectField = Missing.Value;
     this.ArrayField = Missing.Value;
     this.BooleanField = Missing.Value;
     this.DateField = Missing.Value;
     this.EnumeratorField = Missing.Value;
     this.ErrorField = Missing.Value;
     this.EvalErrorField = Missing.Value;
     this.FunctionField = Missing.Value;
     this.MathField = Missing.Value;
     this.NumberField = Missing.Value;
     this.ObjectField = Missing.Value;
     this.RangeErrorField = Missing.Value;
     this.ReferenceErrorField = Missing.Value;
     this.RegExpField = Missing.Value;
     this.StringField = Missing.Value;
     this.SyntaxErrorField = Missing.Value;
     this.TypeErrorField = Missing.Value;
     this.VBArrayField = Missing.Value;
     this.URIErrorField = Missing.Value;
     Type type = typeof(GlobalObject);
     LenientFunctionPrototype functionPrototype = this.functionPrototype;
     this.decodeURI = new BuiltinFunction("decodeURI", this, type.GetMethod("decodeURI"), functionPrototype);
     this.decodeURIComponent = new BuiltinFunction("decodeURIComponent", this, type.GetMethod("decodeURIComponent"), functionPrototype);
     this.encodeURI = new BuiltinFunction("encodeURI", this, type.GetMethod("encodeURI"), functionPrototype);
     this.encodeURIComponent = new BuiltinFunction("encodeURIComponent", this, type.GetMethod("encodeURIComponent"), functionPrototype);
     this.escape = new BuiltinFunction("escape", this, type.GetMethod("escape"), functionPrototype);
     this.eval = new BuiltinFunction("eval", this, type.GetMethod("eval"), functionPrototype);
     this.isNaN = new BuiltinFunction("isNaN", this, type.GetMethod("isNaN"), functionPrototype);
     this.isFinite = new BuiltinFunction("isFinite", this, type.GetMethod("isFinite"), functionPrototype);
     this.parseInt = new BuiltinFunction("parseInt", this, type.GetMethod("parseInt"), functionPrototype);
     this.GetObject = new BuiltinFunction("GetObject", this, type.GetMethod("GetObject"), functionPrototype);
     this.parseFloat = new BuiltinFunction("parseFloat", this, type.GetMethod("parseFloat"), functionPrototype);
     this.ScriptEngine = new BuiltinFunction("ScriptEngine", this, type.GetMethod("ScriptEngine"), functionPrototype);
     this.ScriptEngineBuildVersion = new BuiltinFunction("ScriptEngineBuildVersion", this, type.GetMethod("ScriptEngineBuildVersion"), functionPrototype);
     this.ScriptEngineMajorVersion = new BuiltinFunction("ScriptEngineMajorVersion", this, type.GetMethod("ScriptEngineMajorVersion"), functionPrototype);
     this.ScriptEngineMinorVersion = new BuiltinFunction("ScriptEngineMinorVersion", this, type.GetMethod("ScriptEngineMinorVersion"), functionPrototype);
     this.unescape = new BuiltinFunction("unescape", this, type.GetMethod("unescape"), functionPrototype);
     this.boolean = Typeob.Boolean;
     this.@byte = Typeob.Byte;
     this.@char = Typeob.Char;
     this.@decimal = Typeob.Decimal;
     this.@double = Typeob.Double;
     this.@float = Typeob.Single;
     this.@int = Typeob.Int32;
     this.@long = Typeob.Int64;
     this.@sbyte = Typeob.SByte;
     this.@short = Typeob.Int16;
     this.@void = Typeob.Void;
     this.@uint = Typeob.UInt32;
     this.@ulong = Typeob.UInt64;
     this.@ushort = Typeob.UInt16;
 }
 public static object CallConstructor(string typename, object[] arguments, VsaEngine engine)
 {
     if (engine == null)
     {
         engine = VsaEngine.CreateEngine();
     }
     object type = GetType(typename);
     return LateBinding.CallValue(null, type, arguments, true, false, engine);
 }
Example #26
0
 public static void JScriptImport(String name, VsaEngine engine){
   int dotPos = name.IndexOf('.');
   String rootName = dotPos > 0 ? name.Substring(0, dotPos) : name;
   GlobalScope scope = ((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope();
   FieldInfo field = scope.GetLocalField(rootName);
   if (field == null)
     field = scope.AddNewField(rootName, Namespace.GetNamespace(rootName, engine), FieldAttributes.Public|FieldAttributes.Literal);
   engine.SetEnclosingContext(new WrappedNamespace(name, engine, false));
 }
 public static object CallMethod(string name, object thisob, object[] arguments, VsaEngine engine)
 {
     if (engine == null)
     {
         engine = VsaEngine.CreateEngine();
     }
     LateBinding binding = new LateBinding(name, thisob, true);
     return binding.Call(arguments, false, false, engine);
 }
Example #28
0
		public object Call (object [] arguments, bool construct, bool brackets,
					VsaEngine engine)
		{
			object fun = GetObjectProperty (obj, right_hand_side);

			if (fun == null)
				Console.WriteLine ("Call: No function for {0} ({1}).{2}", obj, obj.GetType (), right_hand_side);
			return CallValue (obj, fun, arguments, construct, brackets, engine);
		}
 public static object CallStaticMethod(string name, string typename, object[] arguments, VsaEngine engine)
 {
     if (engine == null)
     {
         engine = VsaEngine.CreateEngine();
     }
     object type = GetType(typename);
     LateBinding binding = new LateBinding(name, type, true);
     return binding.Call(arguments, false, false, engine);
 }
Example #30
0
File: Try.cs Project: nickchal/pash
		public static Object JScriptExceptionValue (object e, VsaEngine engine)
		{
			Exception exc = e as Exception;
			string message = null;
			if (exc != null)
				message = exc.Message;
			else
				message = String.Format ("Unknown exception of type {0}", exc.GetType ());
			return new ErrorObject (message);
		}
 internal VsaScriptCode(VsaEngine engine, string itemName, JSVsaItemType type, IVsaScriptScope scope) : base(engine, itemName, type, JSVsaItemFlag.None)
 {
     this.binaryCode = null;
     this.executed = false;
     this.scope = (VsaScriptScope) scope;
     this.codeContext = new Context(new DocumentContext(this), null);
     this.compiledBlock = null;
     this.compileToIL = true;
     this.optimize = true;
 }
Example #32
0
        /// <summary>
        /// 计算方法
        /// </summary>
        /// <param name="formule">计算公式</param>
        /// <param name="num">显示小数位数</param>
        /// <param name="statues">数值状态</param>
        /// <returns></returns>
        public string GetCaleFormule(string formule, string num, out string statues)
        {
            double val = 0;
            string res = "0";

            if (num == "-1")
            {
                num = "4";
            }

            try
            {
                Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();

                res = Microsoft.JScript.Eval.JScriptEvaluate(formule, ve).ToString();

                statues = res;

                if (res == "0")
                {
                    return("0");
                }
                else if (res == "非数字")
                {
                    return("0");
                }
                else if (res == "正无穷大")
                {
                    return("0");
                }
                else if (res == "负无穷大")
                {
                    return("0");
                }
                else if (res == "" || res == null)
                {
                    return("0");
                }
                else
                {
                    try
                    { val = Convert.ToDouble(res); }
                    catch
                    { val = 0; }
                }
                return(val.ToString("f" + num));
            }
            catch (Exception ce)
            {
                statues = ce.Message;
            }

            return(res);
        }
Example #33
0
 /// <summary>
 /// 计算方法
 /// </summary>
 /// <param name="formule">数字公式</param>
 /// <returns>Value(Type:string)</returns>
 static public string Cale(string formule)
 {
     try
     {
         Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
         return(Microsoft.JScript.Eval.JScriptEvaluate(formule, ve).ToString());
     }
     catch (Exception ce)
     {
         return("0");
     }
 }
Example #34
0
 // Detach this engine from the primary position.
 private void DetachEngine()
 {
     lock (typeof(VsaEngine))
     {
         if (this == primaryEngine)
         {
             primaryEngine = null;
         }
         if (this == Globals.contextEngine)
         {
             Globals.contextEngine = null;
         }
         engineInstance.DetachOutputStreams();
         detached = true;
     }
 }
Example #35
0
        public JScriptEngine(object scriptGlobal) : base(scriptGlobal)
        {
            engine             = new Microsoft.JScript.Vsa.VsaEngine();
            engine.RootMoniker = "sharpvectors://jsengine/" + counter++;
            engine.Site        = this;
            engine.InitNew();
            engine.RootNamespace     = "SharpVectors.Scripting";
            engine.GenerateDebugInfo = false;
            engine.RevokeCache();
            engine.SetOption("Fast", false);

            items = engine.Items;
            Assembly          asm     = typeof(SharpVectors.Scripting.JScriptEngine).Assembly;
            IVsaReferenceItem refItem = (IVsaReferenceItem)items.CreateItem(asm.Location, VsaItemType.Reference, VsaItemFlag.None);

            refItem.AssemblyName = asm.Location;
        }
Example #36
0
        public static GlobalScope CreateEngineAndGetGlobalScope(bool fast, string [] assembly_names)
        {
            int         i, n;
            GlobalScope scope;

            VsaEngine engine = new VsaEngine(fast);

            engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa",
                                 new DefaultVsaSite());
            n = assembly_names.Length;

            for (i = 0; i < n; i++)
            {
                string           assembly_name = assembly_names [i];
                VsaReferenceItem r             = (VsaReferenceItem)engine.Items.CreateItem(assembly_name,
                                                                                           VsaItemType.Reference,
                                                                                           VsaItemFlag.None);
                r.AssemblyName = assembly_name;
            }
            scope = (GlobalScope)engine.GetGlobalScope().GetObject();
            return(scope);
        }
Example #37
0
    bool Compile(CompilerOptions options)
    {
        if (this.fPrintTargets)
        {
            Console.WriteLine(Localize("Compiling", options.strOutputFileName));
        }

        VsaEngine engine = new Microsoft.JScript.Vsa.VsaEngine();

        if (null == engine)
        {
            throw new CmdLineException(CmdLineError.CannotCreateEngine, JScriptCompiler.GetCultureInfo());
        }
        engine.InitVsaEngine("JSC://Microsoft.JScript.Vsa.VsaEngine", new EngineSite(options));
        engine.LCID = JScriptCompiler.LCID;
        engine.GenerateDebugInfo = options.fDebug;

        engine.SetOption("AutoRef", options.autoRef);
        engine.SetOption("fast", options.fFast);
        engine.SetOption("output", options.strOutputFileName);
        engine.SetOption("PEFileKind", options.PEFileKind);
        engine.SetOption("print", options.fPrint);
        engine.SetOption("libpath", options.libpath);
        if (options.versionInfo != null)
        {
            engine.SetOption("version", options.versionInfo);
        }
        engine.SetOption("VersionSafe", options.fVersionSafe);
        engine.SetOption("defines", options.Defines);
        engine.SetOption("warnaserror", options.fTreatWarningsAsErrors);
        engine.SetOption("WarningLevel", options.nWarningLevel);
        if (options.ManagedResources.Count > 0)
        {
            engine.SetOption("managedResources", options.ManagedResources.Values);
        }

        bool fStdlibAdded   = false;
        bool fWinFormsAdded = false;

        foreach (string assemblyName in options.ImportFileNames)
        {
            this.AddAssemblyReference(engine, assemblyName);
            string filename = Path.GetFileName(assemblyName);
            if (String.Compare(filename, "mscorlib.dll", true, CultureInfo.InvariantCulture) == 0)
            {
                fStdlibAdded = true;
            }
            else if (String.Compare(filename, "System.Windows.Forms.dll", true, CultureInfo.InvariantCulture) == 0)
            {
                fWinFormsAdded = true;
            }
        }

        // Only add mscorlib if it hasn't already been added.
        if (!options.fNoStdlib && !fStdlibAdded)
        {
            AddAssemblyReference(engine, "mscorlib.dll");
        }
        // add System.Windows.Forms if target is winexe and it hasn't already been added
        if ((options.PEFileKind == PEFileKinds.WindowApplication) && !options.fNoStdlib && !fWinFormsAdded)
        {
            AddAssemblyReference(engine, "System.Windows.Forms.dll");
        }

        for (int j = 0; j < options.SourceFileNames.Count; j++)
        {
            AddSourceFile(engine, (string)options.SourceFileNames[j], options.codepage, options.fForceCodepage);
        }

        bool isCompiled = false;

        try{
            isCompiled = engine.Compile();
        }catch (VsaException e) {
            // check for expected errors
            if (e.ErrorCode == VsaError.AssemblyExpected)
            {
                if (e.InnerException != null && e.InnerException is System.BadImageFormatException)
                {
                    // the reference was not for an assembly
                    CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, e.Message, JScriptCompiler.GetCultureInfo());
                    Console.WriteLine(cmdLineError.Message);
                }
                else if (e.InnerException != null && (e.InnerException is System.IO.FileNotFoundException || e.InnerException is System.IO.FileLoadException))
                {
                    // the referenced file not valid
                    CmdLineException cmdLineError = new CmdLineException(CmdLineError.AssemblyNotFound, e.Message, JScriptCompiler.GetCultureInfo());
                    Console.WriteLine(cmdLineError.Message);
                }
                else
                {
                    CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, JScriptCompiler.GetCultureInfo());
                    Console.WriteLine(cmdLineError.Message);
                }
            }
            else if (e.ErrorCode == VsaError.SaveCompiledStateFailed)
            {
                CmdLineException cmdLineError = new CmdLineException(CmdLineError.ErrorSavingCompiledState, e.Message, JScriptCompiler.GetCultureInfo());
                Console.WriteLine(cmdLineError.Message);
            }
            else if (e.ErrorCode == VsaError.AssemblyNameInvalid && e.InnerException != null)
            {
                CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidCharacters, e.Message, JScriptCompiler.GetCultureInfo());
                Console.WriteLine(cmdLineError.Message);
            }
            else
            {
                Console.WriteLine(Localize("INTERNAL COMPILER ERROR"));
                Console.WriteLine(e);
            }
            return(false);
        }catch (Exception e) {
            Console.WriteLine(Localize("INTERNAL COMPILER ERROR"));
            Console.WriteLine(e);
            return(false);
        }
        return(isCompiled);
    }