Skip to content

Commit 381b548

Browse files
ClearScript 7.4: Generic script objects now implement IDictionary<string, object>; added JavaScriptExtensions.ToEnumerable and ToAsyncEnumerable (GitHub Issue #494); DocumentAccessFlags.AllowCategoryMismatch now applies to system documents; added DocumentSettings.AsyncLoadCallback and DocumentAccessFlags.UseAsyncLoadCallback; implemented smarter and safer HeapExpansionMultiplier handling; added ValueRef utility classes; updated API documentation. Tested with V8 11.1.277.14.
1 parent 6106c30 commit 381b548

File tree

819 files changed

+3261
-1300
lines changed

Some content is hidden

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

819 files changed

+3261
-1300
lines changed

ClearScript.NoV8.sln.DotSettings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp73</s:String>
2+
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp80</s:String>
33
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Ejs/@EntryIndexedValue">True</s:Boolean>
4+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=C8AE52BB_002DBFEE_002D4816_002DA9FE_002D8653CEE36C96_002Fdl_003AV8_003A_002E_002E_003F_002E_002E_003FClearScript_003FV8_002Fd_003ASplitProxy_002Ff_003AV8SplitProxyManaged_002ENet5_002Ecs/@EntryIndexedValue">ExplicitlyExcluded</s:String>
45
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/CalculateUnusedTypeMembers/@EntryValue">False</s:Boolean>
56
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeThisQualifier/@EntryIndexedValue">SUGGESTION</s:String>
67
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AssignNullToNotNullAttribute/@EntryIndexedValue">DO_NOT_SHOW</s:String>
@@ -11,12 +12,15 @@
1112
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToUsingDeclaration/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1213
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">HINT</s:String>
1314
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=JsPathNotFound/@EntryIndexedValue">DO_NOT_SHOW</s:String>
15+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeIntoPattern/@EntryIndexedValue">HINT</s:String>
1416
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1517
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReturnFromGlobalScopetWithValue/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1618
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SwapViaDeconstruction/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1719
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedLocals/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1820
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseArrayEmptyMethod/@EntryIndexedValue">DO_NOT_SHOW</s:String>
21+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseIndexFromEndExpression/@EntryIndexedValue">HINT</s:String>
1922
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">DO_NOT_SHOW</s:String>
23+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UsePatternMatching/@EntryIndexedValue">HINT</s:String>
2024
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongExpressionStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
2125
<s:String x:Key="/Default/CodeInspection/JsInspections/LanguageLevel/@EntryValue">Experimental</s:String>
2226
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>

ClearScript.sln.DotSettings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp73</s:String>
2+
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp80</s:String>
33
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Ejs/@EntryIndexedValue">True</s:Boolean>
4+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=C8AE52BB_002DBFEE_002D4816_002DA9FE_002D8653CEE36C96_002Fdl_003AV8_003A_002E_002E_003F_002E_002E_003FClearScript_003FV8_002Fd_003ASplitProxy_002Ff_003AV8SplitProxyManaged_002ENet5_002Ecs/@EntryIndexedValue">ExplicitlyExcluded</s:String>
45
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/CalculateUnusedTypeMembers/@EntryValue">False</s:Boolean>
56
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeThisQualifier/@EntryIndexedValue">SUGGESTION</s:String>
67
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AssignNullToNotNullAttribute/@EntryIndexedValue">DO_NOT_SHOW</s:String>
@@ -11,12 +12,15 @@
1112
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToUsingDeclaration/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1213
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">HINT</s:String>
1314
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=JsPathNotFound/@EntryIndexedValue">DO_NOT_SHOW</s:String>
15+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeIntoPattern/@EntryIndexedValue">HINT</s:String>
1416
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1517
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReturnFromGlobalScopetWithValue/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1618
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SwapViaDeconstruction/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1719
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedLocals/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1820
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseArrayEmptyMethod/@EntryIndexedValue">DO_NOT_SHOW</s:String>
21+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseIndexFromEndExpression/@EntryIndexedValue">HINT</s:String>
1922
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">DO_NOT_SHOW</s:String>
23+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UsePatternMatching/@EntryIndexedValue">HINT</s:String>
2024
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongExpressionStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
2125
<s:String x:Key="/Default/CodeInspection/JsInspections/LanguageLevel/@EntryValue">Experimental</s:String>
2226
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.ClearScript
8+
{
9+
/// <summary>
10+
/// Represents a method to be called asynchronously when a document is loaded.
11+
/// </summary>
12+
/// <param name="info">A structure containing meta-information for the document.</param>
13+
/// <param name="contents">A stream that provides read access to the document.</param>
14+
/// <returns>A task that represents the method's asynchronous operation.</returns>
15+
/// <remarks>
16+
/// The callback can modify the document meta-information by specifying or overriding any of
17+
/// its mutable properties.
18+
/// </remarks>
19+
public delegate Task AsyncDocumentLoadCallback(ValueRef<DocumentInfo> info, Stream contents);
20+
}

ClearScript/DefaultDocumentLoader.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.IO;
99
using System.Linq;
1010
using System.Net.Http;
11+
using System.Text;
1112
using System.Threading;
1213
using System.Threading.Tasks;
1314

@@ -288,11 +289,26 @@ private async Task<Document> LoadDocumentAsync(DocumentSettings settings, Uri ur
288289
}
289290

290291
var documentInfo = new DocumentInfo(uri) { Category = category, ContextCallback = contextCallback };
292+
byte[] bytes = null;
291293

292-
var callback = settings.LoadCallback;
293-
callback?.Invoke(ref documentInfo);
294+
if (!settings.AccessFlags.HasFlag(DocumentAccessFlags.UseAsyncLoadCallback))
295+
{
296+
var callback = settings.LoadCallback;
297+
callback?.Invoke(ref documentInfo);
298+
}
299+
else
300+
{
301+
var callback = settings.AsyncLoadCallback;
302+
if (callback != null)
303+
{
304+
bytes = Encoding.UTF8.GetBytes(contents);
305+
var documentInfoRef = ValueRef.Create(documentInfo);
306+
await callback(documentInfoRef, new MemoryStream(bytes, false)).ConfigureAwait(false);
307+
documentInfo = documentInfoRef.Value;
308+
}
309+
}
294310

295-
var document = CacheDocument(new StringDocument(documentInfo, contents), false);
311+
var document = CacheDocument((bytes != null) ? new StringDocument(documentInfo, bytes) : new StringDocument(documentInfo, contents), false);
296312
if (!settings.AccessFlags.HasFlag(DocumentAccessFlags.AllowCategoryMismatch) && (documentInfo.Category != (category ?? DocumentCategory.Script)))
297313
{
298314
throw new FileLoadException("Document category mismatch", uri.IsFile ? uri.LocalPath : uri.AbsoluteUri);

ClearScript/DocumentAccessFlags.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public enum DocumentAccessFlags
4141
/// <summary>
4242
/// Relaxes the requirement that a loaded document must be of the requested category.
4343
/// </summary>
44-
AllowCategoryMismatch = 0x00000008
44+
AllowCategoryMismatch = 0x00000008,
45+
46+
/// <summary>
47+
/// Enables the use of <c><see cref="DocumentSettings.AsyncLoadCallback"/></c> instead of <c><see cref="DocumentSettings.LoadCallback"/></c>.
48+
/// </summary>
49+
UseAsyncLoadCallback = 0x00000010
4550
}
4651
}

