Skip to content

Commit

Permalink
Version 7.4.5: [V8] Added AddPerformanceObject and SetTimerResolution…
Browse files Browse the repository at this point in the history
… to V8ScriptEngineFlags (GitHub Discussion #568); [V8] Enhanced execution and termination transitions, fixing GitHub Issue #560; optimized document code for string documents (GitHub Discussion #567); switched to Clang and C++20 on all platforms; added .NET 8 targets to test projects; updated API and build documentation. Tested with V8 12.3.219.12.
  • Loading branch information
ClearScriptLib committed Mar 25, 2024
1 parent 78916b6 commit 28663e5
Show file tree
Hide file tree
Showing 909 changed files with 2,819 additions and 2,206 deletions.
6 changes: 2 additions & 4 deletions ClearScript/DefaultDocumentLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ private async Task<Document> LoadDocumentAsync(DocumentSettings settings, Uri ur
}

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

if (!settings.AccessFlags.HasFlag(DocumentAccessFlags.UseAsyncLoadCallback))
{
Expand All @@ -301,14 +300,13 @@ private async Task<Document> LoadDocumentAsync(DocumentSettings settings, Uri ur
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);
await callback(documentInfoRef, new MemoryStream(Encoding.UTF8.GetBytes(contents), false)).ConfigureAwait(false);
documentInfo = documentInfoRef.Value;
}
}

var document = CacheDocument((bytes != null) ? new StringDocument(documentInfo, bytes) : new StringDocument(documentInfo, contents), false);
var document = CacheDocument(new StringDocument(documentInfo, contents), false);

