@@ -223,6 +223,29 @@ public object Evaluate(string expression)
223223 return _jsEngine . Evaluate ( expression ) ;
224224 }
225225
226+ /// <summary>
227+ /// Evaluates an expression
228+ /// </summary>
229+ /// <param name="expression">JavaScript expression</param>
230+ /// <param name="documentName">Document name</param>
231+ /// <returns>Result of the expression</returns>
232+ /// <exception cref="System.ObjectDisposedException">Operation is performed on a disposed MSIE
233+ /// JavaScript engine.</exception>
234+ /// <exception cref="System.ArgumentException" />
235+ /// <exception cref="MsieJavaScriptEngine.JsRuntimeException">JavaScript runtime error.</exception>
236+ public object Evaluate ( string expression , string documentName )
237+ {
238+ VerifyNotDisposed ( ) ;
239+
240+ if ( string . IsNullOrWhiteSpace ( expression ) )
241+ {
242+ throw new ArgumentException (
243+ string . Format ( CommonStrings . Common_ArgumentIsEmpty , "expression" ) , "expression" ) ;
244+ }
245+
246+ return _jsEngine . Evaluate ( expression , documentName ) ;
247+ }
248+
226249 /// <summary>
227250 /// Evaluates an expression
228251 /// </summary>
@@ -257,6 +280,41 @@ public T Evaluate<T>(string expression)
257280 return TypeConverter . ConvertToType < T > ( result ) ;
258281 }
259282
283+ /// <summary>
284+ /// Evaluates an expression
285+ /// </summary>
286+ /// <typeparam name="T">Type of result</typeparam>
287+ /// <param name="expression">JavaScript expression</param>
288+ /// <param name="documentName">Document name</param>
289+ /// <returns>Result of the expression</returns>
290+ /// <exception cref="System.ObjectDisposedException">Operation is performed on a disposed MSIE
291+ /// JavaScript engine.</exception>
292+ /// <exception cref="System.ArgumentException" />
293+ /// <exception cref="MsieJavaScriptEngine.NotSupportedTypeException">The type of return value
294+ /// is not supported.</exception>
295+ /// <exception cref="MsieJavaScriptEngine.JsRuntimeException">JavaScript runtime error.</exception>
296+ public T Evaluate < T > ( string expression , string documentName )
297+ {
298+ VerifyNotDisposed ( ) ;
299+
300+ if ( string . IsNullOrWhiteSpace ( expression ) )
301+ {
302+ throw new ArgumentException (
303+ string . Format ( CommonStrings . Common_ArgumentIsEmpty , "expression" ) , "expression" ) ;
304+ }
305+
306+ Type returnValueType = typeof ( T ) ;
307+ if ( ! ValidationHelpers . IsSupportedType ( returnValueType ) )
308+ {
309+ throw new NotSupportedTypeException (
310+ string . Format ( CommonStrings . Runtime_ReturnValueTypeNotSupported , returnValueType . FullName ) ) ;
311+ }
312+
313+ object result = _jsEngine . Evaluate ( expression , documentName ) ;
314+
315+ return TypeConverter . ConvertToType < T > ( result ) ;
316+ }
317+
260318 /// <summary>
261319 /// Executes a code
262320 /// </summary>
@@ -278,6 +336,28 @@ public void Execute(string code)
278336 _jsEngine . Execute ( code ) ;
279337 }
280338
339+ /// <summary>
340+ /// Executes a code
341+ /// </summary>
342+ /// <param name="code">JavaScript code</param>
343+ /// <param name="documentName">Document name</param>
344+ /// <exception cref="System.ObjectDisposedException">Operation is performed on a disposed MSIE
345+ /// JavaScript engine.</exception>
346+ /// <exception cref="System.ArgumentException" />
347+ /// <exception cref="MsieJavaScriptEngine.JsRuntimeException">JavaScript runtime error.</exception>
348+ public void Execute ( string code , string documentName )
349+ {
350+ VerifyNotDisposed ( ) ;
351+
352+ if ( string . IsNullOrWhiteSpace ( code ) )
353+ {
354+ throw new ArgumentException (
355+ string . Format ( CommonStrings . Common_ArgumentIsEmpty , "code" ) , "code" ) ;
356+ }
357+
358+ _jsEngine . Execute ( code , documentName ) ;
359+ }
360+
281361 /// <summary>
282362 /// Executes a code from JS-file
283363 /// </summary>
@@ -299,7 +379,7 @@ public void ExecuteFile(string path, Encoding encoding = null)
299379 }
300380
301381 string code = Utils . GetFileTextContent ( path , encoding ) ;
302- Execute ( code ) ;
382+ Execute ( code , path ) ;
303383 }
304384
305385 /// <summary>
@@ -336,7 +416,7 @@ public void ExecuteResource(string resourceName, Type type)
336416 }
337417
338418 string code = Utils . GetResourceAsString ( resourceName , type ) ;
339- Execute ( code ) ;
419+ Execute ( code , resourceName ) ;
340420 }
341421
342422 /// <summary>
@@ -372,7 +452,7 @@ public void ExecuteResource(string resourceName, Assembly assembly)
372452 }
373453
374454 string code = Utils . GetResourceAsString ( resourceName , assembly ) ;
375- Execute ( code ) ;
455+ Execute ( code , resourceName ) ;
376456 }
377457
378458 /// <summary>
0 commit comments