internal EnumDeclaration(Context context, IdentifierLiteral id, TypeExpression baseType, Block body, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context, id, new TypeExpression(new ConstantWrapper(typeof(Enum), null)), new TypeExpression[0], body, attributes, false, false, true, false, customAttributes) { this.baseType = baseType != null ? baseType : new TypeExpression(new ConstantWrapper(Typeob.Int32, null)); this.needsEngine = false; this.attributes &= TypeAttributes.VisibilityMask; TypeExpression thisType = new TypeExpression(new ConstantWrapper(this.classob, this.context)); AST currentValue = new ConstantWrapper(-1, null); AST one = new ConstantWrapper(1, null); foreach (FieldInfo f in this.fields) { JSVariableField field = (JSVariableField)f; field.attributeFlags = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal; field.type = thisType; if (field.value == null) { field.value = currentValue = new Plus(currentValue.context, currentValue, one); } else { currentValue = (AST)field.value; } field.value = new EnumWrapper(field.value, field.Name, this.classob); } }
private void AddNameTo(ScriptObject enclosingScope) { while (enclosingScope is WithObject) { enclosingScope = enclosingScope.GetParent(); } if (((IActivationObject) enclosingScope).GetLocalField(this.name) == null) { FieldInfo info; if (enclosingScope is ActivationObject) { if (enclosingScope is FunctionScope) { info = ((ActivationObject) enclosingScope).AddNewField(this.name, null, FieldAttributes.Public); } else { info = ((ActivationObject) enclosingScope).AddNewField(this.name, null, FieldAttributes.Static | FieldAttributes.Public); } } else { info = ((StackFrame) enclosingScope).AddNewField(this.name, null, FieldAttributes.Public); } JSLocalField field = info as JSLocalField; if (field != null) { field.debugOn = base.context.document.debugOn; field.isDefined = true; } this.field = (JSVariableField) info; } }
internal EnumDeclaration(Context context, IdentifierLiteral id, TypeExpression baseType, Block body, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context, id, new TypeExpression(new ConstantWrapper(Typeob.Enum, null)), new TypeExpression[0], body, attributes, false, false, true, false, customAttributes) { this.baseType = (baseType != null) ? baseType : new TypeExpression(new ConstantWrapper(Typeob.Int32, null)); base.needsEngine = false; base.attributes &= TypeAttributes.NestedFamORAssem; TypeExpression expression = new TypeExpression(new ConstantWrapper(base.classob, base.context)); AST ast = new ConstantWrapper(-1, null); AST ast2 = new ConstantWrapper(1, null); JSMemberField[] fields = base.fields; for (int i = 0; i < fields.Length; i++) { FieldInfo info = fields[i]; JSVariableField field = (JSVariableField)info; field.attributeFlags = FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Public; field.type = expression; if (field.value == null) { field.value = ast = new Plus(ast.context, ast, ast2); } else { ast = (AST)field.value; } field.value = new DeclaredEnumValue(field.value, field.Name, base.classob); } }
private void AddNameTo(ScriptObject enclosingScope) { while (enclosingScope is WithObject) { enclosingScope = enclosingScope.GetParent(); } if (((IActivationObject)enclosingScope).GetLocalField(this.name) == null) { FieldInfo info; if (enclosingScope is ActivationObject) { if (enclosingScope is FunctionScope) { info = ((ActivationObject)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public); } else { info = ((ActivationObject)enclosingScope).AddNewField(this.name, null, FieldAttributes.Static | FieldAttributes.Public); } } else { info = ((StackFrame)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public); } JSLocalField field = info as JSLocalField; if (field != null) { field.debugOn = base.context.document.debugOn; field.isDefined = true; } this.field = (JSVariableField)info; } }
internal Constant(Context context, Lookup identifier, TypeExpression type, AST value, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context) { this.attributes = attributes | FieldAttributes.InitOnly; this.customAttributes = customAttributes; this.completion = new Completion(); this.identifier = identifier; this.name = identifier.ToString(); this.value = value; 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(); } if (current_scope is ClassScope) { if (this.name == ((ClassScope)current_scope).name) { identifier.context.HandleError(JSError.CannotUseNameOfClass); this.name = this.name + " const"; } if (attributes == 0) { attributes = FieldAttributes.Public; } } else { if (attributes != 0) { this.context.HandleError(JSError.NotInsideClass); } attributes = FieldAttributes.Public; } FieldInfo field = ((IActivationObject)current_scope).GetLocalField(this.name); if (field != null) { identifier.context.HandleError(JSError.DuplicateName, true); this.name = this.name + " const"; } if (current_scope is ActivationObject) { this.field = ((ActivationObject)current_scope).AddNewField(this.identifier.ToString(), value, attributes); } else { this.field = ((StackFrame)current_scope).AddNewField(this.identifier.ToString(), value, 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 method is used when the definition must obliterate an existing definition. For example when adding formal parameters at compile time. //It is also used when it is known there is no field with this name, since it does not bother to check. internal virtual JSVariableField AddNewField(String name, Object value, FieldAttributes attributeFlags) { JSVariableField result = this.CreateField(name, attributeFlags, value); this.name_table[name] = result; this.field_table.Add(result); return(result); }
internal virtual JSVariableField AddNewField(string name, object value, FieldAttributes attributeFlags) { JSVariableField field = this.CreateField(name, attributeFlags, value); this.name_table[name] = field; this.field_table.Add(field); return(field); }
internal Constant(Context context, Lookup identifier, TypeExpression type, AST value, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context) { this.attributes = attributes | FieldAttributes.InitOnly; this.customAttributes = customAttributes; this.completion = new Completion(); this.identifier = identifier; this.name = identifier.ToString(); this.value = value; ScriptObject parent = base.Globals.ScopeStack.Peek(); while (parent is WithObject) { parent = parent.GetParent(); } if (parent is ClassScope) { if (this.name == ((ClassScope)parent).name) { identifier.context.HandleError(JSError.CannotUseNameOfClass); this.name = this.name + " const"; } if (attributes == FieldAttributes.PrivateScope) { attributes = FieldAttributes.Public; } } else { if (attributes != FieldAttributes.PrivateScope) { base.context.HandleError(JSError.NotInsideClass); } attributes = FieldAttributes.Public; } if (((IActivationObject)parent).GetLocalField(this.name) != null) { identifier.context.HandleError(JSError.DuplicateName, true); this.name = this.name + " const"; } if (parent is ActivationObject) { this.field = ((ActivationObject)parent).AddNewField(this.identifier.ToString(), value, attributes); } else { this.field = ((StackFrame)parent).AddNewField(this.identifier.ToString(), value, attributes | FieldAttributes.Static); } this.field.type = type; this.field.customAttributes = customAttributes; this.field.originalContext = context; if (this.field is JSLocalField) { ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn; } }
protected override JSVariableField CreateField(String name, FieldAttributes attributeFlags, Object value) { if (!(this.parent is ActivationObject)) { return(base.CreateField(name, attributeFlags, value)); } JSVariableField field = ((ActivationObject)this.parent).AddNewField(name + ":" + this.scopeId, value, attributeFlags); field.debuggerName = name; return(field); }
internal override void Compile() { if (!this.compiled && this.isVisible) { JSVariableField field = ((ActivationObject)this.Scope.GetObject()).AddFieldOrUseExistingField(base.name, null, FieldAttributes.Static | FieldAttributes.Public); Type type = base.engine.GetType(this.typeString); if (type != null) { field.type = new TypeExpression(new ConstantWrapper(type, null)); } this.field = field; } }
internal JSVariableField AddNewField(string name, FieldAttributes attributeFlags, FunctionObject func) { if (this.nested_functions == null) { this.nested_functions = new ArrayList(); this.fields_for_nested_functions = new ArrayList(); } this.nested_functions.Add(func); JSVariableField field = this.AddNewField(name, func, attributeFlags); this.fields_for_nested_functions.Add(field); return(field); }
internal override object Evaluate() { ConstructorInfo member = (ConstructorInfo)((Binding)this.ctor).member; ParameterInfo[] parameters = member.GetParameters(); int length = parameters.Length; for (int i = this.positionalArgValues.Count; i < length; i++) { this.positionalArgValues.Add(Microsoft.JScript.Convert.CoerceT(null, parameters[i].ParameterType)); } object[] array = new object[length]; this.positionalArgValues.CopyTo(0, array, 0, length); object obj2 = member.Invoke(BindingFlags.ExactBinding, null, array, null); int num3 = 0; int count = this.namedArgProperties.Count; while (num3 < count) { JSProperty property = this.namedArgProperties[num3] as JSProperty; if (property != null) { property.SetValue(obj2, Microsoft.JScript.Convert.Coerce(this.namedArgPropertyValues[num3], property.PropertyIR()), null); } else { ((PropertyInfo)this.namedArgProperties[num3]).SetValue(obj2, this.namedArgPropertyValues[num3], null); } num3++; } int num5 = 0; int num6 = this.namedArgFields.Count; while (num5 < num6) { JSVariableField field = this.namedArgFields[num5] as JSVariableField; if (field != null) { field.SetValue(obj2, Microsoft.JScript.Convert.Coerce(this.namedArgFieldValues[num5], field.GetInferredType(null))); } else { ((FieldInfo)this.namedArgFields[num5]).SetValue(obj2, this.namedArgFieldValues[num5]); } num5++; } return(obj2); }
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 override void Compile() { // if it is a named item and it has a type push the type into the field so the compiler knows about it if (!this.compiled) { if (this.isVisible) { ActivationObject obj = (ActivationObject)this.Scope.GetObject(); JSVariableField field = (JSVariableField)obj.AddFieldOrUseExistingField(this.name, null, FieldAttributes.Public | FieldAttributes.Static); Type type = this.engine.GetType(this.typeString); if (type != null) { field.type = new TypeExpression(new ConstantWrapper(type, null)); } this.field = field; } } }
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 parent = base.Globals.ScopeStack.Peek(); while (parent is WithObject) { parent = parent.GetParent(); } this.handler_scope = null; this.field = null; if (identifier != null) { this.fieldName = identifier.ToString(); this.field = parent.GetField(this.fieldName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (this.field != null) { if ((((type == null) && (this.field is JSVariableField)) && (this.field.IsStatic && (((JSVariableField)this.field).type == null))) && (!this.field.IsLiteral && !this.field.IsInitOnly)) { return; } if (((IActivationObject)parent).GetLocalField(this.fieldName) != null) { identifier.context.HandleError(JSError.DuplicateName, false); } } this.handler_scope = new BlockScope(parent); this.handler_scope.catchHanderScope = true; JSVariableField field = this.handler_scope.AddNewField(identifier.ToString(), Microsoft.JScript.Missing.Value, FieldAttributes.Public); this.field = field; field.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; }
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; }
internal ParameterDeclaration(Context context, String identifier, TypeExpression type, CustomAttributeList customAttributes) : base() { this.identifier = identifier; this.type = type == null ? new TypeExpression(new ConstantWrapper(Typeob.Object, context)) : type; this.context = context; ActivationObject current_scope = (ActivationObject)context.document.engine.Globals.ScopeStack.Peek(); if (current_scope.name_table[this.identifier] != null) { //Only happens if there is another parameter declarations with the same name context.HandleError(JSError.DuplicateName, this.identifier, current_scope is ClassScope || current_scope.fast || type != null); } else { JSVariableField field = current_scope.AddNewField(this.identifier, null, 0); field.originalContext = context; } this.customAttributes = customAttributes; }
void AddNameTo(ScriptObject enclosingScope){ while (enclosingScope is WithObject) //Can only happen at run time and only if there is an eval enclosingScope = enclosingScope.GetParent(); FieldInfo field = ((IActivationObject)enclosingScope).GetLocalField(this.name); if (field != null) return; if (enclosingScope is ActivationObject) if (enclosingScope is FunctionScope) field = ((ActivationObject)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public); else field = ((ActivationObject)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public|FieldAttributes.Static); else field = ((StackFrame)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public); JSLocalField lfield = field as JSLocalField; if (lfield != null){ // emit debug info for the local only if this block of code is in a section that has debug set lfield.debugOn = this.context.document.debugOn; lfield.isDefined = true; } this.field = (JSVariableField)field; }
internal override Object Evaluate() { ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member; ParameterInfo[] pars = c.GetParameters(); int pn = pars.Length; for (int i = positionalArgValues.Count; i < pn; i++) { positionalArgValues.Add(Convert.CoerceT(null, pars[i].ParameterType)); } Object[] pArgVals = new Object[pn]; positionalArgValues.CopyTo(0, pArgVals, 0, pn); Object ca = c.Invoke(BindingFlags.ExactBinding, null, pArgVals, null); for (int i = 0, n = this.namedArgProperties.Count; i < n; i++) { JSProperty prop = this.namedArgProperties[i] as JSProperty; if (prop != null) { prop.SetValue(ca, Convert.Coerce(this.namedArgPropertyValues[i], prop.PropertyIR()), null); } else { ((PropertyInfo)this.namedArgProperties[i]).SetValue(ca, this.namedArgPropertyValues[i], null); } } for (int i = 0, n = this.namedArgFields.Count; i < n; i++) { JSVariableField field = this.namedArgFields[i] as JSVariableField; if (field != null) { field.SetValue(ca, Convert.Coerce(this.namedArgFieldValues[i], field.GetInferredType(null))); } else { ((FieldInfo)this.namedArgFields[i]).SetValue(ca, this.namedArgFieldValues[i]); } } return(ca); }
internal Constant(Context context, Lookup identifier, TypeExpression type, AST value, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context){ this.attributes = attributes | FieldAttributes.InitOnly; this.customAttributes = customAttributes; this.completion = new Completion(); this.identifier = identifier; this.name = identifier.ToString(); this.value = value; 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(); if (current_scope is ClassScope){ if (this.name == ((ClassScope)current_scope).name){ identifier.context.HandleError(JSError.CannotUseNameOfClass); this.name = this.name + " const"; } if (attributes == 0) attributes = FieldAttributes.Public; }else{ if (attributes != 0) this.context.HandleError(JSError.NotInsideClass); attributes = FieldAttributes.Public; } FieldInfo field = ((IActivationObject)current_scope).GetLocalField(this.name); if (field != null){ identifier.context.HandleError(JSError.DuplicateName, true); this.name = this.name + " const"; } if (current_scope is ActivationObject) this.field = ((ActivationObject)current_scope).AddNewField(this.identifier.ToString(), value, attributes); else this.field = ((StackFrame)current_scope).AddNewField(this.identifier.ToString(), value, 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; }
void AddNameTo(ScriptObject enclosingScope) { while (enclosingScope is WithObject) //Can only happen at run time and only if there is an eval { enclosingScope = enclosingScope.GetParent(); } FieldInfo field = ((IActivationObject)enclosingScope).GetLocalField(this.name); if (field != null) { return; } if (enclosingScope is ActivationObject) { if (enclosingScope is FunctionScope) { field = ((ActivationObject)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public); } else { field = ((ActivationObject)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public | FieldAttributes.Static); } } else { field = ((StackFrame)enclosingScope).AddNewField(this.name, null, FieldAttributes.Public); } JSLocalField lfield = field as JSLocalField; if (lfield != null) { // emit debug info for the local only if this block of code is in a section that has debug set lfield.debugOn = this.context.document.debugOn; lfield.isDefined = true; } this.field = (JSVariableField)field; }
internal override AST PartiallyEvaluate() { if (this.alreadyPartiallyEvaluated) { return(this); } this.alreadyPartiallyEvaluated = true; if (this.inBrackets && this.AllParamsAreMissing()) { if (this.isConstructor) { this.args.context.HandleError(JSError.TypeMismatch); } return(new ConstantWrapper(new TypedArray(((TypeExpression) new TypeExpression(this.func).PartiallyEvaluate()).ToIReflect(), this.args.count + 1), base.context)); } this.func = this.func.PartiallyEvaluateAsCallable(); this.args = (ASTList)this.args.PartiallyEvaluate(); IReflect[] argIRs = this.ArgIRs(); this.func.ResolveCall(this.args, argIRs, this.isConstructor, this.inBrackets); if ((!this.isConstructor && !this.inBrackets) && ((this.func is Binding) && (this.args.count == 1))) { Binding func = (Binding)this.func; if (func.member is Type) { Type member = (Type)func.member; ConstantWrapper wrapper = this.args[0] as ConstantWrapper; if (wrapper != null) { try { if ((wrapper.value == null) || (wrapper.value is DBNull)) { return(this); } if (wrapper.isNumericLiteral && (((member == Typeob.Decimal) || (member == Typeob.Int64)) || ((member == Typeob.UInt64) || (member == Typeob.Single)))) { return(new ConstantWrapper(Microsoft.JScript.Convert.CoerceT(wrapper.context.GetCode(), member, true), base.context)); } return(new ConstantWrapper(Microsoft.JScript.Convert.CoerceT(wrapper.Evaluate(), member, true), base.context)); } catch { wrapper.context.HandleError(JSError.TypeMismatch); goto Label_0354; } } if (!Binding.AssignmentCompatible(member, this.args[0], argIRs[0], false)) { this.args[0].context.HandleError(JSError.ImpossibleConversion); } } else if (func.member is JSVariableField) { JSVariableField field = (JSVariableField)func.member; if (field.IsLiteral) { if (field.value is ClassScope) { ClassScope scope = (ClassScope)field.value; IReflect underlyingTypeIfEnum = scope.GetUnderlyingTypeIfEnum(); if (underlyingTypeIfEnum != null) { if ((!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], underlyingTypeIfEnum) && !Microsoft.JScript.Convert.IsPromotableTo(underlyingTypeIfEnum, argIRs[0])) && ((argIRs[0] != Typeob.String) || (underlyingTypeIfEnum == scope))) { this.args[0].context.HandleError(JSError.ImpossibleConversion); } } else if (!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], scope) && !Microsoft.JScript.Convert.IsPromotableTo(scope, argIRs[0])) { this.args[0].context.HandleError(JSError.ImpossibleConversion); } } else if (field.value is TypedArray) { TypedArray array = (TypedArray)field.value; if (!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], array) && !Microsoft.JScript.Convert.IsPromotableTo(array, argIRs[0])) { this.args[0].context.HandleError(JSError.ImpossibleConversion); } } } } } Label_0354: return(this); }
private void EnterNameIntoEnclosingScopeAndGetOwnField(AST id, bool isStatic){ if (((IActivationObject)this.enclosingScope).GetLocalField(this.name) != null){ id.context.HandleError(JSError.DuplicateName, true); this.name = this.name + " class"; } FieldAttributes fieldAttrs = FieldAttributes.Literal; switch (this.attributes & TypeAttributes.VisibilityMask){ case TypeAttributes.NestedAssembly : fieldAttrs |= FieldAttributes.Assembly; break; case TypeAttributes.NestedFamANDAssem : fieldAttrs |= FieldAttributes.FamANDAssem; break; case TypeAttributes.NestedFamily : fieldAttrs |= FieldAttributes.Family; break; case TypeAttributes.NestedFamORAssem : fieldAttrs |= FieldAttributes.FamORAssem; break; case TypeAttributes.NestedPrivate : fieldAttrs |= FieldAttributes.Private; break; default: fieldAttrs |= FieldAttributes.Public; break; } ScriptObject enclScope = this.enclosingScope; while (enclScope is BlockScope) enclScope = enclScope.GetParent(); if (!(enclScope is GlobalScope) && !(enclScope is PackageScope) && !(enclScope is ClassScope)){ isStatic = false; if (this is EnumDeclaration) this.context.HandleError(JSError.EnumNotAllowed); else this.context.HandleError(JSError.ClassNotAllowed); } if (isStatic) fieldAttrs |= FieldAttributes.Static; if (this.enclosingScope is ActivationObject){ if (this.enclosingScope is ClassScope){ if (this.name == ((ClassScope)this.enclosingScope).name){ context.HandleError(JSError.CannotUseNameOfClass); this.name = this.name + " nested class"; } } this.ownField = ((ActivationObject)this.enclosingScope).AddNewField(this.name, this.classob, fieldAttrs); if (this.ownField is JSLocalField) ((JSLocalField)this.ownField).isDefined = true; }else this.ownField = ((StackFrame)this.enclosingScope).AddNewField(this.name, this.classob, fieldAttrs); this.ownField.originalContext = id.context; }
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); } }
private void TranslateToILSourceTextProvider() { if (!base.Engine.doFast && (string.Compare(this.name, this.field.Name, StringComparison.Ordinal) == 0)) { StringBuilder builder = new StringBuilder(this.func.ToString()); for (JSMemberField field = ((JSMemberField) this.field).nextOverload; field != null; field = field.nextOverload) { field.metaData = this; builder.Append('\n'); builder.Append(field.value.ToString()); } MethodAttributes attributes = MethodAttributes.Static | MethodAttributes.Public; ILGenerator iLGenerator = ((ClassScope) this.func.enclosing_scope).GetTypeBuilder().DefineMethod(this.name + " source", attributes, Typeob.String, new Type[0]).GetILGenerator(); iLGenerator.Emit(OpCodes.Ldstr, builder.ToString()); iLGenerator.Emit(OpCodes.Ret); } }
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); } }
private void TranslateToILSourceTextProvider() { if (!base.Engine.doFast && (string.Compare(this.name, this.field.Name, StringComparison.Ordinal) == 0)) { StringBuilder builder = new StringBuilder(this.func.ToString()); for (JSMemberField field = ((JSMemberField)this.field).nextOverload; field != null; field = field.nextOverload) { field.metaData = this; builder.Append('\n'); builder.Append(field.value.ToString()); } MethodAttributes attributes = MethodAttributes.Static | MethodAttributes.Public; ILGenerator iLGenerator = ((ClassScope)this.func.enclosing_scope).GetTypeBuilder().DefineMethod(this.name + " source", attributes, Typeob.String, new Type[0]).GetILGenerator(); iLGenerator.Emit(OpCodes.Ldstr, builder.ToString()); iLGenerator.Emit(OpCodes.Ret); } }
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) { MethodAttributes methodAttributes = (MethodAttributes)0; if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) { methodAttributes = MethodAttributes.Public; } else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private) { methodAttributes = MethodAttributes.Private; } else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly) { methodAttributes = MethodAttributes.Assembly; } else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family) { methodAttributes = MethodAttributes.Family; } else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem) { methodAttributes = MethodAttributes.FamORAssem; } else { methodAttributes = MethodAttributes.Public; } if ((attributes & FieldAttributes.Static) != 0 || !isMethod) { methodAttributes |= MethodAttributes.Static; } else { methodAttributes |= MethodAttributes.Virtual | MethodAttributes.NewSlot; } if (isAbstract) { methodAttributes |= MethodAttributes.Abstract; } if (isFinal) { methodAttributes |= MethodAttributes.Final; } this.name = id.ToString(); this.isMethod = isMethod; if (ifaceId != null) { if (isMethod) { this.ifaceId = new TypeExpression(ifaceId); methodAttributes &= ~MethodAttributes.MemberAccessMask; methodAttributes |= MethodAttributes.Private | MethodAttributes.Final; } else { this.declaringObject = new Member(ifaceId.context, ifaceId, id); this.name = this.declaringObject.ToString(); } } ScriptObject enclosingScope = Globals.ScopeStack.Peek(); if (attributes == 0 && !isAbstract && !isFinal) { if (enclosingScope is ClassScope) { attributes |= FieldAttributes.Public; } } else { if (!(enclosingScope is ClassScope)) { this.context.HandleError(JSError.NotInsideClass); attributes = (FieldAttributes)0; methodAttributes = MethodAttributes.Public; } } if (enclosingScope is ActivationObject) { this.inFastScope = ((ActivationObject)enclosingScope).fast; // if later on originalName != this.name this is a property getter/setter String originalName = this.name; // mangle the name if (isGetter) { methodAttributes |= MethodAttributes.SpecialName; this.name = "get_" + this.name; if (return_type == null) { return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context)); } } else if (isSetter) { methodAttributes |= MethodAttributes.SpecialName; this.name = "set_" + this.name; return_type = new TypeExpression(new ConstantWrapper(Typeob.Void, context)); } attributes &= FieldAttributes.FieldAccessMask; // create the function object this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, methodAttributes, customAttributes, this.isMethod); if (this.declaringObject != null) { return; } // check whether the function name (possibly mangled) is in use already String fieldName = this.name; if (this.ifaceId != null) { fieldName = ifaceId.ToString() + "." + fieldName; } JSVariableField localField = (JSVariableField)((ActivationObject)enclosingScope).name_table[fieldName]; if (localField != null && (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || this.func.isExpandoMethod)) { if (originalName != this.name) { localField.originalContext.HandleError(JSError.ClashWithProperty); } else { id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod); if (localField.value is FunctionObject) { ((FunctionObject)localField.value).suppressIL = true; } } } // create or update the proper field if (this.isMethod) { if (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || originalName != this.name) { this.field = ((ActivationObject)enclosingScope).AddNewField(fieldName, this.func, attributes | FieldAttributes.Literal); if (originalName == this.name) // if it is a property do not assign the type { ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, this.context)); } } else { this.field = ((JSMemberField)localField).AddOverload(this.func, attributes | FieldAttributes.Literal); } } else if (enclosingScope is FunctionScope) { if (this.inFastScope) { attributes |= FieldAttributes.Literal; } this.field = ((FunctionScope)enclosingScope).AddNewField(this.name, attributes, this.func); if (this.field is JSLocalField) { JSLocalField locField = (JSLocalField)this.field; if (this.inFastScope) { locField.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context)); locField.attributeFlags |= FieldAttributes.Literal; } locField.debugOn = this.context.document.debugOn; locField.isDefined = true; } } else if (this.inFastScope) { this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes | FieldAttributes.Literal); ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context)); //Do not use typeof(Closure) for the field, since that has the arguments and callee properties, which are not //accessible in fast mode } else //enclosingScope is GlobalObject { this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes | FieldAttributes.Static); } ((JSVariableField)this.field).originalContext = context; // if it is a property create/update the PropertyInfo and assign the getter/setter if (originalName != this.name) { String propertyFieldName = originalName; if (this.ifaceId != null) { propertyFieldName = ifaceId.ToString() + "." + originalName; } FieldInfo prop = (FieldInfo)((ClassScope)enclosingScope).name_table[propertyFieldName]; if (prop != null) { // check whether a property was defined already if (prop.IsLiteral) { Object val = ((JSVariableField)prop).value; if (val is JSProperty) { this.enclosingProperty = (JSProperty)val; } } if (this.enclosingProperty == null) { id.context.HandleError(JSError.DuplicateName, true); // the matching name was not a property } } if (this.enclosingProperty == null) { this.enclosingProperty = new JSProperty(originalName); prop = ((ActivationObject)enclosingScope).AddNewField(propertyFieldName, this.enclosingProperty, attributes | FieldAttributes.Literal); ((JSMemberField)prop).originalContext = this.context; } else { if ((isGetter && this.enclosingProperty.getter != null) || (isSetter && this.enclosingProperty.setter != null)) { id.context.HandleError(JSError.DuplicateName, true); // duplicated setter or getter } } if (isGetter) { this.enclosingProperty.getter = new JSFieldMethod(this.field, enclosingScope); } else { this.enclosingProperty.setter = new JSFieldMethod(this.field, enclosingScope); } } } else //Might get here if function declaration is inside of an eval. { this.inFastScope = false; this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, MethodAttributes.Public, null, false); this.field = ((StackFrame)enclosingScope).AddNewField(this.name, new Closure(this.func), attributes | FieldAttributes.Static); } }
internal override AST PartiallyEvaluate() { if (this.alreadyPartiallyEvaluated) { return(this); } this.alreadyPartiallyEvaluated = true; if (this.inBrackets && this.AllParamsAreMissing()) { if (this.isConstructor) { this.args.context.HandleError(JSError.TypeMismatch); } IReflect ir = ((TypeExpression)(new TypeExpression(this.func)).PartiallyEvaluate()).ToIReflect(); return(new ConstantWrapper(new TypedArray(ir, this.args.count + 1), this.context)); } this.func = this.func.PartiallyEvaluateAsCallable(); this.args = (ASTList)this.args.PartiallyEvaluate(); IReflect[] argIRs = this.ArgIRs(); this.func.ResolveCall(this.args, argIRs, this.isConstructor, this.inBrackets); if (!this.isConstructor && !this.inBrackets && this.func is Binding && this.args.count == 1) { Binding b = (Binding)this.func; if (b.member is Type) { Type t = (Type)b.member; ConstantWrapper arg0 = this.args[0] as ConstantWrapper; if (arg0 != null) { try{ if (arg0.value == null || arg0.value is DBNull) { return(this); } else if (arg0.isNumericLiteral && (t == Typeob.Decimal || t == Typeob.Int64 || t == Typeob.UInt64 || t == Typeob.Single)) { return(new ConstantWrapper(Convert.CoerceT(arg0.context.GetCode(), t, true), this.context)); } else { return(new ConstantWrapper(Convert.CoerceT(arg0.Evaluate(), t, true), this.context)); } }catch { arg0.context.HandleError(JSError.TypeMismatch); } } else { if (!Binding.AssignmentCompatible(t, this.args[0], argIRs[0], false)) { this.args[0].context.HandleError(JSError.ImpossibleConversion); } } } else if (b.member is JSVariableField) { JSVariableField field = (JSVariableField)b.member; if (field.IsLiteral) { if (field.value is ClassScope) { ClassScope csc = (ClassScope)field.value; IReflect ut = csc.GetUnderlyingTypeIfEnum(); if (ut != null) { if (!Convert.IsPromotableTo(argIRs[0], ut) && !Convert.IsPromotableTo(ut, argIRs[0]) && (argIRs[0] != Typeob.String || ut == csc)) { this.args[0].context.HandleError(JSError.ImpossibleConversion); } } else { if (!Convert.IsPromotableTo(argIRs[0], csc) && !Convert.IsPromotableTo(csc, argIRs[0])) { this.args[0].context.HandleError(JSError.ImpossibleConversion); } } } else if (field.value is TypedArray) { TypedArray ta = (TypedArray)field.value; if (!Convert.IsPromotableTo(argIRs[0], ta) && !Convert.IsPromotableTo(ta, argIRs[0])) { this.args[0].context.HandleError(JSError.ImpossibleConversion); } } } } } return(this); }
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) { MethodAttributes methodAttributes = (MethodAttributes)0; if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) methodAttributes = MethodAttributes.Public; else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private) methodAttributes = MethodAttributes.Private; else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly) methodAttributes = MethodAttributes.Assembly; else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family) methodAttributes = MethodAttributes.Family; else if ((attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem) methodAttributes = MethodAttributes.FamORAssem; else methodAttributes = MethodAttributes.Public; if ((attributes & FieldAttributes.Static) != 0 || !isMethod) methodAttributes |= MethodAttributes.Static; else methodAttributes |= MethodAttributes.Virtual | MethodAttributes.NewSlot; if (isAbstract) methodAttributes |= MethodAttributes.Abstract; if (isFinal) methodAttributes |= MethodAttributes.Final; this.name = id.ToString(); this.isMethod = isMethod; if (ifaceId != null){ if (isMethod){ this.ifaceId = new TypeExpression(ifaceId); methodAttributes &= ~MethodAttributes.MemberAccessMask; methodAttributes |= MethodAttributes.Private|MethodAttributes.Final; }else{ this.declaringObject = new Member(ifaceId.context, ifaceId, id); this.name = this.declaringObject.ToString(); } } ScriptObject enclosingScope = Globals.ScopeStack.Peek(); if (attributes == 0 && !isAbstract && !isFinal){ if (enclosingScope is ClassScope) attributes |= FieldAttributes.Public; }else{ if (!(enclosingScope is ClassScope)){ this.context.HandleError(JSError.NotInsideClass); attributes = (FieldAttributes)0; methodAttributes = MethodAttributes.Public; } } if (enclosingScope is ActivationObject){ this.inFastScope = ((ActivationObject)enclosingScope).fast; // if later on originalName != this.name this is a property getter/setter String originalName = this.name; // mangle the name if (isGetter){ methodAttributes |= MethodAttributes.SpecialName; this.name = "get_" + this.name; if (return_type == null) return_type = new TypeExpression(new ConstantWrapper(Typeob.Object, context)); }else if (isSetter){ methodAttributes |= MethodAttributes.SpecialName; this.name = "set_" + this.name; return_type = new TypeExpression(new ConstantWrapper(Typeob.Void, context)); } attributes &= FieldAttributes.FieldAccessMask; // create the function object this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, methodAttributes, customAttributes, this.isMethod); if (this.declaringObject != null) return; // check whether the function name (possibly mangled) is in use already String fieldName = this.name; if (this.ifaceId != null) fieldName = ifaceId.ToString()+"."+fieldName; JSVariableField localField = (JSVariableField)((ActivationObject)enclosingScope).name_table[fieldName]; if (localField != null && (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || this.func.isExpandoMethod)){ if (originalName != this.name) localField.originalContext.HandleError(JSError.ClashWithProperty); else{ id.context.HandleError(JSError.DuplicateName, this.func.isExpandoMethod); if (localField.value is FunctionObject) ((FunctionObject)localField.value).suppressIL = true; } } // create or update the proper field if (this.isMethod){ if (!(localField is JSMemberField) || !(((JSMemberField)localField).value is FunctionObject) || originalName != this.name){ this.field = ((ActivationObject)enclosingScope).AddNewField(fieldName, this.func, attributes|FieldAttributes.Literal); if (originalName == this.name) // if it is a property do not assign the type ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.FunctionWrapper, this.context)); }else this.field = ((JSMemberField)localField).AddOverload(this.func, attributes|FieldAttributes.Literal); }else if (enclosingScope is FunctionScope){ if (this.inFastScope) attributes |= FieldAttributes.Literal; this.field = ((FunctionScope)enclosingScope).AddNewField(this.name, attributes, this.func); if (this.field is JSLocalField){ JSLocalField locField = (JSLocalField)this.field; if (this.inFastScope){ locField.type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context)); locField.attributeFlags |= FieldAttributes.Literal; } locField.debugOn = this.context.document.debugOn; locField.isDefined = true; } }else if (this.inFastScope){ this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes|FieldAttributes.Literal); ((JSVariableField)this.field).type = new TypeExpression(new ConstantWrapper(Typeob.ScriptFunction, this.context)); //Do not use typeof(Closure) for the field, since that has the arguments and callee properties, which are not //accessible in fast mode }else //enclosingScope is GlobalObject this.field = ((ActivationObject)enclosingScope).AddNewField(this.name, this.func, attributes|FieldAttributes.Static); ((JSVariableField)this.field).originalContext = context; // if it is a property create/update the PropertyInfo and assign the getter/setter if (originalName != this.name){ String propertyFieldName = originalName; if (this.ifaceId != null) propertyFieldName = ifaceId.ToString()+"."+originalName; FieldInfo prop = (FieldInfo)((ClassScope)enclosingScope).name_table[propertyFieldName]; if (prop != null){ // check whether a property was defined already if (prop.IsLiteral){ Object val = ((JSVariableField)prop).value; if (val is JSProperty) this.enclosingProperty = (JSProperty)val; } if (this.enclosingProperty == null) id.context.HandleError(JSError.DuplicateName, true); // the matching name was not a property } if (this.enclosingProperty == null){ this.enclosingProperty = new JSProperty(originalName); prop = ((ActivationObject)enclosingScope).AddNewField(propertyFieldName, this.enclosingProperty, attributes|FieldAttributes.Literal); ((JSMemberField)prop).originalContext = this.context; }else{ if ((isGetter && this.enclosingProperty.getter != null) || (isSetter && this.enclosingProperty.setter != null)) id.context.HandleError(JSError.DuplicateName, true); // duplicated setter or getter } if (isGetter) this.enclosingProperty.getter = new JSFieldMethod(this.field, enclosingScope); else this.enclosingProperty.setter = new JSFieldMethod(this.field, enclosingScope); } }else{ //Might get here if function declaration is inside of an eval. this.inFastScope = false; this.func = new FunctionObject(this.name, formal_parameters, return_type, body, own_scope, enclosingScope, this.context, MethodAttributes.Public, null, false); this.field = ((StackFrame)enclosingScope).AddNewField(this.name, new Closure(this.func), attributes|FieldAttributes.Static); } }
internal VariableDeclaration(Context context, Lookup identifier, TypeExpression type, AST initializer, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context) { if (initializer != null) { base.context.UpdateWith(initializer.context); } else if (type != null) { base.context.UpdateWith(type.context); } this.identifier = identifier; this.type = type; this.initializer = initializer; ScriptObject parent = base.Globals.ScopeStack.Peek(); while (parent is WithObject) { parent = parent.GetParent(); } string name = this.identifier.ToString(); if (parent is ClassScope) { if (name == ((ClassScope) parent).name) { identifier.context.HandleError(JSError.CannotUseNameOfClass); name = name + " var"; } } else if (attributes != FieldAttributes.PrivateScope) { base.context.HandleError(JSError.NotInsideClass); attributes = FieldAttributes.Public; } else { attributes |= FieldAttributes.Public; } FieldInfo localField = ((IActivationObject) parent).GetLocalField(name); if (localField != null) { if ((localField.IsLiteral || (parent is ClassScope)) || (type != null)) { identifier.context.HandleError(JSError.DuplicateName, true); } this.type = (TypeExpression) (type = null); } if (parent is ActivationObject) { if ((localField == null) || (localField is JSVariableField)) { this.field = ((ActivationObject) parent).AddFieldOrUseExistingField(this.identifier.ToString(), Microsoft.JScript.Missing.Value, attributes); } else { this.field = ((ActivationObject) parent).AddNewField(this.identifier.ToString(), null, attributes); } } else { this.field = ((StackFrame) parent).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) { ((JSLocalField) this.field).debugOn = this.identifier.context.document.debugOn; } this.completion = new Completion(); }
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 VariableDeclaration(Context context, Lookup identifier, TypeExpression type, AST initializer, FieldAttributes attributes, CustomAttributeList customAttributes) : base(context) { if (initializer != null) { base.context.UpdateWith(initializer.context); } else if (type != null) { base.context.UpdateWith(type.context); } this.identifier = identifier; this.type = type; this.initializer = initializer; ScriptObject parent = base.Globals.ScopeStack.Peek(); while (parent is WithObject) { parent = parent.GetParent(); } string name = this.identifier.ToString(); if (parent is ClassScope) { if (name == ((ClassScope)parent).name) { identifier.context.HandleError(JSError.CannotUseNameOfClass); name = name + " var"; } } else if (attributes != FieldAttributes.PrivateScope) { base.context.HandleError(JSError.NotInsideClass); attributes = FieldAttributes.Public; } else { attributes |= FieldAttributes.Public; } FieldInfo localField = ((IActivationObject)parent).GetLocalField(name); if (localField != null) { if ((localField.IsLiteral || (parent is ClassScope)) || (type != null)) { identifier.context.HandleError(JSError.DuplicateName, true); } this.type = (TypeExpression)(type = null); } if (parent is ActivationObject) { if ((localField == null) || (localField is JSVariableField)) { this.field = ((ActivationObject)parent).AddFieldOrUseExistingField(this.identifier.ToString(), Microsoft.JScript.Missing.Value, attributes); } else { this.field = ((ActivationObject)parent).AddNewField(this.identifier.ToString(), null, attributes); } } else { this.field = ((StackFrame)parent).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) { ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn; } this.completion = new Completion(); }