ConvertToObject() public method

Converts a value to Object using regular JavaScript semantics
Requires an active script context.
public ConvertToObject ( ) : EdgeJsValue
return EdgeJsValue
        private object ToObject(EdgeJsValue value)
        {
            object result = value.HasExternalData ?
                            GCHandle.FromIntPtr(value.ExternalData).Target : value.ConvertToObject();

            return(result);
        }
        /// <summary>
        /// Makes a mapping of value from the script type to a host type
        /// </summary>
        /// <param name="value">The source value</param>
        /// <returns>The mapped value</returns>
        private object MapToHostType(EdgeJsValue value)
        {
            JsValueType valueType = value.ValueType;
            EdgeJsValue processedValue;
            object      result;

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

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

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

            case JsValueType.Number:
                processedValue = value.ConvertToNumber();
                result         = NumericHelpers.CastDoubleValueToCorrectType(processedValue.ToDouble());
                break;

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

            case JsValueType.Object:
            case JsValueType.Function:
            case JsValueType.Error:
            case JsValueType.Array:
#if NETSTANDARD1_3
                result = ToObject(value);
#else
                processedValue = value.ConvertToObject();
                object obj = processedValue.ToObject();

                if (!TypeConverter.IsPrimitiveType(obj.GetType()))
                {
                    var hostObj = obj as HostObject;
                    result = hostObj != null ? hostObj.Target : obj;
                }
                else
                {
                    result = obj;
                }
#endif
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(result);
        }