1414
1515namespace MsieJavaScriptEngine . ActiveScript
1616{
17- /// <summary>
18- /// Active Script site
19- /// </summary>
2017 internal abstract partial class ActiveScriptJsEngineBase
2118 {
22- private sealed class ScriptSite : IActiveScriptSite , IActiveScriptSiteInterruptPoll ,
23- IActiveScriptSiteDebug32 , IActiveScriptSiteDebug64 , IActiveScriptSiteDebugEx ,
24- ICustomQueryInterface
19+ /// <summary>
20+ /// Active Script site
21+ /// </summary>
22+ protected abstract class ScriptSiteBase : IActiveScriptSite ,
23+ IActiveScriptSiteDebug32 , IActiveScriptSiteDebug64 ,
24+ IActiveScriptSiteDebugEx , ICustomQueryInterface
2525 {
2626 /// <summary>
27- /// Instance of Active Script engine
27+ /// Instance of the Active Script JS engine
2828 /// </summary>
2929 private readonly ActiveScriptJsEngineBase _jsEngine ;
3030
31+ /// <summary>
32+ /// Gets or sets a last Active Script exception
33+ /// </summary>
34+ public ActiveScriptException LastException
35+ {
36+ get { return _jsEngine . _lastException ; }
37+ set { _jsEngine . _lastException = value ; }
38+ }
39+
40+ /// <summary>
41+ /// Gets a instance of Active Script wrapper
42+ /// </summary>
43+ public IActiveScriptWrapper ActiveScriptWrapper
44+ {
45+ get { return _jsEngine . _activeScriptWrapper ; }
46+ }
47+
48+ /// <summary>
49+ /// Gets a flag that indicates if the script interruption is requested
50+ /// </summary>
51+ public virtual bool InterruptRequested
52+ {
53+ get { return _jsEngine . _interruptRequested ; }
54+ }
55+
3156
3257 /// <summary>
3358 /// Constructs an instance of the Active Script site
3459 /// </summary>
35- /// <param name="jsEngine">Active Script engine</param>
36- public ScriptSite ( ActiveScriptJsEngineBase jsEngine )
60+ /// <param name="jsEngine">Instance of the Active Script JS engine</param>
61+ protected ScriptSiteBase ( ActiveScriptJsEngineBase jsEngine )
3762 {
3863 _jsEngine = jsEngine ;
3964 }
@@ -43,27 +68,18 @@ public ScriptSite(ActiveScriptJsEngineBase jsEngine)
4368 /// Processes a Active Script error
4469 /// </summary>
4570 /// <param name="error">Instance of <see cref="IActiveScriptError"/></param>
46- private void ProcessActiveScriptError ( IActiveScriptError error )
71+ protected virtual void ProcessActiveScriptError ( IActiveScriptError error )
4772 {
4873 var activeScriptException = CreateActiveScriptException ( error ) ;
49- if ( _jsEngine . _engineMode == JsEngineMode . Classic
50- && activeScriptException . ErrorCode == ComErrorCode . E_ABORT )
51- {
52- // Script execution was interrupted explicitly. At this point the script
53- // engine might be in an odd state; the following call seems to get it back
54- // to normal.
55- _jsEngine . _activeScriptWrapper . SetScriptState ( ScriptState . Started ) ;
56- }
57-
58- _jsEngine . _lastException = activeScriptException ;
74+ LastException = activeScriptException ;
5975 }
6076
6177 /// <summary>
6278 /// Creates a instance of <see cref="ActiveScriptException"/>
6379 /// </summary>
6480 /// <param name="error">Instance of <see cref="IActiveScriptError"/></param>
6581 /// <returns>Instance of <see cref="ActiveScriptException"/></returns>
66- private ActiveScriptException CreateActiveScriptException ( IActiveScriptError error )
82+ protected ActiveScriptException CreateActiveScriptException ( IActiveScriptError error )
6783 {
6884 EXCEPINFO exceptionInfo ;
6985 error . GetExceptionInfo ( out exceptionInfo ) ;
@@ -248,86 +264,9 @@ private bool TryWriteFullErrorLocation(StringBuilder buffer, uint sourceContext,
248264 /// </summary>
249265 /// <param name="buffer">Instance of <see cref="StringBuilder"/></param>
250266 /// <returns>true if the writing was successful; otherwise, false</returns>
251- private bool TryWriteStackTrace ( StringBuilder buffer )
267+ protected virtual bool TryWriteStackTrace ( StringBuilder buffer )
252268 {
253- bool result = false ;
254-
255- IEnumDebugStackFrames enumFrames ;
256- _jsEngine . _activeScriptWrapper . EnumStackFrames ( out enumFrames ) ;
257-
258- while ( true )
259- {
260- DebugStackFrameDescriptor descriptor ;
261- uint countFetched ;
262- enumFrames . Next ( 1 , out descriptor , out countFetched ) ;
263- if ( countFetched < 1 )
264- {
265- break ;
266- }
267-
268- try
269- {
270- IDebugStackFrame stackFrame = descriptor . Frame ;
271-
272- string description ;
273- stackFrame . GetDescriptionString ( true , out description ) ;
274-
275- if ( string . Equals ( description , "JScript global code" , StringComparison . Ordinal ) )
276- {
277- description = "Global code" ;
278- }
279-
280- IDebugCodeContext codeContext ;
281- stackFrame . GetCodeContext ( out codeContext ) ;
282-
283- IDebugDocumentContext documentContext ;
284- codeContext . GetDocumentContext ( out documentContext ) ;
285-
286- if ( documentContext == null )
287- {
288- JsErrorHelpers . WriteErrorLocation ( buffer , description ) ;
289- buffer . AppendLine ( ) ;
290- }
291- else
292- {
293- IDebugDocument document ;
294- documentContext . GetDocument ( out document ) ;
295-
296- string documentName ;
297- document . GetName ( DocumentNameType . Title , out documentName ) ;
298-
299- var documentText = ( IDebugDocumentText ) document ;
300-
301- uint position ;
302- uint length ;
303- documentText . GetPositionOfContext ( documentContext , out position , out length ) ;
304-
305- uint lineNumber ;
306- uint offsetInLine ;
307- documentText . GetLineOfPosition ( position , out lineNumber , out offsetInLine ) ;
308- uint columnNumber = offsetInLine + 1 ;
309-
310- buffer . AppendFormatLine ( " at {0} ({1}:{2}:{3})" , description , documentName ,
311- lineNumber , columnNumber ) ;
312- }
313-
314- result = true ;
315- }
316- finally
317- {
318- if ( descriptor . pFinalObject != IntPtr . Zero )
319- {
320- Marshal . Release ( descriptor . pFinalObject ) ;
321- }
322- }
323- }
324-
325- if ( result )
326- {
327- buffer . TrimEnd ( ) ;
328- }
329-
330- return result ;
269+ return false ;
331270 }
332271
333272 #region IActiveScriptSite implementation
@@ -381,35 +320,6 @@ public void OnLeaveScript()
381320
382321 #endregion
383322
384- #region IActiveScriptSiteInterruptPoll implementation
385-
386- public uint QueryContinue ( )
387- {
388- int hResult ;
389-
390- if ( _jsEngine . _engineMode == JsEngineMode . ChakraActiveScript
391- && _jsEngine . _interruptRequested )
392- {
393- hResult = ComErrorCode . E_ABORT ;
394- var activeScriptException = new ActiveScriptException (
395- CommonStrings . Runtime_ScriptInterrupted )
396- {
397- ErrorCode = hResult ,
398- Description = CommonStrings . Runtime_ScriptInterrupted
399- } ;
400-
401- _jsEngine . _lastException = activeScriptException ;
402- }
403- else
404- {
405- hResult = ComErrorCode . S_OK ;
406- }
407-
408- return NumericHelpers . SignedAsUnsigned ( hResult ) ;
409- }
410-
411- #endregion
412-
413323 #region IActiveScriptSiteDebug32 and IActiveScriptSiteDebug64 implementation
414324
415325 public void GetRootApplicationNode ( out IDebugApplicationNode node )
0 commit comments