FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Version 5.4.6: Expanded canonical reference support to all equatable … · 123LHP/ClearScript@a453fe9 · GitHub

Commit a453fe9

Browse files
Version 5.4.6: Expanded canonical reference support to all equatable value types; fixed a bug preventing assembly-qualified type names from being used with ScriptEngine.AddHostType(); fixed double execution of exception-throwing code via C# dynamic (Issue ClearFoundry#105); added IScriptEngineException.ExecutionStarted; fixed cross-engine double execution of exception-throwing code (Issue ClearFoundry#108); tweaked V8 debug protocol implementation to support non-Eclipse debuggers; added tests for bug fixes and new APIs. Tested with V8 5.1.281.50.
1 parent 41036a3 commit a453fe9

35 files changed

Lines changed: 654 additions & 167 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ _ReSharper*/
3030
*.opendb
3131
*.opensdf
3232
*.shfbproj_*
33+
*.VC.db
3334
ClearScript/V8/V8/build/
3435
ClearScript/V8/V8/lib/
3536
ClearScript/V8/V8/include/

‎ClearScript/CanonicalRefTable.cs‎

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
//
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
//
4+
// Microsoft Public License (MS-PL)
5+
//
6+
// This license governs use of the accompanying software. If you use the
7+
// software, you accept this license. If you do not accept the license, do not
8+
// use the software.
9+
//
10+
// 1. Definitions
11+
//
12+
// The terms "reproduce," "reproduction," "derivative works," and
13+
// "distribution" have the same meaning here as under U.S. copyright law. A
14+
// "contribution" is the original software, or any additions or changes to
15+
// the software. A "contributor" is any person that distributes its
16+
// contribution under this license. "Licensed patents" are a contributor's
17+
// patent claims that read directly on its contribution.
18+
//
19+
// 2. Grant of Rights
20+
//
21+
// (A) Copyright Grant- Subject to the terms of this license, including the
22+
// license conditions and limitations in section 3, each contributor
23+
// grants you a non-exclusive, worldwide, royalty-free copyright license
24+
// to reproduce its contribution, prepare derivative works of its
25+
// contribution, and distribute its contribution or any derivative works
26+
// that you create.
27+
//
28+
// (B) Patent Grant- Subject to the terms of this license, including the
29+
// license conditions and limitations in section 3, each contributor
30+
// grants you a non-exclusive, worldwide, royalty-free license under its
31+
// licensed patents to make, have made, use, sell, offer for sale,
32+
// import, and/or otherwise dispose of its contribution in the software
33+
// or derivative works of the contribution in the software.
34+
//
35+
// 3. Conditions and Limitations
36+
//
37+
// (A) No Trademark License- This license does not grant you rights to use
38+
// any contributors' name, logo, or trademarks.
39+
//
40+
// (B) If you bring a patent claim against any contributor over patents that
41+
// you claim are infringed by the software, your patent license from such
42+
// contributor to the software ends automatically.
43+
//
44+
// (C) If you distribute any portion of the software, you must retain all
45+
// copyright, patent, trademark, and attribution notices that are present
46+
// in the software.
47+
//
48+
// (D) If you distribute any portion of the software in source code form, you
49+
// may do so only under this license by including a complete copy of this
50+
// license with your distribution. If you distribute any portion of the
51+
// software in compiled or object code form, you may only do so under a
52+
// license that complies with this license.
53+
//
54+
// (E) The software is licensed "as-is." You bear the risk of using it. The
55+
// contributors give no express warranties, guarantees or conditions. You
56+
// may have additional consumer rights under your local laws which this
57+
// license cannot change. To the extent permitted under your local laws,
58+
// the contributors exclude the implied warranties of merchantability,
59+
// fitness for a particular purpose and non-infringement.
60+
//
61+
62+
using System;
63+
using System.Collections.Generic;
64+
using System.Linq;
65+
using Microsoft.ClearScript.Util;
66+
67+
namespace Microsoft.ClearScript
68+
{
69+
internal static class CanonicalRefTable
70+
{
71+
private static readonly object tableLock = new object();
72+
private static readonly Dictionary<Type, ICanonicalRefMap> table = new Dictionary<Type, ICanonicalRefMap>();
73+
74+
public static object GetCanonicalRef(object obj)
75+
{
76+
if (obj is ValueType)
77+
{
78+
var map = GetMap(obj);
79+
if (map != null)
80+
{
81+
obj = map.GetRef(obj);
82+
}
83+
}
84+
85+
return obj;
86+
}
87+
88+
private static ICanonicalRefMap GetMap(object obj)
89+
{
90+
var type = obj.GetType();
91+
lock (tableLock)
92+
{
93+
ICanonicalRefMap map;
94+
if (!table.TryGetValue(type, out map))
95+
{
96+
if (type.IsEnum || typeof(IEquatable<>).MakeGenericType(type).IsAssignableFrom(type))
97+
{
98+
map = (ICanonicalRefMap)typeof(CanonicalRefMap<>).MakeGenericType(type).CreateInstance();
99+
}
100+
101+
table.Add(type, map);
102+
}
103+
104+
return map;
105+
}
106+
}
107+
108+
#region Nested type: ICanonicalRefMap
109+
110+
private interface ICanonicalRefMap
111+
{
112+
object GetRef(object obj);
113+
}
114+
115+
#endregion
116+
117+
#region Nested type: CanonicalRefMapBase
118+
119+
private abstract class CanonicalRefMapBase : ICanonicalRefMap
120+
{
121+
protected const int CompactionThreshold = 256 * 1024;
122+
protected static readonly TimeSpan CompactionInterval = TimeSpan.FromMinutes(2);
123+
124+
#region ICanonicalRefMap implementation (abstract)
125+
126+
public abstract object GetRef(object obj);
127+
128+
#endregion
129+
}
130+
131+
#endregion
132+
133+
#region Nested type: CanonicalRefMap<T>
134+
135+
private class CanonicalRefMap<T> : CanonicalRefMapBase
136+
{
137+
private readonly object mapLock = new object();
138+
private readonly Dictionary<T, WeakReference> map = new Dictionary<T, WeakReference>();
139+
private DateTime lastCompactionTime = DateTime.MinValue;
140+
141+
private object GetRefInternal(object obj)
142+
{
143+
var value = (T)obj;
144+
object result;
145+
146+
WeakReference weakRef;
147+
if (map.TryGetValue(value, out weakRef))
148+
{
149+
result = weakRef.Target;
150+
if (result == null)
151+
{
152+
result = obj;
153+
weakRef.Target = result;
154+
}
155+
}
156+
else
157+
{
158+
result = obj;
159+
map.Add(value, new WeakReference(result));
160+
}
161+
162+
return result;
163+
}
164+
165+
private void CompactIfNecessary()
166+
{
167+
if (map.Count >= CompactionThreshold)
168+
{
169+
var now = DateTime.UtcNow;
170+
if ((lastCompactionTime + CompactionInterval) <= now)
171+
{
172+
map.Where(pair => !pair.Value.IsAlive).ToList().ForEach(pair => map.Remove(pair.Key));
173+
lastCompactionTime = now;
174+
}
175+
}
176+
}
177+
178+
#region CanonicalRefMapBase overrides
179+
180+
public override object GetRef(object obj)
181+
{
182+
lock (mapLock)
183+
{
184+
var result = GetRefInternal(obj);
185+
CompactIfNecessary();
186+
return result;
187+
}
188+
}
189+
190+
#endregion
191+
}
192+
193+
#endregion
194+
}
195+
}

