| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 41036a3 commit a453fe9
35 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,7 @@ _ReSharper*/ | |||
| 30 | 30 | *.opendb | |
| 31 | 31 | *.opensdf | |
| 32 | 32 | *.shfbproj_* | |
| 33 | + *.VC.db | ||
| 33 | 34 | ClearScript/V8/V8/build/ | |
| 34 | 35 | ClearScript/V8/V8/lib/ | |
| 35 | 36 | ClearScript/V8/V8/include/ | |
| Original file line number | Diff line number | Diff 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 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,6 +60,7 @@ | |||
| 60 | 60 | <Reference Include="WindowsBase" /> | |
| 61 | 61 | </ItemGroup> | |
| 62 | 62 | <ItemGroup> | |
| 63 | + <Compile Include="CanonicalRefTable.cs" /> | ||
| 63 | 64 | <Compile Include="ContinuationCallback.cs" /> | |
| 64 | 65 | <Compile Include="HostItemCollateral.cs" /> | |
| 65 | 66 | <Compile Include="HostItemFlags.cs" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,5 +63,5 @@ | |||
| 63 | 63 | ||
| 64 | 64 | #pragma once | |
| 65 | 65 | ||
| 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,8 +60,6 @@ | |||
| 60 | 60 | // | |
| 61 | 61 | ||
| 62 | 62 | using System; | |
| 63 | - using System.Collections.Generic; | ||
| 64 | - using System.Linq; | ||
| 65 | 63 | using System.Reflection; | |
| 66 | 64 | using Microsoft.ClearScript.Util; | |
| 67 | 65 | ||
@@ -74,15 +72,14 @@ internal class HostObject : HostTarget | |||
| 74 | 72 | private readonly object target; | |
| 75 | 73 | private readonly Type type; | |
| 76 | 74 | private static readonly MethodInfo getNullWrapperGenericMethod = typeof(HostObject).GetMethod("GetNullWrapperGeneric", BindingFlags.NonPublic | BindingFlags.Static); | |
| 77 | - private static readonly CanonicalRefMap canonicalRefMap = new CanonicalRefMap(); | ||
| 78 | 75 | ||
| 79 | 76 | #endregion | |
| 80 | 77 | ||
| 81 | 78 | #region constructors | |
| 82 | 79 | ||
| 83 | 80 | private HostObject(object target, Type type) | |
| 84 | 81 | { | |
| 85 | - this.target = canonicalRefMap.GetCanonicalRef(target); | ||
| 82 | + this.target = CanonicalRefTable.GetCanonicalRef(target); | ||
| 86 | 83 | this.type = type ?? target.GetType(); | |
| 87 | 84 | } | |
| 88 | 85 | ||
@@ -206,70 +203,5 @@ public static HostObject Value | |||
| 206 | 203 | // ReSharper restore UnusedMember.Local | |
| 207 | 204 | ||
| 208 | 205 | #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 | ||
| 274 | 206 | } | |
| 275 | 207 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,6 +93,11 @@ public interface IScriptEngineException | |||
| 93 | 93 | /// </summary> | |
| 94 | 94 | bool IsFatal { get; } | |
| 95 | 95 | ||
| 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 | + | ||
| 96 | 101 | /// <summary> | |
| 97 | 102 | /// Gets the exception that caused the current exception to be thrown, or <c>null</c> if one was not specified. | |
| 98 | 103 | /// </summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,5 +75,5 @@ | |||
| 75 | 75 | [assembly: InternalsVisibleTo("ClearScriptTest")] | |
| 76 | 76 | ||
| 77 | 77 | [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")] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1395,10 +1395,10 @@ internal static void ThrowScriptError(IScriptEngineException scriptError) | |||
| 1395 | 1395 | { | |
| 1396 | 1396 | if (scriptError is ScriptInterruptedException) | |
| 1397 | 1397 | { | |
| 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); | ||
| 1399 | 1399 | } | |
| 1400 | 1400 | ||
| 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); | ||
| 1402 | 1402 | } | |
| 1403 | 1403 | } | |
| 1404 | 1404 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments