상속: System.ApplicationException, IVsaFullErrorInfo, IJSVsaError
예제 #1
0
        private void CheckCompatibility()
        {
            // If reference is agnostic, then compatible
            PortableExecutableKinds RefPEKindFlags;
            ImageFileMachine        RefPEMachineArchitecture;

            this.assembly.ManifestModule.GetPEKind(out RefPEKindFlags, out RefPEMachineArchitecture);

            if (RefPEMachineArchitecture == ImageFileMachine.I386 &&
                PortableExecutableKinds.ILOnly == (RefPEKindFlags & (PortableExecutableKinds.ILOnly | PortableExecutableKinds.Required32Bit)))
            {
                return;
            }

            // Warn if building an agnostic assembly, but referenced assembly is not.
            PortableExecutableKinds PEKindFlags           = engine.PEKindFlags;
            ImageFileMachine        PEMachineArchitecture = engine.PEMachineArchitecture;

            if (PEMachineArchitecture == ImageFileMachine.I386 &&
                PortableExecutableKinds.ILOnly == (PEKindFlags & (PortableExecutableKinds.ILOnly | PortableExecutableKinds.Required32Bit)))
            {
                // We are agnostic, but the reference is not. Do not emit a warning - this is a very common
                // case. Many of the system libraries are platform specific.
                return;
            }

            // Warning if architectures don't match.
            if (RefPEMachineArchitecture != PEMachineArchitecture)
            {
                JScriptException e = new JScriptException(JSError.IncompatibleAssemblyReference);
                e.value = this.assemblyName;
                this.engine.OnCompilerError(e);
            }
        }
예제 #2
0
 internal void HandleError(JScriptException error)
 {
     if (this.sourceItem == null)
     {
         if (error.Severity == 0)
         {
             throw error;
         }
     }
     else if (!this.sourceItem.engine.OnCompilerError(error))
     {
         throw new EndOfFile();
     }
 }
        internal void PrintBanner(VsaEngine engine, TextWriter output)
        {
            string jsVersion = BuildVersionInfo.MajorVersion.ToString(CultureInfo.InvariantCulture)
                               + "." + BuildVersionInfo.MinorVersion.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0')
                               + "." + BuildVersionInfo.Build.ToString(CultureInfo.InvariantCulture).PadLeft(4, '0');
            Version version        = System.Environment.Version;
            string  runtimeVersion = version.Major.ToString(CultureInfo.InvariantCulture)
                                     + "." + version.Minor.ToString(CultureInfo.InvariantCulture)
                                     + "." + version.Build.ToString(CultureInfo.InvariantCulture).PadLeft(4, '0');

            output.WriteLine(String.Format(engine.ErrorCultureInfo, JScriptException.Localize("Banner line 1", engine.ErrorCultureInfo), jsVersion));
            output.WriteLine(String.Format(engine.ErrorCultureInfo, JScriptException.Localize("Banner line 2", engine.ErrorCultureInfo), runtimeVersion));
            output.WriteLine(JScriptException.Localize("Banner line 3", engine.ErrorCultureInfo) + Environment.NewLine);
        }
 private void CheckCompatibility()
 {
     PortableExecutableKinds kinds;
     ImageFileMachine machine;
     this.assembly.ManifestModule.GetPEKind(out kinds, out machine);
     if ((machine != ImageFileMachine.I386) || (PortableExecutableKinds.ILOnly != (kinds & (PortableExecutableKinds.Required32Bit | PortableExecutableKinds.ILOnly))))
     {
         PortableExecutableKinds pEKindFlags = base.engine.PEKindFlags;
         ImageFileMachine pEMachineArchitecture = base.engine.PEMachineArchitecture;
         if (((pEMachineArchitecture != ImageFileMachine.I386) || (PortableExecutableKinds.ILOnly != (pEKindFlags & (PortableExecutableKinds.Required32Bit | PortableExecutableKinds.ILOnly)))) && (machine != pEMachineArchitecture))
         {
             JScriptException se = new JScriptException(JSError.IncompatibleAssemblyReference) {
                 value = this.assemblyName
             };
             base.engine.OnCompilerError(se);
         }
     }
 }
예제 #5
0
        public string GetErrorMessageForHR(int hr, IJSVsaEngine engine)
        {
            CultureInfo culture = null;
            VsaEngine   engine2 = engine as VsaEngine;

            if (engine2 != null)
            {
                culture = engine2.ErrorCultureInfo;
            }
            if (((hr & 0xffff0000L) == 0x800a0000L) && Enum.IsDefined(typeof(JSError), hr & 0xffff))
            {
                int num = hr & 0xffff;
                return(JScriptException.Localize(num.ToString(CultureInfo.InvariantCulture), culture));
            }
            int num2 = 0x177b;

            return(JScriptException.Localize(num2.ToString(CultureInfo.InvariantCulture), "0x" + hr.ToString("X", CultureInfo.InvariantCulture), culture));
        }
        //---------------------------------------------------------------------------------------
        // HandleError
        //
        //  Handle an error. There are two actions that can be taken when an error occurs:
        //    - throwing an exception with no recovering action (eval case)
        //    - notify the host that an error occurred and let the host decide whether or not
        //      parsing has to continue (the host returns true when parsing has to continue)
        //---------------------------------------------------------------------------------------

        internal void HandleError(JScriptException error)
        {
            if (this.sourceItem == null) //Called from eval
            {
                if (error.Severity == 0)
                {
                    throw error;
                }
                else
                {
                    return;
                }
            }
            if (!this.sourceItem.engine.OnCompilerError(error))
            {
                throw new EndOfFile(); // this exception terminates the parser
            }
        }
        private void CheckCompatibility()
        {
            PortableExecutableKinds kinds;
            ImageFileMachine        machine;

            this.assembly.ManifestModule.GetPEKind(out kinds, out machine);
            if ((machine != ImageFileMachine.I386) || (PortableExecutableKinds.ILOnly != (kinds & (PortableExecutableKinds.Required32Bit | PortableExecutableKinds.ILOnly))))
            {
                PortableExecutableKinds pEKindFlags           = base.engine.PEKindFlags;
                ImageFileMachine        pEMachineArchitecture = base.engine.PEMachineArchitecture;
                if (((pEMachineArchitecture != ImageFileMachine.I386) || (PortableExecutableKinds.ILOnly != (pEKindFlags & (PortableExecutableKinds.Required32Bit | PortableExecutableKinds.ILOnly)))) && (machine != pEMachineArchitecture))
                {
                    JScriptException se = new JScriptException(JSError.IncompatibleAssemblyReference)
                    {
                        value = this.assemblyName
                    };
                    base.engine.OnCompilerError(se);
                }
            }
        }
