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; }
public JSScanner(Context sourceContext) { this.IsAuthoring = false; this.peekModeOn = false; this.keywords = s_Keywords; this.preProcessorOn = false; this.matchIf = 0; this.ppTable = null; this.SetSource(sourceContext); this.currentDocument = null; this.globals = sourceContext.document.engine.Globals; }
//--------------------------------------------------------------------------------------- // JSParser // // create a parser with a context. The context is the code that has to be compiled. // Typically used by the runtime //--------------------------------------------------------------------------------------- public JSParser(Context context){ this.sourceContext = context; this.currentToken = context.Clone(); this.scanner = new JSScanner(this.currentToken); this.noSkipTokenSet = new NoSkipTokenSet(); this.errorToken = null; this.program = null; this.blockType = new ArrayList(16); this.labelTable = new SimpleHashtable(16); this.finallyEscaped = 0; this.Globals = context.document.engine.Globals; this.Severity = 5; }
public JSScanner(){ this.keywords = JSScanner.s_Keywords; this.strSourceCode = null; this.startPos = 0; this.endPos = 0; this.currentPos = 0; this.currentLine = 1; this.startLinePos = 0; this.currentToken = null; this.escapedString = null; this.identifier = new StringBuilder(128); this.idLastPosOnBuilder = 0; this.gotEndOfLine = false; this.IsAuthoring = false; this.peekModeOn = false; this.preProcessorOn = false; this.matchIf = 0; this.ppTable = null; this.currentDocument = null; this.globals = null; this.scanForDebugger = false; }
protected override void ResetCompiledState(){ if (this.globalScope != null){ this.globalScope.Reset(); this.globalScope = null; } this.classCounter = 0; this.haveCompiledState = false; this.failedCompilation = true; this.compiledRootNamespace = null; this.startupClass = null; this.compilerGlobals = null; this.globals = null; foreach (Object item in this.vsaItems) ((VsaItem)item).Reset(); this.implicitAssemblies = null; this.implicitAssemblyCache = null; this.cachedTypeLookups = null; this.isEngineCompiled = false; this.isEngineRunning = false; this.isCompilerSet = false; this.packages = null; this.DeleteCachedCompiledState(); }
public VsaEngine(bool fast) : base("JScript", "7.0.3300.0", true){ this.alwaysGenerateIL = false; this.autoRef = false; this.doCRS = false; this.doFast = fast; this.cachedPEFileName = ""; this.genDebugInfo = false; this.genStartupClass = true; this.doPrint = false; this.doWarnAsError = false; this.nWarningLevel = 4; this.isCLSCompliant = false; this.versionSafe = false; this.PEFileName = null; this.PEFileKind = PEFileKinds.Dll; this.errorCultureInfo = null; this.libpath = null; this.libpathList = null; this.globalScope = null; this.vsaItems = new VsaItems(this); this.packages = null; this.scopes = null; this.classCounter = 0; this.implicitAssemblies = null; this.implicitAssemblyCache = null; this.cachedTypeLookups = null; this.isEngineRunning = false; this.isEngineCompiled = false; this.isCompilerSet = false; this.isClosed = false; this.runningThread = null; this.compilerGlobals = null; this.globals = null; this.runtimeDirectory = null; Globals.contextEngine = this; this.runtimeAssembly = null; this.typenameTable = null; }
protected override void DoClose(){ ((VsaItems)this.vsaItems).Close(); if (null != this.globalScope) this.globalScope.Close(); this.vsaItems = null; this.engineSite = null; this.globalScope = null; this.runningThread = null; this.compilerGlobals = null; this.globals = null; ScriptStream.Out = Console.Out; ScriptStream.Error = Console.Error; this.DeleteCachedCompiledState(); this.isClosed = true; // The following calls ensure that all pointers to unmanaged objects get properly released // and avoid memory leaks on shutdown. GC.Collect() should be enough by itself when COM+ // takes care of the second automatically. GC.Collect(); }
internal void SetUpCompilerEnvironment(){ if (!this.isCompilerSet){ this.globals = this.Globals; this.isCompilerSet = true; } }
// the debugger restart the engine to run different expression evaluation public virtual void Restart(){ this.TryObtainLock(); try{ ((VsaItems)this.vsaItems).Close(); if (null != this.globalScope) this.globalScope.Close(); this.globalScope = null; this.vsaItems = new VsaItems(this); this.isEngineRunning = false; this.isEngineCompiled = false; this.isCompilerSet = false; this.isClosed = false; this.runningThread = null; this.globals = null; // These are the same as the calls in Close(). Ideally, they should be necessary only in Close(), // but actually the debugger leaks memory on shutdown if they are not present at both places. GC.Collect(); }finally{ this.ReleaseLock(); } }
internal void SetUpCompilerEnvironment(){ if (!this.isCompilerSet){ Microsoft.JScript.Globals.TypeRefs = this.TypeRefs; this.globals = this.Globals; this.isCompilerSet = true; } }
public void Restart(){ this.TryObtainLock(); try{ ((VsaItems)this.vsaItems).Close(); if (null != this.globalScope) this.globalScope.Close(); this.globalScope = null; this.vsaItems = new VsaItems(this); this.isEngineRunning = false; this.isEngineCompiled = false; this.isCompilerSet = false; this.isClosed = false; this.runningThread = null; this.globals = null; }finally{ this.ReleaseLock(); } }
public VsaEngine(bool fast) : base("JScript", VsaEngine.engineVersion, true){ this.alwaysGenerateIL = false; this.autoRef = false; this.doCRS = false; this.doFast = fast; this.genDebugInfo = false; this.genStartupClass = true; this.doPrint = false; this.doWarnAsError = false; this.nWarningLevel = 4; this.isCLSCompliant = false; this.versionSafe = false; this.PEFileName = null; this.PEFileKind = PEFileKinds.Dll; this.PEKindFlags = PortableExecutableKinds.ILOnly; this.PEMachineArchitecture = ImageFileMachine.I386; this.ReferenceLoaderAPI = LoaderAPI.LoadFrom; this.errorCultureInfo = null; this.libpath = null; this.libpathList = null; this.globalScope = null; this.vsaItems = new VsaItems(this); this.packages = null; this.scopes = null; this.classCounter = 0; this.implicitAssemblies = null; this.implicitAssemblyCache = null; this.cachedTypeLookups = null; this.isEngineRunning = false; this.isEngineCompiled = false; this.isCompilerSet = false; this.isClosed = false; this.runningThread = null; this.compilerGlobals = null; this.globals = null; this.runtimeDirectory = null; Globals.contextEngine = this; this.runtimeAssembly = null; this.typenameTable = null; }
internal FunctionObject(string name, ParameterDeclaration[] parameter_declarations, TypeExpression return_type_expr, Block body, FunctionScope own_scope, ScriptObject enclosing_scope, Context funcContext, MethodAttributes attributes, CustomAttributeList customAttributes, bool isMethod) : base(body.Globals.globalObject.originalFunction.originalPrototype, name, parameter_declarations.Length) { this.parameter_declarations = parameter_declarations; int length = parameter_declarations.Length; this.formal_parameters = new string[length]; for (int i = 0; i < length; i++) { this.formal_parameters[i] = parameter_declarations[i].identifier; } this.argumentsSlotNumber = 0; this.return_type_expr = return_type_expr; if (this.return_type_expr != null) { own_scope.AddReturnValueField(); } this.body = body; this.method = null; this.parameterInfos = null; this.funcContext = funcContext; this.own_scope = own_scope; this.own_scope.owner = this; if ((!(enclosing_scope is ActivationObject) || !((ActivationObject) enclosing_scope).fast) && !isMethod) { this.argumentsSlotNumber = this.own_scope.GetNextSlotNumber(); JSLocalField field = (JSLocalField) this.own_scope.AddNewField("arguments", null, FieldAttributes.PrivateScope); field.type = new TypeExpression(new ConstantWrapper(Typeob.Object, funcContext)); field.isDefined = true; this.hasArgumentsObject = true; } else { this.hasArgumentsObject = false; } this.implementedIface = null; this.implementedIfaceMethod = null; this.isMethod = isMethod; this.isExpandoMethod = (customAttributes != null) && customAttributes.ContainsExpandoAttribute(); this.isStatic = this.own_scope.isStatic = (attributes & MethodAttributes.Static) != MethodAttributes.PrivateScope; this.suppressIL = false; this.noVersionSafeAttributeSpecified = true; this.fields = this.own_scope.GetLocalFields(); this.enclosing_scope = enclosing_scope; this.must_save_stack_locals = false; this.text = null; this.mb = null; this.cb = null; this.attributes = attributes; if (!this.isStatic) { this.attributes |= MethodAttributes.HideBySig; } this.globals = body.Globals; this.superConstructor = null; this.superConstructorCall = null; this.customAttributes = customAttributes; base.noExpando = false; this.clsCompliance = CLSComplianceSpec.NotAttributed; this.engineLocal = null; this.partiallyEvaluated = false; }
internal CompilerGlobals(VsaEngine engine, string assemName, string assemblyFileName, PEFileKinds PEFileKind, bool save, bool run, bool debugOn, bool isCLSCompliant, Version version, Globals globals) { string fileName = null; string dir = null; if (assemblyFileName != null) { try { dir = Path.GetDirectoryName(Path.GetFullPath(assemblyFileName)); } catch (Exception exception) { throw new JSVsaException(JSVsaError.AssemblyNameInvalid, assemblyFileName, exception); } fileName = Path.GetFileName(assemblyFileName); if ((assemName == null) || (string.Empty == assemName)) { assemName = Path.GetFileName(assemblyFileName); if (Path.HasExtension(assemName)) { assemName = assemName.Substring(0, assemName.Length - Path.GetExtension(assemName).Length); } } } if ((assemName == null) || (assemName == string.Empty)) { assemName = "JScriptAssembly"; } if (fileName == null) { if (PEFileKind == PEFileKinds.Dll) { fileName = "JScriptModule.dll"; } else { fileName = "JScriptModule.exe"; } } AssemblyName name = new AssemblyName { CodeBase = assemblyFileName }; if (globals.assemblyCulture != null) { name.CultureInfo = globals.assemblyCulture; } name.Flags = AssemblyNameFlags.None; if ((globals.assemblyFlags & AssemblyFlags.PublicKey) != AssemblyFlags.SideBySideCompatible) { name.Flags = AssemblyNameFlags.PublicKey; } AssemblyFlags flags = globals.assemblyFlags & AssemblyFlags.CompatibilityMask; if (flags == AssemblyFlags.NonSideBySideAppDomain) { name.VersionCompatibility = AssemblyVersionCompatibility.SameDomain; } else if (flags == AssemblyFlags.NonSideBySideProcess) { name.VersionCompatibility = AssemblyVersionCompatibility.SameProcess; } else if (flags == AssemblyFlags.NonSideBySideMachine) { name.VersionCompatibility = AssemblyVersionCompatibility.SameMachine; } else { name.VersionCompatibility = (AssemblyVersionCompatibility) 0; } name.HashAlgorithm = globals.assemblyHashAlgorithm; if (globals.assemblyKeyFileName != null) { try { using (FileStream stream = new FileStream(globals.assemblyKeyFileName, FileMode.Open, FileAccess.Read)) { StrongNameKeyPair pair = new StrongNameKeyPair(stream); if (globals.assemblyDelaySign) { if (stream.Length == 160L) { byte[] buffer = new byte[160]; stream.Seek(0L, SeekOrigin.Begin); stream.Read(buffer, 0, 160); name.SetPublicKey(buffer); } else { name.SetPublicKey(pair.PublicKey); } } else { byte[] publicKey = pair.PublicKey; name.KeyPair = pair; } } goto Label_024E; } catch { globals.assemblyKeyFileNameContext.HandleError(JSError.InvalidAssemblyKeyFile, globals.assemblyKeyFileName); goto Label_024E; } } if (globals.assemblyKeyName != null) { try { StrongNameKeyPair pair2 = new StrongNameKeyPair(globals.assemblyKeyName); byte[] buffer2 = pair2.PublicKey; name.KeyPair = pair2; } catch { globals.assemblyKeyNameContext.HandleError(JSError.InvalidAssemblyKeyFile, globals.assemblyKeyName); } } Label_024E: name.Name = assemName; if (version != null) { name.Version = version; } else if (globals.assemblyVersion != null) { name.Version = globals.assemblyVersion; } AssemblyBuilderAccess reflectionOnly = save ? (run ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Save) : AssemblyBuilderAccess.Run; if (engine.ReferenceLoaderAPI == LoaderAPI.ReflectionOnlyLoadFrom) { reflectionOnly = AssemblyBuilderAccess.ReflectionOnly; } if (globals.engine.genStartupClass) { this.assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(name, reflectionOnly, dir, globals.engine.Evidence); } else { this.assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(name, reflectionOnly, dir); } if (save) { this.module = this.assemblyBuilder.DefineDynamicModule("JScript Module", fileName, debugOn); } else { this.module = this.assemblyBuilder.DefineDynamicModule("JScript Module", debugOn); } if (isCLSCompliant) { this.module.SetCustomAttribute(new CustomAttributeBuilder(clsCompliantAttributeCtor, new object[] { isCLSCompliant })); } if (debugOn) { ConstructorInfo constructor = Typeob.DebuggableAttribute.GetConstructor(new Type[] { Typeob.Boolean, Typeob.Boolean }); this.assemblyBuilder.SetCustomAttribute(new CustomAttributeBuilder(constructor, new object[] { (globals.assemblyFlags & AssemblyFlags.EnableJITcompileTracking) != AssemblyFlags.SideBySideCompatible, (globals.assemblyFlags & AssemblyFlags.DisableJITcompileOptimizer) != AssemblyFlags.SideBySideCompatible })); } this.compilationEvidence = globals.engine.Evidence; this.classwriter = null; }
protected override void DoClose(){ ((VsaItems)this.vsaItems).Close(); if (null != this.globalScope) this.globalScope.Close(); this.vsaItems = null; this.engineSite = null; this.globalScope = null; this.runningThread = null; this.compilerGlobals = null; this.globals = null; ScriptStream.Out = Console.Out; ScriptStream.Error = Console.Error; this.rawPE = null; this.rawPDB = null; this.isClosed = true; if (this.tempDirectory != null && Directory.Exists(this.tempDirectory)) Directory.Delete(this.tempDirectory); }
internal CompilerGlobals(VsaEngine engine, String assemName, String assemblyFileName, PEFileKinds PEFileKind, bool save, bool run, bool debugOn, bool isCLSCompliant, Version version, Globals globals) { String moduleFileName = null; String directory = null; //Default has assembly stored in current directory if (assemblyFileName != null){ //The directory is an absolute path where the assembly is written try{ directory = Path.GetDirectoryName(Path.GetFullPath(assemblyFileName)); }catch(Exception e){ throw new VsaException(VsaError.AssemblyNameInvalid, assemblyFileName, e); }catch{ throw new JScriptException(JSError.NonClsException); } //For a single file assembly module filename is set to assembly filename moduleFileName = Path.GetFileName(assemblyFileName); //If simple name is not specified, get it by extracting the basename from assembly name if (null == assemName || String.Empty == assemName){ assemName = Path.GetFileName(assemblyFileName); if (Path.HasExtension(assemName)) assemName = assemName.Substring(0, assemName.Length - Path.GetExtension(assemName).Length); } } //Setup default simple assembly name and module name for the case where no assemblyFileName is specified. if (assemName == null || assemName == String.Empty) assemName = "JScriptAssembly"; if (moduleFileName == null) { if (PEFileKind == PEFileKinds.Dll) moduleFileName = "JScriptModule.dll"; else moduleFileName = "JScriptModule.exe"; } AssemblyName assemblyName = new AssemblyName(); assemblyName.CodeBase = assemblyFileName; if (globals.assemblyCulture != null) assemblyName.CultureInfo = globals.assemblyCulture; assemblyName.Flags = AssemblyNameFlags.None; if ((globals.assemblyFlags & AssemblyFlags.PublicKey) != 0) assemblyName.Flags = AssemblyNameFlags.PublicKey; switch ((AssemblyFlags)(globals.assemblyFlags & AssemblyFlags.CompatibilityMask)){ case AssemblyFlags.NonSideBySideAppDomain: assemblyName.VersionCompatibility = AssemblyVersionCompatibility.SameDomain; break; case AssemblyFlags.NonSideBySideMachine: assemblyName.VersionCompatibility = AssemblyVersionCompatibility.SameMachine; break; case AssemblyFlags.NonSideBySideProcess: assemblyName.VersionCompatibility = AssemblyVersionCompatibility.SameProcess; break; default: assemblyName.VersionCompatibility = (AssemblyVersionCompatibility)0; break; } assemblyName.HashAlgorithm = globals.assemblyHashAlgorithm; if (globals.assemblyKeyFileName != null){ try { using (FileStream fs = new FileStream(globals.assemblyKeyFileName, FileMode.Open, FileAccess.Read)) { StrongNameKeyPair keyPair = new StrongNameKeyPair(fs); if (globals.assemblyDelaySign) if (fs.Length == 160) { Byte[] pkey = new Byte[160]; fs.Seek(0, SeekOrigin.Begin); int len = fs.Read(pkey, 0, 160); assemblyName.SetPublicKey(pkey); } else assemblyName.SetPublicKey(keyPair.PublicKey); else { // Fetch to force reflection to try and process the key file data and throw an exception byte[] publicKey = keyPair.PublicKey; assemblyName.KeyPair = keyPair; } } } catch { globals.assemblyKeyFileNameContext.HandleError(JSError.InvalidAssemblyKeyFile, globals.assemblyKeyFileName); } }else if (globals.assemblyKeyName != null){ try{ StrongNameKeyPair keyPair = new StrongNameKeyPair(globals.assemblyKeyName); byte[] publicKey = keyPair.PublicKey; // Force validation assemblyName.KeyPair = keyPair; }catch{ globals.assemblyKeyNameContext.HandleError(JSError.InvalidAssemblyKeyFile, globals.assemblyKeyName); } } assemblyName.Name = assemName; if (version != null) assemblyName.Version = version; else if (globals.assemblyVersion != null) assemblyName.Version = globals.assemblyVersion; AssemblyBuilderAccess access = save ? (run ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Save) : AssemblyBuilderAccess.Run; if (engine.ReferenceLoaderAPI == LoaderAPI.ReflectionOnlyLoadFrom) access = AssemblyBuilderAccess.ReflectionOnly; // Supply the evidence to assemblies built for VSA if (globals.engine.genStartupClass) this.assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(assemblyName, access, directory, globals.engine.Evidence); else this.assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(assemblyName, access, directory); if (save) this.module = this.assemblyBuilder.DefineDynamicModule("JScript Module", moduleFileName, debugOn); else this.module = this.assemblyBuilder.DefineDynamicModule("JScript Module", debugOn); if (isCLSCompliant) this.module.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new Object[]{isCLSCompliant})); if (debugOn){ ConstructorInfo debuggableAttr = Typeob.DebuggableAttribute.GetConstructor(new Type[] {Typeob.Boolean, Typeob.Boolean}); assemblyBuilder.SetCustomAttribute(new CustomAttributeBuilder(debuggableAttr, new Object[] {(globals.assemblyFlags & AssemblyFlags.EnableJITcompileTracking) != 0, (globals.assemblyFlags & AssemblyFlags.DisableJITcompileOptimizer) != 0})); } this.compilationEvidence = globals.engine.Evidence; this.classwriter = null; }
protected override void ResetCompiledState() { if (this.globalScope != null) { this.globalScope.Reset(); this.globalScope = null; } this.classCounter = 0; base.haveCompiledState = false; base.failedCompilation = true; base.compiledRootNamespace = null; base.startupClass = null; this.compilerGlobals = null; this.globals = null; foreach (object obj2 in base.vsaItems) { ((VsaItem) obj2).Reset(); } this.implicitAssemblies = null; this.implicitAssemblyCache = null; this.cachedTypeLookups = null; base.isEngineCompiled = false; base.isEngineRunning = false; this.isCompilerSet = false; this.packages = null; if (!this.doSaveAfterCompile) { this.PEFileName = null; } this.rawPE = null; this.rawPDB = null; }