ConvertToNumber() public method

Converts the value to Number using regular JavaScript semantics.
Requires an active script context.
public ConvertToNumber ( ) : JavaScriptValue
return JavaScriptValue
        /// <summary>
        /// Executes a mapping from the script type to a host type
        /// </summary>
        /// <param name="value">The source value</param>
        /// <returns>The mapped value</returns>
        private static object MapToHostType(JavaScriptValue value)
        {
            JavaScriptValueType valueType = value.ValueType;
            JavaScriptValue     processedValue;
            object result;

            switch (valueType)
            {
            case JavaScriptValueType.Null:
                result = null;
                break;

            case JavaScriptValueType.Undefined:
                result = Undefined.Value;
                break;

            case JavaScriptValueType.Boolean:
                processedValue = value.ConvertToBoolean();
                result         = processedValue.ToBoolean();
                break;

            case JavaScriptValueType.Number:
                processedValue = value.ConvertToNumber();
                result         = processedValue.ToDouble();
                break;

            case JavaScriptValueType.String:
                processedValue = value.ConvertToString();
                result         = processedValue.ToString();
                break;

            case JavaScriptValueType.Object:
            case JavaScriptValueType.Function:
            case JavaScriptValueType.Error:
            case JavaScriptValueType.Array:
                processedValue = value.ConvertToObject();
                result         = processedValue.ToObject();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(result);
        }
        private JsRuntimeException ConvertJavaScriptExceptionToJsRuntimeException(
            JavaScriptException jsException)
        {
            string message        = jsException.Message;
            string category       = string.Empty;
            int    lineNumber     = 0;
            int    columnNumber   = 0;
            string sourceFragment = string.Empty;

            if (jsException is JavaScriptScriptException)
            {
                category = "Script error";

                var             jsScriptException = (JavaScriptScriptException)jsException;
                JavaScriptValue errorValue        = jsScriptException.Error;

                JavaScriptPropertyId messagePropertyId    = JavaScriptPropertyId.FromString("message");
                JavaScriptValue      messagePropertyValue = errorValue.GetProperty(messagePropertyId);
                string scriptMessage = messagePropertyValue.ConvertToString().ToString();
                if (!string.IsNullOrWhiteSpace(scriptMessage))
                {
                    message = string.Format("{0}: {1}", message.TrimEnd('.'), scriptMessage);
                }

                JavaScriptPropertyId linePropertyId = JavaScriptPropertyId.FromString("line");
                if (errorValue.HasProperty(linePropertyId))
                {
                    JavaScriptValue linePropertyValue = errorValue.GetProperty(linePropertyId);
                    lineNumber = (int)linePropertyValue.ConvertToNumber().ToDouble() + 1;
                }

                JavaScriptPropertyId columnPropertyId = JavaScriptPropertyId.FromString("column");
                if (errorValue.HasProperty(columnPropertyId))
                {
                    JavaScriptValue columnPropertyValue = errorValue.GetProperty(columnPropertyId);
                    columnNumber = (int)columnPropertyValue.ConvertToNumber().ToDouble() + 1;
                }

                JavaScriptPropertyId sourcePropertyId = JavaScriptPropertyId.FromString("source");
                if (errorValue.HasProperty(sourcePropertyId))
                {
                    JavaScriptValue sourcePropertyValue = errorValue.GetProperty(sourcePropertyId);
                    sourceFragment = sourcePropertyValue.ConvertToString().ToString();
                }
            }
            else if (jsException is JavaScriptUsageException)
            {
                category = "Usage error";
            }
            else if (jsException is JavaScriptEngineException)
            {
                category = "Engine error";
            }
            else if (jsException is JavaScriptFatalException)
            {
                category = "Fatal error";
            }

            var jsEngineException = new JsRuntimeException(message, ENGINE_MODE_NAME)
            {
                ErrorCode      = ((uint)jsException.ErrorCode).ToString(CultureInfo.InvariantCulture),
                Category       = category,
                LineNumber     = lineNumber,
                ColumnNumber   = columnNumber,
                SourceFragment = sourceFragment,
                HelpLink       = jsException.HelpLink
            };

            return(jsEngineException);
        }