예제 #8
0
        internal void PrintBanner(VsaEngine engine, TextWriter output)
        {
            string[] strArray = new string[5];
            strArray[0] = 10.ToString(CultureInfo.InvariantCulture);
            strArray[1] = ".";
            int num2 = 0;

            strArray[2] = num2.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0');
            strArray[3] = ".";
            int num3 = 0x766f;

            strArray[4] = num3.ToString(CultureInfo.InvariantCulture).PadLeft(4, '0');
            string  str     = string.Concat(strArray);
            Version version = Environment.Version;
            string  str2    = version.Major.ToString(CultureInfo.InvariantCulture) + "." + version.Minor.ToString(CultureInfo.InvariantCulture) + "." + version.Build.ToString(CultureInfo.InvariantCulture).PadLeft(4, '0');

            output.WriteLine(string.Format(engine.ErrorCultureInfo, JScriptException.Localize("Banner line 1", engine.ErrorCultureInfo), new object[] { str }));
            output.WriteLine(string.Format(engine.ErrorCultureInfo, JScriptException.Localize("Banner line 2", engine.ErrorCultureInfo), new object[] { str2 }));
            output.WriteLine(JScriptException.Localize("Banner line 3", engine.ErrorCultureInfo) + Environment.NewLine);
        }
예제 #9
0
 internal void HandleError(JSError errorId, string message, bool treatAsError)
 {
     if ((errorId != JSError.UndeclaredVariable) || !this.document.HasAlreadySeenErrorFor(this.GetCode()))
     {
         JScriptException error = new JScriptException(errorId, this);
         if (message != null)
         {
             error.value = message;
         }
         if (treatAsError)
         {
             error.isError = treatAsError;
         }
         int severity = error.Severity;
         if (severity < this.errorReported)
         {
             this.document.HandleError(error);
             this.errorReported = severity;
         }
     }
 }
예제 #10
0
        internal override Object Evaluate()
        {
            int        i  = Globals.ScopeStack.Size();
            int        j  = Globals.CallContextStack.Size();
            Completion bc = null;
            Completion fc = null;

            try{
                Object eValue = null;
                try{
                    bc = (Completion)this.body.Evaluate();
                }catch (Exception e) {
                    if (this.handler == null)
                    {
                        throw;
                    }
                    eValue = e;
                    if (this.type != null)
                    {
                        Type ht = this.type.ToType();
                        if (Typeob.Exception.IsAssignableFrom(ht))
                        {
                            if (!ht.IsInstanceOfType(e))
                            {
                                throw;
                            }
                        }
                        else if (!ht.IsInstanceOfType(eValue = JScriptExceptionValue(e, this.Engine)))
                        {
                            throw;
                        }
                    }
                    else
                    {
                        eValue = JScriptExceptionValue(e, this.Engine);
                    }
                }catch {
                    eValue = new JScriptException(JSError.NonClsException);
                }

                if (eValue != null)
                {
                    Globals.ScopeStack.TrimToSize(i);
                    Globals.CallContextStack.TrimToSize(j);
                    if (this.handler_scope != null)
                    {
                        this.handler_scope.SetParent(Globals.ScopeStack.Peek());
                        Globals.ScopeStack.Push(this.handler_scope);
                    }
                    if (this.field != null)
                    {
                        this.field.SetValue(Globals.ScopeStack.Peek(), eValue);
                    }
                    bc = (Completion)this.handler.Evaluate();
                }
            }finally{
                Globals.ScopeStack.TrimToSize(i);
                Globals.CallContextStack.TrimToSize(j);
                if (this.finally_block != null)
                {
                    fc = (Completion)this.finally_block.Evaluate();
                }
            }
            if (bc == null || fc != null && (fc.Exit > 0 || fc.Continue > 0 || fc.Return))
            {
                bc = fc;
            }
            else
            {
                if (fc != null && fc.value is Missing)
                {
                    bc.value = fc.value;
                }
            }
            Completion result = new Completion();

            result.Continue = bc.Continue - 1;
            result.Exit     = bc.Exit - 1;
            result.Return   = bc.Return;
            result.value    = bc.value;
            return(result);
        }
예제 #11
0
파일: vsaengine.cs 프로젝트: ArildF/masters
 internal bool OnCompilerError(JScriptException se){
   if (se.Severity == 0 || (this.doWarnAsError && se.Severity <= this.nWarningLevel))
     this.numberOfErrors++;
   bool canRecover = this.engineSite.OnCompilerError(se); //true means carry on with compilation.
   if (!canRecover)
     this.isEngineCompiled = false;
   return canRecover;
 }
 //---------------------------------------------------------------------------------------
 // HandleError
 //
 //  Handle an error. There are two actions that can be taken when an error occurs:
 //    - throwing an exception with no recovering action (eval case)
 //    - notify the host that an error occurred and let the host decide whether or not
 //      parsing has to continue (the host returns true when parsing has to continue)
 //---------------------------------------------------------------------------------------
 
 internal void HandleError(JScriptException error) {
   if (this.sourceItem == null) //Called from eval
     if (error.Severity == 0)
       throw error;
     else
       return;
   if (!this.sourceItem.engine.OnCompilerError(error))
     throw new EndOfFile(); // this exception terminates the parser
 }
 internal bool OnCompilerError(JScriptException se)
 {
     if ((se.Severity == 0) || (this.doWarnAsError && (se.Severity <= this.nWarningLevel)))
     {
         this.numberOfErrors++;
     }
     bool flag = base.engineSite.OnCompilerError(se);
     if (!flag)
     {
         base.isEngineCompiled = false;
     }
     return flag;
 }
예제 #14
0
 public NoContextException() : base(JScriptException.Localize("No Source Context available", CultureInfo.CurrentUICulture))
 {
 }
예제 #15
0
      private void CheckCompatibility() {
        // If reference is agnostic, then compatible
        PortableExecutableKinds RefPEKindFlags;
        ImageFileMachine RefPEMachineArchitecture;
        this.assembly.ManifestModule.GetPEKind(out RefPEKindFlags, out RefPEMachineArchitecture);

        if (RefPEMachineArchitecture == ImageFileMachine.I386 && 
            PortableExecutableKinds.ILOnly == (RefPEKindFlags & (PortableExecutableKinds.ILOnly | PortableExecutableKinds.Required32Bit))) {
          return;          
        }
     
        // Warn if building an agnostic assembly, but referenced assembly is not.
        PortableExecutableKinds PEKindFlags = engine.PEKindFlags;
        ImageFileMachine PEMachineArchitecture = engine.PEMachineArchitecture;
        if (PEMachineArchitecture == ImageFileMachine.I386 && 
            PortableExecutableKinds.ILOnly == (PEKindFlags & (PortableExecutableKinds.ILOnly | PortableExecutableKinds.Required32Bit))) {
          // We are agnostic, but the reference is not. Do not emit a warning - this is a very common
          // case. Many of the system libraries are platform specific.
          return;
        }
        
        // Warning if architectures don't match.
        if (RefPEMachineArchitecture != PEMachineArchitecture) {
          JScriptException e = new JScriptException(JSError.IncompatibleAssemblyReference);
          e.value = this.assemblyName;              
          this.engine.OnCompilerError(e);
        }
      }
