internal object GetPrimitiveValuePreES6(PrimitiveTypeHint typeHint)
{
if (typeHint == PrimitiveTypeHint.None || typeHint == PrimitiveTypeHint.Number)
{
// Try calling valueOf().
object valueOfResult;
if (TryCallMemberFunction(out valueOfResult, "valueOf") == true)
{
// Return value must be primitive.
if (valueOfResult is double || TypeUtilities.IsPrimitive(valueOfResult) == true)
return valueOfResult;
}
// Try calling toString().
object toStringResult;
if (TryCallMemberFunction(out toStringResult, "toString") == true)
{
// Return value must be primitive.
if (toStringResult is string || TypeUtilities.IsPrimitive(toStringResult) == true)
return toStringResult;
}
}
else
{
// Try calling toString().
object toStringResult;
if (TryCallMemberFunction(out toStringResult, "toString") == true)
{
// Return value must be primitive.
if (toStringResult is string || TypeUtilities.IsPrimitive(toStringResult) == true)
return toStringResult;
}
// Try calling valueOf().
object valueOfResult;
if (TryCallMemberFunction(out valueOfResult, "valueOf") == true)
{
// Return value must be primitive.
if (valueOfResult is double || TypeUtilities.IsPrimitive(valueOfResult) == true)
return valueOfResult;
}
}
throw new JavaScriptException(this.Engine, ErrorType.TypeError, "Attempted conversion of the object to a primitive value failed. Check the toString() and valueOf() functions.");
}