Skip to content

Commit

Permalink
ClearScript 7.4: Generic script objects now implement IDictionary<str…
Browse files Browse the repository at this point in the history
…ing, 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.
  • Loading branch information
ClearScriptLib committed Mar 9, 2023
1 parent 6106c30 commit 381b548
Show file tree
Hide file tree
Showing 819 changed files with 3,261 additions and 1,300 deletions.
6 changes: 5 additions & 1 deletion ClearScript.NoV8.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<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">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp73</s:String>
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp80</s:String>
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Ejs/@EntryIndexedValue">True</s:Boolean>
<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>
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/CalculateUnusedTypeMembers/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeThisQualifier/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AssignNullToNotNullAttribute/@EntryIndexedValue">DO_NOT_SHOW</s:String>
Expand All @@ -11,12 +12,15 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToUsingDeclaration/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=JsPathNotFound/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeIntoPattern/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReturnFromGlobalScopetWithValue/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SwapViaDeconstruction/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedLocals/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseArrayEmptyMethod/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseIndexFromEndExpression/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UsePatternMatching/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongExpressionStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/JsInspections/LanguageLevel/@EntryValue">Experimental</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
Expand Down
6 changes: 5 additions & 1 deletion ClearScript.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<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">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp73</s:String>
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp80</s:String>
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Ejs/@EntryIndexedValue">True</s:Boolean>
<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>
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/CalculateUnusedTypeMembers/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeThisQualifier/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AssignNullToNotNullAttribute/@EntryIndexedValue">DO_NOT_SHOW</s:String>
Expand All @@ -11,12 +12,15 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToUsingDeclaration/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=JsPathNotFound/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeIntoPattern/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReturnFromGlobalScopetWithValue/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SwapViaDeconstruction/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedLocals/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseArrayEmptyMethod/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseIndexFromEndExpression/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UsePatternMatching/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongExpressionStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/JsInspections/LanguageLevel/@EntryValue">Experimental</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
Expand Down
20 changes: 20 additions & 0 deletions ClearScript/AsyncDocumentLoadCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.IO;
using System.Threading.Tasks;

namespace Microsoft.ClearScript
{
/// <summary>
/// Represents a method to be called asynchronously when a document is loaded.
/// </summary>
/// <param name="info">A structure containing meta-information for the document.</param>
/// <param name="contents">A stream that provides read access to the document.</param>
/// <returns>A task that represents the method's asynchronous operation.</returns>
/// <remarks>
/// The callback can modify the document meta-information by specifying or overriding any of
/// its mutable properties.
/// </remarks>
public delegate Task AsyncDocumentLoadCallback(ValueRef<DocumentInfo> info, Stream contents);
}
22 changes: 19 additions & 3 deletions ClearScript/DefaultDocumentLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

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

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

var callback = settings.LoadCallback;
callback?.Invoke(ref documentInfo);
if (!settings.AccessFlags.HasFlag(DocumentAccessFlags.UseAsyncLoadCallback))
{
var callback = settings.LoadCallback;
callback?.Invoke(ref documentInfo);
}
else
{
var callback = settings.AsyncLoadCallback;
if (callback != null)
{
bytes = Encoding.UTF8.GetBytes(contents);
var documentInfoRef = ValueRef.Create(documentInfo);
await callback(documentInfoRef, new MemoryStream(bytes, false)).ConfigureAwait(false);
documentInfo = documentInfoRef.Value;
}
}

var document = CacheDocument(new StringDocument(documentInfo, contents), false);
var document = CacheDocument((bytes != null) ? new StringDocument(documentInfo, bytes) : new StringDocument(documentInfo, contents), false);
if (!settings.AccessFlags.HasFlag(DocumentAccessFlags.AllowCategoryMismatch) && (documentInfo.Category != (category ?? DocumentCategory.Script)))
{
throw new FileLoadException("Document category mismatch", uri.IsFile ? uri.LocalPath : uri.AbsoluteUri);
Expand Down
7 changes: 6 additions & 1 deletion ClearScript/DocumentAccessFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public enum DocumentAccessFlags
/// <summary>
/// Relaxes the requirement that a loaded document must be of the requested category.
/// </summary>
AllowCategoryMismatch = 0x00000008
AllowCategoryMismatch = 0x00000008,

/// <summary>
/// Enables the use of <c><see cref="DocumentSettings.AsyncLoadCallback"/></c> instead of <c><see cref="DocumentSettings.LoadCallback"/></c>.
/// </summary>
UseAsyncLoadCallback = 0x00000010
}
}
16 changes: 16 additions & 0 deletions ClearScript/DocumentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public DocumentLoader Loader
/// </summary>
public DocumentLoadCallback LoadCallback { get; set; }

/// <summary>
/// Gets or set an optional method to be called asynchronously when a document is loaded.
/// </summary>
public AsyncDocumentLoadCallback AsyncLoadCallback { get; set; }

/// <summary>
/// Gets or sets an optional document context callback.
/// </summary>
Expand Down Expand Up @@ -170,6 +175,17 @@ private Document FindSystemDocument(string identifier, DocumentCategory category
return document;
}

if (AccessFlags.HasFlag(DocumentAccessFlags.AllowCategoryMismatch))
{
foreach (var pair in systemDocumentMap)
{
if (pair.Key.Item1 == identifier)
{
return pair.Value;
}
}
}

return null;
}
}
Expand Down
6 changes: 3 additions & 3 deletions ClearScript/Exports/VersionSymbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#define CLEARSCRIPT_VERSION_STRING "7.3.7"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,3,7
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.3.7"
#define CLEARSCRIPT_VERSION_STRING "7.4.0"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,4,0
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.4.0"
#define CLEARSCRIPT_FILE_FLAGS 0L
Loading

0 comments on commit 381b548

Please sign in to comment.