Skip to content

Commit d0a6a51

Browse files
committed
Was made refactoring
1 parent 17ad92a commit d0a6a51

File tree

4 files changed

+47
-42
lines changed

4 files changed

+47
-42
lines changed

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -846,17 +846,17 @@ private void Dispose(bool disposing)
846846
}
847847

848848
ComHelpers.ReleaseAndEmpty(ref _pActiveScript);
849+
});
849850

850-
if (disposing)
851+
if (disposing)
852+
{
853+
if (_hostItems != null)
851854
{
852-
if (_hostItems != null)
853-
{
854-
_hostItems.Clear();
855-
}
856-
857-
_lastException = null;
855+
_hostItems.Clear();
858856
}
859-
});
857+
858+
_lastException = null;
859+
}
860860
}
861861
}
862862

src/MsieJavaScriptEngine/JsRt/Edge/ChakraEdgeJsRtJsEngine.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,22 +1102,23 @@ protected override void Dispose(bool disposing)
11021102
{
11031103
if (_disposedFlag.Set())
11041104
{
1105-
_dispatcher.Invoke(() =>
1105+
if (_dispatcher != null)
11061106
{
1107-
_jsRuntime.Dispose();
1108-
base.Dispose(disposing);
1107+
_dispatcher.Invoke(() => _jsRuntime.Dispose());
1108+
_dispatcher.Dispose();
1109+
}
1110+
1111+
base.Dispose(disposing);
11091112
#if NETSTANDARD1_3
11101113

1111-
if (disposing)
1114+
if (disposing)
1115+
{
1116+
if (_nativeFunctions != null)
11121117
{
1113-
if (_nativeFunctions != null)
1114-
{
1115-
_nativeFunctions.Clear();
1116-
}
1118+
_nativeFunctions.Clear();
11171119
}
1120+
}
11181121
#endif
1119-
});
1120-
_dispatcher.Dispose();
11211122
}
11221123
}
11231124

src/MsieJavaScriptEngine/JsRt/Ie/ChakraIeJsRtJsEngine.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,22 +1140,23 @@ protected override void Dispose(bool disposing)
11401140
{
11411141
if (_disposedFlag.Set())
11421142
{
1143-
_dispatcher.Invoke(() =>
1143+
if (_dispatcher != null)
11441144
{
1145-
_jsRuntime.Dispose();
1146-
base.Dispose(disposing);
1145+
_dispatcher.Invoke(() => _jsRuntime.Dispose());
1146+
_dispatcher.Dispose();
1147+
}
1148+
1149+
base.Dispose(disposing);
11471150
#if NETSTANDARD1_3
11481151

1149-
if (disposing)
1152+
if (disposing)
1153+
{
1154+
if (_nativeFunctions != null)
11501155
{
1151-
if (_nativeFunctions != null)
1152-
{
1153-
_nativeFunctions.Clear();
1154-
}
1156+
_nativeFunctions.Clear();
11551157
}
1158+
}
11561159
#endif
1157-
});
1158-
_dispatcher.Dispose();
11591160
}
11601161
}
11611162

src/MsieJavaScriptEngine/ScriptDispatcher.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private void StartThread()
101101
task = _taskQueue.Dequeue();
102102
if (task == null)
103103
{
104+
_taskQueue.Clear();
104105
return;
105106
}
106107
}
@@ -176,6 +177,11 @@ public T Invoke<T>(Func<T> func)
176177
{
177178
VerifyNotDisposed();
178179

180+
if (func == null)
181+
{
182+
throw new ArgumentNullException("func");
183+
}
184+
179185
return (T)InnnerInvoke(() => func());
180186
}
181187

@@ -188,6 +194,11 @@ public void Invoke(Action action)
188194
{
189195
VerifyNotDisposed();
190196

197+
if (action == null)
198+
{
199+
throw new ArgumentNullException("action");
200+
}
201+
191202
InnnerInvoke(() =>
192203
{
193204
action();
@@ -216,25 +227,17 @@ private void Dispose(bool disposing)
216227
if (_disposedFlag.Set())
217228
{
218229
EnqueueTask(null);
219-
_thread.Join();
220230

221-
if (_waitHandle != null)
231+
if (_thread != null)
222232
{
223-
_waitHandle.Dispose();
224-
_waitHandle = null;
233+
_thread.Join();
234+
_thread = null;
225235
}
226236

227-
if (disposing)
237+
if (_waitHandle != null)
228238
{
229-
lock (_taskQueueSynchronizer)
230-
{
231-
if (_taskQueue != null)
232-
{
233-
_taskQueue.Clear();
234-
}
235-
}
236-
237-
_thread = null;
239+
_waitHandle.Dispose();
240+
_waitHandle = null;
238241
}
239242
}
240243
}

0 commit comments

Comments
 (0)