public string ToString(EcmaState state) { switch (this.type) { case EcmaValueType.Undefined: return("undefined"); case EcmaValueType.Null: return("null"); case EcmaValueType.Boolean: return(this.ToBoolean(state) ? "true" : "false"); case EcmaValueType.Number: return(EcmaGramma.ConvertStringToNumber(this.ToNumber(state))); case EcmaValueType.String: return((string)this.value); case EcmaValueType.Object: return((this.value as EcmaHeadObject).DefaultValue(state, "String").ToString(state)); default: throw new EcmaRuntimeException("Cant convert " + this.type.ToString() + " to string"); } }
public double ToNumber(EcmaState state) { switch (this.type) { case EcmaValueType.Undefined: return(Double.NaN); case EcmaValueType.Null: return(0.0); case EcmaValueType.Boolean: return(this.ToBoolean(state) ? 1.0 : 0.0); case EcmaValueType.Number: return((double)this.value); case EcmaValueType.String: return(EcmaGramma.ConvertStringToNumber(this.ToString(state))); case EcmaValueType.Object: return((this.value as EcmaHeadObject).DefaultValue(state, "Number").ToNumber(state)); } throw new EcmaRuntimeException("Cant convert " + this.type + " to Number"); }