Skip to content

Commit

Permalink
Version 7.2.1: (V8) Added support for interrupt propagation and cance…
Browse files Browse the repository at this point in the history
…llation to address GitHub Issue #324; (V8) eliminated host proxies implemented as immutable prototype exotics (GitHub Issue #330); added `ScriptEngine.Global` to facilitate fast non-dynamic access to script resources; added project blog on GitHub Pages; updated build and API documentation. Tested with V8 9.7.106.18.
  • Loading branch information
ClearScriptLib committed Jan 11, 2022
1 parent d5f5baa commit 91dfb30
Show file tree
Hide file tree
Showing 672 changed files with 4,098 additions and 1,039 deletions.
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.2.0"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,2,0
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.2.0"
#define CLEARSCRIPT_VERSION_STRING "7.2.1"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,2,1
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.2.1"
#define CLEARSCRIPT_FILE_FLAGS 0L
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.2.0")]
[assembly: AssemblyFileVersion("7.2.0")]
[assembly: AssemblyInformationalVersion("7.2.0")]
[assembly: AssemblyVersion("7.2.1")]
[assembly: AssemblyFileVersion("7.2.1")]
[assembly: AssemblyInformationalVersion("7.2.1")]

namespace Microsoft.ClearScript.Properties
{
internal static class ClearScriptVersion
{
public const string Triad = "7.2.0";
public const string Informational = "7.2.0";
public const string Triad = "7.2.1";
public const string Informational = "7.2.1";
}
}
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.2.0")]
[assembly: AssemblyFileVersion("7.2.0")]
[assembly: AssemblyInformationalVersion("7.2.0")]
[assembly: AssemblyVersion("7.2.1")]
[assembly: AssemblyFileVersion("7.2.1")]
[assembly: AssemblyInformationalVersion("7.2.1")]
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.2.0")]
[assembly: AssemblyFileVersion("7.2.0")]
[assembly: AssemblyInformationalVersion("7.2.0")]
[assembly: AssemblyVersion("7.2.1")]
[assembly: AssemblyFileVersion("7.2.1")]
[assembly: AssemblyInformationalVersion("7.2.1")]
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.2.0")]
[assembly: AssemblyFileVersion("7.2.0")]
[assembly: AssemblyInformationalVersion("7.2.0")]
[assembly: AssemblyVersion("7.2.1")]
[assembly: AssemblyFileVersion("7.2.1")]
[assembly: AssemblyInformationalVersion("7.2.1")]
13 changes: 12 additions & 1 deletion ClearScript/ScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public bool DisableExtensionMethods
public ContinuationCallback ContinuationCallback { get; set; }

/// <summary>
/// Allows the host to access script resources directly.
/// Allows the host to access script resources dynamically.
/// </summary>
/// <remarks>
/// The value of this property is an object that is bound to the script engine's root
Expand All @@ -316,6 +316,17 @@ public bool DisableExtensionMethods
/// </remarks>
public abstract dynamic Script { get; }

/// <summary>
/// Allows the host to access script resources.
/// </summary>
/// <remarks>
/// The value of this property is an object that is bound to the script engine's root
/// namespace. It allows you to access global script resources via the
/// <see cref="ScriptObject"/> class interface. Doing so is likely to perform better than
/// dynamic access via <see cref="Script"/>.
/// </remarks>
public abstract ScriptObject Global { get; }

/// <summary>
/// Gets or sets the script engine's document settings.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions ClearScript/Util/Web/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private async Task<Frame> ReceiveFrameAsync()
Debug.Assert(length < long.MaxValue);
var payload = new byte[length];

// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (length <= int.MaxValue)
{
await socket.ReceiveBytesAsync(payload, 0, Convert.ToInt32(length)).ConfigureAwait(false);
Expand Down
5 changes: 5 additions & 0 deletions ClearScript/V8/SplitProxy/IV8SplitProxyNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ internal interface IV8SplitProxyNative
V8Script.Handle V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code);
V8Script.Handle V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes);
V8Script.Handle V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
bool V8Isolate_GetEnableInterruptPropagation(V8Isolate.Handle hIsolate);
void V8Isolate_SetEnableInterruptPropagation(V8Isolate.Handle hIsolate, bool value);
void V8Isolate_GetHeapStatistics(V8Isolate.Handle hIsolate, out ulong totalHeapSize, out ulong totalHeapSizeExecutable, out ulong totalPhysicalSize, out ulong usedHeapSize, out ulong heapSizeLimit);
void V8Isolate_GetStatistics(V8Isolate.Handle hIsolate, out ulong scriptCount, out ulong scriptCacheSize, out ulong moduleCount, out ulong[] postedTaskCounts, out ulong[] invokedTaskCounts);
void V8Isolate_CollectGarbage(V8Isolate.Handle hIsolate, bool exhaustive);
Expand Down Expand Up @@ -171,6 +173,9 @@ internal interface IV8SplitProxyNative
V8Script.Handle V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
object V8Context_ExecuteScript(V8Context.Handle hContext, V8Script.Handle hScript, bool evaluate);
void V8Context_Interrupt(V8Context.Handle hContext);
void V8Context_CancelInterrupt(V8Context.Handle hContext);
bool V8Context_GetEnableIsolateInterruptPropagation(V8Context.Handle hContext);
void V8Context_SetEnableIsolateInterruptPropagation(V8Context.Handle hContext, bool value);
void V8Context_GetIsolateHeapStatistics(V8Context.Handle hContext, out ulong totalHeapSize, out ulong totalHeapSizeExecutable, out ulong totalPhysicalSize, out ulong usedHeapSize, out ulong heapSizeLimit);
void V8Context_GetIsolateStatistics(V8Context.Handle hContext, out ulong scriptCount, out ulong scriptCacheSize, out ulong moduleCount, out ulong[] postedTaskCounts, out ulong[] invokedTaskCounts);
void V8Context_GetStatistics(V8Context.Handle hContext, out ulong scriptCount, out ulong moduleCount, out ulong moduleCacheSize);
Expand Down
23 changes: 17 additions & 6 deletions ClearScript/V8/SplitProxy/V8ContextProxyImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public V8ContextProxyImpl(V8IsolateProxy isolateProxy, string name, V8ScriptEngi

#region V8ContextProxy overrides

public override UIntPtr MaxRuntimeHeapSize
public override UIntPtr MaxIsolateHeapSize
{
get => V8SplitProxyNative.Invoke(instance => instance.V8Context_GetMaxIsolateHeapSize(Handle));
set => V8SplitProxyNative.Invoke(instance => instance.V8Context_SetMaxIsolateHeapSize(Handle, value));
}

public override TimeSpan RuntimeHeapSizeSampleInterval
public override TimeSpan IsolateHeapSizeSampleInterval
{
get => V8SplitProxyNative.Invoke(instance => TimeSpan.FromMilliseconds(instance.V8Context_GetIsolateHeapSizeSampleInterval(Handle)));
set => V8SplitProxyNative.Invoke(instance => instance.V8Context_SetIsolateHeapSizeSampleInterval(Handle, value.TotalMilliseconds));
}

public override UIntPtr MaxRuntimeStackUsage
public override UIntPtr MaxIsolateStackUsage
{
get => V8SplitProxyNative.Invoke(instance => instance.V8Context_GetMaxIsolateStackUsage(Handle));
set => V8SplitProxyNative.Invoke(instance => instance.V8Context_SetMaxIsolateStackUsage(Handle, value));
Expand Down Expand Up @@ -172,7 +172,18 @@ public override void Interrupt()
V8SplitProxyNative.Invoke(instance => instance.V8Context_Interrupt(Handle));
}

public override V8RuntimeHeapInfo GetRuntimeHeapInfo()
public override void CancelInterrupt()
{
V8SplitProxyNative.Invoke(instance => instance.V8Context_CancelInterrupt(Handle));
}

public override bool EnableIsolateInterruptPropagation
{
get => V8SplitProxyNative.Invoke(instance => instance.V8Context_GetEnableIsolateInterruptPropagation(Handle));
set => V8SplitProxyNative.Invoke(instance => instance.V8Context_SetEnableIsolateInterruptPropagation(Handle, value));
}

public override V8RuntimeHeapInfo GetIsolateHeapInfo()
{
var totalHeapSize = 0UL;
var totalHeapSizeExecutable = 0UL;
Expand All @@ -191,7 +202,7 @@ public override V8RuntimeHeapInfo GetRuntimeHeapInfo()
};
}

public override V8Runtime.Statistics GetRuntimeStatistics()
public override V8Runtime.Statistics GetIsolateStatistics()
{
var statistics = new V8Runtime.Statistics();
V8SplitProxyNative.Invoke(instance => instance.V8Context_GetIsolateStatistics(Handle, out statistics.ScriptCount, out statistics.ScriptCacheSize, out statistics.ModuleCount, out statistics.PostedTaskCounts, out statistics.InvokedTaskCounts));
Expand Down Expand Up @@ -245,7 +256,7 @@ public override uint CpuProfileSampleInterval
set => V8SplitProxyNative.Invoke(instance => instance.V8Context_SetCpuProfileSampleInterval(Handle, value));
}