예제 #16
0
파일: call.cs 프로젝트: ArildF/masters
 internal override Object Evaluate(){
   if (this.outParameterCount > 0 && VsaEngine.executeForJSEE)
     throw new JScriptException(JSError.RefParamsNonSupportedInDebugger);
   LateBinding funcref = this.func.EvaluateAsLateBinding();
   Object[] actual_arguments = this.args == null ? null : this.args.EvaluateAsArray();
   Globals.CallContextStack.Push(new CallContext(this.context, funcref, actual_arguments));
   try{
     try{
       Object result = null;
       CallableExpression cexpr = this.func as CallableExpression;
       if (cexpr == null || !(cexpr.expression is Call))
         result = funcref.Call(actual_arguments, this.isConstructor, this.inBrackets, this.Engine);
       else
         result = LateBinding.CallValue(funcref.obj, actual_arguments, this.isConstructor, this.inBrackets, this.Engine,
           cexpr.GetObject2(), JSBinder.ob, null, null);
       if (this.outParameterCount > 0)
         for (int i = 0, n = this.args.count; i < n; i++)
           if (this.args[i] is AddressOf)
             this.args[i].SetValue(actual_arguments[i]);
       return result;
     }catch(TargetInvocationException e){
       JScriptException se;
       if (e.InnerException is JScriptException){
         se = (JScriptException)e.InnerException;
         if (se.context == null)
           if (((uint)se.Number) == (0x800A0000|(uint)JSError.ObjectExpected))
             se.context = this.func.context;
           else
             se.context = this.context;
       }else
         se = new JScriptException(e.InnerException, this.context);
       throw se;
     }catch(JScriptException e){
       if (e.context == null){
         if (((uint)e.Number) == (0x800A0000|(uint)JSError.ObjectExpected))
           e.context = this.func.context;
         else
           e.context = this.context;
       }
       throw e;
     }catch(Exception e){
       throw new JScriptException(e, this.context);
     }
   }finally{    
     Globals.CallContextStack.Pop();
   }
 }
예제 #17
0
        internal override Object Evaluate()
        {
            if (this.outParameterCount > 0 && VsaEngine.executeForJSEE)
            {
                throw new JScriptException(JSError.RefParamsNonSupportedInDebugger);
            }
            LateBinding funcref = this.func.EvaluateAsLateBinding();

            Object[] actual_arguments = this.args == null ? null : this.args.EvaluateAsArray();
            Globals.CallContextStack.Push(new CallContext(this.context, funcref, actual_arguments));
            try{
                try{
                    Object             result = null;
                    CallableExpression cexpr  = this.func as CallableExpression;
                    if (cexpr == null || !(cexpr.expression is Call))
                    {
                        result = funcref.Call(actual_arguments, this.isConstructor, this.inBrackets, this.Engine);
                    }
                    else
                    {
                        result = LateBinding.CallValue(funcref.obj, actual_arguments, this.isConstructor, this.inBrackets, this.Engine,
                                                       cexpr.GetObject2(), JSBinder.ob, null, null);
                    }
                    if (this.outParameterCount > 0)
                    {
                        for (int i = 0, n = this.args.count; i < n; i++)
                        {
                            if (this.args[i] is AddressOf)
                            {
                                this.args[i].SetValue(actual_arguments[i]);
                            }
                        }
                    }
                    return(result);
                }catch (TargetInvocationException e) {
                    JScriptException se;
                    if (e.InnerException is JScriptException)
                    {
                        se = (JScriptException)e.InnerException;
                        if (se.context == null)
                        {
                            if (((uint)se.Number) == (0x800A0000 | (uint)JSError.ObjectExpected))
                            {
                                se.context = this.func.context;
                            }
                            else
                            {
                                se.context = this.context;
                            }
                        }
                    }
                    else
                    {
                        se = new JScriptException(e.InnerException, this.context);
                    }
                    throw se;
                }catch (JScriptException e) {
                    if (e.context == null)
                    {
                        if (((uint)e.Number) == (0x800A0000 | (uint)JSError.ObjectExpected))
                        {
                            e.context = this.func.context;
                        }
                        else
                        {
                            e.context = this.context;
                        }
                    }
                    throw e;
                }catch (Exception e) {
                    throw new JScriptException(e, this.context);
                }catch {
                    throw new JScriptException(JSError.NonClsException, this.context);
                }
            }finally{
                Globals.CallContextStack.Pop();
            }
        }
