Skip to content

Commit bfd0644

Browse files
Version 5.4.2: Updated ClearScriptBenchmarks to use SunSpider 1.0.2; host methods and delegates in V8ScriptEngine now support toFunction(), which creates a native JavaScript function wrapper; fixed syntax error reporting in nested WindowsScriptEngine invocations; added defensive code to tolerate IProcessDebugManager::AddApplication() failure (Issue ClearFoundry#76); added ScriptEngine.AddHostType() overloads that derive the script item name from the type name; implemented host item data sharing and other optimizations, boosting memory efficiency in many scenarios; added default ScriptAccess settings at the type, assembly, and engine levels; enhanced support for default properties, fixing Issue ClearFoundry#74; added IHostWindow and WindowsScriptEngine.HostWindow (Issue ClearFoundry#73); V8RuntimeConstraints limits <= 1048576 are now interpreted as MiB; fixed V8 debug agent in ASP.NET and eliminated excessive thread usage (Issue ClearFoundry#75); added ScriptMemberFlags.WrapNullResult, ScriptEngine.EnableNullResultWrapping, and HostFunctions.isNull() (Issue ClearFoundry#72); added enforcement of restricted access to non-public accessors of public properties (Issue ClearFoundry#71); added tests for bug fixes and new APIs. Tested with V8 4.2.77.18.
1 parent dc5de12 commit bfd0644

File tree

85 files changed

+4167
-1214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4167
-1214
lines changed

ClearScript/ByRefArg.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ protected ByRefArg(HostVariable<T> target)
9191
public T Value
9292
{
9393
get { return target.Value; }
94-
9594
set { target.Value = value; }
9695
}
9796

@@ -122,24 +121,24 @@ public override HostTargetFlags Flags
122121
get { return target.Flags; }
123122
}
124123

125-
public override string[] GetAuxMethodNames(BindingFlags bindFlags)
124+
public override string[] GetAuxMethodNames(IHostInvokeContext context, BindingFlags bindFlags)
126125
{
127-
return target.GetAuxMethodNames(bindFlags);
126+
return target.GetAuxMethodNames(context, bindFlags);
128127
}
129128

130-
public override string[] GetAuxPropertyNames(BindingFlags bindFlags)
129+
public override string[] GetAuxPropertyNames(IHostInvokeContext context, BindingFlags bindFlags)
131130
{
132-
return target.GetAuxPropertyNames(bindFlags);
131+
return target.GetAuxPropertyNames(context, bindFlags);
133132
}
134133

