Skip to content

Commit

Permalink
Version 7.2.2: Added V8Settings.GlobalFlags and V8GlobalFlags.Disable…
Browse files Browse the repository at this point in the history
…JITCompilation; added IArrayBuffer.InvokeWithDirectAccess and IArrayBufferView.InvokeWithDirectAccess (GitHub Issue #349); added disposal of enumerators created for JavaScript iteration (GitHub Issue #348); fixed dynamic module import from host-invoked functions (GitHub Issue #339); updated API documentation. Tested with V8 9.8.177.9.
  • Loading branch information
ClearScriptLib committed Feb 6, 2022
1 parent b1fb84b commit c00be79
Show file tree
Hide file tree
Showing 683 changed files with 2,318 additions and 1,138 deletions.
2 changes: 1 addition & 1 deletion ClearScript.sln
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClearScriptTest.NetStandard", "NetStandard\ClearScriptTest.NetStandard\ClearScriptTest.NetStandard.csproj", "{BF28C9F2-2935-4FDE-B812-977D601F9208}"
ProjectSection(ProjectDependencies) = postProject
{EDC7144E-FDA9-4CC7-B2CD-B5EBFD610A7D} = {EDC7144E-FDA9-4CC7-B2CD-B5EBFD610A7D}
{497012BC-959C-43A0-90A6-156A35DF2F43} = {497012BC-959C-43A0-90A6-156A35DF2F43}
{C0E7BCAD-B4B3-4291-A87A-384D5F99C413} = {C0E7BCAD-B4B3-4291-A87A-384D5F99C413}
{6F6B59D0-6538-4D02-91D2-07D24DAFE39A} = {6F6B59D0-6538-4D02-91D2-07D24DAFE39A}
EndProjectSection
EndProject
Expand Down
1 change: 1 addition & 0 deletions ClearScript.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=E_00F3in/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=FILEEXISTS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fine/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=foobarbaz/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=FUNCDESC/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=FUNCFLAGS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=guids/@EntryIndexedValue">True</s:Boolean>
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.2.1"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,2,1
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.2.1"
#define CLEARSCRIPT_VERSION_STRING "7.2.2"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,2,2
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.2.2"
#define CLEARSCRIPT_FILE_FLAGS 0L
18 changes: 14 additions & 4 deletions ClearScript/HostItem.NetFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT license.

using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.ClearScript.Util;

namespace Microsoft.ClearScript
{
Expand All @@ -21,15 +23,23 @@ private static HostItem Create(ScriptEngine engine, HostTarget target, HostItemF

#region member invocation

// ReSharper disable once UnusedParameter.Local
private static object CreateAsyncEnumerator<T>(IEnumerable<T> enumerable)
private object CreateAsyncEnumerator<T>(IEnumerable<T> enumerable)
{
throw new PlatformNotSupportedException("Async enumerators are not supported on this platform");
return HostObject.Wrap(enumerable.GetEnumerator().ToAsyncEnumerator(Engine), typeof(IAsyncEnumeratorPromise<T>));
}

private object CreateAsyncEnumerator()
{
throw new PlatformNotSupportedException("Async enumerators are not supported on this platform");
if (BindSpecialTarget(out IEnumerable _))
{
var enumerableHelpersHostItem = Wrap(Engine, EnumerableHelpers.HostType, HostItemFlags.PrivateAccess);
if (MiscHelpers.Try(out var enumerator, () => ((IDynamic)enumerableHelpersHostItem).InvokeMethod("GetAsyncEnumerator", this, Engine)))
{
return enumerator;
}
}

throw new NotSupportedException("The object is not async-enumerable");
}

#endregion
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions ClearScript/HostObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
using Microsoft.ClearScript.Util;
Expand Down Expand Up @@ -33,8 +32,8 @@ private HostObject(object target, Type type)
{
if (target is IEnumVARIANT enumVariant)
{
target = new EnumeratorWrapper(enumVariant);
type = typeof(IEnumerator);
target = new DisposableEnumeratorOnEnumVariant(enumVariant);
type = typeof(IDisposableEnumerator);
}
}

Expand Down
26 changes: 26 additions & 0 deletions ClearScript/JavaScript/IArrayBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;

namespace Microsoft.ClearScript.JavaScript
{
/// <summary>
Expand Down Expand Up @@ -39,5 +41,29 @@ public interface IArrayBuffer
/// <param name="offset">The offset within the <c>ArrayBuffer</c> at which to store the first copied byte.</param>
/// <returns>The number of bytes copied.</returns>
ulong WriteBytes(byte[] source, ulong sourceIndex, ulong count, ulong offset);

/// <summary>
/// Invokes a delegate that returns no value, giving it direct access to the <c>ArrayBuffer</c>'s contents.
/// </summary>
/// <param name="action">The delegate to invoke.</param>
/// <remarks>
/// This method invokes the specified delegate, passing in the memory address of the
/// <c>ArrayBuffer</c>'s contents. This memory address is valid only while the delegate is
/// executing. The delegate must not access memory outside the <c>ArrayBuffer</c>'s range.
/// </remarks>
void InvokeWithDirectAccess(Action<IntPtr> action);

/// <summary>
/// Invokes a delegate that returns a value, giving it direct access to the <c>ArrayBuffer</c>'s contents.
/// </summary>
/// <typeparam name="T">The delegate's return type.</typeparam>
/// <param name="func">The delegate to invoke.</param>
/// <returns>The delegate's return value.</returns>
/// <remarks>
/// This method invokes the specified delegate, passing in the memory address of the
/// <c>ArrayBuffer</c>'s contents. This memory address is valid only while the delegate is
/// executing. The delegate must not access memory outside the <c>ArrayBuffer</c>'s range.
/// </remarks>
T InvokeWithDirectAccess<T>(Func<IntPtr, T> func);
}
}
26 changes: 26 additions & 0 deletions ClearScript/JavaScript/IArrayBufferView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;

namespace Microsoft.ClearScript.JavaScript
{
/// <summary>
Expand Down Expand Up @@ -50,5 +52,29 @@ public interface IArrayBufferView
/// <param name="offset">The offset within the view at which to store the first copied byte.</param>
/// <returns>The number of bytes copied.</returns>
ulong WriteBytes(byte[] source, ulong sourceIndex, ulong count, ulong offset);

/// <summary>
/// Invokes a delegate that returns no value, giving it direct access to the view's contents.
/// </summary>
/// <param name="action">The delegate to invoke.</param>
/// <remarks>
/// This method invokes the specified delegate, passing in the memory address of the view's
/// contents. This memory address is valid only while the delegate is executing. The
/// delegate must not access memory outside the view's range.
/// </remarks>
void InvokeWithDirectAccess(Action<IntPtr> action);

/// <summary>
/// Invokes a delegate that returns a value, giving it direct access to the view's contents.
/// </summary>
/// <typeparam name="T">The delegate's return type.</typeparam>
/// <param name="func">The delegate to invoke.</param>
/// <returns>The delegate's return value.</returns>
/// <remarks>
/// This method invokes the specified delegate, passing in the memory address of the view's
/// contents. This memory address is valid only while the delegate is executing. The
/// delegate must not access memory outside the view's range.
/// </remarks>
T InvokeWithDirectAccess<T>(Func<IntPtr, T> func);
}
}
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.1")]
[assembly: AssemblyFileVersion("7.2.1")]
[assembly: AssemblyInformationalVersion("7.2.1")]
[assembly: AssemblyVersion("7.2.2")]
[assembly: AssemblyFileVersion("7.2.2")]
[assembly: AssemblyInformationalVersion("7.2.2")]

namespace Microsoft.ClearScript.Properties
{
internal static class ClearScriptVersion
{
public const string Triad = "7.2.1";
public const string Informational = "7.2.1";
public const string Triad = "7.2.2";
public const string Informational = "7.2.2";
}
}
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.1")]
[assembly: AssemblyFileVersion("7.2.1")]
[assembly: AssemblyInformationalVersion("7.2.1")]
[assembly: AssemblyVersion("7.2.2")]
[assembly: AssemblyFileVersion("7.2.2")]
[assembly: AssemblyInformationalVersion("7.2.2")]
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.1")]
[assembly: AssemblyFileVersion("7.2.1")]
[assembly: AssemblyInformationalVersion("7.2.1")]
[assembly: AssemblyVersion("7.2.2")]
[assembly: AssemblyFileVersion("7.2.2")]
[assembly: AssemblyInformationalVersion("7.2.2")]
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.1")]
[assembly: AssemblyFileVersion("7.2.1")]
[assembly: AssemblyInformationalVersion("7.2.1")]
[assembly: AssemblyVersion("7.2.2")]
[assembly: AssemblyFileVersion("7.2.2")]
[assembly: AssemblyInformationalVersion("7.2.2")]
File renamed without changes.
File renamed without changes.
132 changes: 132 additions & 0 deletions ClearScript/Util/EnumerableHelpers.NetFramework.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.ClearScript.JavaScript;

namespace Microsoft.ClearScript.Util
{
/// <exclude/>
public interface IAsyncEnumeratorPromise<out T>
{
/// <exclude/>
T Current { get; }

/// <exclude/>
Task<bool> MoveNextAsync();

/// <exclude/>
Task DisposeAsync();

/// <exclude/>
object MoveNextPromise();

/// <exclude/>
object DisposePromise();
}

internal static partial class EnumerableHelpers
{
public static IAsyncEnumeratorPromise<T> ToAsyncEnumerator<T>(this IEnumerator<T> enumerator, ScriptEngine engine)
{
return new AsyncEnumeratorPromiseOnEnumerator<T>(engine, enumerator);
}

public static IAsyncEnumeratorPromise<object> ToAsyncEnumerator(this IEnumerator enumerator, ScriptEngine engine)
{
return new AsyncEnumeratorPromiseOnEnumerator(engine, enumerator);
}

public static IAsyncEnumeratorPromise<T> GetAsyncEnumerator<T>(IEnumerable<T> source, ScriptEngine engine)
{
return source.GetEnumerator().ToAsyncEnumerator(engine);
}

public static IAsyncEnumeratorPromise<object> GetAsyncEnumerator(IEnumerable source, ScriptEngine engine)
{
return source.GetEnumerator().ToAsyncEnumerator(engine);
}
}

internal abstract class AsyncEnumeratorPromiseBase
{
protected static readonly Task CompletedTask = Task.FromResult(0);
}

internal abstract class AsyncEnumeratorPromise<T> : AsyncEnumeratorPromiseBase, IAsyncEnumeratorPromise<T>
{
private readonly ScriptEngine engine;

protected AsyncEnumeratorPromise(ScriptEngine engine)
{
this.engine = engine;
}

public abstract T Current { get; }

public abstract Task<bool> MoveNextAsync();

public abstract Task DisposeAsync();

public object MoveNextPromise()
{
return MoveNextAsync().ToPromise(engine);
}

public object DisposePromise()
{
return DisposeAsync().ToPromise(engine);
}
}

internal sealed class AsyncEnumeratorPromiseOnEnumerator<T> : AsyncEnumeratorPromise<T>
{
private readonly IEnumerator<T> enumerator;

public AsyncEnumeratorPromiseOnEnumerator(ScriptEngine engine, IEnumerator<T> enumerator)
: base(engine)
{
this.enumerator = enumerator;
}

public override T Current => enumerator.Current;

public override Task<bool> MoveNextAsync()
{
return Task.FromResult(enumerator.MoveNext());
}

public override Task DisposeAsync()
{
enumerator.Dispose();
return CompletedTask;
}
}

internal sealed class AsyncEnumeratorPromiseOnEnumerator : AsyncEnumeratorPromise<object>
{
private readonly IEnumerator enumerator;

public AsyncEnumeratorPromiseOnEnumerator(ScriptEngine engine, IEnumerator enumerator)
: base(engine)
{
this.enumerator = enumerator;
}

public override object Current => enumerator.Current;

public override Task<bool> MoveNextAsync()
{
return Task.FromResult(enumerator.MoveNext());
}

public override Task DisposeAsync()
{
(enumerator as IDisposable)?.Dispose();
return CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -13,6 +14,9 @@ public interface IAsyncEnumeratorPromise<out T> : IAsyncEnumerator<T>
{
/// <exclude/>
object MoveNextPromise();

/// <exclude/>
object DisposePromise();
}

internal static partial class EnumerableHelpers
Expand Down Expand Up @@ -56,15 +60,19 @@ protected AsyncEnumeratorPromise(ScriptEngine engine)

public abstract ValueTask<bool> MoveNextAsync();

public abstract ValueTask DisposeAsync();

public object MoveNextPromise()
{
return MoveNextAsync().ToPromise(engine);
}

public abstract ValueTask DisposeAsync();
public object DisposePromise()
{
return DisposeAsync().ToPromise(engine);
}
}


internal sealed class AsyncEnumeratorPromiseOnAsyncEnumerator<T> : AsyncEnumeratorPromise<T>
{
private readonly IAsyncEnumerator<T> enumerator;
Expand Down Expand Up @@ -131,6 +139,7 @@ public override ValueTask<bool> MoveNextAsync()

public override ValueTask DisposeAsync()
{
(enumerator as IDisposable)?.Dispose();
return default;
}
}
Expand Down
Loading

0 comments on commit c00be79

Please sign in to comment.