예제 #18
0
 internal override Object Evaluate(){
   int i = Globals.ScopeStack.Size();
   int j = Globals.CallContextStack.Size();
   Completion bc = null;
   Completion fc = null;
   try{
     Object eValue = null;
     try{
       bc = (Completion)this.body.Evaluate();
     }catch(Exception e){
       if (this.handler == null) throw;
       eValue = e;
       if (this.type != null){
         Type ht = this.type.ToType();
         if (Typeob.Exception.IsAssignableFrom(ht)){
           if (!ht.IsInstanceOfType(e)) throw;
         }else if (!ht.IsInstanceOfType(eValue = JScriptExceptionValue(e, this.Engine)))
           throw;
       }else
         eValue = JScriptExceptionValue(e, this.Engine);
     }catch{
       eValue = new JScriptException(JSError.NonClsException);
     }
     
     if (eValue != null) {
       Globals.ScopeStack.TrimToSize(i);
       Globals.CallContextStack.TrimToSize(j);
       if (this.handler_scope != null){
         this.handler_scope.SetParent(Globals.ScopeStack.Peek());
         Globals.ScopeStack.Push(this.handler_scope);
       }
       if (this.field != null)
         this.field.SetValue(Globals.ScopeStack.Peek(), eValue);
       bc = (Completion)this.handler.Evaluate();
     }
   }finally{
     Globals.ScopeStack.TrimToSize(i);
     Globals.CallContextStack.TrimToSize(j);
     if (this.finally_block != null){
       fc = (Completion)this.finally_block.Evaluate();
     }
   }
   if (bc == null || fc != null && (fc.Exit > 0 || fc.Continue > 0 || fc.Return))
     bc = fc;
   else{
     if (fc != null && fc.value is Missing)
       bc.value = fc.value;
   }
   Completion result = new Completion();
   result.Continue = bc.Continue - 1;
   result.Exit = bc.Exit - 1;
   result.Return = bc.Return;
   result.value = bc.value;
   return result;
 }
        public virtual Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target,
                                           Object[] args, ParameterModifier[] modifiers, CultureInfo locale, String[] namedParameters)
        {
            if (target != this)
            {
                throw new TargetException();
            }

            bool preferredTypeSpecified = name.StartsWith("< JScript-", StringComparison.Ordinal);
            bool dispid0 = (name == null || name == String.Empty || name.Equals("[DISPID=0]") || preferredTypeSpecified);

            if ((invokeAttr & BindingFlags.CreateInstance) != 0)
            {
                if ((invokeAttr & (BindingFlags.InvokeMethod | BindingFlags.GetField | BindingFlags.GetProperty |
                                   BindingFlags.SetField | BindingFlags.SetProperty | BindingFlags.PutDispProperty)) != 0)
                {
                    throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
                }
                //js: x = new foo() --> dispid0, create
                if (dispid0)
                {
                    throw new MissingMethodException();
                }

                //js: x = new foo.name() --> dispid0, create
                LateBinding lb = new LateBinding(name, this);
                return(lb.Call(binder, args, modifiers, locale, namedParameters, true, false, this.engine));
            }

            //According to docs, name == null is only valid for CreateInstance
            if (name == null)
            {
                throw new ArgumentException(JScriptException.Localize("Bad name", locale));
            }

            if ((invokeAttr & (BindingFlags.InvokeMethod | BindingFlags.GetField | BindingFlags.GetProperty)) != 0)
            {
                if ((invokeAttr & (BindingFlags.SetField | BindingFlags.SetProperty | BindingFlags.PutDispProperty)) != 0)
                {
                    throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
                }

                if (dispid0)
                {
                    //All callable functions inherit from ScriptFunction which overrides this method to handle
                    //the InvokeMethod case.

                    //js,vbs: x = foo() --> dispid0, invoke
                    if ((invokeAttr & (BindingFlags.GetField | BindingFlags.GetProperty)) == 0)
                    {
                        throw new MissingMethodException();
                    }

                    //js: x = foo --> dispid0, propget; vbs: x = foo --> dispid0, invoke|propget
                    if (args == null || args.Length == 0)
                    {
                        if (this is JSObject || this is GlobalScope || this is ClassScope)
                        {
                            PreferredType preferredType = PreferredType.Either;
                            if (preferredTypeSpecified)
                            {
                                if (name.StartsWith("< JScript-Number", StringComparison.Ordinal))
                                {
                                    preferredType = PreferredType.Number;
                                }
                                else if (name.StartsWith("< JScript-String", StringComparison.Ordinal))
                                {
                                    preferredType = PreferredType.String;
                                }
                                else if (name.StartsWith("< JScript-LocaleString", StringComparison.Ordinal))
                                {
                                    preferredType = PreferredType.LocaleString;
                                }
                            }
                            return(this.GetDefaultValue(preferredType));
                        }
                        throw new MissingFieldException();
                    }

                    //We support indexed properties with exactly one index on all script objects.

                    //js,vbs: x = foo(1,2) --> dispid0, invoke|propget
                    if (args.Length > 1)
                    {
                        throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
                    }

                    //js,vbs: x = foo(1) --> dispid0, invoke|propget
                    Object val = args[0];
                    if (val is Int32)
                    {
                        return(this[(int)val]);
                    }
                    IConvertible ic = Convert.GetIConvertible(val);
                    if (ic != null && Convert.IsPrimitiveNumericTypeCode(ic.GetTypeCode()))
                    {
                        double d = ic.ToDouble(null);
                        if (d >= 0 && d <= Int32.MaxValue && d == System.Math.Round(d))
                        {
                            return(this[(int)d]);
                        }
                    }
                    return(this[Convert.ToString(val)]);
                }

                //If no arguments are supplied, prefer GetXXXX rather than Invoke.
                //js: x = foo.bar --> name="bar", propget; vbs: x = foo.bar --> name="bar", propget|invoke
                if ((args == null || args.Length == 0) && (invokeAttr & (BindingFlags.GetField | BindingFlags.GetProperty)) != 0)
                {
                    Object member = this.GetMemberValue(name);
                    if (member != Missing.Value)
                    {
                        return(member);
                    }

                    //js: x = foo.bar --> name="bar", propget
                    if ((invokeAttr & BindingFlags.InvokeMethod) == 0)
                    {
                        throw new MissingFieldException();
                    }
                }

                //Use LateBinding to call because arguments have been supplied.
                //vbs: x = foo.bar --> name="bar", propget|invoke
                //js,vbs: x = foo.bar() --> name="bar", invoke
                //js,vbs: x = foo.bar(1) --> name="bar", invoke|propget
                LateBinding lb = new LateBinding(name, this);
                return(lb.Call(binder, args, modifiers, locale, namedParameters, false, false, this.engine));
            }

            if ((invokeAttr & (BindingFlags.SetField | BindingFlags.SetProperty | BindingFlags.PutDispProperty)) != 0)
            {
                if (dispid0)
                {
                    if (args == null || args.Length < 2)
                    {
                        throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
                    }
                    else if (args.Length > 2)
                    {
                        throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
                    }
                    Object val = args[0];
                    if (val is Int32)
                    {
                        this[(int)val] = args[1];
                        return(null);
                    }
                    IConvertible ic = Convert.GetIConvertible(val);
                    if (ic != null && Convert.IsPrimitiveNumericTypeCode(ic.GetTypeCode()))
                    {
                        double d = ic.ToDouble(null);
                        if (d >= 0 && d <= Int32.MaxValue && d == System.Math.Round(d))
                        {
                            this[(int)d] = args[1];
                            return(null);
                        }
                    }
                    this[Convert.ToString(val)] = args[1];
                    return(null);
                }
                if (args == null || args.Length < 1)
                {
                    throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
                }
                else if (args.Length > 1)
                {
                    throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
                }
                this.SetMemberValue(name, args[0]);
                return(null);
            }

            throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
        }
 protected override bool DoCompile()
 {
     if (!base.isClosed && !base.isEngineCompiled)
     {
         this.SetUpCompilerEnvironment();
         if (this.PEFileName == null)
         {
             this.PEFileName = this.GenerateRandomPEFileName();
         }
         this.SaveSourceForDebugging();
         this.numberOfErrors = 0;
         base.isEngineCompiled = true;
         this.Globals.ScopeStack.Push(this.GetGlobalScope().GetObject());
         try
         {
             foreach (object obj2 in base.vsaItems)
             {
                 if (obj2 is VsaReference)
                 {
                     ((VsaReference) obj2).Compile();
                 }
             }
             if (base.vsaItems.Count > 0)
             {
                 this.SetEnclosingContext(new WrappedNamespace("", this));
             }
             foreach (object obj3 in base.vsaItems)
             {
                 if (obj3 is VsaHostObject)
                 {
                     ((VsaHostObject) obj3).Compile();
                 }
             }
             foreach (object obj4 in base.vsaItems)
             {
                 if (obj4 is VsaStaticCode)
                 {
                     ((VsaStaticCode) obj4).Parse();
                 }
             }
             foreach (object obj5 in base.vsaItems)
             {
                 if (obj5 is VsaStaticCode)
                 {
                     ((VsaStaticCode) obj5).ProcessAssemblyAttributeLists();
                 }
             }
             foreach (object obj6 in base.vsaItems)
             {
                 if (obj6 is VsaStaticCode)
                 {
                     ((VsaStaticCode) obj6).PartiallyEvaluate();
                 }
             }
             foreach (object obj7 in base.vsaItems)
             {
                 if (obj7 is VsaStaticCode)
                 {
                     ((VsaStaticCode) obj7).TranslateToIL();
                 }
             }
             foreach (object obj8 in base.vsaItems)
             {
                 if (obj8 is VsaStaticCode)
                 {
                     ((VsaStaticCode) obj8).GetCompiledType();
                 }
             }
             if (this.globalScope != null)
             {
                 this.globalScope.Compile();
             }
         }
         catch (JScriptException exception)
         {
             this.OnCompilerError(exception);
         }
         catch (FileLoadException exception2)
         {
             JScriptException se = new JScriptException(JSError.ImplicitlyReferencedAssemblyNotFound) {
                 value = exception2.FileName
             };
             this.OnCompilerError(se);
             base.isEngineCompiled = false;
         }
         catch (EndOfFile)
         {
         }
         catch
         {
             base.isEngineCompiled = false;
             throw;
         }
         finally
         {
             this.Globals.ScopeStack.Pop();
         }
         if (base.isEngineCompiled)
         {
             base.isEngineCompiled = (this.numberOfErrors == 0) || this.alwaysGenerateIL;
         }
     }
     if (this.win32resource != null)
     {
         this.CompilerGlobals.assemblyBuilder.DefineUnmanagedResource(this.win32resource);
     }
     else if (this.compilerGlobals != null)
     {
         this.compilerGlobals.assemblyBuilder.DefineVersionInfoResource();
     }
     if (this.managedResources != null)
     {
         foreach (ResInfo info in this.managedResources)
         {
             if (info.isLinked)
             {
                 this.CompilerGlobals.assemblyBuilder.AddResourceFile(info.name, Path.GetFileName(info.filename), info.isPublic ? ResourceAttributes.Public : ResourceAttributes.Private);
             }
             else
             {
                 try
                 {
                     using (ResourceReader reader = new ResourceReader(info.filename))
                     {
                         IResourceWriter writer = this.CompilerGlobals.module.DefineResource(info.name, info.filename, info.isPublic ? ResourceAttributes.Public : ResourceAttributes.Private);
                         foreach (DictionaryEntry entry in reader)
                         {
                             writer.AddResource((string) entry.Key, entry.Value);
                         }
                     }
                 }
                 catch (ArgumentException)
                 {
                     JScriptException exception4 = new JScriptException(JSError.InvalidResource) {
                         value = info.filename
                     };
                     this.OnCompilerError(exception4);
                     base.isEngineCompiled = false;
                     return false;
                 }
             }
         }
     }
     if (base.isEngineCompiled)
     {
         this.EmitReferences();
     }
     if (base.isEngineCompiled)
     {
         if (this.doSaveAfterCompile)
         {
             if (this.PEFileKind != PEFileKinds.Dll)
             {
                 this.CreateMain();
             }
             try
             {
                 this.compilerGlobals.assemblyBuilder.Save(Path.GetFileName(this.PEFileName), this.PEKindFlags, this.PEMachineArchitecture);
                 goto Label_052D;
             }
             catch (Exception exception5)
             {
                 throw new JSVsaException(JSVsaError.SaveCompiledStateFailed, exception5.Message, exception5);
             }
         }
         if (this.genStartupClass)
         {
             this.CreateStartupClass();
         }
     }
 Label_052D:
     return base.isEngineCompiled;
 }