var expectedCategory = category ?? DocumentCategory.Script;
if (!settings.AccessFlags.HasFlag(DocumentAccessFlags.AllowCategoryMismatch) && (documentInfo.Category != expectedCategory))
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.4.4"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,4,4
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.4.4"
#define CLEARSCRIPT_VERSION_STRING "7.4.5"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,4,5
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.4.5"
#define CLEARSCRIPT_FILE_FLAGS 0L
2 changes: 1 addition & 1 deletion ClearScript/HostSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static class HostSettings
/// </summary>
/// <remarks>
/// When not explicitly assigned to a non-<c>null</c> value, this property returns the
/// <see cref="CustomAttributeLoader.Default">default custom attribute loader.</see>.
/// <see cref="CustomAttributeLoader.Default">default custom attribute loader</see>.
/// </remarks>
public static CustomAttributeLoader CustomAttributeLoader
{
Expand Down
8 changes: 4 additions & 4 deletions ClearScript/IScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ public interface IScriptEngine : IDisposable
/// <summary>
/// Executes script code with an associated document name.
/// </summary>
/// <param name="documentName">A document name for the script code. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="documentName">A document name for the script code. Currently, this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="code">The script code to execute.</param>
/// <remarks>
/// <para>
Expand All @@ -904,7 +904,7 @@ public interface IScriptEngine : IDisposable
/// <summary>
/// Executes script code with an associated document name, optionally discarding the document after execution.
/// </summary>
/// <param name="documentName">A document name for the script code. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="documentName">A document name for the script code. Currently, this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="discard"><c>True</c> to discard the script document after execution, <c>false</c> otherwise.</param>
/// <param name="code">The script code to execute.</param>
/// <remarks>
Expand Down Expand Up @@ -1009,7 +1009,7 @@ public interface IScriptEngine : IDisposable
/// <summary>
/// Evaluates script code with an associated document name.
/// </summary>
/// <param name="documentName">A document name for the script code. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="documentName">A document name for the script code. Currently, this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="code">The script code to evaluate.</param>
/// <returns>The result value.</returns>
/// <remarks>
Expand All @@ -1032,7 +1032,7 @@ public interface IScriptEngine : IDisposable
/// <summary>
/// Evaluates script code with an associated document name, optionally discarding the document after execution.
/// </summary>
/// <param name="documentName">A document name for the script code. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="documentName">A document name for the script code. Currently, this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="discard"><c>True</c> to discard the script document after execution, <c>false</c> otherwise.</param>
/// <param name="code">The script code to evaluate.</param>
/// <returns>The result value.</returns>
Expand Down
10 changes: 5 additions & 5 deletions ClearScript/Properties/AssemblyInfo.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
[assembly: InternalsVisibleTo("ClearScriptTest")]

[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.4")]
[assembly: AssemblyFileVersion("7.4.4")]
[assembly: AssemblyInformationalVersion("7.4.4")]
[assembly: AssemblyVersion("7.4.5")]
[assembly: AssemblyFileVersion("7.4.5")]
[assembly: AssemblyInformationalVersion("7.4.5")]

namespace Microsoft.ClearScript.Properties
{
internal static class ClearScriptVersion
{
public const string Triad = "7.4.4";
public const string Informational = "7.4.4";
public const string Triad = "7.4.5";
public const string Informational = "7.4.5";
}
}
6 changes: 3 additions & 3 deletions ClearScript/Properties/AssemblyInfo.V8.ICUData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
[assembly: InternalsVisibleTo("ClearScript.V8")]

[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.4")]
[assembly: AssemblyFileVersion("7.4.4")]
[assembly: AssemblyInformationalVersion("7.4.4")]
[assembly: AssemblyVersion("7.4.5")]
[assembly: AssemblyFileVersion("7.4.5")]
[assembly: AssemblyInformationalVersion("7.4.5")]
6 changes: 3 additions & 3 deletions ClearScript/Properties/AssemblyInfo.V8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
[assembly: InternalsVisibleTo("ClearScriptTest")]

[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.4")]
[assembly: AssemblyFileVersion("7.4.4")]
[assembly: AssemblyInformationalVersion("7.4.4")]
[assembly: AssemblyVersion("7.4.5")]
[assembly: AssemblyFileVersion("7.4.5")]
[assembly: AssemblyInformationalVersion("7.4.5")]
6 changes: 3 additions & 3 deletions ClearScript/Properties/AssemblyInfo.Windows.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
[assembly: InternalsVisibleTo("ClearScriptTest")]

[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.4")]
[assembly: AssemblyFileVersion("7.4.4")]
[assembly: AssemblyInformationalVersion("7.4.4")]
[assembly: AssemblyVersion("7.4.5")]
[assembly: AssemblyFileVersion("7.4.5")]
[assembly: AssemblyInformationalVersion("7.4.5")]
6 changes: 3 additions & 3 deletions ClearScript/Properties/AssemblyInfo.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
[assembly: InternalsVisibleTo("ClearScriptTest")]

[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.4")]
[assembly: AssemblyFileVersion("7.4.4")]
[assembly: AssemblyInformationalVersion("7.4.4")]
[assembly: AssemblyVersion("7.4.5")]
[assembly: AssemblyFileVersion("7.4.5")]
[assembly: AssemblyInformationalVersion("7.4.5")]
4 changes: 2 additions & 2 deletions ClearScript/ScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class ScriptEngine : IScriptEngine, IHostContext
/// <summary>
/// Initializes a new script engine instance.
/// </summary>
/// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="name">A name to associate with the instance. Currently, this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
[Obsolete("Use ScriptEngine(string name, string fileNameExtensions) instead.")]
protected ScriptEngine(string name)
: this(name, null)
Expand All @@ -47,7 +47,7 @@ protected ScriptEngine(string name)
/// <summary>
/// Initializes a new script engine instance with the specified list of supported file name extensions.
/// </summary>
/// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="name">A name to associate with the instance. Currently, this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="fileNameExtensions">A semicolon-delimited list of supported file name extensions.</param>
protected ScriptEngine(string name, string fileNameExtensions)
{
Expand Down
16 changes: 7 additions & 9 deletions ClearScript/StringDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ namespace Microsoft.ClearScript
/// </summary>
public class StringDocument : Document
{
private readonly byte[] contents;

/// <summary>
/// Initializes a new <c><see cref="StringDocument"/></c> instance.
/// </summary>
/// <param name="info">A structure containing meta-information for the document.</param>
/// <param name="contents">A string containing the document's contents.</param>
public StringDocument(DocumentInfo info, string contents)
: this(info, Encoding.UTF8.GetBytes(contents))
{
}

internal StringDocument(DocumentInfo info, byte[] contents)
{
Info = info;
this.contents = contents;
StringContents = contents;
}

/// <summary>
/// Gets the document's contents as a string.
/// </summary>
public string StringContents { get; }

#region Document overrides

/// <summary>
Expand All @@ -43,7 +41,7 @@ internal StringDocument(DocumentInfo info, byte[] contents)
/// The <c><see cref="StringDocument"/></c> implementation of this property returns a
/// <c><see cref="MemoryStream"/></c> instance.
/// </remarks>
public override Stream Contents => new MemoryStream(contents, false);
public override Stream Contents => new MemoryStream(Encoding.GetBytes(StringContents), false);

/// <summary>
/// Gets the document's character encoding.
Expand Down
23 changes: 11 additions & 12 deletions ClearScript/Util/MemberComparer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.Collections.Generic;
Expand All @@ -16,29 +16,28 @@ private MemberComparer()

public override bool Equals(T x, T y)
{
if ((x == null) && (y == null))
if (ReferenceEquals(x, y))
{
return true;
}
else if ((x == null) || (y == null))

if (ReferenceEquals(x, null) || ReferenceEquals(y, null))
{
return false;
}

try
{
return (x.Module == y.Module) && (x.MetadataToken == y.MetadataToken);
}
catch
{
return x == y;
}
return MiscHelpers.Try(out var result, () => UnsafeEquals(x, y)) && result;
}

public override int GetHashCode(T obj)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return (obj == null) ? 0 : obj.GetHashCode();
return ReferenceEquals(obj, null) ? 0 : obj.GetHashCode();
}

private static bool UnsafeEquals(T x, T y)
{
return (x.Module == y.Module) && (x.MetadataToken == y.MetadataToken);
}
}
}
7 changes: 6 additions & 1 deletion ClearScript/Util/MiscHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public static void QueueNativeCallback(INativeCallback callback)
//
// UPDATE: The observed behavior is actually documented. As Dispose is invoked via
// the callback's only reference, the callback may become eligible for finalization
// during the call. Typically Dispose invokes GC.SuppressFinalize just before
// during the call. Typically, Dispose invokes GC.SuppressFinalize just before
// exiting, which, in addition to canceling finalization, extends the object's
// lifetime until Dispose has done its job. The callback here is unusual in that it
// requires finalization regardless of disposal, so the correct fix is for Dispose
Expand Down Expand Up @@ -506,6 +506,11 @@ public static byte[] ReadToEnd(this Stream stream)

public static string GetTextContents(this Document document)
{
if (document is StringDocument stringDocument)
{
return stringDocument.StringContents;
}

using (var reader = new StreamReader(document.Contents, document.Encoding ?? Encoding.UTF8))
{
return reader.ReadToEnd();
Expand Down
10 changes: 3 additions & 7 deletions ClearScript/Util/TypeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,20 +1180,18 @@ private void GetUpcastCountInternal(Type targetType, uint count, ref uint lowest

#region Nested type: PropertySignatureComparer

private sealed class PropertySignatureComparer : IEqualityComparer<PropertyInfo>
private sealed class PropertySignatureComparer : EqualityComparer<PropertyInfo>
{
public static readonly PropertySignatureComparer Instance = new PropertySignatureComparer();

#region IEqualityComparer<PropertyInfo> implementation

public bool Equals(PropertyInfo first, PropertyInfo second)
public override bool Equals(PropertyInfo first, PropertyInfo second)
{
var firstParamTypes = first.GetIndexParameters().Select(param => param.ParameterType);
var secondParamTypes = second.GetIndexParameters().Select(param => param.ParameterType);
return firstParamTypes.SequenceEqual(secondParamTypes);
}

public int GetHashCode(PropertyInfo property)
public override int GetHashCode(PropertyInfo property)
{
var hashCode = 0;

Expand All @@ -1205,8 +1203,6 @@ public int GetHashCode(PropertyInfo property)

return hashCode;
}

#endregion
}

#endregion
Expand Down
1 change: 1 addition & 0 deletions ClearScript/V8/SplitProxy/V8SplitProxyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ public readonly struct Ptr

#endregion
}

internal static class V8CpuProfile
{
public static void ProcessProfile(V8Entity.Handle hEntity, Ptr pProfile, V8.V8CpuProfile profile)
Expand Down
Loading

0 comments on commit 28663e5

Please sign in to comment.