Skip to content

Commit cf64708

Browse files
Fixed delegate construction syntax for JavaScript, added tests, bumped version to 5.1.2.
1 parent b99c939 commit cf64708

File tree

14 files changed

+134
-19
lines changed

14 files changed

+134
-19
lines changed

ClearScript/HostItem.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ private object InvokeHostMember(string name, BindingFlags invokeFlags, object[]
645645
// ReSharper disable CoVariantArrayConversion
646646

647647
object result;
648-
if (hostType.TryInvoke(BindingFlags.InvokeMethod, typeArgs, bindArgs, out result))
648+
if (hostType.TryInvoke(BindingFlags.InvokeMethod, typeArgs, typeArgs, out result))
649649
{
650650
hostType = result as HostType;
651651
if (hostType != null)
@@ -660,7 +660,18 @@ private object InvokeHostMember(string name, BindingFlags invokeFlags, object[]
660660
// ReSharper restore CoVariantArrayConversion
661661
}
662662

663-
return hostType.GetSpecificType().CreateInstance(invokeFlags, args);
663+
var type = hostType.GetSpecificType();
664+
if (typeof(Delegate).IsAssignableFrom(type))
665+
{
666+
if (args.Length != 1)
667+
{
668+
throw new InvalidOperationException("Invalid constructor invocation");
669+
}
670+
671+
return DelegateFactory.CreateDelegate(engine, args[0], type);
672+
}
673+
674+
return type.CreateInstance(invokeFlags, args);
664675
}
665676
}
666677

@@ -1064,7 +1075,7 @@ object IReflect.InvokeMember(string name, BindingFlags invokeFlags, Binder binde
10641075
}
10651076