예제 #21
0
        internal int Compile(CompilerParameters options, string partialCmdLine, string[] sourceFiles, string outputFile)
        {
            StreamWriter output = null;
            int          num    = 0;

            try
            {
                output = new StreamWriter(outputFile)
                {
                    AutoFlush = true
                };
                if (options.IncludeDebugInformation)
                {
                    this.PrintOptions(output, options);
                    this.debugCommandLine = partialCmdLine;
                }
                VsaEngine engine = null;
                try
                {
                    engine = this.CreateAndInitEngine(options, sourceFiles, outputFile, output);
                }
                catch (CmdLineException exception)
                {
                    output.WriteLine(exception.Message);
                    num = 10;
                }
                catch (Exception exception2)
                {
                    output.WriteLine("fatal error JS2999: " + exception2);
                    num = 10;
                }
                if (engine == null)
                {
                    return(num);
                }
                if (options.IncludeDebugInformation)
                {
                    StringBuilder builder = new StringBuilder(this.debugCommandLine);
                    foreach (string str in sourceFiles)
                    {
                        builder.Append(" \"");
                        builder.Append(str);
                        builder.Append("\"");
                    }
                    this.debugCommandLine = builder.ToString();
                    string       path    = options.TempFiles.AddExtension("cmdline");
                    StreamWriter writer2 = null;
                    try
                    {
                        writer2 = new StreamWriter(path);
                        writer2.WriteLine(this.debugCommandLine);
                        writer2.Flush();
                    }
                    finally
                    {
                        if (writer2 != null)
                        {
                            writer2.Close();
                        }
                    }
                    StringBuilder builder2 = new StringBuilder();
                    builder2.Append(Environment.NewLine);
                    builder2.Append(JScriptException.Localize("CmdLine helper", CultureInfo.CurrentUICulture));
                    builder2.Append(":");
                    builder2.Append(Environment.NewLine);
                    builder2.Append("    ");
                    builder2.Append(options.TempFiles.TempDir);
                    builder2.Append("> jsc.exe @\"");
                    builder2.Append(path);
                    builder2.Append("\"");
                    builder2.Append(Environment.NewLine);
                    output.WriteLine(builder2.ToString());
                    this.PrintBanner(engine, output);
                }
                try
                {
                    if (!engine.Compile())
                    {
                        return(10);
                    }
                    return(0);
                }
                catch (JSVsaException exception3)
                {
                    if (exception3.ErrorCode == JSVsaError.AssemblyExpected)
                    {
                        if ((exception3.InnerException != null) && (exception3.InnerException is BadImageFormatException))
                        {
                            CmdLineException exception4 = new CmdLineException(CmdLineError.InvalidAssembly, exception3.Message, engine.ErrorCultureInfo);
                            output.WriteLine(exception4.Message);
                        }
                        else if ((exception3.InnerException != null) && (exception3.InnerException is FileNotFoundException))
                        {
                            CmdLineException exception5 = new CmdLineException(CmdLineError.AssemblyNotFound, exception3.Message, engine.ErrorCultureInfo);
                            output.WriteLine(exception5.Message);
                        }
                        else
                        {
                            CmdLineException exception6 = new CmdLineException(CmdLineError.InvalidAssembly, engine.ErrorCultureInfo);
                            output.WriteLine(exception6.Message);
                        }
                    }
                    else if (exception3.ErrorCode == JSVsaError.SaveCompiledStateFailed)
                    {
                        CmdLineException exception7 = new CmdLineException(CmdLineError.ErrorSavingCompiledState, exception3.Message, engine.ErrorCultureInfo);
                        output.WriteLine(exception7.Message);
                    }
                    else
                    {
                        output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo));
                        output.WriteLine(exception3);
                    }
                    num = 10;
                }
                catch (Exception exception8)
                {
                    output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo));
                    output.WriteLine(exception8);
                    num = 10;
                }
            }
            finally
            {
                if (output != null)
                {
                    output.Close();
                }
            }
            return(num);
        }
예제 #22
0
		// Constructor.
		public ErrorRecovery(JScriptException error)
				{
					this.error = error;
				}
