Skip to content

Commit 6ce0ef7

Browse files
Fixed support for multiple application domains. Tested with V8 8.7.220.10.
1 parent b126818 commit 6ce0ef7

22 files changed

Lines changed: 105 additions & 57 deletions

ClearScript/Exports/VersionSymbols.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
#define CLEARSCRIPT_VERSION_STRING "7.0.0"
99
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,0,0
10-
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.0.0-rc3"
10+
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.0.0-rc4"
1111
#define CLEARSCRIPT_FILE_FLAGS VS_FF_PRERELEASE

ClearScript/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
[assembly: ComVisible(false)]
1818
[assembly: AssemblyVersion("7.0.0")]
1919
[assembly: AssemblyFileVersion("7.0.0")]
20-
[assembly: AssemblyInformationalVersion("7.0.0-rc3")]
20+
[assembly: AssemblyInformationalVersion("7.0.0-rc4")]
2121

2222
namespace Microsoft.ClearScript.Properties
2323
{
2424
internal static class ClearScriptVersion
2525
{
2626
public const string Triad = "7.0.0";
27-
public const string Informational = "7.0.0-rc3";
27+
public const string Informational = "7.0.0-rc4";
2828
}
2929
}

ClearScript/V8/SplitProxy/IV8SplitProxyNative.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal interface IV8SplitProxyNative
99
{
1010
#region initialization
1111

12-
void V8SplitProxyManaged_SetMethodTable(IntPtr pMethodTable);
12+
IntPtr V8SplitProxyManaged_SetMethodTable(IntPtr pMethodTable);
1313

1414
#endregion
1515

ClearScript/V8/SplitProxy/V8SplitProxyNative.Unix.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ private sealed class Impl : IV8SplitProxyNative
2020

2121
#region initialization
2222

23-
void IV8SplitProxyNative.V8SplitProxyManaged_SetMethodTable(IntPtr pMethodTable)
23+
IntPtr IV8SplitProxyNative.V8SplitProxyManaged_SetMethodTable(IntPtr pMethodTable)
2424
{
25-
V8SplitProxyManaged_SetMethodTable(pMethodTable);
25+
return V8SplitProxyManaged_SetMethodTable(pMethodTable);
2626
}
2727

2828
#endregion
@@ -964,7 +964,7 @@ void IV8SplitProxyNative.V8UnitTestSupport_GetStatistics(out ulong isolateCount,
964964
#region initialization
965965

966966
[DllImport("ClearScriptV8", CallingConvention = CallingConvention.Cdecl)]
967-
private static extern void V8SplitProxyManaged_SetMethodTable(
967+
private static extern IntPtr V8SplitProxyManaged_SetMethodTable(
968968
[In] IntPtr pMethodTable
969969
);
970970

ClearScript/V8/SplitProxy/V8SplitProxyNative.Windows.32.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ private sealed class Impl32 : IV8SplitProxyNative
1818

1919
#region initialization
2020

21-
void IV8SplitProxyNative.V8SplitProxyManaged_SetMethodTable(IntPtr pMethodTable)
21+
IntPtr IV8SplitProxyNative.V8SplitProxyManaged_SetMethodTable(IntPtr pMethodTable)
2222
{
23-
V8SplitProxyManaged_SetMethodTable(pMethodTable);
23+
return V8SplitProxyManaged_SetMethodTable(pMethodTable);
2424
}
2525

2626
#endregion
@@ -962,7 +962,7 @@ void IV8SplitProxyNative.V8UnitTestSupport_GetStatistics(out ulong isolateCount,
962962
#region initialization
963963

964964
[DllImport("ClearScriptV8-32", CallingConvention = CallingConvention.Cdecl)]
965-
private static extern void V8SplitProxyManaged_SetMethodTable(
965+
private static extern IntPtr V8SplitProxyManaged_SetMethodTable(
966966
[In] IntPtr pMethodTable
967967
);
968968

ClearScript/V8/SplitProxy/V8SplitProxyNative.Windows.64.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ private sealed class Impl64 : IV8SplitProxyNative
1818

1919
#region initialization
2020

21-
void IV8SplitProxyNative.V8SplitProxyManaged_SetMethodTable(IntPtr pMethodTable)
21+
IntPtr IV8SplitProxyNative.V8SplitProxyManaged_SetMethodTable(IntPtr pMethodTable)
2222
{
23-
V8SplitProxyManaged_SetMethodTable(pMethodTable);
23+
return V8SplitProxyManaged_SetMethodTable(pMethodTable);
2424
}
2525

2626
#endregion
@@ -962,7 +962,7 @@ void IV8SplitProxyNative.V8UnitTestSupport_GetStatistics(out ulong isolateCount,
962962
#region initialization
963963

964964
[DllImport("ClearScriptV8-64", CallingConvention = CallingConvention.Cdecl)]
965-
private static extern void V8SplitProxyManaged_SetMethodTable(
965+
private static extern IntPtr V8SplitProxyManaged_SetMethodTable(
966966
[In] IntPtr pMethodTable
967967
);
968968

ClearScript/V8/SplitProxy/V8SplitProxyNative.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ internal static partial class V8SplitProxyNative
1111
public static void Invoke(Action<IV8SplitProxyNative> action)
1212
{
1313
var previousScheduledException = MiscHelpers.Exchange(ref V8SplitProxyManaged.ScheduledException, null);
14+
var previousMethodTable = instance.V8SplitProxyManaged_SetMethodTable(V8SplitProxyManaged.MethodTable);
1415
try
1516
{
1617
action(instance);
1718
ThrowScheduledException();
1819
}
1920
finally
2021
{
22+
instance.V8SplitProxyManaged_SetMethodTable(previousMethodTable);
2123
V8SplitProxyManaged.ScheduledException = previousScheduledException;
2224
}
2325
}
2426

2527
public static T Invoke<T>(Func<IV8SplitProxyNative, T> func)
2628
{
2729
var previousScheduledException = MiscHelpers.Exchange(ref V8SplitProxyManaged.ScheduledException, null);
30+
var previousMethodTable = instance.V8SplitProxyManaged_SetMethodTable(V8SplitProxyManaged.MethodTable);
2831
try
2932
{
3033
var result = func(instance);
@@ -33,18 +36,35 @@ public static T Invoke<T>(Func<IV8SplitProxyNative, T> func)
3336
}
3437
finally
3538
{
39+
instance.V8SplitProxyManaged_SetMethodTable(previousMethodTable);
3640
V8SplitProxyManaged.ScheduledException = previousScheduledException;
3741
}
3842
}
3943

4044
public static void InvokeNoThrow(Action<IV8SplitProxyNative> action)
4145
{
42-
action(instance);
46+
var previousMethodTable = instance.V8SplitProxyManaged_SetMethodTable(V8SplitProxyManaged.MethodTable);
47+
try
48+
{
49+
action(instance);
50+
}
51+
finally
52+
{
53+
instance.V8SplitProxyManaged_SetMethodTable(previousMethodTable);
54+
}
4355
}
4456

4557
public static T InvokeNoThrow<T>(Func<IV8SplitProxyNative, T> func)
4658
{
47-
return func(instance);
59+
var previousMethodTable = instance.V8SplitProxyManaged_SetMethodTable(V8SplitProxyManaged.MethodTable);
60+
try
61+
{
62+
return func(instance);
63+
}
64+
finally
65+
{
66+
instance.V8SplitProxyManaged_SetMethodTable(previousMethodTable);
67+
}
4868
}
4969

5070
private static void ThrowScheduledException()

ClearScript/V8/V8Proxy.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Linq;
88
using System.Text;
99
using Microsoft.ClearScript.Util;
10-
using Microsoft.ClearScript.V8.SplitProxy;
1110

1211
namespace Microsoft.ClearScript.V8
1312
{
@@ -25,7 +24,6 @@ internal static bool OnEntityHolderCreated()
2524
if (hNativeAssembly == IntPtr.Zero)
2625
{
2726
hNativeAssembly = LoadNativeAssembly();
28-
V8SplitProxyNative.InvokeNoThrow(instance => instance.V8SplitProxyManaged_SetMethodTable(V8SplitProxyManaged.MethodTable));
2927
}
3028

3129
++splitImplCount;

ClearScriptBenchmarks/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
[assembly: ComVisible(false)]
1414
[assembly: AssemblyVersion("7.0.0")]
1515
[assembly: AssemblyFileVersion("7.0.0")]
16-
[assembly: AssemblyInformationalVersion("7.0.0-rc3")]
16+
[assembly: AssemblyInformationalVersion("7.0.0-rc4")]

ClearScriptConsole/ConsoleTest.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Reflection;
67
using System.Threading;
78
using Microsoft.ClearScript.V8;
89
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -11,6 +12,8 @@ namespace Microsoft.ClearScript.Test
1112
{
1213
internal static class ConsoleTest
1314
{
15+
#region test methods
16+
1417
public static unsafe void BugFix_V8StackLimitIntegerOverflow()
1518
{
1619
var threads = new List<Thread>();
@@ -72,5 +75,41 @@ public static unsafe void BugFix_V8StackLimitIntegerOverflow()
7275
threads.ForEach(thread => thread.Join());
7376
}
7477
}
78+
79+
public static void BugFix_MultipleAppDomains()
80+
{
81+
var domain1 = AppDomain.CreateDomain("domain1");
82+
var domain2 = AppDomain.CreateDomain("domain2");
83+
84+
var obj1 = (MultiAppDomainTest)domain1.CreateInstanceAndUnwrap(Assembly.GetEntryAssembly().FullName, typeof(MultiAppDomainTest).FullName);
85+
var obj2 = (MultiAppDomainTest)domain2.CreateInstanceAndUnwrap(Assembly.GetEntryAssembly().FullName, typeof(MultiAppDomainTest).FullName);
86+
87+
obj1.CreateEngine();
88+
obj2.CreateEngine();
89+
90+
obj1.DisposeEngine();
91+
obj2.DisposeEngine();
92+
}
93+
94+
#endregion
95+
96+
#region miscellaneous
97+
98+
public class MultiAppDomainTest : MarshalByRefObject
99+
{
100+
private ScriptEngine engine;
101+
102+
public void CreateEngine()
103+
{
104+
engine = new V8ScriptEngine();
105+
}
106+
107+
public void DisposeEngine()
108+
{
109+
engine.Dispose();
110+
}
111+
}
112+
113+
#endregion
75114
}
76115
}

0 commit comments

Comments
 (0)