Skip to content

Commit 8b5b794

Browse files
Version 7.1.2: Added optional ValueTask conversions (GitHub Issue #248); patched V8 to avoid Date.prototype.toLocaleString crash when ICU data is unavailable (GitHub Issue #246); added HostSettings.AuxiliarySearchPath; fixed default document loader issue with foreign file name extensions; updated V8 debug agent web responses for Node.js alignment; updated API documentation. Tested with V8 9.0.257.19.
1 parent 041b5b4 commit 8b5b794

File tree

831 files changed

+3554
-2683
lines changed

Some content is hidden

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

831 files changed

+3554
-2683
lines changed

ClearScript/DocumentLoader.cs

+31-17
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static async Task<List<Uri>> GetCandidateUrisAsync(DocumentSettings sett
139139
}
140140
else
141141
{
142-
foreach (var testUri in ApplyFileNameExtensions(sourceInfo, uri, settings.FileNameExtensions))
142+
foreach (var testUri in ApplyExtensions(sourceInfo, uri, settings.FileNameExtensions))
143143
{
144144
if (await IsCandidateUriAsync(settings, testUri).ConfigureAwait(false))
145145
{
@@ -158,7 +158,7 @@ private static async Task<List<Uri>> GetCandidateUrisAsync(DocumentSettings sett
158158
var rawUris = GetRawUris(settings, sourceInfo, specifier).Distinct();
159159
if (!string.IsNullOrWhiteSpace(settings.FileNameExtensions))
160160
{
161-
rawUris = rawUris.SelectMany(uri => ApplyFileNameExtensions(sourceInfo, uri, settings.FileNameExtensions));
161+
rawUris = rawUris.SelectMany(uri => ApplyExtensions(sourceInfo, uri, settings.FileNameExtensions));
162162
}
163163

164164
foreach (var testUri in rawUris)
@@ -218,34 +218,48 @@ private static IEnumerable<Uri> GetRawUris(DocumentSettings settings, DocumentIn
218218
}
219219
}
220220

221-
private static IEnumerable<Uri> ApplyFileNameExtensions(DocumentInfo? sourceInfo, Uri uri, string fileNameExtensions)
221+
private static IEnumerable<Uri> ApplyExtensions(DocumentInfo? sourceInfo, Uri uri, string extensions)
222222
{
223223
yield return uri;
224224

225225
var builder = new UriBuilder(uri);
226-
227226
var path = builder.Path;
228-
if (!string.IsNullOrEmpty(Path.GetFileName(path)) && !Path.HasExtension(path))
227+
228+
if (!string.IsNullOrEmpty(Path.GetFileName(path)))
229229
{
230-
string sourceFileNameExtension = null;
231-
if (sourceInfo.HasValue)
230+
var existingExtension = Path.GetExtension(path);
231+
var compatibleExtensions = GetCompatibleExtensions(sourceInfo, extensions).ToList();
232+
233+
if (!compatibleExtensions.Contains(existingExtension, StringComparer.OrdinalIgnoreCase))
232234
{
233-
sourceFileNameExtension = Path.GetExtension((sourceInfo.Value.Uri != null) ? new UriBuilder(sourceInfo.Value.Uri).Path : sourceInfo.Value.Name);
234-
if (!string.IsNullOrEmpty(sourceFileNameExtension))
235+
foreach (var compatibleExtension in compatibleExtensions)
235236
{
236-
builder.Path = Path.ChangeExtension(path, sourceFileNameExtension);
237+
builder.Path = Path.ChangeExtension(path, existingExtension + compatibleExtension);
237238
yield return builder.Uri;
238239
}
239240
}
241+
}
242+
}
243+
244+
private static IEnumerable<string> GetCompatibleExtensions(DocumentInfo? sourceInfo, string extensions)
245+
{
246+
string sourceExtension = null;
247+
248+
if (sourceInfo.HasValue)
249+
{
250+
sourceExtension = Path.GetExtension((sourceInfo.Value.Uri != null) ? new UriBuilder(sourceInfo.Value.Uri).Path : sourceInfo.Value.Name);
251+
if (!string.IsNullOrEmpty(sourceExtension))
252+
{
253+
yield return sourceExtension;
254+
}
255+
}
240256

241-
foreach (var fileNameExtension in fileNameExtensions.SplitSearchPath())
257+
foreach (var extension in extensions.SplitSearchPath())
258+
{
259+
var tempExtension = extension.StartsWith(".", StringComparison.Ordinal) ? extension : "." + extension;
260+
if (!tempExtension.Equals(sourceExtension, StringComparison.OrdinalIgnoreCase))
242261
{
243-
var testFileNameExtension = fileNameExtension.StartsWith(".", StringComparison.Ordinal) ? fileNameExtension : "." + fileNameExtension;
244-
if (!testFileNameExtension.Equals(sourceFileNameExtension, StringComparison.OrdinalIgnoreCase))
245-
{
246-
builder.Path = Path.ChangeExtension(path, testFileNameExtension);
247-
yield return builder.Uri;
248-
}
262+
yield return tempExtension;
249263
}
250264
}
251265
}

ClearScript/Exports/VersionSymbols.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#pragma once
77

8-
#define CLEARSCRIPT_VERSION_STRING "7.1.1"
9-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,1,1
10-
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.1.1"
8+
#define CLEARSCRIPT_VERSION_STRING "7.1.2"
9+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,1,2
10+
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.1.2"
1111
#define CLEARSCRIPT_FILE_FLAGS 0L

ClearScript/HostSettings.cs

+9
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,14 @@ public static class HostSettings
2525
/// </para>
2626
/// </remarks>
2727
public static bool UseAssemblyTable { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets a semicolon-delimited list of directory paths to search for auxiliary files.
31+
/// </summary>
32+
/// <remarks>
33+
/// This property allows the host to augment ClearScript's algorithm for locating unmanaged
34+
/// resources such as native assemblies and related data files.
35+
/// </remarks>
36+
public static string AuxiliarySearchPath { get; set; }
2837
}
2938
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.Threading.Tasks;
5+
6+
namespace Microsoft.ClearScript.JavaScript
7+
{
8+
internal partial interface IJavaScriptEngine
9+
{
10+
object CreatePromiseForValueTask<T>(ValueTask<T> valueTask);
11+
object CreatePromiseForValueTask(ValueTask valueTask);
12+
}
13+
}

ClearScript/JavaScript/IJavaScriptEngine.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
namespace Microsoft.ClearScript.JavaScript
77
{
8-
internal interface IJavaScriptEngine
8+
// ReSharper disable once PartialTypeWithSinglePart
9+
internal partial interface IJavaScriptEngine
910
{
1011
uint BaseLanguageVersion { get; }
1112

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.ClearScript.Util;
7+
8+
namespace Microsoft.ClearScript.JavaScript
9+
{
10+
public static partial class JavaScriptExtensions
11+
{
12+
/// <summary>
13+
/// Converts a <see cref="ValueTask{T}"/> instance to a
14+
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</see>
15+
/// for use with script code currently running on the calling thread.
16+
/// </summary>
17+
/// <typeparam name="T">The task's result type.</typeparam>
18+
/// <param name="valueTask">The task to convert to a promise.</param>
19+
/// <returns>A promise that represents the task's asynchronous operation.</returns>
20+
/// <remarks>
21+
/// This method is not available on .NET Framework or Universal Windows Platform (UWP).
22+
/// </remarks>
23+
public static object ToPromise<T>(this ValueTask<T> valueTask)
24+
{
25+
return valueTask.ToPromise(ScriptEngine.Current);
26+
}
27+
28+
/// <summary>
29+
/// Converts a <see cref="ValueTask{T}"/> instance to a
30+
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</see>
31+
/// for use with script code running in the specified script engine.
32+
/// </summary>
33+
/// <typeparam name="T">The task's result type.</typeparam>
34+
/// <param name="valueTask">The task to convert to a promise.</param>
35+
/// <param name="engine">The script engine in which the promise will be used.</param>
36+
/// <returns>A promise that represents the task's asynchronous operation.</returns>
37+
/// <remarks>
38+
/// This method is not available on .NET Framework or Universal Windows Platform (UWP).
39+
/// </remarks>
40+
public static object ToPromise<T>(this ValueTask<T> valueTask, ScriptEngine engine)
41+
{
42+
MiscHelpers.VerifyNonNullArgument(valueTask, nameof(valueTask));
43+
MiscHelpers.VerifyNonNullArgument(engine, nameof(engine));
44+
45+
var javaScriptEngine = engine as IJavaScriptEngine;
46+
if ((javaScriptEngine == null) || (javaScriptEngine.BaseLanguageVersion < 6))
47+
{
48+
throw new NotSupportedException("The script engine does not support promises");
49+
}
50+
51+
return javaScriptEngine.CreatePromiseForValueTask(valueTask);
52+
}
53+
54+
/// <summary>
55+
/// Converts a <see cref="ValueTask"/> instance to a
56+
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</see>
57+
/// for use with script code currently running on the calling thread.
58+
/// </summary>
59+
/// <param name="valueTask">The task to convert to a promise.</param>
60+
/// <returns>A promise that represents the task's asynchronous operation.</returns>
61+
/// <remarks>
62+
/// This method is not available on .NET Framework or Universal Windows Platform (UWP).
63+
/// </remarks>
64+
public static object ToPromise(this ValueTask valueTask)
65+
{
66+
return valueTask.ToPromise(ScriptEngine.Current);
67+
}
68+
69+
/// <summary>
70+
/// Converts a <see cref="ValueTask"/> instance to a
71+
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</see>
72+
/// for use with script code running in the specified script engine.
73+
/// </summary>
74+
/// <param name="valueTask">The task to convert to a promise.</param>
75+
/// <param name="engine">The script engine in which the promise will be used.</param>
76+
/// <returns>A promise that represents the task's asynchronous operation.</returns>
77+
/// <remarks>
78+
/// This method is not available on .NET Framework or Universal Windows Platform (UWP).
79+
/// </remarks>
80+
public static object ToPromise(this ValueTask valueTask, ScriptEngine engine)
81+
{
82+
MiscHelpers.VerifyNonNullArgument(valueTask, nameof(valueTask));
83+
MiscHelpers.VerifyNonNullArgument(engine, nameof(engine));
84+
85+
var javaScriptEngine = engine as IJavaScriptEngine;
86+
if ((javaScriptEngine == null) || (javaScriptEngine.BaseLanguageVersion < 6))
87+
{
88+
throw new NotSupportedException("The script engine does not support promises");
89+
}
90+
91+
return javaScriptEngine.CreatePromiseForValueTask(valueTask);
92+
}
93+
}
94+
}

ClearScript/JavaScript/JavaScriptExtensions.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,36 @@
77

88
namespace Microsoft.ClearScript.JavaScript
99
{
10+
// ReSharper disable once PartialTypeWithSinglePart
11+
1012
/// <summary>
1113
/// Defines extension methods for use with JavaScript engines.
1214
/// </summary>
13-
public static class JavaScriptExtensions
15+
public static partial class JavaScriptExtensions
1416
{
1517
/// <summary>
16-
/// Converts a <see cref="Task{TResult}"/> instance to a
18+
/// Converts a <see cref="Task{T}"/> instance to a
1719
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</see>
1820
/// for use with script code currently running on the calling thread.
1921
/// </summary>
20-
/// <typeparam name="TResult">The task's result type.</typeparam>
22+
/// <typeparam name="T">The task's result type.</typeparam>
2123
/// <param name="task">The task to convert to a promise.</param>
2224
/// <returns>A promise that represents the task's asynchronous operation.</returns>
23-
public static object ToPromise<TResult>(this Task<TResult> task)
25+
public static object ToPromise<T>(this Task<T> task)
2426
{
2527
return task.ToPromise(ScriptEngine.Current);
2628
}
2729

2830
/// <summary>
29-
/// Converts a <see cref="Task{TResult}"/> instance to a
31+
/// Converts a <see cref="Task{T}"/> instance to a
3032
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</see>
3133
/// for use with script code running in the specified script engine.
3234
/// </summary>
33-
/// <typeparam name="TResult">The task's result type.</typeparam>
35+
/// <typeparam name="T">The task's result type.</typeparam>
3436
/// <param name="task">The task to convert to a promise.</param>
3537
/// <param name="engine">The script engine in which the promise will be used.</param>
3638
/// <returns>A promise that represents the task's asynchronous operation.</returns>
37-
public static object ToPromise<TResult>(this Task<TResult> task, ScriptEngine engine)
39+
public static object ToPromise<T>(this Task<T> task, ScriptEngine engine)
3840
{
3941
MiscHelpers.VerifyNonNullArgument(task, nameof(task));
4042
MiscHelpers.VerifyNonNullArgument(engine, nameof(engine));

ClearScript/Properties/AssemblyInfo.Core.cs

+5-5
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.1")]
22-
[assembly: AssemblyFileVersion("7.1.1")]
23-
[assembly: AssemblyInformationalVersion("7.1.1")]
21+
[assembly: AssemblyVersion("7.1.2")]
22+
[assembly: AssemblyFileVersion("7.1.2")]
23+
[assembly: AssemblyInformationalVersion("7.1.2")]
2424

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

ClearScript/Properties/AssemblyInfo.V8.cs

+3-3
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.1")]
19-
[assembly: AssemblyFileVersion("7.1.1")]
20-
[assembly: AssemblyInformationalVersion("7.1.1")]
18+
[assembly: AssemblyVersion("7.1.2")]
19+
[assembly: AssemblyFileVersion("7.1.2")]
20+
[assembly: AssemblyInformationalVersion("7.1.2")]

ClearScript/Properties/AssemblyInfo.Windows.Core.cs

+3-3
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.1")]
20-
[assembly: AssemblyFileVersion("7.1.1")]
21-
[assembly: AssemblyInformationalVersion("7.1.1")]
19+
[assembly: AssemblyVersion("7.1.2")]
20+
[assembly: AssemblyFileVersion("7.1.2")]
21+
[assembly: AssemblyInformationalVersion("7.1.2")]

ClearScript/Properties/AssemblyInfo.Windows.cs

+3-3
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.1")]
19-
[assembly: AssemblyFileVersion("7.1.1")]
20-
[assembly: AssemblyInformationalVersion("7.1.1")]
18+
[assembly: AssemblyVersion("7.1.2")]
19+
[assembly: AssemblyFileVersion("7.1.2")]
20+
[assembly: AssemblyInformationalVersion("7.1.2")]

ClearScript/V8/V8CpuProfile.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
@@ -134,13 +135,21 @@ private void WriteTimeDeltasJson(TextWriter writer)
134135

135136
if ((Samples != null) && (Samples.Count > 0))
136137
{
138+
const ulong maxSafeInteger = 9007199254740991UL; // 2^53 - 1
139+
137140
writer.Write(",\"timeDeltas\":[");
138141
{
139142
writer.Write(Samples[0].Timestamp - StartTimestamp);
140143
for (var index = 1; index < Samples.Count; index++)
141144
{
145+
var current = Samples[index].Timestamp;
146+
var previous = Samples[index - 1].Timestamp;
147+
148+
var delta = (current > previous) ? (current - previous) : 0;
149+
delta = Math.Min(delta, maxSafeInteger);
150+
142151
writer.Write(',');
143-
writer.Write(Samples[index].Timestamp - Samples[index - 1].Timestamp);
152+
writer.Write(delta);
144153
}
145154
}
146155
writer.Write(']');

ClearScript/V8/V8DebugAgent.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ private void HandleWebRequest(WebContext webContext)
175175
" \"title\": \"{2}\",\r\n" +
176176
" \"url\": \"{3}\",\r\n" +
177177
" \"faviconUrl\": \"{6}\",\r\n" +
178-
" \"devtoolsFrontendUrl\": \"chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws={4}:{5}/{0}\",\r\n" +
178+
" \"devtoolsFrontendUrl\": \"devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws={4}:{5}/{0}\",\r\n" +
179+
" \"devtoolsFrontendUrlCompat\": \"devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws={4}:{5}/{0}\",\r\n" +
179180
" \"webSocketDebuggerUrl\": \"ws://{4}:{5}/{0}\"\r\n" +
180181
"}} ]\r\n",
181182
targetId,
@@ -192,7 +193,7 @@ private void HandleWebRequest(WebContext webContext)
192193
{
193194
SendWebResponse(webContext, MiscHelpers.FormatInvariant(
194195
"{{\r\n" +
195-
" \"Browser\": \"ClearScript {0} [V8 {1}]\",\r\n" +
196+
" \"Browser\": \"ClearScript/v{0}, V8 {1}\",\r\n" +
196197
" \"Protocol-Version\": \"1.1\"\r\n" +
197198
"}}\r\n",
198199
ClearScriptVersion.Informational,

0 commit comments

Comments
 (0)