internal PostOrPrefixOperator(Context context, AST operand, PostOrPrefix operatorTok) : base(context, operand) { this.operatorMeth = null; this.operatorTok = operatorTok; this.metaData = null; this.type = null; }
internal ClassScope(AST name, GlobalScope scope) : base(scope) { this.name = name.ToString(); base.engine = scope.engine; base.fast = scope.fast; this.noExpando = true; base.isKnownAtCompileTime = true; this.owner = null; this.constructors = new JSConstructor[0]; ScriptObject parent = base.engine.ScriptObjectStackTop(); while (parent is WithObject) { parent = parent.GetParent(); } if (parent is ClassScope) { this.package = ((ClassScope) parent).GetPackage(); } else if (parent is PackageScope) { this.package = (PackageScope) parent; } else { this.package = null; } this.itemProp = null; this.outerClassField = null; this.inStaticInitializerCode = false; this.staticInitializerUsesEval = false; this.instanceInitializerUsesEval = false; }
internal override AST PartiallyEvaluate() { if (this.operand != null) { this.operand = this.operand.PartiallyEvaluate(); } else { BlockScope scope = null; for (ScriptObject obj2 = base.Engine.ScriptObjectStackTop(); obj2 != null; obj2 = obj2.GetParent()) { if (!(obj2 is WithObject)) { scope = obj2 as BlockScope; if ((scope == null) || scope.catchHanderScope) { break; } } } if (scope == null) { base.context.HandleError(JSError.BadThrow); this.operand = new ConstantWrapper(null, base.context); } } return this; }
internal ASTList Append(AST elem){ int n = this.count++; if (this.list.Length == n) this.Grow(); this.list[n] = elem; this.context.UpdateWith(elem.context); return this; }
internal Try(Context context, AST body, AST identifier, TypeExpression type, AST handler, AST finally_block, bool finallyHasControlFlowOutOfIt, Context tryEndContext) : base(context) { this.body = body; this.type = type; this.handler = handler; this.finally_block = finally_block; ScriptObject current_scope = (ScriptObject)Globals.ScopeStack.Peek(); while (current_scope is WithObject) //Can only happen at run time and only if there is an eval current_scope = current_scope.GetParent(); this.handler_scope = null; this.field = null; if (identifier != null){ this.fieldName = identifier.ToString(); this.field = current_scope.GetField(this.fieldName, BindingFlags.Public|BindingFlags.Instance|BindingFlags.Static); if (this.field != null){ if (type == null && (field is JSVariableField && field.IsStatic && ((JSVariableField)field).type == null) && !field.IsLiteral && !field.IsInitOnly) return; //preserve legacy semantics by using the existing variable if (((IActivationObject)current_scope).GetLocalField(this.fieldName) != null) identifier.context.HandleError(JSError.DuplicateName, false); } this.handler_scope = new BlockScope(current_scope); this.handler_scope.catchHanderScope = true; JSVariableField f = this.handler_scope.AddNewField(identifier.ToString(), Missing.Value, FieldAttributes.Public); // must be a local this.field = f; f.originalContext = identifier.context; if (identifier.context.document.debugOn && this.field is JSLocalField){ this.handler_scope.AddFieldForLocalScopeDebugInfo((JSLocalField)this.field); } } this.finallyHasControlFlowOutOfIt = finallyHasControlFlowOutOfIt; this.tryEndContext = tryEndContext; }
private void FirstPass() { foreach (JSMethodItem methodItem in GetMethods()) { if (CheckWorker()) { break; } JS.AST mi = methodItem.MethodInfo; // Get the type, itemPath and parameter list from the ToString override. string id = methodItem.GetID(); // Add the graph node with a link back to the method. AddNode(methodItem.Name, methodItem.Name, _sharedOptions.MethodColor, methodItem); //child = (Node)_graph.AddNode(methodItem.Name); //child.UserData = methodItem; // Hang onto the method and the corresponding graph node. _methodInfos.Add(methodItem.Name, mi); //id, mi); // Make note of overloaded methods. if (_names.Contains(methodItem.Name)) { _overloads.Add(methodItem.Name); } else { _names.Add(methodItem.Name); } } }
internal Call(Context context, AST func, ASTList args, bool inBrackets) : base(context) { this.func = func; this.args = (args == null) ? new ASTList(context) : args; this.argValues = null; this.outParameterCount = 0; int num = 0; int count = this.args.count; while (num < count) { if (this.args[num] is AddressOf) { this.outParameterCount++; } num++; } this.isConstructor = false; this.inBrackets = inBrackets; this.enclosingFunctionScope = null; this.alreadyPartiallyEvaluated = false; this.isAssignmentToDefaultIndexedProperty = false; ScriptObject parent = base.Globals.ScopeStack.Peek(); while (!(parent is FunctionScope)) { parent = parent.GetParent(); if (parent == null) { return; } } this.enclosingFunctionScope = (FunctionScope) parent; }
internal Eval(Context context, AST operand, AST unsafeOption) : base(context) { this.operand = operand; this.unsafeOption = unsafeOption; ScriptObject obj2 = base.Globals.ScopeStack.Peek(); ((IActivationObject) obj2).GetGlobalScope().evilScript = true; if (obj2 is ActivationObject) { ((ActivationObject) obj2).isKnownAtCompileTime = base.Engine.doFast; } if (obj2 is FunctionScope) { this.enclosingFunctionScope = (FunctionScope) obj2; this.enclosingFunctionScope.mustSaveStackLocals = true; for (ScriptObject obj3 = this.enclosingFunctionScope.GetParent(); obj3 != null; obj3 = obj3.GetParent()) { FunctionScope scope = obj3 as FunctionScope; if (scope != null) { scope.mustSaveStackLocals = true; scope.closuresMightEscape = true; } } } else { this.enclosingFunctionScope = null; } }
internal BinaryOp (AST parent, AST left, AST right, JSToken op, Location location) : base (parent, location) { operand1 = left; operand2 = right; operatorTok = op; }
internal PostOrPrefixOperator(AST parent, AST operand, JSToken oper, bool prefix, Location location) : base(parent, location) { this.operand = operand; this.oper = oper; this.prefix = prefix; }
internal override AST PartiallyEvaluate(){ AST lhref = this.lhside.PartiallyEvaluateAsReference(); this.lhside = lhref; this.rhside = this.rhside.PartiallyEvaluate(); lhref.SetPartialValue(this.rhside); return this; }
internal If(Context context, AST condition, AST true_branch, AST false_branch) : base(context) { this.condition = condition; this.operand1 = true_branch; this.operand2 = false_branch; this.completion = new Completion(); }
internal override AST PartiallyEvaluate() { this.initializer = this.initializer.PartiallyEvaluate(); ScriptObject parent = base.Globals.ScopeStack.Peek(); while (parent is WithObject) { parent = parent.GetParent(); } if (parent is FunctionScope) { FunctionScope scope = (FunctionScope) parent; BitArray definedFlags = scope.DefinedFlags; this.condition = this.condition.PartiallyEvaluate(); this.body = this.body.PartiallyEvaluate(); scope.DefinedFlags = definedFlags; this.incrementer = this.incrementer.PartiallyEvaluate(); scope.DefinedFlags = definedFlags; } else { this.condition = this.condition.PartiallyEvaluate(); this.body = this.body.PartiallyEvaluate(); this.incrementer = this.incrementer.PartiallyEvaluate(); } IReflect reflect = this.condition.InferType(null); if ((reflect is FunctionPrototype) || (reflect == Typeob.ScriptFunction)) { base.context.HandleError(JSError.SuspectLoopCondition); } return this; }
internal override AST PartiallyEvaluate() { if (this.leavesFinally) { base.context.HandleError(JSError.BadWayToLeaveFinally); } if (this.operand != null) { this.operand = this.operand.PartiallyEvaluate(); if (this.enclosingFunctionScope.returnVar != null) { if (this.enclosingFunctionScope.returnVar.type == null) { this.enclosingFunctionScope.returnVar.SetInferredType(this.operand.InferType(this.enclosingFunctionScope.returnVar), this.operand); } else { Binding.AssignmentCompatible(this.enclosingFunctionScope.returnVar.type.ToIReflect(), this.operand, this.operand.InferType(null), true); } } else { base.context.HandleError(JSError.CannotReturnValueFromVoidFunction); this.operand = null; } } else if (this.enclosingFunctionScope.returnVar != null) { this.enclosingFunctionScope.returnVar.SetInferredType(Typeob.Object, null); } return this; }
internal FunctionExpression (AST parent, string name, FormalParameterList p, string return_type, Block body, Location location) : base (parent, location) { func_obj = new FunctionObject (name, p, return_type, body, location); }
internal Try (AST guarded_block, ArrayList catch_block, AST finally_block, AST parent, Location location) : base (parent, location) { this.guarded_block = guarded_block; this.catch_blocks = catch_block; this.finally_block = finally_block; }
internal override Object Evaluate(){ if (this.value == null) this.completion.value = this.field.value; else this.completion.value = this.value.Evaluate(); return this.completion; }
internal override AST PartiallyEvaluate(){ this.field.attributeFlags &= ~FieldAttributes.InitOnly; this.identifier.PartiallyEvaluateAsReference(); if (this.field.type != null) this.field.type.PartiallyEvaluate(); ScriptObject scope = (ScriptObject)Globals.ScopeStack.Peek(); if (this.value != null){ this.value = this.value.PartiallyEvaluate(); this.identifier.SetPartialValue(this.value); if (this.value is ConstantWrapper){ Object val = this.field.value = this.value.Evaluate(); if (this.field.type != null) this.field.value = Convert.Coerce(val, this.field.type, true); if (this.field.IsStatic && (val is Type || val is ClassScope || val is TypedArray || Convert.GetTypeCode(val) != TypeCode.Object)){ this.field.attributeFlags |= FieldAttributes.Literal; goto set_field_type; } } this.field.attributeFlags |= FieldAttributes.InitOnly; set_field_type: if (this.field.type == null) this.field.type = new TypeExpression(new ConstantWrapper(this.value.InferType(null), null)); }else{ this.value = new ConstantWrapper(null, this.context); this.field.attributeFlags |= FieldAttributes.InitOnly; } // deal with custom attributes if (this.field != null && this.field.customAttributes != null) this.field.customAttributes.PartiallyEvaluate(); return this; }
internal ForIn (AST parent, AST lhs, AST obj, AST body, Location location) : base (parent, location) { this.lhs = lhs; this.obj = obj; this.body = body; }
internal If (AST parent, AST condition, AST true_stm, AST false_stm, Location location) : base (parent, location) { this.cond = condition; this.true_stm = true_stm; this.false_stm = false_stm; }
internal For(Context context, AST initializer, AST condition, AST incrementer, AST body) : base(context) { this.initializer = initializer; this.condition = condition; this.incrementer = incrementer; this.body = body; this.completion = new Completion(); }
internal Import(Context context, AST name) : base(context) { if (name == null) //could happen if constructed while in error recovery mode return; WrappedNamespace ns = name.EvaluateAsWrappedNamespace(true); this.Engine.SetEnclosingContext(ns); this.name = ns.name; }
internal override AST PartiallyEvaluate(){ this.operand = this.operand.PartiallyEvaluate(); if (this.operand is ConstantWrapper) this.operand.context.HandleError(JSError.UselessExpression); else if (this.operand is Binding) ((Binding)this.operand).CheckIfUseless(); return this; }
internal override AST PartiallyEvaluate() { AST ast = this.lhside.PartiallyEvaluateAsReference(); this.lhside = ast; this.rhside = this.rhside.PartiallyEvaluate(); ast.SetPartialValue(this.rhside); return this; }
internal Import(Context context, AST name) : base(context) { if (name != null) { WrappedNamespace ob = name.EvaluateAsWrappedNamespace(true); base.Engine.SetEnclosingContext(ob); this.name = ob.name; } }
internal override AST PartiallyEvaluate() { if (this.case_value != null) { this.case_value = this.case_value.PartiallyEvaluate(); } this.statements = this.statements.PartiallyEvaluate(); return this; }
internal CallableExpression(AST expression) : base(expression.context, ""){ this.expression = expression; JSLocalField field = new JSLocalField("", null, 0, Missing.Value); this.expressionInferredType = expression.InferType(field); field.inferred_type = this.expressionInferredType; this.member = field; this.members = new MemberInfo[]{field}; }
internal BinaryOp(Context context, AST operand1, AST operand2, JSToken operatorTok) : base(context) { this.operand1 = operand1; this.operand2 = operand2; this.operatorTok = operatorTok; this.type1 = null; this.type2 = null; this.operatorMeth = null; }
internal override AST PartiallyEvaluate() { if (this.recursive) { if (!(this.expression is ConstantWrapper)) { this.expression = new ConstantWrapper(Typeob.Object, base.context); } return this; } Member expression = this.expression as Member; if (expression != null) { object obj2 = expression.EvaluateAsType(); if (obj2 != null) { this.expression = new ConstantWrapper(obj2, expression.context); return this; } } this.recursive = true; this.expression = this.expression.PartiallyEvaluate(); this.recursive = false; if (!(this.expression is TypeExpression)) { Type c = null; if (this.expression is ConstantWrapper) { object obj3 = this.expression.Evaluate(); if (obj3 == null) { this.expression.context.HandleError(JSError.NeedType); this.expression = new ConstantWrapper(Typeob.Object, base.context); return this; } c = Globals.TypeRefs.ToReferenceContext(obj3.GetType()); Binding.WarnIfObsolete(obj3 as Type, this.expression.context); } else if (this.expression.OkToUseAsType()) { c = Globals.TypeRefs.ToReferenceContext(this.expression.Evaluate().GetType()); } else { this.expression.context.HandleError(JSError.NeedCompileTimeConstant); this.expression = new ConstantWrapper(Typeob.Object, this.expression.context); return this; } if ((c == null) || (((c != Typeob.ClassScope) && (c != Typeob.TypedArray)) && !Typeob.Type.IsAssignableFrom(c))) { this.expression.context.HandleError(JSError.NeedType); this.expression = new ConstantWrapper(Typeob.Object, this.expression.context); } } return this; }
bool ICanLookupPrototype.ResolveFieldAccess(AST ast) { if (ast is Identifier) { Identifier name = (Identifier) ast; Type prototype = typeof (NumberPrototype); MemberInfo [] members = prototype.GetMember (name.name.Value); return members.Length > 0; } else return false; }
public static bool IsBadIndex(AST ast){ Int32 i; if (!(ast is ConstantWrapper)) return false; try{ i = (Int32)CoerceT(((ConstantWrapper)ast).value, typeof(System.Int32)); }catch(Exception){ return true; } return i < 0; }
internal ASTList Add(AST elem) { elems.Add(elem); return(this); }
internal ASTList(AST parent, Location location) : base(parent, location) { elems = new ArrayList(); }
private void ParseAst(JS.AST ast, string sp) { if (ast == null) { return; } if (CheckWorker()) { return; } //_logView.LogStr("JSM->" + sp + ast.ToString() + "\t\t" + ast.GetType().Name); if (ast is JS.FunctionDeclaration) { JS.Function func = ast as JS.Function; ParseAstList(func.func_obj.body.elems, sp + " "); } else if (ast is JS.Assign) { JS.Assign ass = ast as JS.Assign; ParseAst(ass.left, sp + "l "); ParseAst(ass.right, sp + "r "); } else if (ast is JS.Binary) { JS.Binary bin = ast as JS.Binary; string[] parts = bin.ToString().Split('.'); if (parts.Length > 1) { if (parts[parts.Length - 2] == "This") { string calledId = parts[parts.Length - 1] + "()"; //dup // If we have a method of this name in this file/class if (_addedNodes.ContainsKey(calledId)) { // Create an edge. // A definite functional assignment link. AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Aqua); } else { // It's a call to a method outside this class/file. // //_logView.LogStr("skipped assign ref -->" + _methodNodeId + " --------> " + calledId); // } } else if (parts[parts.Length - 2] == "self") { string calledId = parts[parts.Length - 1] + "()"; //dup // If we have a method of this name in this file/class if (_addedNodes.ContainsKey(calledId)) { // Get the graph node that we're linking to. //Node calledNode = _addedNodes[calledId]; // Create an edge. // A definite functional assignment link. AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Aqua); } else { // It's a call to a method outside this class/file. _logView.LogStr("skipped assign ref -->" + _methodNodeId + " --------> " + calledId); } } } } else if (ast is JS.Expression) { JS.Expression expr = ast as JS.Expression; ParseAstList(expr.exprs, sp + " "); } else if (ast is JS.FunctionExpression) { JS.FunctionExpression expr = ast as JS.FunctionExpression; ParseAstList(expr.func_obj.body.elems, sp + " "); } else if (ast is JS.For) { JS.For fr = ast as JS.For; ParseAst(fr.stms, sp + " "); } else if (ast is JS.If) { JS.If iff = ast as JS.If; ParseAst(iff.false_stm, sp + "f "); ParseAst(iff.true_stm, sp + "t "); } else if (ast is JS.Block) { JS.Block block = ast as JS.Block; ParseAstList(block.elems, sp + " "); } else if (ast is JS.VariableStatement) { JS.VariableStatement var = ast as JS.VariableStatement; //var. ParseAstList(var.var_decls, sp + " "); } else if (ast is JS.Return) { JS.Return ret = ast as JS.Return; ParseAst(ret.expression, sp + " "); } else if (ast is JS.VariableDeclaration) { JS.VariableDeclaration var = ast as JS.VariableDeclaration; Microsoft.JScript.New newval = var.val as Microsoft.JScript.New; if (newval != null && newval.exp != null) { //_logView.LogStr("new:" + newval.exp.ToString()); string[] parts = newval.exp.ToString().Split('.'); if (parts.Length > 0) { string calledId = parts[parts.Length - 1] + "()"; // If we have a method of this name in this file/class, then // we have a possible constructor link. if (_addedNodes.ContainsKey(calledId)) { // Create an edge. AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Green); } } } else { if (var.val != null) { string valStr = var.val.ToString(); string[] parts = valStr.Split('.'); if (parts.Length > 1 && parts[0] == "self") { // dup.. string calledId = parts[parts.Length - 1] + "()"; // If we have a method of this name in this file/class, then // we have a possible constructor link. if (_addedNodes.ContainsKey(calledId)) { // Create an edge. AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Green); } } } } //ParseAstList(var.var_decls, sp + " "); } else if (ast is JS.Call) { JS.Call call = ast as JS.Call; string[] parts = call.ToString().Split(' '); string[] bits = parts[0].Split('.'); string calledId = bits[bits.Length - 1] + "()"; bool methodInThisClass = true; if (bits.Length > 1) { if ((bits[bits.Length - 2] != "This") && (bits[bits.Length - 2] != "self")) { methodInThisClass = false; } } // If we have a method of this name in this file/class if (_addedNodes.ContainsKey(calledId)) { // Create an edge. if (methodInThisClass) { // A definite link. AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Black); } else { // A tentative link. AddEdge(_methodNodeId, calledId, EdgeStyle.NormalArrow, Color.Gray); } } else { // It's a call to a method outside this class/file. // //_logView.LogStr("skipped -------->" + _methodNodeId + " --------> " + parts[0]); // } } }
internal VoidOp(Context context, AST operand) : base(context, operand) { }
internal override AST PartiallyEvaluate() { this.ctor = this.ctor.PartiallyEvaluateAsCallable(); //first weed out assignment expressions and use them as property initializers ASTList positionalArgs = new ASTList(this.args.context); ASTList namedArgs = new ASTList(this.args.context); for (int i = 0, m = this.args.count; i < m; i++) { AST arg = this.args[i]; Assign assign = arg as Assign; if (assign != null) { assign.rhside = assign.rhside.PartiallyEvaluate(); namedArgs.Append(assign); } else { positionalArgs.Append(arg.PartiallyEvaluate()); } } int n = positionalArgs.count; IReflect[] argIRs = new IReflect[n]; for (int i = 0; i < n; i++) { AST arg = positionalArgs[i]; // only accept ConstantWrappers if (arg is ConstantWrapper) { Object argument = arg.Evaluate(); if ((argIRs[i] = CustomAttribute.TypeOfArgument(argument)) != null) { this.positionalArgValues.Add(argument); continue; } } else if (arg is ArrayLiteral && ((ArrayLiteral)arg).IsOkToUseInCustomAttribute()) { argIRs[i] = Typeob.ArrayObject; this.positionalArgValues.Add(arg.Evaluate()); continue; } arg.context.HandleError(JSError.InvalidCustomAttributeArgument); return(null); // the custom attribute is not good and it will be ignored } //Get the custom attribute and the appropriate constructor (under the covers) this.type = this.ctor.ResolveCustomAttribute(positionalArgs, argIRs, this.target); if (this.type == null) { return(null); } if (Convert.IsPromotableTo((IReflect)this.type, typeof(CodeAccessSecurityAttribute))) { this.context.HandleError(JSError.CannotUseStaticSecurityAttribute); return(null); } //Coerce the positional arguments to the right type and supply default values for optional parameters ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member; ParameterInfo[] parameters = c.GetParameters(); int j = 0; int len = this.positionalArgValues.Count; foreach (ParameterInfo p in parameters) { IReflect ir = p is ParameterDeclaration ? ((ParameterDeclaration)p).ParameterIReflect : p.ParameterType; if (j < len) { Object value = this.positionalArgValues[j]; this.positionalArgValues[j] = Convert.Coerce(value, ir, value is ArrayObject); j++; } else { Object value; if (p.DefaultValue == System.Convert.DBNull) { value = Convert.Coerce(null, ir); } else { value = p.DefaultValue; } this.positionalArgValues.Add(value); } } //Check validity of property/field initializers for (int i = 0, m = namedArgs.count; i < m; i++) { Assign assign = (Assign)namedArgs[i]; if (assign.lhside is Lookup && (assign.rhside is ConstantWrapper || (assign.rhside is ArrayLiteral && ((ArrayLiteral)assign.rhside).IsOkToUseInCustomAttribute()))) { Object value = assign.rhside.Evaluate(); IReflect argType = null; if (value is ArrayObject || ((argType = CustomAttribute.TypeOfArgument(value)) != null && argType != Typeob.Object)) { String name = ((Lookup)assign.lhside).Name; MemberInfo [] members = ((IReflect)this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance); if (members == null || members.Length == 0) { assign.context.HandleError(JSError.NoSuchMember); return(null); } if (members.Length == 1) { MemberInfo member = members[0]; if (member is FieldInfo) { FieldInfo fieldInfo = (FieldInfo)member; if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly) { try{ IReflect ir = fieldInfo is JSVariableField ? ((JSVariableField)fieldInfo).GetInferredType(null) : fieldInfo.FieldType; value = Convert.Coerce(value, ir, value is ArrayObject); this.namedArgFields.Add(member); this.namedArgFieldValues.Add(value); continue; }catch (JScriptException) { assign.rhside.context.HandleError(JSError.TypeMismatch); return(null); // the custom attribute is not good and it will be ignored } } } else if (member is PropertyInfo) { PropertyInfo propertyInfo = (PropertyInfo)member; MethodInfo setMethodInfo = JSProperty.GetSetMethod(propertyInfo, false); if (setMethodInfo != null) { ParameterInfo [] paramInfo = setMethodInfo.GetParameters(); if (paramInfo != null && paramInfo.Length == 1) { try{ IReflect ir = paramInfo[0] is ParameterDeclaration ? ((ParameterDeclaration)paramInfo[0]).ParameterIReflect : paramInfo[0].ParameterType; value = Convert.Coerce(value, ir, value is ArrayObject); this.namedArgProperties.Add(member); this.namedArgPropertyValues.Add(value); }catch (JScriptException) { assign.rhside.context.HandleError(JSError.TypeMismatch); return(null); // the custom attribute is not good and it will be ignored } continue; } } } } } } assign.context.HandleError(JSError.InvalidCustomAttributeArgument); return(null); } if (!this.CheckIfTargetOK(this.type)) { return(null); //Ignore attribute } //Consume and discard assembly name attributes try{ Type ty = this.type as Type; if (ty != null && this.target is AssemblyCustomAttributeList) { if (ty.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm)); } return(null); } if (ty.FullName == "System.Reflection.AssemblyCultureAttribute") { if (this.positionalArgValues.Count > 0) { String cultureId = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.PEFileKind != PEFileKinds.Dll && cultureId.Length > 0) { this.context.HandleError(JSError.ExecutablesCannotBeLocalized); return(null); } this.Engine.Globals.assemblyCulture = new CultureInfo(cultureId); } return(null); } if (ty.FullName == "System.Reflection.AssemblyDelaySignAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyDelaySign = Convert.ToBoolean(this.positionalArgValues[0], false); } return(null); } if (ty.FullName == "System.Reflection.AssemblyFlagsAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyFlags = (AssemblyFlags)(uint)Convert.CoerceT(this.positionalArgValues[0], typeof(uint)); } return(null); } if (ty.FullName == "System.Reflection.AssemblyKeyFileAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyKeyFileName = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.Globals.assemblyKeyFileName != null && this.Engine.Globals.assemblyKeyFileName.Length == 0) { this.Engine.Globals.assemblyKeyFileName = null; } } return(null); } if (ty.FullName == "System.Reflection.AssemblyKeyNameAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyKeyName = Convert.ToString(this.positionalArgValues[0]); if (this.Engine.Globals.assemblyKeyName != null && this.Engine.Globals.assemblyKeyName.Length == 0) { this.Engine.Globals.assemblyKeyName = null; } } return(null); } if (ty.FullName == "System.Reflection.AssemblyVersionAttribute") { if (this.positionalArgValues.Count > 0) { this.Engine.Globals.assemblyVersion = this.ParseVersion(Convert.ToString(this.positionalArgValues[0])); } return(null); } if (ty.FullName == "System.CLSCompliantAttribute") { this.Engine.isCLSCompliant = this.args == null || this.args.count == 0 || Convert.ToBoolean(this.positionalArgValues[0], false); return(this); } } }catch (ArgumentException) { this.context.HandleError(JSError.InvalidCall); } return(this); }
internal VariableDeclaration(Context context, Lookup identifier, TypeExpression type, AST initializer, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context) { if (initializer != null) { this.context.UpdateWith(initializer.context); } else if (type != null) { this.context.UpdateWith(type.context); } this.identifier = identifier; this.type = type; this.initializer = initializer; ScriptObject current_scope = (ScriptObject)Globals.ScopeStack.Peek(); while (current_scope is WithObject) //Can only happen at run time and only if there is an eval { current_scope = current_scope.GetParent(); } String name = this.identifier.ToString(); if (current_scope is ClassScope) { if (name == ((ClassScope)current_scope).name) { identifier.context.HandleError(JSError.CannotUseNameOfClass); name = name + " var"; } } else { if (attributes != (FieldAttributes)0) { this.context.HandleError(JSError.NotInsideClass); attributes = FieldAttributes.Public; } else { attributes |= FieldAttributes.Public; } } FieldInfo field = ((IActivationObject)current_scope).GetLocalField(name); if (field != null) { if (field.IsLiteral || current_scope is ClassScope || type != null) { identifier.context.HandleError(JSError.DuplicateName, true); } this.type = type = null; } if (current_scope is ActivationObject) { if (field == null || field is JSVariableField) { this.field = ((ActivationObject)current_scope).AddFieldOrUseExistingField(this.identifier.ToString(), Missing.Value, attributes); } else { this.field = ((ActivationObject)current_scope).AddNewField(this.identifier.ToString(), null, attributes); } } else { this.field = ((StackFrame)current_scope).AddNewField(this.identifier.ToString(), null, attributes | FieldAttributes.Static); } this.field.type = type; this.field.customAttributes = customAttributes; this.field.originalContext = context; if (this.field is JSLocalField) { // emit debug info for the local only if this block of code is in a section that has debug set ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn; } this.completion = new Completion(); }
internal FunctionDeclaration(AST parent, string name, Location location) : this(parent, name, null, String.Empty, null, location) { }
internal virtual void PropagateParent(AST parent) { this.parent = parent; }
internal Delete(Context context, AST operand) : base(context, operand) { }
internal In(Context context, AST operand1, AST operand2) : base(context, operand1, operand2) { }
internal Equality(AST parent, AST left, AST right, JSToken op, Location location) : base(parent, left, right, op, location) { }
internal StrictEquality(Context context, AST operand1, AST operand2, JSToken operatorTok) : base(context, operand1, operand2, operatorTok) { }
internal NumericBinary(Context context, AST operand1, AST operand2, JSToken operatorTok) : base(context, operand1, operand2, operatorTok) { }
internal AST(AST parent, Location location) { this.parent = parent; this.location = location; }
internal FunctionDeclaration(Context context, AST ifaceId, IdentifierLiteral id, ParameterDeclaration[] formal_parameters, TypeExpression return_type, Block body, FunctionScope own_scope, FieldAttributes attributes, bool isMethod, bool isGetter, bool isSetter, bool isAbstract, bool isFinal, CustomAttributeList customAttributes) : base(context) { this.completion = new Completion(); MethodAttributes privateScope = MethodAttributes.PrivateScope; if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) { privateScope = MethodAttributes.Public; } else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private) { privateScope = MethodAttributes.Private; } else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly) { privateScope = MethodAttributes.Assembly; } else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family) { privateScope = MethodAttributes.Family; } else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem) { privateScope = MethodAttributes.FamORAssem; } else { privateScope = MethodAttributes.Public; } if (((attributes & FieldAttributes.Static) != FieldAttributes.PrivateScope) || !isMethod) { privateScope |= MethodAttributes.Static; } else { privateScope |= MethodAttributes.NewSlot | MethodAttributes.Virtual; } if (isAbstract) { privateScope |= MethodAttributes.Abstract; } if (isFinal) { privateScope |= MethodAttributes.Final; } this.name = id.ToString(); this.isMethod = isMethod; if (ifaceId != null) { if (isMethod) { this.ifaceId = new TypeExpression(ifaceId); privateScope &= ~MethodAttributes.MemberAccessMask; privateScope |= MethodAttributes.Final | MethodAttributes.Private; } else { this.declaringObject = new Member(ifaceId.context, ifaceId, id); this.name = this.declaringObject.ToString(); } } ScriptObject obj2 = base.Globals.ScopeStack.Peek(); if (((attributes == FieldAttributes.PrivateScope) && !isAbstract) && !isFinal) { if (obj2 is ClassScope) { attributes |= FieldAttributes.Public; } } else if (!(obj2 is ClassScope)) { base.context.HandleError(JSError.NotInsideClass); attributes = FieldAttributes.PrivateScope; privateScope = MethodAttributes.Public; } if (obj2 is ActivationObject) { this.inFastScope = ((ActivationObject)obj2).fast; string name = this.name; if (isGetter) { privateScope |= MethodAttributes.SpecialName; this.name = "get_" + this.name; if (return_type == null) { return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context)); } } else if (isSetter) { privateScope |= MethodAttributes.SpecialName; this.name = "set_" + this.name; return_type = new TypeExpression(new ConstantWrapper(Typeob.Void, context)); } attributes &= FieldAttributes.FieldAccessMask; MethodAttributes attributes3 = privateScope & MethodAttributes.MemberAccessMask; if ((((privateScope & MethodAttributes.Virtual) != MethodAttributes.PrivateScope) && ((privateScope & MethodAttributes.Final) == MethodAttributes.PrivateScope)) && (((attributes3 == MethodAttributes.Private) || (attributes3 == MethodAttributes.Assembly)) || (attributes3 == MethodAttributes.FamANDAssem))) { privateScope |= MethodAttributes.CheckAccessOnOverride; } this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, obj2, base.context, privateScope, customAttributes, this.isMethod); if (this.declaringObject == null) { string str2 = this.name; if (this.ifaceId != null) { str2 = ifaceId.ToString() + "." + str2; } JSVariableField field = (JSVariableField)((ActivationObject)obj2).name_table[str2]; if ((field != null) && ((!(field is JSMemberField) || !(((JSMemberField)field).value is FunctionObject)) || this.func.isExpandoMethod)) { if (name != this.name) { field.originalContext.HandleError(JSError.ClashWithProperty); } else { id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod); if (field.value is FunctionObject) { ((FunctionObject)field.value).suppressIL = true; } } } if (this.isMethod) { if ((!(field is JSMemberField) || !(((JSMemberField)field).value is FunctionObject)) || (name != this.name)) { this.field = ((ActivationObject)obj2).AddNewField(str2, this.func, attributes | FieldAttributes.Literal); if (name == this.name) { this.field.type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, base.context)); } } else { this.field = ((JSMemberField)field).AddOverload(this.func, attributes | FieldAttributes.Literal); } } else if (obj2 is FunctionScope) { if (this.inFastScope) { attributes |= FieldAttributes.Literal; } this.field = ((FunctionScope)obj2).AddNewField(this.name, attributes, this.func); if (this.field is JSLocalField) { JSLocalField field2 = (JSLocalField)this.field; if (this.inFastScope) { field2.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, base.context)); field2.attributeFlags |= FieldAttributes.Literal; } field2.debugOn = base.context.document.debugOn; field2.isDefined = true; } } else if (this.inFastScope) { this.field = ((ActivationObject)obj2).AddNewField(this.name, this.func, attributes | FieldAttributes.Literal); this.field.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, base.context)); } else { this.field = ((ActivationObject)obj2).AddNewField(this.name, this.func, attributes | FieldAttributes.Static); } this.field.originalContext = context; if (name != this.name) { string str3 = name; if (this.ifaceId != null) { str3 = ifaceId.ToString() + "." + name; } FieldInfo info = (FieldInfo)((ClassScope)obj2).name_table[str3]; if (info != null) { if (info.IsLiteral) { object obj3 = ((JSVariableField)info).value; if (obj3 is JSProperty) { this.enclosingProperty = (JSProperty)obj3; } } if (this.enclosingProperty == null) { id.context.HandleError(JSError.DuplicateName, true); } } if (this.enclosingProperty == null) { this.enclosingProperty = new JSProperty(name); ((JSMemberField)((ActivationObject)obj2).AddNewField(str3, this.enclosingProperty, attributes | FieldAttributes.Literal)).originalContext = base.context; } else if ((isGetter && (this.enclosingProperty.getter != null)) || (isSetter && (this.enclosingProperty.setter != null))) { id.context.HandleError(JSError.DuplicateName, true); } if (isGetter) { this.enclosingProperty.getter = new JSFieldMethod(this.field, obj2); } else { this.enclosingProperty.setter = new JSFieldMethod(this.field, obj2); } } } } else { this.inFastScope = false; this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, obj2, base.context, MethodAttributes.Public, null, false); this.field = ((StackFrame)obj2).AddNewField(this.name, new Closure(this.func), attributes | FieldAttributes.Static); } }
internal Function(AST parent, Location location) : base(parent, location) { }
internal void Append(AST elem) { this.list.Add(elem); }
internal void SetTarget(AST target) { this.target = target; }
internal BinaryOp(Context context, AST operand1, AST operand2) : this(context, operand1, operand2, (JSToken)0) { }
internal Comma(Context context, AST operand1, AST operand2) : base(context, operand1, operand2) { }
internal override AST PartiallyEvaluate() { if (this.recursive) { if (this.expression is ConstantWrapper) { return(this); } this.expression = new ConstantWrapper(Typeob.Object, this.context); return(this); } Member member = this.expression as Member; if (member != null) { //Dealing with a qualified name. See if there is a type/class with such a name, bypassing normal scope lookup. Object type = member.EvaluateAsType(); if (type != null) { this.expression = new ConstantWrapper(type, member.context); return(this); } } this.recursive = true; this.expression = this.expression.PartiallyEvaluate(); this.recursive = false; if (this.expression is TypeExpression) { return(this); } //Make sure that the expression represents a Type Type t = null; if (this.expression is ConstantWrapper) { Object val = this.expression.Evaluate(); if (val == null) { this.expression.context.HandleError(JSError.NeedType); this.expression = new ConstantWrapper(Typeob.Object, this.context); return(this); } t = Globals.TypeRefs.ToReferenceContext(val.GetType()); Binding.WarnIfObsolete(val as Type, this.expression.context); } else { if (this.expression.OkToUseAsType()) { t = Globals.TypeRefs.ToReferenceContext(this.expression.Evaluate().GetType()); } else { this.expression.context.HandleError(JSError.NeedCompileTimeConstant); this.expression = new ConstantWrapper(Typeob.Object, this.expression.context); return(this); } } if (t == null || (t != Typeob.ClassScope && t != Typeob.TypedArray && !Typeob.Type.IsAssignableFrom(t))) { this.expression.context.HandleError(JSError.NeedType); this.expression = new ConstantWrapper(Typeob.Object, this.expression.context); } return(this); }
internal Relational(Context context, AST operand1, AST operand2, JSToken operatorTok) : base(context, operand1, operand2, operatorTok) { }
internal Typeof(Context context, AST operand) : base(context, operand) { }
internal Logical_and(Context context, AST operand1, AST operand2) : base(context, operand1, operand2) { }
internal Plus(Context context, AST operand1, AST operand2) : base(context, operand1, operand2, JSToken.Plus) { }
internal override AST PartiallyEvaluate() { this.condition = this.condition.PartiallyEvaluate(); if (this.condition is ConstantWrapper) { if (Convert.ToBoolean(this.condition.Evaluate()) == true) { this.operand2 = null; } else { this.operand1 = null; } this.condition = null; } ScriptObject current_scope = Globals.ScopeStack.Peek(); while (current_scope is WithObject) { current_scope = current_scope.GetParent(); } if (current_scope is FunctionScope) { FunctionScope scope = (FunctionScope)current_scope; BitArray before = scope.DefinedFlags; BitArray after1 = before; if (this.operand1 != null) { this.operand1 = this.operand1.PartiallyEvaluate(); after1 = scope.DefinedFlags; scope.DefinedFlags = before; } if (this.operand2 != null) { this.operand2 = this.operand2.PartiallyEvaluate(); BitArray after2 = scope.DefinedFlags; int n = after1.Length; int m = after2.Length; if (n < m) { after1.Length = m; } if (m < n) { after2.Length = n; } before = after1.And(after2); } scope.DefinedFlags = before; } else { if (this.operand1 != null) { this.operand1 = this.operand1.PartiallyEvaluate(); } if (this.operand2 != null) { this.operand2 = this.operand2.PartiallyEvaluate(); } } return(this); }
internal Instanceof(Context context, AST operand1, AST operand2) : base(context, operand1, operand2) { }
internal UnaryOp(Context context, AST operand) : base(context) { this.operand = operand; }
internal override AST PartiallyEvaluateAsReference() { this.func = this.func.PartiallyEvaluateAsCallable(); this.args = (ASTList)this.args.PartiallyEvaluate(); return(this); }