| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3ad795c commit 5f7bd54
610 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,7 @@ protected DocumentLoader() | |||
| 46 | 46 | public virtual uint MaxCacheSize | |
| 47 | 47 | { | |
| 48 | 48 | get => 0; | |
| 49 | - set => throw new NotSupportedException("Loader does not support caching"); | ||
| 49 | + set => throw new NotSupportedException("The document loader does not support caching"); | ||
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | 52 | /// <summary> | |
@@ -101,6 +101,30 @@ public virtual Document LoadDocument(DocumentSettings settings, DocumentInfo? so | |||
| 101 | 101 | /// </remarks> | |
| 102 | 102 | public abstract Task<Document> LoadDocumentAsync(DocumentSettings settings, DocumentInfo? sourceInfo, string specifier, DocumentCategory category, DocumentContextCallback contextCallback); | |
| 103 | 103 | ||
| 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 | + | ||
| 104 | 128 | /// <summary> | |
| 105 | 129 | /// Discards all cached documents. | |
| 106 | 130 | /// </summary> | |
@@ -359,48 +383,7 @@ private async Task<Document> LoadDocumentAsync(DocumentSettings settings, Uri ur | |||
| 359 | 383 | var callback = settings.LoadCallback; | |
| 360 | 384 | callback?.Invoke(ref documentInfo); | |
| 361 | 385 | ||
| 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); | ||
| 404 | 387 | } | |
| 405 | 388 | ||
| 406 | 389 | #region DocumentLoader overrides | |
@@ -481,14 +464,71 @@ public override async Task<Document> LoadDocumentAsync(DocumentSettings settings | |||
| 481 | 464 | throw new AggregateException(exceptions).Flatten(); | |
| 482 | 465 | } | |
| 483 | 466 | ||
| 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 | + | ||
| 484 | 526 | public override void DiscardCachedDocuments() | |
| 485 | 527 | { | |
| 486 | 528 | lock (cache) | |
| 487 | 529 | { | |
| 488 | 530 | cache.Clear(); | |
| 489 | 531 | } | |
| 490 | - | ||
| 491 | - base.DiscardCachedDocuments(); | ||
| 492 | 532 | } | |
| 493 | 533 | ||
| 494 | 534 | #endregion | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | #pragma once | |
| 7 | 7 | ||
| 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" | ||
| 11 | 11 | #define CLEARSCRIPT_FILE_FLAGS 0L | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,15 +18,15 @@ | |||
| 18 | 18 | [assembly: InternalsVisibleTo("ClearScriptTest")] | |
| 19 | 19 | ||
| 20 | 20 | [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")] | ||
| 24 | 24 | ||
| 25 | 25 | namespace Microsoft.ClearScript.Properties | |
| 26 | 26 | { | |
| 27 | 27 | internal static class ClearScriptVersion | |
| 28 | 28 | { | |
| 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"; | ||
| 31 | 31 | } | |
| 32 | 32 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,6 @@ | |||
| 15 | 15 | [assembly: InternalsVisibleTo("ClearScriptTest")] | |
| 16 | 16 | ||
| 17 | 17 | [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")] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,6 @@ | |||
| 16 | 16 | [assembly: InternalsVisibleTo("ClearScriptTest")] | |
| 17 | 17 | ||
| 18 | 18 | [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")] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,6 @@ | |||
| 15 | 15 | [assembly: InternalsVisibleTo("ClearScriptTest")] | |
| 16 | 16 | ||
| 17 | 17 | [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")] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -165,11 +165,9 @@ public static bool IsUnknownCOMObject(this Type type) | |||
| 165 | 165 | ||
| 166 | 166 | public static bool IsAssignableFrom(this Type type, ref object value) | |
| 167 | 167 | { | |
| 168 | - var isByRef = false; | ||
| 169 | 168 | if (type.IsByRef) | |
| 170 | 169 | { | |
| 171 | 170 | type = type.GetElementType(); | |
| 172 | - isByRef = true; | ||
| 173 | 171 | } | |
| 174 | 172 | ||
| 175 | 173 | if (type.IsNullable()) | |
@@ -183,23 +181,18 @@ public static bool IsAssignableFrom(this Type type, ref object value) | |||
| 183 | 181 | } | |
| 184 | 182 | ||
| 185 | 183 | var valueType = value.GetType(); | |
| 186 | - if (valueType == type || type.IsAssignableFrom(valueType)) | ||
| 184 | + if ((valueType == type) || type.IsAssignableFrom(valueType)) | ||
| 187 | 185 | { | |
| 188 | 186 | return true; | |
| 189 | 187 | } | |
| 190 | 188 | ||
| 191 | - if (!isByRef && type.IsImplicitlyConvertibleFrom(valueType, ref value)) | ||
| 189 | + if (type.IsImplicitlyConvertibleFrom(valueType, ref value)) | ||
| 192 | 190 | { | |
| 193 | 191 | return true; | |
| 194 | 192 | } | |
| 195 | 193 | ||
| 196 | 194 | if (!type.IsValueType) | |
| 197 | 195 | { | |
| 198 | - if (type.IsAssignableFrom(valueType)) | ||
| 199 | - { | ||
| 200 | - return true; | ||
| 201 | - } | ||
| 202 | - | ||
| 203 | 196 | if (type.IsInterface && type.IsImport && valueType.IsCOMObject) | |
| 204 | 197 | { | |
| 205 | 198 | var result = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. | |
| 2 | 2 | // Licensed under the MIT license. | |
| 3 | 3 | ||
| 4 | + using System; | ||
| 4 | 5 | using Microsoft.ClearScript.Util; | |
| 5 | 6 | ||
| 6 | 7 | namespace Microsoft.ClearScript.V8.SplitProxy | |
@@ -30,6 +31,7 @@ public void Invoke() | |||
| 30 | 31 | public void Dispose() | |
| 31 | 32 | { | |
| 32 | 33 | holder.ReleaseEntity(); | |
| 34 | + GC.KeepAlive(this); | ||
| 33 | 35 | } | |
| 34 | 36 | ||
| 35 | 37 | ~NativeCallbackImpl() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -256,6 +256,7 @@ public override void WriteRuntimeHeapSnapshot(Stream stream) | |||
| 256 | 256 | public override void Dispose() | |
| 257 | 257 | { | |
| 258 | 258 | holder.ReleaseEntity(); | |
| 259 | + GC.KeepAlive(this); | ||
| 259 | 260 | } | |
| 260 | 261 | ||
| 261 | 262 | ~V8ContextProxyImpl() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. | |
| 2 | 2 | // Licensed under the MIT license. | |
| 3 | 3 | ||
| 4 | + using System; | ||
| 5 | + | ||
| 4 | 6 | namespace Microsoft.ClearScript.V8.SplitProxy | |
| 5 | 7 | { | |
| 6 | 8 | internal sealed class V8DebugListenerImpl : IV8DebugListener | |
@@ -38,6 +40,7 @@ public void DisconnectClient() | |||
| 38 | 40 | public void Dispose() | |
| 39 | 41 | { | |
| 40 | 42 | holder.ReleaseEntity(); | |
| 43 | + GC.KeepAlive(this); | ||
| 41 | 44 | } | |
| 42 | 45 | ||
| 43 | 46 | ~V8DebugListenerImpl() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments