/// <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> public object MapToHostType(JsValue value) { JsValueType valueType = value.ValueType; object result = null; switch (valueType) { case JsValueType.Null: result = null; break; case JsValueType.Undefined: result = Undefined.Value; break; case JsValueType.Boolean: result = value.ToBoolean(); break; case JsValueType.Number: result = NumericHelpers.CastDoubleValueToCorrectType(value.ToDouble()); break; case JsValueType.String: result = value.ToString(); break; case JsValueType.Function: JsPropertyId externalObjectPropertyId = JsPropertyId.FromString(ExternalObjectPropertyName); if (value.HasProperty(externalObjectPropertyId)) { JsValue externalObjectValue = value.GetProperty(externalObjectPropertyId); result = externalObjectValue.HasExternalData ? GCHandle.FromIntPtr(externalObjectValue.ExternalData).Target : null; } result = result ?? value.ConvertToObject(); break; case JsValueType.Object: case JsValueType.Error: case JsValueType.Array: case JsValueType.Symbol: case JsValueType.ArrayBuffer: case JsValueType.TypedArray: case JsValueType.DataView: result = value.HasExternalData ? GCHandle.FromIntPtr(value.ExternalData).Target : value.ConvertToObject(); break; default: throw new ArgumentOutOfRangeException(); } return(result); }