135-
public override bool TryInvokeAuxMember(ScriptEngine engine, string name, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
134+
public override bool TryInvokeAuxMember(IHostInvokeContext context, string name, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
136135
{
137-
return target.TryInvokeAuxMember(engine, name, invokeFlags, args, bindArgs, out result);
136+
return target.TryInvokeAuxMember(context, name, invokeFlags, args, bindArgs, out result);
138137
}
139138

140-
public override bool TryInvoke(ScriptEngine engine, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
139+
public override bool TryInvoke(IHostInvokeContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
141140
{
142-
return target.TryInvoke(engine, invokeFlags, args, bindArgs, out result);
141+
return target.TryInvoke(context, invokeFlags, args, bindArgs, out result);
143142
}
144143

145144
#endregion
@@ -149,7 +148,6 @@ public override bool TryInvoke(ScriptEngine engine, BindingFlags invokeFlags, ob
149148
object IByRefArg.Value
150149
{
151150
get { return target.Value; }
152-
153151
set { ((IHostVariable)target).Value = value; }
154152
}
155153

ClearScript/ClearScript.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@
6161
</ItemGroup>
6262
<ItemGroup>
6363
<Compile Include="ContinuationCallback.cs" />
64+
<Compile Include="HostItemCollateral.cs" />
6465
<Compile Include="HostItemFlags.cs" />
66+
<Compile Include="HostTargetMemberData.cs" />
6567
<Compile Include="HostTargetFlags.cs" />
6668
<Compile Include="IScriptableObject.cs" />
6769
<Compile Include="BindSignature.cs" />
6870
<Compile Include="IScriptEngineException.cs" />
71+
<Compile Include="DefaultScriptUsageAttribute.cs" />
72+
<Compile Include="NoDefaultScriptAccessAttribute.cs" />
6973
<Compile Include="NoScriptAccessAttribute.cs" />
7074
<Compile Include="Properties\AssemblyInfo.cs">
7175
<AutoGen>True</AutoGen>
@@ -79,9 +83,11 @@
7983
<Compile Include="ScriptMethod.cs" />
8084
<Compile Include="ScriptMemberAttribute.cs" />
8185
<Compile Include="ScriptUsageAttribute.cs" />
86+
<Compile Include="Util\Collateral.cs" />
8287
<Compile Include="Util\COMDispatchHelpers.cs" />
8388
<Compile Include="Util\CoTaskMemBlock.cs" />
8489
<Compile Include="Util\DisposedFlag.cs" />
90+
<Compile Include="Util\IHostInvokeContext.cs" />
8591
<Compile Include="Util\NativeMethods.cs" />
8692
<Compile Include="Util\COMDispatch.cs" />
8793
<Compile Include="Util\IScriptMarshalWrapper.cs" />
@@ -98,6 +104,7 @@
98104
<Compile Include="V8\V8RuntimeConstraints.cs" />
99105
<Compile Include="V8\V8Runtime.cs" />
100106
<Compile Include="V8\V8RuntimeFlags.cs" />
107+
<Compile Include="Windows\IHostWindow.cs" />
101108
<Compile Include="Windows\WindowsScriptEngineFlags.cs" />
102109
<Compile Include="Util\IDynamic.cs" />
103110
<Compile Include="Util\SpecialMemberNames.cs" />
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 defaults for how type members are to be exposed to script code.
68+
/// </summary>
69+
/// <remarks>
70+
/// This attribute is applicable to classes, enums, interfaces, structs, and assemblies. Use
71+
/// <see cref="ScriptUsageAttribute"/>, <see cref="ScriptMemberAttribute"/>, or
72+
/// <see cref="NoScriptAccessAttribute"/> to override it for individual type members.
73+
/// </remarks>
74+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Assembly)]
75+
public class DefaultScriptUsageAttribute : Attribute
76+
{
77+
private readonly ScriptAccess access;
78+
79+
/// <summary>
80+
/// Initializes a new <see cref="DefaultScriptUsageAttribute"/> instance.
81+
/// </summary>
82+
public DefaultScriptUsageAttribute()
83+
{
84+
}
85+
86+
/// <summary>
87+
/// Initializes a new <see cref="DefaultScriptUsageAttribute"/> instance with the specified default script access setting.
88+
/// </summary>
89+
/// <param name="access">The default script access setting for type members.</param>
90+
public DefaultScriptUsageAttribute(ScriptAccess access)
91+
{
92+
this.access = access;
93+
}
94+
95+
/// <summary>
96+
/// Gets the default script access setting for type members.
97+
/// </summary>
98+
public ScriptAccess Access { get { return access; } }
99+
}
100+
}

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.1.0"
67-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,4,1,0
66+
#define CLEARSCRIPT_VERSION_STRING "5.4.2.0"
67+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,4,2,0

ClearScript/ExtensionMethods.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,23 @@ public ExtensionMethodSummary Summary
7979
get { return summary; }
8080
}
8181

82-
public bool ProcessType(Type type)
82+
public bool ProcessType(Type type, ScriptAccess defaultAccess)
8383
{
8484
Debug.Assert(type.IsSpecific());
8585
if (!table.ContainsKey(type) && type.HasExtensionMethods())
8686
{
8787
const BindingFlags bindFlags = BindingFlags.Public | BindingFlags.Static;
88-
table[type] = type.GetMethods(bindFlags).Where(IsScriptableExtensionMethod).ToArray();
88+
table[type] = type.GetMethods(bindFlags).Where(method => IsScriptableExtensionMethod(method, defaultAccess)).ToArray();
8989
summary = new ExtensionMethodSummary(table);
9090
return true;
9191
}
9292

9393
return false;
9494
}
9595

96-
private static bool IsScriptableExtensionMethod(MethodInfo method)
96+
private static bool IsScriptableExtensionMethod(MethodInfo method, ScriptAccess defaultAccess)
9797
{
98-
return method.IsScriptable() && method.IsDefined(typeof(ExtensionAttribute), false);
98+
return method.IsScriptable(defaultAccess) && method.IsDefined(typeof(ExtensionAttribute), false);
9999
}
100100
}
101101

ClearScript/HostFunctions.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public object newObj(IDynamicMetaObjectProvider target, params object[] args)
197197
MiscHelpers.VerifyNonNullArgument(target, "target");
198198

199199
object result;
200-
if (target.GetMetaObject(Expression.Constant(target)).TryCreateInstance(GetEngine(), args, out result))
200+
if (target.GetMetaObject(Expression.Constant(target)).TryCreateInstance(args, out result))
201201
{
202202
return result;
203203
}
@@ -642,6 +642,24 @@ public bool isTypeObj<T>()
642642

643643
// ReSharper restore UnusedTypeParameter
644644

645+
/// <summary>
646+
/// Determines whether the specified value is <c>null</c>.
647+
/// </summary>
648+
/// <param name="value">The value to test.</param>
649+
/// <returns><c>True</c> if <paramref name="value"/> is <c>null</c>, <c>false</c> otherwise.</returns>
650+
/// <remarks>
651+
/// Use this function to test field, property, and method return values when <c>null</c>
652+
/// result wrapping is in effect (see
653+
/// <see cref="ScriptMemberFlags.WrapNullResult"/> and
654+
/// <see cref="ScriptEngine.EnableNullResultWrapping"/>).
655+
/// </remarks>
656+
/// <seealso cref="ScriptMemberFlags.WrapNullResult"/>
657+
/// <seealso cref="ScriptEngine.EnableNullResultWrapping"/>
658+
public bool isNull(object value)
659+
{
660+
return value == null;
661+
}
662+
645663
/// <summary>
646664
/// Creates a strongly typed flag set.
647665
/// </summary>

ClearScript/HostIndexedProperty.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,24 @@ public override HostTargetFlags Flags
114114
get { return HostTargetFlags.None; }
115115
}
116116

117-
public override string[] GetAuxMethodNames(BindingFlags bindFlags)
117+
public override string[] GetAuxMethodNames(IHostInvokeContext context, BindingFlags bindFlags)
118118
{
119119
return auxMethodNames;
120120
}
121121

122-
public override bool TryInvokeAuxMember(ScriptEngine engine, string memberName, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
122+
public override bool TryInvokeAuxMember(IHostInvokeContext context, string memberName, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
123123
{
124124
if (invokeFlags.HasFlag(BindingFlags.InvokeMethod))
125125
{
126126
if (memberName == "get")
127127
{
128-
result = target.InvokeMember(name, BindingFlags.GetProperty, args, bindArgs, null);
128+
result = target.InvokeMember(name, BindingFlags.GetProperty, args, bindArgs, null, true);
129129
return true;
130130
}
131131

132132
if (memberName == "set")
133133
{
134-
result = target.InvokeMember(name, BindingFlags.SetProperty, args, bindArgs, null);
134+
result = target.InvokeMember(name, BindingFlags.SetProperty, args, bindArgs, null, true);
135135
return true;
136136
}
137137
}
@@ -140,9 +140,9 @@ public override bool TryInvokeAuxMember(ScriptEngine engine, string memberName,
140140
return false;
141141
}
142142

143-
public override bool TryInvoke(ScriptEngine engine, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
143+
public override bool TryInvoke(IHostInvokeContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
144144
{
145-
result = target.InvokeMember(name, invokeFlags.HasFlag(BindingFlags.SetField) ? BindingFlags.SetProperty : BindingFlags.GetProperty, args, bindArgs, null);
145+
result = target.InvokeMember(name, invokeFlags.HasFlag(BindingFlags.SetField) ? BindingFlags.SetProperty : BindingFlags.GetProperty, args, bindArgs, null, true);
146146
return true;
147147
}
148148

0 commit comments

Comments
 (0)