예제 #23
0
 internal ScannerException(JSError errorId) : base(JScriptException.Localize("Scanner Exception", CultureInfo.CurrentUICulture))
 {
     this.m_errorId = errorId;
 }
 internal override object Evaluate()
 {
     object obj3;
     if ((this.outParameterCount > 0) && VsaEngine.executeForJSEE)
     {
         throw new JScriptException(JSError.RefParamsNonSupportedInDebugger);
     }
     LateBinding callee = this.func.EvaluateAsLateBinding();
     object[] objArray = (this.args == null) ? null : this.args.EvaluateAsArray();
     base.Globals.CallContextStack.Push(new CallContext(base.context, callee, objArray));
     try
     {
         object obj2 = null;
         CallableExpression func = this.func as CallableExpression;
         if ((func == null) || !(func.expression is Call))
         {
             obj2 = callee.Call(objArray, this.isConstructor, this.inBrackets, base.Engine);
         }
         else
         {
             obj2 = LateBinding.CallValue(callee.obj, objArray, this.isConstructor, this.inBrackets, base.Engine, func.GetObject2(), JSBinder.ob, null, null);
         }
         if (this.outParameterCount > 0)
         {
             int index = 0;
             int count = this.args.count;
             while (index < count)
             {
                 if (this.args[index] is AddressOf)
                 {
                     this.args[index].SetValue(objArray[index]);
                 }
                 index++;
             }
         }
         obj3 = obj2;
     }
     catch (TargetInvocationException exception)
     {
         JScriptException innerException;
         if (exception.InnerException is JScriptException)
         {
             innerException = (JScriptException) exception.InnerException;
             if (innerException.context == null)
             {
                 if (innerException.Number == -2146823281)
                 {
                     innerException.context = this.func.context;
                 }
                 else
                 {
                     innerException.context = base.context;
                 }
             }
         }
         else
         {
             innerException = new JScriptException(exception.InnerException, base.context);
         }
         throw innerException;
     }
     catch (JScriptException exception3)
     {
         if (exception3.context == null)
         {
             if (exception3.Number == -2146823281)
             {
                 exception3.context = this.func.context;
             }
             else
             {
                 exception3.context = base.context;
             }
         }
         throw exception3;
     }
     catch (Exception exception4)
     {
         throw new JScriptException(exception4, base.context);
     }
     finally
     {
         base.Globals.CallContextStack.Pop();
     }
     return obj3;
 }
 internal ParserException() : base(JScriptException.Localize("Parser Exception", CultureInfo.CurrentUICulture))
 {
 }
예제 #26
0
 internal static String Localize(String key, CultureInfo culture)
 {
     return(JScriptException.Localize(key, null, culture));
 }
예제 #27
0
        internal override object Evaluate()
        {
            object obj3;

            if ((this.outParameterCount > 0) && VsaEngine.executeForJSEE)
            {
                throw new JScriptException(JSError.RefParamsNonSupportedInDebugger);
            }
            LateBinding callee = this.func.EvaluateAsLateBinding();

            object[] objArray = (this.args == null) ? null : this.args.EvaluateAsArray();
            base.Globals.CallContextStack.Push(new CallContext(base.context, callee, objArray));
            try
            {
                object             obj2 = null;
                CallableExpression func = this.func as CallableExpression;
                if ((func == null) || !(func.expression is Call))
                {
                    obj2 = callee.Call(objArray, this.isConstructor, this.inBrackets, base.Engine);
                }
                else
                {
                    obj2 = LateBinding.CallValue(callee.obj, objArray, this.isConstructor, this.inBrackets, base.Engine, func.GetObject2(), JSBinder.ob, null, null);
                }
                if (this.outParameterCount > 0)
                {
                    int index = 0;
                    int count = this.args.count;
                    while (index < count)
                    {
                        if (this.args[index] is AddressOf)
                        {
                            this.args[index].SetValue(objArray[index]);
                        }
                        index++;
                    }
                }
                obj3 = obj2;
            }
            catch (TargetInvocationException exception)
            {
                JScriptException innerException;
                if (exception.InnerException is JScriptException)
                {
                    innerException = (JScriptException)exception.InnerException;
                    if (innerException.context == null)
                    {
                        if (innerException.Number == -2146823281)
                        {
                            innerException.context = this.func.context;
                        }
                        else
                        {
                            innerException.context = base.context;
                        }
                    }
                }
                else
                {
                    innerException = new JScriptException(exception.InnerException, base.context);
                }
                throw innerException;
            }
            catch (JScriptException exception3)
            {
                if (exception3.context == null)
                {
                    if (exception3.Number == -2146823281)
                    {
                        exception3.context = this.func.context;
                    }
                    else
                    {
                        exception3.context = base.context;
                    }
                }
                throw exception3;
            }
            catch (Exception exception4)
            {
                throw new JScriptException(exception4, base.context);
            }
            finally
            {
                base.Globals.CallContextStack.Pop();
            }
            return(obj3);
        }
예제 #28
0
 internal void HandleError(JSError errorId, String message, bool treatAsError) {
   if (errorId == JSError.UndeclaredVariable && this.document.HasAlreadySeenErrorFor(this.GetCode()))
     return;
   JScriptException error = new JScriptException(errorId, this);
   if (message != null)
     error.value = message;
   if (treatAsError)
     error.isError = treatAsError;
   int sev = error.Severity;
   if (sev < this.errorReported){
     this.document.HandleError(error);
     this.errorReported = sev;
   }
 }
예제 #29
0
	// Report a syntax error at the current token, and start error recovery.
	private void SyntaxError(Context tokenInfo, String msg)
			{
				++numErrors;
				JScriptException e = new JScriptException
					(JSError.SyntaxError, tokenInfo.MakeCopy());
				e.message = msg;
				if(context.codebase != null && context.codebase.site != null)
				{
					if(context.codebase.site.OnCompilerError(e))
					{
						// The site wants us to perform error recovery.
						throw new ErrorRecovery(e);
					}
				}
				throw e;
			}
 internal void HandleError(JScriptException error)
 {
     if (this.sourceItem == null)
     {
         if (error.Severity == 0)
         {
             throw error;
         }
     }
     else if (!this.sourceItem.engine.OnCompilerError(error))
     {
         throw new EndOfFile();
     }
 }
예제 #31
0
파일: vsaengine.cs 프로젝트: ArildF/masters
      protected override bool DoCompile(){
        if (!this.isClosed && !this.isEngineCompiled){
          this.SetUpCompilerEnvironment();
          if (this.PEFileName == null){
            // we use random default names to avoid overwriting cached assembly files when debugging VSA
            this.PEFileName = this.GenerateRandomPEFileName();
          }
          this.SaveSourceForDebugging();  // Save sources needed for debugging (does nothing if no debug info)
          this.numberOfErrors = 0;        // Records number of errors during compilation.
          this.isEngineCompiled = true;         // OnCompilerError sets to false if it encounters an unrecoverable error.
          Globals.ScopeStack.Push(this.GetGlobalScope().GetObject());
          try{
            try{
              foreach (Object item in this.vsaItems){
                Debug.Assert(item is VsaReference || item is VsaStaticCode || item is VsaHostObject);
                if (item is VsaReference)
                  ((VsaReference)item).Compile(); //Load the assembly into memory.
              }
              if (this.vsaItems.Count > 0)
                this.SetEnclosingContext(new WrappedNamespace("", this)); //Provide a way to find types that are not inside of a name space
              // Add VSA global items to the global scope
              foreach (Object item in this.vsaItems){
                if (item is VsaHostObject)
                  ((VsaHostObject)item).Compile();
              }
              foreach (Object item in this.vsaItems){
                if (item is VsaStaticCode)
                  ((VsaStaticCode)item).Parse();
              }
              foreach (Object item in this.vsaItems){
                if (item is VsaStaticCode)
                  ((VsaStaticCode)item).ProcessAssemblyAttributeLists();
              }
              foreach (Object item in this.vsaItems){
                if (item is VsaStaticCode)
                  ((VsaStaticCode)item).PartiallyEvaluate();
              }
              foreach (Object item in this.vsaItems){
                if (item is VsaStaticCode)
                  ((VsaStaticCode)item).TranslateToIL();
              }
              foreach (Object item in this.vsaItems){
                if (item is VsaStaticCode)
                  ((VsaStaticCode)item).GetCompiledType();
              }
              if (null != this.globalScope)
                this.globalScope.Compile(); //In case the host added items to the global scope
            }catch(JScriptException se){
              // It's a bit strange because we may be capturing an exception 
              // thrown by VsaEngine.OnCompilerError (in the case where 
              // this.engineSite is null. This is fine though. All we end up doing
              // is capturing and then rethrowing the same error.
              this.OnCompilerError(se);
            }catch(System.IO.FileLoadException e){
              JScriptException se = new JScriptException(JSError.ImplicitlyReferencedAssemblyNotFound);
              se.value = e.FileName;
              this.OnCompilerError(se);
              this.isEngineCompiled = false;
            }catch(EndOfFile){
              // an error was reported during PartiallyEvaluate and the host decided to abort
              // swallow the exception and keep going
            }catch(Exception){
              // internal compiler error -- make sure we don't claim to have compiled, then rethrow
              this.isEngineCompiled = false;
              throw;
            }
          }finally{
            Globals.ScopeStack.Pop();
          }
          if (this.isEngineCompiled){
            // there were no unrecoverable errors, but we want to return true only if there is IL
            this.isEngineCompiled = (this.numberOfErrors == 0 || this.alwaysGenerateIL);
          }
        }

        if (this.managedResources != null){
          foreach (ResInfo managedResource in this.managedResources){
            if (managedResource.isLinked){
              this.CompilerGlobals.assemblyBuilder.AddResourceFile(managedResource.name,
                                                              Path.GetFileName(managedResource.filename),
                                                              managedResource.isPublic?
                                                              ResourceAttributes.Public:
                                                              ResourceAttributes.Private);
            }else{
              ResourceReader reader = null;
              try{
                reader = new ResourceReader(managedResource.filename);
              }catch(System.ArgumentException){
                JScriptException se = new JScriptException(JSError.InvalidResource);
                se.value = managedResource.filename;
                this.OnCompilerError(se);
                this.isEngineCompiled = false;
                return false;
              }
              IResourceWriter writer = this.CompilerGlobals.module.DefineResource(managedResource.name,
                                                                                  managedResource.filename,
                                                                                  managedResource.isPublic?
                                                                                  ResourceAttributes.Public:
                                                                                  ResourceAttributes.Private);
              foreach (DictionaryEntry resource in reader)
                writer.AddResource((string)resource.Key, resource.Value);
              reader.Close();
            }
          }
        }

        if (this.isEngineCompiled)
          this.EmitReferences();

        // Save things out to a local PE file when doSaveAfterCompile is set; this is set when an
        // output name is given (allows JSC to avoid IVsaEngine.SaveCompiledState).  The proper
        // values for VSA are doSaveAfterCompile == false and genStartupClass == true.  We allow
        // genStartupClass to be false for scenarios like JSTest and the Debugger
        if (this.isEngineCompiled){
          if (this.doSaveAfterCompile){
            if (this.PEFileKind != PEFileKinds.Dll)
              this.CreateMain();
            try {
              // After executing this code path, it is an error to call SaveCompiledState (until the engine is recompiled)
              compilerGlobals.assemblyBuilder.Save(Path.GetFileName(this.PEFileName));
            }catch(Exception e){
              throw new VsaException(VsaError.SaveCompiledStateFailed, e.Message, e);
            }
          }else if (this.genStartupClass){
            // this is generated for VSA hosting
            this.CreateStartupClass();
          }
        }
        return this.isEngineCompiled;
      }
 internal void HandleError(JSError errorId, string message, bool treatAsError)
 {
     if ((errorId != JSError.UndeclaredVariable) || !this.document.HasAlreadySeenErrorFor(this.GetCode()))
     {
         JScriptException error = new JScriptException(errorId, this);
         if (message != null)
         {
             error.value = message;
         }
         if (treatAsError)
         {
             error.isError = treatAsError;
         }
         int severity = error.Severity;
         if (severity < this.errorReported)
         {
             this.document.HandleError(error);
             this.errorReported = severity;
         }
     }
 }