public override void WriteRuntimeHeapSnapshot(Stream stream)
public override void WriteIsolateHeapSnapshot(Stream stream)
{
using (var streamScope = V8ProxyHelpers.CreateAddRefHostObjectScope(stream))
{
Expand Down
6 changes: 6 additions & 0 deletions ClearScript/V8/SplitProxy/V8IsolateProxyImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ out tempCacheAccepted
}
}

public override bool EnableInterruptPropagation
{
get => V8SplitProxyNative.Invoke(instance => instance.V8Isolate_GetEnableInterruptPropagation(Handle));
set => V8SplitProxyNative.Invoke(instance => instance.V8Isolate_SetEnableInterruptPropagation(Handle, value));
}

public override V8RuntimeHeapInfo GetHeapInfo()
{
var totalHeapSize = 0UL;
Expand Down
54 changes: 54 additions & 0 deletions ClearScript/V8/SplitProxy/V8SplitProxyNative.Common.tt
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,16 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}

bool IV8SplitProxyNative.V8Isolate_GetEnableInterruptPropagation(V8Isolate.Handle hIsolate)
{
return V8Isolate_GetEnableInterruptPropagation(hIsolate);
}

void IV8SplitProxyNative.V8Isolate_SetEnableInterruptPropagation(V8Isolate.Handle hIsolate, bool value)
{
V8Isolate_SetEnableInterruptPropagation(hIsolate, value);
}

void IV8SplitProxyNative.V8Isolate_GetHeapStatistics(V8Isolate.Handle hIsolate, out ulong totalHeapSize, out ulong totalHeapSizeExecutable, out ulong totalPhysicalSize, out ulong usedHeapSize, out ulong heapSizeLimit)
{
V8Isolate_GetHeapStatistics(hIsolate, out totalHeapSize, out totalHeapSizeExecutable, out totalPhysicalSize, out usedHeapSize, out heapSizeLimit);
Expand Down Expand Up @@ -758,6 +768,21 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Context_Interrupt(hContext);
}

void IV8SplitProxyNative.V8Context_CancelInterrupt(V8Context.Handle hContext)
{
V8Context_CancelInterrupt(hContext);
}

bool IV8SplitProxyNative.V8Context_GetEnableIsolateInterruptPropagation(V8Context.Handle hContext)
{
return V8Context_GetEnableIsolateInterruptPropagation(hContext);
}

void IV8SplitProxyNative.V8Context_SetEnableIsolateInterruptPropagation(V8Context.Handle hContext, bool value)
{
V8Context_SetEnableIsolateInterruptPropagation(hContext, value);
}

void IV8SplitProxyNative.V8Context_GetIsolateHeapStatistics(V8Context.Handle hContext, out ulong totalHeapSize, out ulong totalHeapSizeExecutable, out ulong totalPhysicalSize, out ulong usedHeapSize, out ulong heapSizeLimit)
{
V8Context_GetIsolateHeapStatistics(hContext, out totalHeapSize, out totalHeapSizeExecutable, out totalPhysicalSize, out usedHeapSize, out heapSizeLimit);
Expand Down Expand Up @@ -1545,6 +1570,18 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);

[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool V8Isolate_GetEnableInterruptPropagation(
[In] V8Isolate.Handle hIsolate
);

[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Isolate_SetEnableInterruptPropagation(
[In] V8Isolate.Handle hIsolate,
[In] [MarshalAs(UnmanagedType.I1)] bool value
);

[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Isolate_GetHeapStatistics(
[In] V8Isolate.Handle hIsolate,
Expand Down Expand Up @@ -1739,6 +1776,23 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] V8Context.Handle hContext
);

[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Context_CancelInterrupt(
[In] V8Context.Handle hContext
);

[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool V8Context_GetEnableIsolateInterruptPropagation(
[In] V8Context.Handle hContext
);

[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Context_SetEnableIsolateInterruptPropagation(
[In] V8Context.Handle hContext,
[In] [MarshalAs(UnmanagedType.I1)] bool value
);

[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Context_GetIsolateHeapStatistics(
[In] V8Context.Handle hContext,
Expand Down
Loading

0 comments on commit 91dfb30

Please sign in to comment.