FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Version 7.1.4: Fixed intermittent crashes in heavily multithreaded ap… · ClearFoundry/ClearScript@5f7bd54 · GitHub

Version 7.1.4: Fixed intermittent crashes in heavily multithreaded ap… · ClearFoundry/ClearScript@5f7bd54 · GitHub
Skip to content

Navigation Menu

Commit 5f7bd54

Browse files
Version 7.1.4: Fixed intermittent crashes in heavily multithreaded applications (GitHub Issue #268); made DocumentLoader.CacheDocument and DocumentLoader.GetCachedDocument public; updated API documentation. Tested with V8 9.1.269.36.
1 parent 3ad795c commit 5f7bd54

610 files changed

Lines changed: 1026 additions & 899 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ClearScript/DocumentLoader.cs‎

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected DocumentLoader()
4646
public virtual uint MaxCacheSize
4747
{
4848
get => 0;
49-
set => throw new NotSupportedException("Loader does not support caching");
49+
set => throw new NotSupportedException("The document loader does not support caching");
5050
}
5151

5252
/// <summary>
@@ -101,6 +101,30 @@ public virtual Document LoadDocument(DocumentSettings settings, DocumentInfo? so
101101
/// </remarks>
102102
public abstract Task<Document> LoadDocumentAsync(DocumentSettings settings, DocumentInfo? sourceInfo, string specifier, DocumentCategory category, DocumentContextCallback contextCallback);
103103

104+
/// <summary>
105+
/// Searches for a cached document by <see cref="DocumentInfo.Uri">URI</see>.
106+
/// </summary>
107+
/// <param name="uri">The document URI for which to search.</param>
108+
/// <returns>The cached document if it was found, <c>null</c> otherwise.</returns>
109+
public virtual Document GetCachedDocument(Uri uri)
110+
{
111+
return null;
112+
}
113+
114+
/// <summary>
115+
/// Stores a document in the cache.
116+
/// </summary>
117+
/// <param name="document">The document to store in the cache.</param>
118+
/// <param name="replace"><c>True</c> to replace any existing document with the same URI, <c>false</c> otherwise.</param>
119+
/// <returns>The cached document, which may be different from <paramref name="document"/> if <paramref name="replace"/> is <c>false</c>.</returns>
120+
/// <remarks>
121+
/// A cached document must have an absolute <see cref="DocumentInfo.Uri">URI</see>.
122+
/// </remarks>
123+
public virtual Document CacheDocument(Document document, bool replace)
124+
{
125+
throw new NotSupportedException("The document loader does not support caching");
126+
}
127+
104128
/// <summary>
105129
/// Discards all cached documents.
106130
/// </summary>
@@ -359,48 +383,7 @@ private async Task<Document> LoadDocumentAsync(DocumentSettings settings, Uri ur
359383
var callback = settings.LoadCallback;
360384
callback?.Invoke(ref documentInfo);
361385

362-
return CacheDocument(new StringDocument(documentInfo, contents));
363-
}
364-
365-
private Document GetCachedDocument(Uri uri)
366-
{
367-
lock (cache)
368-
{
369-
for (var index = 0; index < cache.Count; index++)
370-
{
371-
var cachedDocument = cache[index];
372-
if (cachedDocument.Info.Uri == uri)
373-
{
374-
cache.RemoveAt(index);
375-
cache.Insert(0, cachedDocument);
376-
return cachedDocument;
377-
}
378-
}
379-
380-
return null;
381-
}
382-
}
383-
384-
private Document CacheDocument(Document document)
385-
{
386-
lock (cache)
387-
{
388-
var cachedDocument = cache.FirstOrDefault(testDocument => testDocument.Info.Uri == document.Info.Uri);
389-
if (cachedDocument != null)
390-
{
391-
Debug.Assert(cachedDocument.Contents.ReadToEnd().SequenceEqual(document.Contents.ReadToEnd()));
392-
return cachedDocument;
393-
}
394-
395-
var maxCacheSize = Math.Max(16, Convert.ToInt32(Math.Min(MaxCacheSize, int.MaxValue)));
396-
while (cache.Count >= maxCacheSize)
397-
{
398-
cache.RemoveAt(cache.Count - 1);
399-
}
400-
401-
cache.Insert(0, document);
402-
return document;
403-
}
386+
return CacheDocument(new StringDocument(documentInfo, contents), false);
404387
}
405388

406389
#region DocumentLoader overrides
@@ -481,14 +464,71 @@ public override async Task<Document> LoadDocumentAsync(DocumentSettings settings
481464
throw new AggregateException(exceptions).Flatten();
482465
}
483466

467+
public override Document GetCachedDocument(Uri uri)
468+
{
469+
lock (cache)
470+
{
471+
for (var index = 0; index < cache.Count; index++)
472+
{
473+
var cachedDocument = cache[index];
474+
if (cachedDocument.Info.Uri == uri)
475+
{
476+
cache.RemoveAt(index);
477+
cache.Insert(0, cachedDocument);
478+
return cachedDocument;
479+
}
480+
}
481+
482+
return null;
483+
}
484+
}
485+
486+
public override Document CacheDocument(Document document, bool replace)
487+
{
488+
MiscHelpers.VerifyNonNullArgument(document, nameof(document));
489+
if (!document.Info.Uri.IsAbsoluteUri)
490+
{
491+
throw new ArgumentException("The document must have an absolute URI");
492+
}
493+
494+
lock (cache)
495+
{
496+
for (var index = 0; index < cache.Count;)
497+
{
498+
var cachedDocument = cache[index];
499+
if (cachedDocument.Info.Uri != document.Info.Uri)
500+
{
501+
index++;
502+
}
503+
else
504+
{
505+
if (!replace)
506+
{
507+
Debug.Assert(cachedDocument.Contents.ReadToEnd().SequenceEqual(document.Contents.ReadToEnd()));
508+
return cachedDocument;
509+
}
510+
511+
cache.RemoveAt(index);
512+
}
513+
}
514+
515+
var maxCacheSize = Math.Max(16, Convert.ToInt32(Math.Min(MaxCacheSize, int.MaxValue)));
516+
while (cache.Count >= maxCacheSize)
517+
{
518+
cache.RemoveAt(cache.Count - 1);
519+
}
520+
521+
cache.Insert(0, document);
522+
return document;
523+
}
524+
}
525+
484526
public override void DiscardCachedDocuments()
485527
{
486528
lock (cache)
487529
{
488530
cache.Clear();
489531
}
490-
491-
base.DiscardCachedDocuments();
492532
}
493533

494534
#endregion

‎ClearScript/Exports/VersionSymbols.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#pragma once
77

8-
#define CLEARSCRIPT_VERSION_STRING "7.1.3"
9-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,1,3
10-
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.1.3"
8+
#define CLEARSCRIPT_VERSION_STRING "7.1.4"
9+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,1,4
10+
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.1.4"
1111
#define CLEARSCRIPT_FILE_FLAGS 0L

‎ClearScript/Properties/AssemblyInfo.Core.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
[assembly: InternalsVisibleTo("ClearScriptTest")]
1919

2020
[assembly: ComVisible(false)]
21-
[assembly: AssemblyVersion("7.1.3")]
22-
[assembly: AssemblyFileVersion("7.1.3")]
23-
[assembly: AssemblyInformationalVersion("7.1.3")]
21+
[assembly: AssemblyVersion("7.1.4")]
22+
[assembly: AssemblyFileVersion("7.1.4")]
23+
[assembly: AssemblyInformationalVersion("7.1.4")]
2424

2525
namespace Microsoft.ClearScript.Properties
2626
{
2727
internal static class ClearScriptVersion
2828
{
29-
public const string Triad = "7.1.3";
30-
public const string Informational = "7.1.3";
29+
public const string Triad = "7.1.4";
30+
public const string Informational = "7.1.4";
3131
}
3232
}

‎ClearScript/Properties/AssemblyInfo.V8.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
[assembly: InternalsVisibleTo("ClearScriptTest")]
1616

1717
[assembly: ComVisible(false)]
18-
[assembly: AssemblyVersion("7.1.3")]
19-
[assembly: AssemblyFileVersion("7.1.3")]
20-
[assembly: AssemblyInformationalVersion("7.1.3")]
18+
[assembly: AssemblyVersion("7.1.4")]
19+
[assembly: AssemblyFileVersion("7.1.4")]
20+
[assembly: AssemblyInformationalVersion("7.1.4")]

‎ClearScript/Properties/AssemblyInfo.Windows.Core.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
[assembly: InternalsVisibleTo("ClearScriptTest")]
1717

1818
[assembly: ComVisible(false)]
19-
[assembly: AssemblyVersion("7.1.3")]
20-
[assembly: AssemblyFileVersion("7.1.3")]
21-
[assembly: AssemblyInformationalVersion("7.1.3")]
19+
[assembly: AssemblyVersion("7.1.4")]
20+
[assembly: AssemblyFileVersion("7.1.4")]
21+
[assembly: AssemblyInformationalVersion("7.1.4")]

‎ClearScript/Properties/AssemblyInfo.Windows.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
[assembly: InternalsVisibleTo("ClearScriptTest")]
1616

1717
[assembly: ComVisible(false)]
18-
[assembly: AssemblyVersion("7.1.3")]
19-
[assembly: AssemblyFileVersion("7.1.3")]
20-
[assembly: AssemblyInformationalVersion("7.1.3")]
18+
[assembly: AssemblyVersion("7.1.4")]
19+
[assembly: AssemblyFileVersion("7.1.4")]
20+
[assembly: AssemblyInformationalVersion("7.1.4")]

‎ClearScript/Util/TypeHelpers.cs‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,9 @@ public static bool IsUnknownCOMObject(this Type type)
165165

166166
public static bool IsAssignableFrom(this Type type, ref object value)
167167
{
168-
var isByRef = false;
169168
if (type.IsByRef)
170169
{
171170
type = type.GetElementType();
172-
isByRef = true;
173171
}
174172

175173
if (type.IsNullable())
@@ -183,23 +181,18 @@ public static bool IsAssignableFrom(this Type type, ref object value)
183181
}
184182

185183
var valueType = value.GetType();
186-
if (valueType == type || type.IsAssignableFrom(valueType))
184+
if ((valueType == type) || type.IsAssignableFrom(valueType))
187185
{
188186
return true;
189187
}
190188

191-
if (!isByRef && type.IsImplicitlyConvertibleFrom(valueType, ref value))
189+
if (type.IsImplicitlyConvertibleFrom(valueType, ref value))
192190
{
193191
return true;
194192
}
195193

196194
if (!type.IsValueType)
197195
{
198-
if (type.IsAssignableFrom(valueType))
199-
{
200-
return true;
201-
}
202-
203196
if (type.IsInterface && type.IsImport && valueType.IsCOMObject)
204197
{
205198
var result = false;

‎ClearScript/V8/SplitProxy/NativeCallbackImpl.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
45
using Microsoft.ClearScript.Util;
56

67
namespace Microsoft.ClearScript.V8.SplitProxy
@@ -30,6 +31,7 @@ public void Invoke()
3031
public void Dispose()
3132
{
3233
holder.ReleaseEntity();
34+
GC.KeepAlive(this);
3335
}
3436

3537
~NativeCallbackImpl()

‎ClearScript/V8/SplitProxy/V8ContextProxyImpl.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ public override void WriteRuntimeHeapSnapshot(Stream stream)
256256
public override void Dispose()
257257
{
258258
holder.ReleaseEntity();
259+
GC.KeepAlive(this);
259260
}
260261

261262
~V8ContextProxyImpl()

‎ClearScript/V8/SplitProxy/V8DebugListenerImpl.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
5+
46
namespace Microsoft.ClearScript.V8.SplitProxy
57
{
68
internal sealed class V8DebugListenerImpl : IV8DebugListener
@@ -38,6 +40,7 @@ public void DisconnectClient()
3840
public void Dispose()
3941
{
4042
holder.ReleaseEntity();
43+
GC.KeepAlive(this);
4144
}
4245

4346
~V8DebugListenerImpl()

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.

Back | FazBrowse Home | New Git URL