ClearScript/DocumentSettings.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public DocumentLoader Loader
6262
/// </summary>
6363
public DocumentLoadCallback LoadCallback { get; set; }
6464

65+
/// <summary>
66+
/// Gets or set an optional method to be called asynchronously when a document is loaded.
67+
/// </summary>
68+
public AsyncDocumentLoadCallback AsyncLoadCallback { get; set; }
69+
6570
/// <summary>
6671
/// Gets or sets an optional document context callback.
6772
/// </summary>
@@ -170,6 +175,17 @@ private Document FindSystemDocument(string identifier, DocumentCategory category
170175
return document;
171176
}
172177

178+
if (AccessFlags.HasFlag(DocumentAccessFlags.AllowCategoryMismatch))
179+
{
180+
foreach (var pair in systemDocumentMap)
181+
{
182+
if (pair.Key.Item1 == identifier)
183+
{
184+
return pair.Value;
185+
}
186+
}
187+
}
188+
173189
return null;
174190
}
175191
}

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.3.7"
9-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,3,7
10-
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.3.7"
8+
#define CLEARSCRIPT_VERSION_STRING "7.4.0"
9+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,4,0
10+
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.4.0"
1111
#define CLEARSCRIPT_FILE_FLAGS 0L

0 commit comments

Comments
 (0)