Skip to content

Commit 26ec250

Browse files
Version 5.4.7: Added ImmutableValueAttribute and fixed canonical reference support; fixed nested V8 syntax error reporting; added tests for bug fixes and new APIs. Tested with V8 5.3.332.45.
1 parent df2b725 commit 26ec250

21 files changed

Lines changed: 397 additions & 161 deletions

ClearScript/CanonicalRefTable.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ private static ICanonicalRefMap GetMap(object obj)
9393
ICanonicalRefMap map;
9494
if (!table.TryGetValue(type, out map))
9595
{
96-
if (type.IsEnum || typeof(IEquatable<>).MakeGenericType(type).IsAssignableFrom(type))
96+
if (type.IsEnum ||
97+
type.IsNumeric() ||
98+
type == typeof(DateTime) ||
99+
type == typeof(DateTimeOffset) ||
100+
type == typeof(TimeSpan) ||
101+
type.GetCustomAttributes(typeof(ImmutableValueAttribute), false).Any())
97102
{
98103
map = (ICanonicalRefMap)typeof(CanonicalRefMap<>).MakeGenericType(type).CreateInstance();
99104
}

ClearScript/ClearScript.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<ItemGroup>
6363
<Compile Include="CanonicalRefTable.cs" />
6464
<Compile Include="ContinuationCallback.cs" />
65+
<Compile Include="ImmutableValueAttribute.cs" />
6566
<Compile Include="HostItemCollateral.cs" />
6667
<Compile Include="HostItemFlags.cs" />
6768
<Compile Include="HostTargetMemberData.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.6.0"
67-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,4,6,0
66+
#define CLEARSCRIPT_VERSION_STRING "5.4.7.0"
67+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,4,7,0
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
64+
namespace Microsoft.ClearScript
65+
{
66+
/// <summary>
67+
/// Specifies that instances of the target struct are immutable.
68+
/// </summary>
69+
/// <remarks>
70+
/// When this attribute is applied to a struct, ClearScript exposes the same object reference
71+
/// for all instances of the struct that satisfy equality comparison, giving script code the
72+
/// ability to use native equality operators to compare the exposed objects. This behavior is
73+
/// also enabled automatically for all enums, numeric types, <see cref="DateTime"/>,
74+
/// <see cref="DateTimeOffset"/>, and <see cref="TimeSpan"/>.
75+
/// </remarks>
76+
[AttributeUsage(AttributeTargets.Struct)]
77+
public sealed class ImmutableValueAttribute : Attribute
78+
{
79+
// ReSharper disable EmptyConstructor
80+
81+
/// <summary>
82+
/// Initializes a new <see cref="ImmutableValueAttribute"/> instance.
83+
/// </summary>
84+
public ImmutableValueAttribute()
85+
{
86+
// the help file builder (SHFB) insists on an empty constructor here
87+
}
88+
89+
// ReSharper restore EmptyConstructor
90+
}
91+
}

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.6.0")]
79-
[assembly: AssemblyFileVersion("5.4.6.0")]
78+
[assembly: AssemblyVersion("5.4.7.0")]
79+
[assembly: AssemblyFileVersion("5.4.7.0")]

ClearScript/V8/ClearScriptV8/HighResolutionClock.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ double HighResolutionClock::GetRelativeSeconds()
8686

8787
return wholeSeconds + (static_cast<double>(remainingTicks) / s_TicksPerSecond.QuadPart);
8888
}
89+
90+
//-----------------------------------------------------------------------------
91+
92+
size_t HighResolutionClock::GetHardwareConcurrency()
93+
{
94+
SYSTEM_INFO info;
95+
::GetNativeSystemInfo(&info);
96+
return info.dwNumberOfProcessors;
97+
}

ClearScript/V8/ClearScriptV8/HighResolutionClock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ class HighResolutionClock
7272
public:
7373

7474
static double GetRelativeSeconds();
75+
static size_t GetHardwareConcurrency();
7576
};

0 commit comments

Comments
 (0)