10661077
object[] bindArgs = null;
1067-
if (invokeFlags.HasFlag(BindingFlags.InvokeMethod))
1078+
if (invokeFlags.HasFlag(BindingFlags.InvokeMethod) || invokeFlags.HasFlag(BindingFlags.CreateInstance))
10681079
{
10691080
bindArgs = engine.MarshalToHost(wrappedArgs, true);
10701081
if (skipFirst)

ClearScript/Properties/AssemblyInfo.cs

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

7575
[assembly: ComVisible(false)]
76-
[assembly: AssemblyVersion("5.1.1.0")]
77-
[assembly: AssemblyFileVersion("5.1.1.0")]
76+
[assembly: AssemblyVersion("5.1.2.0")]
77+
[assembly: AssemblyFileVersion("5.1.2.0")]

ClearScript/ScriptEngine.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ public virtual string ExecuteCommand(string command)
501501
/// document with an automatically selected name. This document will be discarded after
502502
/// execution.
503503
/// </para>
504+
/// <para>
505+
/// For information about the types of result values that script code can return, see
506+
/// <see cref="Evaluate(string, bool, string)"/>.
507+
/// </para>
504508
/// </remarks>
505509
public object Evaluate(string code)
506510
{
@@ -521,6 +525,10 @@ public object Evaluate(string code)
521525
/// If a debugger is attached, it will present the specified script code to the user as a
522526
/// document with the specified name. This document will be discarded after execution.
523527
/// </para>
528+
/// <para>
529+
/// For information about the types of result values that script code can return, see
530+
/// <see cref="Evaluate(string, bool, string)"/>.
531+
/// </para>
524532
/// </remarks>
525533
public object Evaluate(string documentName, string code)
526534
{
@@ -543,6 +551,85 @@ public object Evaluate(string documentName, string code)
543551
/// document with the specified name. Discarding this document removes it from view but
544552
/// has no effect on the script engine.
545553
/// </para>
554+
/// <para>
555+
/// The following table summarizes the types of result values that script code can return.
556+
/// <list type="table">
557+
/// <listheader>
558+
/// <term>Type</term>
559+
/// <term>Returned&#xA0;As</term>
560+
/// <description>Remarks</description>
561+
/// </listheader>
562+
/// <item>
563+
/// <term><b>String</b></term>
564+
/// <term><see href="http://msdn.microsoft.com/en-us/library/system.string.aspx">System.String</see></term>
565+
/// <description>N/A</description>
566+
/// </item>
567+
/// <item>
568+
/// <term><b>Boolean</b></term>
569+
/// <term><see href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">System.Boolean</see></term>
570+
/// <description>N/A</description>
571+
/// </item>
572+
/// <item>
573+
/// <term><b>Number</b></term>
574+
/// <term><see href="http://msdn.microsoft.com/en-us/library/system.int32.aspx">System.Int32</see>&#xA0;or&#xA0;<see href="http://msdn.microsoft.com/en-us/library/system.double.aspx">System.Double</see></term>
575+
/// <description>
576+
/// Other numeric types are possible. The exact conversions between script and .NET
577+
/// numeric types are defined by the script engine.
578+
/// </description>
579+
/// </item>
580+
/// <item>
581+
/// <term><b>Null&#xA0;Reference</b></term>
582+
/// <term><c>null</c></term>
583+
/// <description>N/A</description>
584+
/// </item>
585+
/// <item>
586+
/// <term><b>Undefined</b></term>
587+
/// <term><see cref="Undefined"/></term>
588+
/// <description>
589+
/// This represents JavaScript’s
590+
/// <see href="http://msdn.microsoft.com/en-us/library/ie/dae3sbk5(v=vs.94).aspx">undefined</see>,
591+
/// VBScript’s
592+
/// <see href="http://msdn.microsoft.com/en-us/library/f8tbc79x(v=vs.85).aspx">Empty</see>,
593+
/// etc.
594+
/// </description>
595+
/// </item>
596+
/// <item>
597+
/// <term><b>Void</b></term>
598+
/// <term><see cref="VoidResult"/></term>
599+
/// <description>
600+
/// This is returned when script code forwards the result of a host method that returns no value.
601+
/// </description>
602+
/// </item>
603+
/// <item>
604+
/// <term><b>Host&#xA0;Object</b></term>
605+
/// <term>Native&#xA0;.NET&#xA0;type</term>
606+
/// <description>
607+
/// This includes all .NET types not mentioned above, including value types (enums,
608+
/// structs, etc.), and instances of all other classes. Script code can only create
609+
/// these objects by invoking a host method or constructor. They are returned to
610+
/// the host in their native .NET form.
611+
/// </description>
612+
/// </item>
613+
/// <item>
614+
/// <term><b>Script&#xA0;Object</b></term>
615+
/// <term><see href="http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject.aspx">System.Dynamic.DynamicObject</see></term>
616+
/// <description>
617+
/// This includes all native script objects that have no .NET representation. C#'s
618+
/// <see href="http://msdn.microsoft.com/en-us/library/dd264741.aspx">dynamic</see>
619+
/// keyword provides a convenient way to access them.
620+
/// </description>
621+
/// </item>
622+
/// <item>
623+
/// <term>Other</term>
624+
/// <term>Unspecified</term>
625+
/// <description>
626+
/// This includes host types and other ClearScript-specific objects intended for
627+
/// script code use only. It may also include language-specific values that the
628+
/// ClearScript library does not support.
629+
/// </description>
630+
/// </item>
631+
/// </list>
632+
/// </para>
546633
/// </remarks>
547634
public object Evaluate(string documentName, bool discard, string code)
548635
{

ClearScript/V8/V8/V8Patch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Index: tools/gyp/v8.gyp
22
===================================================================
3-
--- tools/gyp/v8.gyp (revision 13740)
3+
--- tools/gyp/v8.gyp (revision 13745)
44
+++ tools/gyp/v8.gyp (working copy)
55
@@ -32,6 +32,7 @@
66
'targets': [

ClearScript/VersionSymbols.h

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

6262

6363

64-
#define CLEARSCRIPT_VERSION_STRING "5.1.1.0"
65-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,1,1,0
64+
#define CLEARSCRIPT_VERSION_STRING "5.1.2.0"
65+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,1,2,0

ClearScript/VoidResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ namespace Microsoft.ClearScript
6767
/// <remarks>
6868
/// Some script languages expect every subroutine call to return a value. When script code
6969
/// written in such a language invokes a host method that explicitly returns no value (such as
70-
/// a C# void method), the ClearScript library provides an instance of this class as a dummy
71-
/// return value.
70+
/// a C# <see href="http://msdn.microsoft.com/en-us/library/yah0tteb.aspx">void</see> method),
71+
/// the ClearScript library provides an instance of this class as a dummy return value.
7272
/// </remarks>
7373
public class VoidResult
7474
{

ClearScript/doc/FAQtorial.docx

807 Bytes
Binary file not shown.

ClearScript/doc/FAQtorial.pdf

-7.04 KB
Binary file not shown.

ClearScript/doc/Reference.chm

1.53 KB
Binary file not shown.

ClearScriptBenchmarks/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@
6969
[assembly: AssemblyCopyright("© Microsoft Corporation")]
7070

7171
[assembly: ComVisible(false)]
72-
[assembly: AssemblyVersion("5.1.1.0")]
73-
[assembly: AssemblyFileVersion("5.1.1.0")]
72+
[assembly: AssemblyVersion("5.1.2.0")]
73+
[assembly: AssemblyFileVersion("5.1.2.0")]

0 commit comments

Comments
 (0)