예제 #33
0
        internal int Compile(CompilerParameters options, string partialCmdLine, string[] sourceFiles, string outputFile)
        {
            // write compiler output to a stream with outputFile as the name
            StreamWriter output            = null;
            int          nativeReturnValue = 0;

            try
            {
                // Compiler output must be UTF-8 encoded
                output           = new StreamWriter(outputFile);
                output.AutoFlush = true;
                if (options.IncludeDebugInformation)
                {
                    Debug.Assert(partialCmdLine != null);
                    this.PrintOptions(output, options);
                    this.debugCommandLine = partialCmdLine;
                }
                VsaEngine engine = null;
                try
                {
                    engine = this.CreateAndInitEngine(options, sourceFiles, outputFile, output);
                }
                catch (CmdLineException e)
                {
                    output.WriteLine(e.Message);
                    nativeReturnValue = 10;
                }
                catch (Exception e)
                {
                    output.WriteLine("fatal error JS2999: " + e);
                    nativeReturnValue = 10;
                }
                catch
                {
                    output.WriteLine("fatal error JS2999");
                    nativeReturnValue = 10;
                }
                if (engine == null)
                {
                    return(nativeReturnValue);
                }
                if (options.IncludeDebugInformation)
                {
                    // this.debugCommandLine was completed during CreateAndInitEngine (except for filenames)
                    StringBuilder fullCmdLine = new StringBuilder(this.debugCommandLine);
                    foreach (string sourceFile in sourceFiles)
                    {
                        fullCmdLine.Append(" \"");
                        fullCmdLine.Append(sourceFile);
                        fullCmdLine.Append("\"");
                    }
                    this.debugCommandLine = fullCmdLine.ToString();
                    // write the full command line to a response file for debugging
                    string       responseFileName = options.TempFiles.AddExtension("cmdline");
                    StreamWriter responseFile     = null;
                    try
                    {
                        responseFile = new StreamWriter(responseFileName);
                        responseFile.WriteLine(this.debugCommandLine);
                        responseFile.Flush();
                    }
                    finally
                    {
                        if (responseFile != null)
                        {
                            responseFile.Close();
                        }
                    }
                    // show full debug command line in compiler output
                    StringBuilder sb = new StringBuilder();
                    sb.Append(Environment.NewLine);
                    sb.Append(JScriptException.Localize("CmdLine helper", CultureInfo.CurrentUICulture));
                    sb.Append(":");
                    sb.Append(Environment.NewLine);
                    sb.Append("    ");
                    sb.Append(options.TempFiles.TempDir);
                    sb.Append("> jsc.exe @\"");
                    sb.Append(responseFileName);
                    sb.Append("\"");
                    sb.Append(Environment.NewLine);
                    output.WriteLine(sb.ToString());
                    this.PrintBanner(engine, output);
                }
                try
                {
                    if (!engine.Compile())
                    {
                        nativeReturnValue = 10;
                    }
                    else
                    {
                        nativeReturnValue = 0;
                    }
                }
                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, engine.ErrorCultureInfo);
                            output.WriteLine(cmdLineError.Message);
                        }
                        else if (e.InnerException != null && e.InnerException is System.IO.FileNotFoundException)
                        {
                            // the referenced file not valid
                            CmdLineException cmdLineError = new CmdLineException(CmdLineError.AssemblyNotFound, e.Message, engine.ErrorCultureInfo);
                            output.WriteLine(cmdLineError.Message);
                        }
                        else
                        {
                            CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, engine.ErrorCultureInfo);
                            output.WriteLine(cmdLineError.Message);
                        }
                    }
                    else if (e.ErrorCode == VsaError.SaveCompiledStateFailed)
                    {
                        CmdLineException cmdLineError = new CmdLineException(CmdLineError.ErrorSavingCompiledState, e.Message, engine.ErrorCultureInfo);
                        output.WriteLine(cmdLineError.Message);
                    }
                    else
                    {
                        output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo));
                        output.WriteLine(e);
                    }
                    nativeReturnValue = 10;
                }
                catch (Exception e)
                {
                    output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo));
                    output.WriteLine(e);
                    nativeReturnValue = 10;
                }
                catch
                {
                    output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo));
                    nativeReturnValue = 10;
                }
            }
            finally
            {
                if (output != null)
                {
                    output.Close();
                }
            }
            return(nativeReturnValue);
        }
예제 #34
0
        public virtual object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo locale, string[] namedParameters)
        {
            if (target != this)
            {
                throw new TargetException();
            }
            bool flag  = name.StartsWith("< JScript-", StringComparison.Ordinal);
            bool flag2 = (((name == null) || (name == string.Empty)) || name.Equals("[DISPID=0]")) || flag;

            if ((invokeAttr & BindingFlags.CreateInstance) != BindingFlags.Default)
            {
                if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.GetProperty | BindingFlags.SetField | BindingFlags.GetField | BindingFlags.InvokeMethod)) != BindingFlags.Default)
                {
                    throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
                }
                if (flag2)
                {
                    throw new MissingMethodException();
                }
                LateBinding binding = new LateBinding(name, this);
                return(binding.Call(binder, args, modifiers, locale, namedParameters, true, false, this.engine));
            }
            if (name == null)
            {
                throw new ArgumentException(JScriptException.Localize("Bad name", locale));
            }
            if ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField | BindingFlags.InvokeMethod)) != BindingFlags.Default)
            {
                if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.SetField)) != BindingFlags.Default)
                {
                    throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
                }
                if (flag2)
                {
                    if ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField)) == BindingFlags.Default)
                    {
                        throw new MissingMethodException();
                    }
                    if ((args == null) || (args.Length == 0))
                    {
                        if ((!(this is JSObject) && !(this is GlobalScope)) && !(this is ClassScope))
                        {
                            throw new MissingFieldException();
                        }
                        PreferredType either = PreferredType.Either;
                        if (flag)
                        {
                            if (name.StartsWith("< JScript-Number", StringComparison.Ordinal))
                            {
                                either = PreferredType.Number;
                            }
                            else if (name.StartsWith("< JScript-String", StringComparison.Ordinal))
                            {
                                either = PreferredType.String;
                            }
                            else if (name.StartsWith("< JScript-LocaleString", StringComparison.Ordinal))
                            {
                                either = PreferredType.LocaleString;
                            }
                        }
                        return(this.GetDefaultValue(either));
                    }
                    if (args.Length > 1)
                    {
                        throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
                    }
                    object ob = args[0];
                    if (ob is int)
                    {
                        return(this[(int)ob]);
                    }
                    IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(ob);
                    if ((iConvertible != null) && Microsoft.JScript.Convert.IsPrimitiveNumericTypeCode(iConvertible.GetTypeCode()))
                    {
                        double a = iConvertible.ToDouble(null);
                        if (((a >= 0.0) && (a <= 2147483647.0)) && (a == Math.Round(a)))
                        {
                            return(this[(int)a]);
                        }
                    }
                    return(this[Microsoft.JScript.Convert.ToString(ob)]);
                }
                if (((args == null) || (args.Length == 0)) && ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField)) != BindingFlags.Default))
                {
                    object memberValue = this.GetMemberValue(name);
                    if (memberValue != Microsoft.JScript.Missing.Value)
                    {
                        return(memberValue);
                    }
                    if ((invokeAttr & BindingFlags.InvokeMethod) == BindingFlags.Default)
                    {
                        throw new MissingFieldException();
                    }
                }
                LateBinding binding2 = new LateBinding(name, this);
                return(binding2.Call(binder, args, modifiers, locale, namedParameters, false, false, this.engine));
            }
            if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.SetField)) == BindingFlags.Default)
            {
                throw new ArgumentException(JScriptException.Localize("Bad binding flags", locale));
            }
            if (flag2)
            {
                if ((args == null) || (args.Length < 2))
                {
                    throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
                }
                if (args.Length > 2)
                {
                    throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
                }
                object obj4 = args[0];
                if (obj4 is int)
                {
                    this[(int)obj4] = args[1];
                    return(null);
                }
                IConvertible convertible2 = Microsoft.JScript.Convert.GetIConvertible(obj4);
                if ((convertible2 != null) && Microsoft.JScript.Convert.IsPrimitiveNumericTypeCode(convertible2.GetTypeCode()))
                {
                    double num2 = convertible2.ToDouble(null);
                    if (((num2 >= 0.0) && (num2 <= 2147483647.0)) && (num2 == Math.Round(num2)))
                    {
                        this[(int)num2] = args[1];
                        return(null);
                    }
                }
                this[Microsoft.JScript.Convert.ToString(obj4)] = args[1];
                return(null);
            }
            if ((args == null) || (args.Length < 1))
            {
                throw new ArgumentException(JScriptException.Localize("Too few arguments", locale));
            }
            if (args.Length > 1)
            {
                throw new ArgumentException(JScriptException.Localize("Too many arguments", locale));
            }
            this.SetMemberValue(name, args[0]);
            return(null);
        }