/// <summary>
 /// Constructs an instance of JS evaluation view model
 /// </summary>
 public JsEvaluationViewModel()
 {
     EngineName          = string.Empty;
     AvailableEngineList = new List <SelectListItem>();
     Expression          = string.Empty;
     Result = null;
 }
		/// <summary>
		/// Constructs an instance of JS evaluation view model
		/// </summary>
		public JsEvaluationViewModel()
		{
			EngineName = string.Empty;
			AvailableEngineList = new List<SelectListItem>();
			Expression = string.Empty;
			Result = null;
		}
		public JsEvaluationViewModel Evaluate(JsEvaluationViewModel model)
		{
			IJsEngine engine = null;
			var result = new JsEvaluationResultViewModel();

			try
			{
				engine = _engineSwitcher.CreateEngine(model.EngineName);
				result.Value = engine.Evaluate<string>(model.Expression);
			}
			catch (JsEngineLoadException e)
			{
				var error = GetJsEvaluationErrorFromException(e);
				result.Errors.Add(error);
			}
			catch (JsRuntimeException e)
			{
				var error = GetJsEvaluationErrorFromException(e);
				error.LineNumber = e.LineNumber;
				error.ColumnNumber = e.ColumnNumber;
				error.SourceFragment = e.SourceFragment;

				result.Errors.Add(error);
			}
			finally
			{
				if (engine != null)
				{
					engine.Dispose();
				}
			}

			model.Result = result;

			return model;
		}