internal object GetPrimitiveValue(PrimitiveTypeHint typeHint)
{
// The first step is to try calling the @@toPrimitive symbol.
string hintStr;
switch (typeHint)
{
case PrimitiveTypeHint.None:
hintStr = "default";
break;
case PrimitiveTypeHint.Number:
hintStr = "number";
break;
case PrimitiveTypeHint.String:
hintStr = "string";
break;
default:
throw new InvalidOperationException($"Unsupported PrimitiveTypeHint value '{typeHint}'.");
}
object toPrimitiveResult;
if (TryCallMemberFunction(out toPrimitiveResult, Engine.Symbol.ToPrimitive, hintStr) == true)
{
// Return value must be primitive.
if (TypeUtilities.IsPrimitive(toPrimitiveResult) == false)
throw new JavaScriptException(Engine, ErrorType.TypeError, "Cannot convert object to primitive value.");
return toPrimitiveResult;
}
// If that didn't work.
return GetPrimitiveValuePreES6(typeHint);
}