private HandleError ( JSError errorId ) : void | ||
errorId | JSError | |
return | void |
internal void CoerceToBaseType(Type bt, Context errCtx){ Object val = 0; AST pval = ((AST)this.value).PartiallyEvaluate(); if (pval is ConstantWrapper) val = ((ConstantWrapper)pval).Evaluate(); else pval.context.HandleError(JSError.NotConst); try{ this.value = Convert.CoerceT(val, bt); }catch(Exception){ errCtx.HandleError(JSError.TypeMismatch); this.value = Convert.CoerceT(0, bt); } }
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; }
internal ParameterDeclaration(Context context, string identifier, TypeExpression type, CustomAttributeList customAttributes) { this.identifier = identifier; this.type = (type == null) ? new TypeExpression(new ConstantWrapper(Typeob.Object, context)) : type; this.context = context; ActivationObject obj2 = (ActivationObject) context.document.engine.Globals.ScopeStack.Peek(); if (obj2.name_table[this.identifier] != null) { context.HandleError(JSError.DuplicateName, this.identifier, ((obj2 is ClassScope) || obj2.fast) || (type != null)); } else { obj2.AddNewField(this.identifier, null, FieldAttributes.PrivateScope).originalContext = context; } this.customAttributes = customAttributes; }
internal ParameterDeclaration(Context context, string identifier, TypeExpression type, CustomAttributeList customAttributes) { this.identifier = identifier; this.type = (type == null) ? new TypeExpression(new ConstantWrapper(Typeob.Object, context)) : type; this.context = context; ActivationObject obj2 = (ActivationObject)context.document.engine.Globals.ScopeStack.Peek(); if (obj2.name_table[this.identifier] != null) { context.HandleError(JSError.DuplicateName, this.identifier, ((obj2 is ClassScope) || obj2.fast) || (type != null)); } else { obj2.AddNewField(this.identifier, null, FieldAttributes.PrivateScope).originalContext = context; } this.customAttributes = customAttributes; }
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; }
internal void CoerceToBaseType(Type bt, Context errCtx) { Object val = 0; AST pval = ((AST)this.value).PartiallyEvaluate(); if (pval is ConstantWrapper) { val = ((ConstantWrapper)pval).Evaluate(); } else { pval.context.HandleError(JSError.NotConst); } try{ this.value = Convert.CoerceT(val, bt); }catch (Exception) { errCtx.HandleError(JSError.TypeMismatch); this.value = Convert.CoerceT(0, bt); } }
internal void CoerceToBaseType(Type bt, Context errCtx) { object obj2 = 0; AST ast = ((AST) this.value).PartiallyEvaluate(); if (ast is ConstantWrapper) { obj2 = ((ConstantWrapper) ast).Evaluate(); } else { ast.context.HandleError(JSError.NotConst); } try { this._value = Microsoft.JScript.Convert.CoerceT(obj2, bt); } catch { errCtx.HandleError(JSError.TypeMismatch); this._value = Microsoft.JScript.Convert.CoerceT(0, bt); } }
internal void CoerceToBaseType(Type bt, Context errCtx) { object obj2 = 0; AST ast = ((AST)this.value).PartiallyEvaluate(); if (ast is ConstantWrapper) { obj2 = ((ConstantWrapper)ast).Evaluate(); } else { ast.context.HandleError(JSError.NotConst); } try { this._value = Microsoft.JScript.Convert.CoerceT(obj2, bt); } catch { errCtx.HandleError(JSError.TypeMismatch); this._value = Microsoft.JScript.Convert.CoerceT(0, bt); } }
//--------------------------------------------------------------------------------------- // ReportError // // Generate a parser error. // The function is told whether or not next call to GetToken() should return the same // token or not //--------------------------------------------------------------------------------------- private void ReportError(JSError errorId, Context context, bool skipToken){ Debug.Assert(context != null); int previousSeverity = this.Severity; this.Severity = (new JScriptException(errorId)).Severity; // EOF error is special and it's the last error we can possibly get if (JSToken.EndOfFile == context.token) EOFError(errorId); // EOF context is special else{ // report the error if not in error condition and the // error for this token is not worse than the one for the // previous token if (this.goodTokensProcessed > 0 || this.Severity < previousSeverity) context.HandleError(errorId); // reset proper info if (skipToken) this.goodTokensProcessed = -1; else{ this.errorToken = this.currentToken; this.goodTokensProcessed = 0; } } }
internal void CheckTypeNameForCLSCompliance(String name, String fullname, Context context){ if (!this.isCLSCompliant) return; if (name[0] == '_'){ context.HandleError(JSError.NonCLSCompliantType); return; } if (!VsaEngine.CheckIdentifierForCLSCompliance(fullname)){ context.HandleError(JSError.NonCLSCompliantType); return; } if (this.typenameTable == null) this.typenameTable = new Hashtable(StringComparer.OrdinalIgnoreCase); if (this.typenameTable[fullname] == null) this.typenameTable[fullname] = fullname; else context.HandleError(JSError.NonCLSCompliantType); }
internal static object LiteralToNumber(string str, Context context) { uint rdx = 10; if ((str[0] == '0') && (str.Length > 1)) { if ((str[1] == 'x') || (str[1] == 'X')) { rdx = 0x10; } else { rdx = 8; } } object obj2 = parseRadix(str.ToCharArray(), rdx, (rdx == 0x10) ? 2 : 0, 1, false); if (obj2 != null) { if (((rdx == 8) && (context != null)) && ((obj2 is int) && (((int) obj2) > 7))) { context.HandleError(JSError.OctalLiteralsAreDeprecated); } return obj2; } context.HandleError(JSError.BadOctalLiteral); return parseRadix(str.ToCharArray(), 10, 0, 1, false); }
//--------------------------------------------------------------------------------------- // ForceReportInfo // // Generate a parser error (info), does not change the error state in the parse //--------------------------------------------------------------------------------------- private void ForceReportInfo(Context context, JSError errorId){ Debug.Assert(context != null); context.HandleError(errorId); }
private void ReportError(JSError errorId, Context context, bool skipToken) { int severity = this.Severity; this.Severity = new JScriptException(errorId).Severity; if (context.token == JSToken.EndOfFile) { this.EOFError(errorId); } else { if ((this.goodTokensProcessed > 0L) || (this.Severity < severity)) { context.HandleError(errorId); } if (skipToken) { this.goodTokensProcessed = -1L; } else { this.errorToken = this.currentToken; this.goodTokensProcessed = 0L; } } }
internal void CheckTypeNameForCLSCompliance(String name, String fullname, Context context){ if (!this.isCLSCompliant) return; if (name[0] == '_'){ context.HandleError(JSError.NonCLSCompliantType); return; } if (!VsaEngine.CheckIdentifierForCLSCompliance(fullname)){ context.HandleError(JSError.NonCLSCompliantType); return; } if (this.typenameTable == null) this.typenameTable = new Hashtable(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture)); if (this.typenameTable[fullname] == null) this.typenameTable[fullname] = fullname; else context.HandleError(JSError.NonCLSCompliantType); }
internal static bool CheckParameters(ParameterInfo[] pars, IReflect[] argIRs, ASTList argAST, Context ctx, int offset, bool defaultIsUndefined, bool reportError){ int n = argIRs.Length; int m = pars.Length; bool tooManyParams = false; if (n > m-offset) {n = m-offset; tooManyParams = true;} for (int i = 0; i < n; i++){ IReflect formalIR = (pars[i+offset] is ParameterDeclaration) ? ((ParameterDeclaration)pars[i+offset]).ParameterIReflect : pars[i+offset].ParameterType; IReflect actualIR = argIRs[i]; if (i == n-1 && ((formalIR is Type && Typeob.Array.IsAssignableFrom((Type)formalIR)) || formalIR is TypedArray) && pars[i+offset].IsDefined(Typeob.ParamArrayAttribute, false)){ tooManyParams = false; int k = argIRs.Length; if (i == k - 1){ if (Binding.AssignmentCompatible(formalIR, argAST[i], argIRs[i], false)) return true; } IReflect elemIR = formalIR is Type ? ((Type)formalIR).GetElementType() : ((TypedArray)formalIR).elementType; for (int j = i; j < k; j++) if (!Binding.AssignmentCompatible(elemIR, argAST[j], argIRs[j], reportError)) return false; return true; } if (!Binding.AssignmentCompatible(formalIR, argAST[i], actualIR, reportError)) return false; } if (tooManyParams && reportError) ctx.HandleError(JSError.TooManyParameters); if (offset == 0 && n < m && !defaultIsUndefined) //Fewer actual parameters than formal parameters for (int j = n; j < m; j++) if (pars[j].DefaultValue == System.Convert.DBNull){ //No default value specified if (j < m-1 || !pars[j].IsDefined(Typeob.ParamArrayAttribute, false)){ if (reportError) ctx.HandleError(JSError.TooFewParameters); IReflect formalIR = (pars[j+offset] is ParameterDeclaration) ? ((ParameterDeclaration)pars[j+offset]).ParameterIReflect : pars[j+offset].ParameterType; Type formalType = formalIR as Type; if (formalType != null && formalType.IsValueType && !formalType.IsPrimitive && !formalType.IsEnum) return false; //Can't generate valid code for this since there is no general mapping from undefined to value types } } return true; }
internal static void WarnIfObsolete(MemberInfo member, Context context){ if (member == null) return; String message = null; bool isError = false; Object[] custAttribs = member.GetCustomAttributes(Typeob.ObsoleteAttribute, false); if (custAttribs != null && custAttribs.Length > 0){ ObsoleteAttribute attr = (ObsoleteAttribute)custAttribs[0]; message = attr.Message; isError = attr.IsError; }else{ custAttribs = member.GetCustomAttributes(Typeob.NotRecommended, false); if (custAttribs != null && custAttribs.Length > 0){ NotRecommended attr = (NotRecommended)custAttribs[0]; message = ": " + attr.Message; isError = false; }else return; } context.HandleError(JSError.Deprecated, message, isError); }
internal void CheckTypeNameForCLSCompliance(string name, string fullname, Context context) { if (this.isCLSCompliant) { if (name[0] == '_') { context.HandleError(JSError.NonCLSCompliantType); } else if (!CheckIdentifierForCLSCompliance(fullname)) { context.HandleError(JSError.NonCLSCompliantType); } else { if (this.typenameTable == null) { this.typenameTable = new Hashtable(StringComparer.OrdinalIgnoreCase); } if (this.typenameTable[fullname] == null) { this.typenameTable[fullname] = fullname; } else { context.HandleError(JSError.NonCLSCompliantType); } } } }
internal static Object LiteralToNumber(String str, Context context){ //Called from the parser for integer literals uint r = 10; if (str[0] == '0' && str.Length > 1) if (str[1] == 'x' || str[1] == 'X') r = 16; else r = 8; Object result = Convert.parseRadix(str.ToCharArray(), r, r == 16 ? 2 : 0, 1, false); if (result != null){ if (r == 8 && context != null && result is Int32 && ((int)result) > 7) context.HandleError(JSError.OctalLiteralsAreDeprecated); return result; } context.HandleError(JSError.BadOctalLiteral); return Convert.parseRadix(str.ToCharArray(), 10, 0, 1, false); }
private void ForceReportInfo(Context context, JSError errorId) { context.HandleError(errorId); }