‎ClearScript/ClearScript.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Reference Include="WindowsBase" />
6161
</ItemGroup>
6262
<ItemGroup>
63+
<Compile Include="CanonicalRefTable.cs" />
6364
<Compile Include="ContinuationCallback.cs" />
6465
<Compile Include="HostItemCollateral.cs" />
6566
<Compile Include="HostItemFlags.cs" />

‎ClearScript/Exports/VersionSymbols.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@
6363

6464
#pragma once
6565

66-
#define CLEARSCRIPT_VERSION_STRING "5.4.5.0"
67-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,4,5,0
66+
#define CLEARSCRIPT_VERSION_STRING "5.4.6.0"
67+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,4,6,0

‎ClearScript/HostObject.cs‎

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
//
6161

6262
using System;
63-
using System.Collections.Generic;
64-
using System.Linq;
6563
using System.Reflection;
6664
using Microsoft.ClearScript.Util;
6765

@@ -74,15 +72,14 @@ internal class HostObject : HostTarget
7472
private readonly object target;
7573
private readonly Type type;
7674
private static readonly MethodInfo getNullWrapperGenericMethod = typeof(HostObject).GetMethod("GetNullWrapperGeneric", BindingFlags.NonPublic | BindingFlags.Static);
77-
private static readonly CanonicalRefMap canonicalRefMap = new CanonicalRefMap();
7875

