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); }
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)); }
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); }
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); }
internal ParserException() : base(JScriptException.Localize("Parser Exception", CultureInfo.CurrentUICulture)) { }
public NoContextException() : base(JScriptException.Localize("No Source Context available", CultureInfo.CurrentUICulture)) { }
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); }
internal static String Localize(String key, CultureInfo culture) { return(JScriptException.Localize(key, null, culture)); }
internal ScannerException(JSError errorId) : base(JScriptException.Localize("Scanner Exception", CultureInfo.CurrentUICulture)) { this.m_errorId = errorId; }
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)); }
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); }