Skip to content

Commit 2f1d35d

Browse files
committed
In JavaScriptEngineSwitcher.Msie added a ability to interrupt execution of the script
1 parent 6ae6130 commit 2f1d35d

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

NuGet/JavaScriptEngineSwitcher.Msie/JavaScriptEngineSwitcher.Msie.nuspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>JavaScriptEngineSwitcher.Msie contains adapter `MsieJsEngine` (wrapper for the MSIE JavaScript Engine for .Net (http://github.com/Taritsyn/MsieJavaScriptEngine)). For correct working of the MSIE JavaScript Engine it is recommended to install Internet Explorer 9+ or Microsoft Edge on the machine.</description>
1414
<summary>JavaScriptEngineSwitcher.Msie contains adapter `MsieJsEngine` (wrapper for the MSIE JavaScript Engine for .Net).</summary>
15-
<releaseNotes>Added support of MSIE JavaScript Engine version 3.0.0 Alpha 1.</releaseNotes>
15+
<releaseNotes>1. Added support of MSIE JavaScript Engine version 3.0.0 Alpha 1;
16+
2. Added a ability to interrupt execution of the script.</releaseNotes>
1617
<copyright>Copyright (c) 2013-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
1718
<language>en-US</language>
1819
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript MSIE IE Chakra</tags>

NuGet/JavaScriptEngineSwitcher.Msie/readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
=============
2020
RELEASE NOTES
2121
=============
22-
Added support of MSIE JavaScript Engine version 3.0.0 Alpha 1.
22+
1. Added support of MSIE JavaScript Engine version 3.0.0 Alpha 1;
23+
2. Added a ability to interrupt execution of the script.
2324

2425
=============
2526
DOCUMENTATION

src/JavaScriptEngineSwitcher.Msie/MsieJsEngine.cs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using OriginalJsEngine = MsieJavaScriptEngine.MsieJsEngine;
77
using OriginalJsEngineLoadException = MsieJavaScriptEngine.JsEngineLoadException;
88
using OriginalJsEngineMode = MsieJavaScriptEngine.JsEngineMode;
9+
using OriginalJsException = MsieJavaScriptEngine.JsException;
910
using OriginalJsRuntimeException = MsieJavaScriptEngine.JsRuntimeException;
11+
using OriginalJsScriptInterruptedException = MsieJavaScriptEngine.JsScriptInterruptedException;
1012
using OriginalJsEngineSettings = MsieJavaScriptEngine.JsEngineSettings;
1113
using OriginalTypeConverter = MsieJavaScriptEngine.Utilities.TypeConverter;
1214
using OriginalUndefined = MsieJavaScriptEngine.Undefined;
@@ -112,18 +114,35 @@ private static object MapToHostType(object value)
112114
return value;
113115
}
114116

115-
private JsRuntimeException ConvertScriptExceptionToHostException(
116-
OriginalJsRuntimeException scriptException)
117+
private JsException ConvertScriptExceptionToHostException(
118+
OriginalJsException scriptException)
117119
{
118-
var hostException = new JsRuntimeException(scriptException.Message,
119-
EngineName, _engineVersion, scriptException)
120+
JsException hostException;
121+
122+
if (scriptException is OriginalJsRuntimeException)
120123
{
121-
ErrorCode = scriptException.ErrorCode,
122-
Category = scriptException.Category,
123-
LineNumber = scriptException.LineNumber,
124-
ColumnNumber = scriptException.ColumnNumber,
125-
SourceFragment = scriptException.SourceFragment
126-
};
124+
var scriptRuntimeException = (OriginalJsRuntimeException)scriptException;
125+
hostException = new JsRuntimeException(scriptRuntimeException.Message,
126+
EngineName, _engineVersion, scriptRuntimeException)
127+
{
128+
ErrorCode = scriptRuntimeException.ErrorCode,
129+
Category = scriptRuntimeException.Category,
130+
LineNumber = scriptRuntimeException.LineNumber,
131+
ColumnNumber = scriptRuntimeException.ColumnNumber,
132+
SourceFragment = scriptRuntimeException.SourceFragment
133+
};
134+
}
135+
else if (scriptException is OriginalJsScriptInterruptedException)
136+
{
137+
var scriptInterruptedException = (OriginalJsScriptInterruptedException)scriptException;
138+
hostException = new JsScriptInterruptedException(CoreStrings.Runtime_ScriptInterrupted,
139+
EngineName, _engineVersion, scriptInterruptedException);
140+
}
141+
else
142+
{
143+
hostException = new JsException(scriptException.Message,
144+
EngineName, _engineVersion, scriptException);
145+
}
127146

128147
return hostException;
129148
}
@@ -145,7 +164,7 @@ protected override object InnerEvaluate(string expression, string documentName)
145164
{
146165
result = _jsEngine.Evaluate(expression, documentName);
147166
}
148-
catch (OriginalJsRuntimeException e)
167+
catch (OriginalJsException e)
149168
{
150169
throw ConvertScriptExceptionToHostException(e);
151170
}
@@ -178,7 +197,7 @@ protected override void InnerExecute(string code, string documentName)
178197
{
179198
_jsEngine.Execute(code, documentName);
180199
}
181-
catch (OriginalJsRuntimeException e)
200+
catch (OriginalJsException e)
182201
{
183202
throw ConvertScriptExceptionToHostException(e);
184203
}
@@ -202,7 +221,7 @@ protected override object InnerCallFunction(string functionName, params object[]
202221
{
203222
result = _jsEngine.CallFunction(functionName, processedArgs);
204223
}
205-
catch (OriginalJsRuntimeException e)
224+
catch (OriginalJsException e)
206225
{
207226
throw ConvertScriptExceptionToHostException(e);
208227
}
@@ -227,7 +246,7 @@ protected override bool InnerHasVariable(string variableName)
227246
{
228247
result = _jsEngine.HasVariable(variableName);
229248
}
230-
catch (OriginalJsRuntimeException e)
249+
catch (OriginalJsException e)
231250
{
232251
throw ConvertScriptExceptionToHostException(e);
233252
}
@@ -243,7 +262,7 @@ protected override object InnerGetVariableValue(string variableName)
243262
{
244263
result = _jsEngine.GetVariableValue(variableName);
245264
}
246-
catch (OriginalJsRuntimeException e)
265+
catch (OriginalJsException e)
247266
{
248267
throw ConvertScriptExceptionToHostException(e);
249268
}
@@ -268,7 +287,7 @@ protected override void InnerSetVariableValue(string variableName, object value)
268287
{
269288
_jsEngine.SetVariableValue(variableName, processedValue);
270289
}
271-
catch (OriginalJsRuntimeException e)
290+
catch (OriginalJsException e)
272291
{
273292
throw ConvertScriptExceptionToHostException(e);
274293
}
@@ -280,7 +299,7 @@ protected override void InnerRemoveVariable(string variableName)
280299
{
281300
_jsEngine.RemoveVariable(variableName);
282301
}
283-
catch (OriginalJsRuntimeException e)
302+
catch (OriginalJsException e)
284303
{
285304
throw ConvertScriptExceptionToHostException(e);
286305
}
@@ -294,7 +313,7 @@ protected override void InnerEmbedHostObject(string itemName, object value)
294313
{
295314
_jsEngine.EmbedHostObject(itemName, processedValue);
296315
}
297-
catch (OriginalJsRuntimeException e)
316+
catch (OriginalJsException e)
298317
{
299318
throw ConvertScriptExceptionToHostException(e);
300319
}
@@ -306,15 +325,15 @@ protected override void InnerEmbedHostType(string itemName, Type type)
306325
{
307326
_jsEngine.EmbedHostType(itemName, type);
308327
}
309-
catch (OriginalJsRuntimeException e)
328+
catch (OriginalJsException e)
310329
{
311330
throw ConvertScriptExceptionToHostException(e);
312331
}
313332
}
314333

315334
protected override void InnerInterrupt()
316335
{
317-
throw new NotImplementedException();
336+
_jsEngine.Interrupt();
318337
}
319338

320339
protected override void InnerCollectGarbage()
@@ -345,7 +364,7 @@ public override string Version
345364
/// </summary>
346365
public override bool SupportsScriptInterruption
347366
{
348-
get { return false; }
367+
get { return true; }
349368
}
350369

351370
/// <summary>

0 commit comments

Comments
 (0)