7976
#endregion
8077

8178
#region constructors
8279

8380
private HostObject(object target, Type type)
8481
{
85-
this.target = canonicalRefMap.GetCanonicalRef(target);
82+
this.target = CanonicalRefTable.GetCanonicalRef(target);
8683
this.type = type ?? target.GetType();
8784
}
8885

@@ -206,70 +203,5 @@ public static HostObject Value
206203
// ReSharper restore UnusedMember.Local
207204

208205
#endregion
209-
210-
#region Nested type: CanonicalRefMap
211-
212-
private class CanonicalRefMap
213-
{
214-
private readonly object dataLock = new object();
215-
private readonly Dictionary<object, WeakReference> map = new Dictionary<object, WeakReference>();
216-
private DateTime lastCompactionTime = DateTime.MinValue;
217-
218-
private const int compactionThreshold = 1024 * 1024;
219-
private static readonly TimeSpan compactionInterval = TimeSpan.FromMinutes(3);
220-
221-
public object GetCanonicalRef(object obj)
222-
{
223-
if (obj is Enum)
224-
{
225-
lock (dataLock)
226-
{
227-
var result = GetCanonicalRefInternal(obj);
228-
CompactIfNecessary();
229-
return result;
230-
}
231-
}
232-
233-
return obj;
234-
}
235-
236-
private object GetCanonicalRefInternal(object obj)
237-
{
238-
object result;
239-
240-
WeakReference weakRef;
241-
if (map.TryGetValue(obj, out weakRef))
242-
{
243-
result = weakRef.Target;
244-
if (result == null)
245-
{
246-
result = obj;
247-
weakRef.Target = result;
248-
}
249-
}
250-
else
251-
{
252-
result = obj;
253-
map.Add(obj, new WeakReference(result));
254-
}
255-
256-
return result;
257-
}
258-
259-
private void CompactIfNecessary()
260-
{
261-
if (map.Count >= compactionThreshold)
262-
{
263-
var now = DateTime.UtcNow;
264-
if ((lastCompactionTime + compactionInterval) <= now)
265-
{
266-
map.Where(pair => !pair.Value.IsAlive).ToList().ForEach(pair => map.Remove(pair.Key));
267-
lastCompactionTime = now;
268-
}
269-
}
270-
}
271-
}
272-
273-
#endregion
274206
}
275207
}

‎ClearScript/IScriptEngineException.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public interface IScriptEngineException
9393
/// </summary>
9494
bool IsFatal { get; }
9595

96+
/// <summary>
97+
/// Gets a value that indicates whether script code execution had started before the current exception was thrown.
98+
/// </summary>
99+
bool ExecutionStarted { get; }
100+
96101
/// <summary>
97102
/// Gets the exception that caused the current exception to be thrown, or <c>null</c> if one was not specified.
98103
/// </summary>

‎ClearScript/Properties/AssemblyInfo.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@
7575
[assembly: InternalsVisibleTo("ClearScriptTest")]
7676

7777
[assembly: ComVisible(false)]
78-
[assembly: AssemblyVersion("5.4.5.0")]
79-
[assembly: AssemblyFileVersion("5.4.5.0")]
78+
[assembly: AssemblyVersion("5.4.6.0")]
79+
[assembly: AssemblyFileVersion("5.4.6.0")]

‎ClearScript/ScriptEngine.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,10 @@ internal static void ThrowScriptError(IScriptEngineException scriptError)
13951395
{
13961396
if (scriptError is ScriptInterruptedException)
13971397
{
1398-
throw new ScriptInterruptedException(scriptError.EngineName, scriptError.Message, scriptError.ErrorDetails, scriptError.HResult, scriptError.IsFatal, scriptError.InnerException);
1398+
throw new ScriptInterruptedException(scriptError.EngineName, scriptError.Message, scriptError.ErrorDetails, scriptError.HResult, scriptError.IsFatal, scriptError.ExecutionStarted, scriptError.InnerException);
13991399
}
14001400

1401-
throw new ScriptEngineException(scriptError.EngineName, scriptError.Message, scriptError.ErrorDetails, scriptError.HResult, scriptError.IsFatal, scriptError.InnerException);
1401+
throw new ScriptEngineException(scriptError.EngineName, scriptError.Message, scriptError.ErrorDetails, scriptError.HResult, scriptError.IsFatal, scriptError.ExecutionStarted, scriptError.InnerException);
14021402
}
14031403
}
14041404

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL