ClearScript 5.2: Revamped error handling, host member type restriction, V8Update improvements, bug fixes, test fixes.
This commit is contained in:
Родитель
645a752dac
Коммит
6a0f089ce8
|
@ -14,6 +14,7 @@
|
|||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">NEXT_LINE</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_SIZEOF_PARENTHESES/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TYPEOF_PARENTHESES/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">NEXT_LINE</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_SIZEOF_PARENTHESES/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TYPEOF_PARENTHESES/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<Compile Include="HostTargetFlags.cs" />
|
||||
<Compile Include="IScriptableObject.cs" />
|
||||
<Compile Include="BindSignature.cs" />
|
||||
<Compile Include="IScriptEngineException.cs" />
|
||||
<Compile Include="NoScriptAccessAttribute.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
@ -67,6 +68,9 @@
|
|||
<DependentUpon>AssemblyInfo.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ScriptAccess.cs" />
|
||||
<Compile Include="ScriptEngineException.cs" />
|
||||
<Compile Include="ScriptInterruptedException.cs" />
|
||||
<Compile Include="ScriptMemberFlags.cs" />
|
||||
<Compile Include="ScriptMethod.cs" />
|
||||
<Compile Include="ScriptMemberAttribute.cs" />
|
||||
<Compile Include="ScriptUsageAttribute.cs" />
|
||||
|
|
|
@ -173,7 +173,7 @@ namespace Microsoft.ClearScript
|
|||
/// </code>
|
||||
/// </example>
|
||||
/// <seealso cref="ExtendedHostFunctions.type(string, object[])"/>
|
||||
public Array newArr<T>(params int[] lengths)
|
||||
public object newArr<T>(params int[] lengths)
|
||||
{
|
||||
return Array.CreateInstance(typeof(T), lengths);
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
if (result is MethodBindSuccess)
|
||||
{
|
||||
result = new MethodBindFailure(new MissingMemberException(MiscHelpers.FormatInvariant("Object has no method named '{0}' that matches the specified arguments", name)));
|
||||
result = new MethodBindFailure(() => new MissingMemberException(MiscHelpers.FormatInvariant("Object has no method named '{0}' that matches the specified arguments", name)));
|
||||
}
|
||||
|
||||
foreach (var altName in GetAltMethodNames(name))
|
||||
|
@ -254,13 +254,13 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
if ((method.IsStatic) && !hostTarget.Flags.HasFlag(HostTargetFlags.AllowStaticMembers))
|
||||
{
|
||||
return new MethodBindFailure(new InvalidOperationException(MiscHelpers.FormatInvariant("Cannot access static method '{0}' in non-static context", method.Name)));
|
||||
return new MethodBindFailure(() => new InvalidOperationException(MiscHelpers.FormatInvariant("Cannot access static method '{0}' in non-static context", method.Name)));
|
||||
}
|
||||
|
||||
return new MethodBindSuccess(hostTarget, method, args);
|
||||
}
|
||||
|
||||
return new MethodBindFailure((rawResult as Exception) ?? new NotSupportedException(MiscHelpers.FormatInvariant("Invocation of method '{0}' failed (unrecognized binding)", name)));
|
||||
return new MethodBindFailure((rawResult as Func<Exception>) ?? (() => new NotSupportedException(MiscHelpers.FormatInvariant("Invocation of method '{0}' failed (unrecognized binding)", name))));
|
||||
}
|
||||
|
||||
public abstract object RawResult { get; }
|
||||
|
@ -327,18 +327,18 @@ namespace Microsoft.ClearScript
|
|||
|
||||
private class MethodBindFailure : MethodBindResult
|
||||
{
|
||||
private readonly Exception exception;
|
||||
private readonly Func<Exception> exceptionFactory;
|
||||
|
||||
public MethodBindFailure(Exception exception)
|
||||
public MethodBindFailure(Func<Exception> exceptionFactory)
|
||||
{
|
||||
this.exception = exception;
|
||||
this.exceptionFactory = exceptionFactory;
|
||||
}
|
||||
|
||||
#region MethodBindResult overrides
|
||||
|
||||
public override object RawResult
|
||||
{
|
||||
get { return exception; }
|
||||
get { return exceptionFactory; }
|
||||
}
|
||||
|
||||
public override bool IsPreferredMethod(string name)
|
||||
|
@ -350,9 +350,10 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override object Invoke(ScriptEngine engine)
|
||||
{
|
||||
throw exception;
|
||||
throw exceptionFactory();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -377,7 +378,7 @@ namespace Microsoft.ClearScript
|
|||
if (results.Count != 1)
|
||||
{
|
||||
results.Clear();
|
||||
results.Add(new NotSupportedException(MiscHelpers.FormatInvariant("Invocation of method '{0}' failed (unrecognized binding)", name)));
|
||||
AddResult(() => new NotSupportedException(MiscHelpers.FormatInvariant("Invocation of method '{0}' failed (unrecognized binding)", name)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -398,7 +399,7 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
if (node.Method.Name == name)
|
||||
{
|
||||
results.Add(node.Method);
|
||||
AddResult(node.Method);
|
||||
}
|
||||
|
||||
return base.VisitMethodCall(node);
|
||||
|
@ -412,7 +413,7 @@ namespace Microsoft.ClearScript
|
|||
var del = DynamicHelpers.InvokeExpression(node.Expression) as Delegate;
|
||||
if (del == targetDelegate)
|
||||
{
|
||||
results.Add(del.GetType().GetMethod("Invoke"));
|
||||
AddResult(del.GetType().GetMethod("Invoke"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,12 +427,22 @@ namespace Microsoft.ClearScript
|
|||
var exception = DynamicHelpers.InvokeExpression(node.Operand) as Exception;
|
||||
if (exception != null)
|
||||
{
|
||||
results.Add(exception);
|
||||
AddResult(() => (Exception)DynamicHelpers.InvokeExpression(node.Operand));
|
||||
}
|
||||
}
|
||||
|
||||
return base.VisitUnary(node);
|
||||
}
|
||||
|
||||
private void AddResult(MethodInfo method)
|
||||
{
|
||||
results.Add(method);
|
||||
}
|
||||
|
||||
private void AddResult(Func<Exception> exceptionFactory)
|
||||
{
|
||||
results.Add(exceptionFactory);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -66,7 +66,6 @@ using System.Dynamic;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Expando;
|
||||
using Microsoft.ClearScript.Util;
|
||||
|
||||
|
@ -499,14 +498,11 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
return targetDynamic.Invoke(args, false);
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch (Exception)
|
||||
{
|
||||
if ((exception is NotSupportedException) || (exception is InvalidOperationException) || (exception is ExternalException))
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField) && (args.Length < 1))
|
||||
{
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField))
|
||||
{
|
||||
return targetDynamic;
|
||||
}
|
||||
return targetDynamic;
|
||||
}
|
||||
|
||||
throw;
|
||||
|
@ -517,14 +513,11 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
return targetDynamic.InvokeMethod(name, args);
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch (Exception)
|
||||
{
|
||||
if ((exception is MissingMemberException) || (exception is NotSupportedException) || (exception is InvalidOperationException) || (exception is ExternalException))
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField) && (args.Length < 1))
|
||||
{
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField))
|
||||
{
|
||||
return targetDynamic.GetProperty(name);
|
||||
}
|
||||
return targetDynamic.GetProperty(name);
|
||||
}
|
||||
|
||||
throw;
|
||||
|
@ -552,7 +545,7 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
if (name == SpecialMemberNames.Default)
|
||||
{
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField))
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField) && (args.Length < 1))
|
||||
{
|
||||
return targetPropertyBag;
|
||||
}
|
||||
|
@ -572,7 +565,7 @@ namespace Microsoft.ClearScript
|
|||
return result;
|
||||
}
|
||||
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField))
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField) && (args.Length < 1))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
@ -609,7 +602,7 @@ namespace Microsoft.ClearScript
|
|||
return result;
|
||||
}
|
||||
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField))
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField) && (args.Length < 1))
|
||||
{
|
||||
return targetList[index];
|
||||
}
|
||||
|
@ -688,7 +681,7 @@ namespace Microsoft.ClearScript
|
|||
return result;
|
||||
}
|
||||
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField))
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField) && (args.Length < 1))
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
@ -803,13 +796,15 @@ namespace Microsoft.ClearScript
|
|||
return new HostIndexer(this, name);
|
||||
}
|
||||
|
||||
return property.GetValue(target.InvokeTarget, invokeFlags, Type.DefaultBinder, args, culture);
|
||||
var result = property.GetValue(target.InvokeTarget, invokeFlags, Type.DefaultBinder, args, culture);
|
||||
return property.IsRestrictedForScript() ? HostObject.WrapResult(result, property.PropertyType) : result;
|
||||
}
|
||||
|
||||
var field = target.Type.GetScriptableField(name, invokeFlags);
|
||||
if (field != null)
|
||||
{
|
||||
return field.GetValue(target.InvokeTarget);
|
||||
var result = field.GetValue(target.InvokeTarget);
|
||||
return field.IsRestrictedForScript() ? HostObject.WrapResult(result, field.FieldType) : result;
|
||||
}
|
||||
|
||||
var eventInfo = target.Type.GetScriptableEvent(name, invokeFlags);
|
||||
|
|
|
@ -85,10 +85,45 @@ namespace Microsoft.ClearScript
|
|||
return (target != null) ? new HostObject(target, type) : null;
|
||||
}
|
||||
|
||||
public static object WrapResult<T>(T result)
|
||||
{
|
||||
return WrapResult(result, typeof(T));
|
||||
}
|
||||
|
||||
public static object WrapResult(object result, Type type)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((result is HostItem) || (result is HostTarget))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((type == typeof(void)) || (type == typeof(object)))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((type == result.GetType()) || (Type.GetTypeCode(type) != TypeCode.Object))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return Wrap(result, type);
|
||||
}
|
||||
|
||||
#region Object overrides
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if ((target is ScriptItem) && (typeof(ScriptItem).IsAssignableFrom(type)))
|
||||
{
|
||||
return "ScriptItem";
|
||||
}
|
||||
|
||||
var objectName = target.GetFriendlyName(type);
|
||||
return MiscHelpers.FormatInvariant("HostObject:{0}", objectName);
|
||||
}
|
||||
|
|
|
@ -87,12 +87,12 @@ namespace Microsoft.ClearScript
|
|||
|
||||
public HostVariable(T initValue)
|
||||
{
|
||||
if (typeof(HostTarget).IsAssignableFrom(typeof(T)))
|
||||
if (typeof(HostItem).IsAssignableFrom(typeof(T)) || typeof(HostTarget).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
throw new NotSupportedException("Unsupported variable type");
|
||||
}
|
||||
|
||||
if (initValue is HostTarget)
|
||||
if ((initValue is HostItem) || (initValue is HostTarget))
|
||||
{
|
||||
throw new NotSupportedException("Unsupported value type");
|
||||
}
|
||||
|
@ -183,9 +183,9 @@ namespace Microsoft.ClearScript
|
|||
return true;
|
||||
}
|
||||
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField))
|
||||
if (invokeFlags.HasFlag(BindingFlags.GetField) && (args.Length < 1))
|
||||
{
|
||||
result = value;
|
||||
result = HostObject.WrapResult(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ namespace Microsoft.ClearScript
|
|||
|
||||
if ((invokeFlags & getPropertyFlags) != 0)
|
||||
{
|
||||
result = value;
|
||||
result = HostObject.WrapResult(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
result = ((IHostVariable)this).Value = args[0];
|
||||
result = HostObject.WrapResult(((IHostVariable)this).Value = args[0], typeof(T));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ namespace Microsoft.ClearScript
|
|||
throw new InvalidOperationException("Assignment invalid due to type mismatch");
|
||||
}
|
||||
|
||||
if (tempValue is HostTarget)
|
||||
if ((tempValue is HostItem) || (tempValue is HostTarget))
|
||||
{
|
||||
throw new NotSupportedException("Unsupported value type");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
//
|
||||
// This license governs use of the accompanying software. If you use the
|
||||
// software, you accept this license. If you do not accept the license, do not
|
||||
// use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
//
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S. copyright law. A
|
||||
// "contribution" is the original software, or any additions or changes to
|
||||
// the software. A "contributor" is any person that distributes its
|
||||
// contribution under this license. "Licensed patents" are a contributor's
|
||||
// patent claims that read directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
//
|
||||
// (A) Copyright Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free copyright license
|
||||
// to reproduce its contribution, prepare derivative works of its
|
||||
// contribution, and distribute its contribution or any derivative works
|
||||
// that you create.
|
||||
//
|
||||
// (B) Patent Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free license under its
|
||||
// licensed patents to make, have made, use, sell, offer for sale,
|
||||
// import, and/or otherwise dispose of its contribution in the software
|
||||
// or derivative works of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
//
|
||||
// (A) No Trademark License- This license does not grant you rights to use
|
||||
// any contributors' name, logo, or trademarks.
|
||||
//
|
||||
// (B) If you bring a patent claim against any contributor over patents that
|
||||
// you claim are infringed by the software, your patent license from such
|
||||
// contributor to the software ends automatically.
|
||||
//
|
||||
// (C) If you distribute any portion of the software, you must retain all
|
||||
// copyright, patent, trademark, and attribution notices that are present
|
||||
// in the software.
|
||||
//
|
||||
// (D) If you distribute any portion of the software in source code form, you
|
||||
// may do so only under this license by including a complete copy of this
|
||||
// license with your distribution. If you distribute any portion of the
|
||||
// software in compiled or object code form, you may only do so under a
|
||||
// license that complies with this license.
|
||||
//
|
||||
// (E) The software is licensed "as-is." You bear the risk of using it. The
|
||||
// contributors give no express warranties, guarantees or conditions. You
|
||||
// may have additional consumer rights under your local laws which this
|
||||
// license cannot change. To the extent permitted under your local laws,
|
||||
// the contributors exclude the implied warranties of merchantability,
|
||||
// fitness for a particular purpose and non-infringement.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.ClearScript
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines common script engine exception properties.
|
||||
/// </summary>
|
||||
public interface IScriptEngineException
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the error message.
|
||||
/// </summary>
|
||||
string Message { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see href="http://en.wikipedia.org/wiki/HRESULT">HRESULT</see> error code if one is available, zero otherwise.
|
||||
/// </summary>
|
||||
int HResult { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name associated with the script engine instance.
|
||||
/// </summary>
|
||||
string EngineName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a detailed error message if one is available, <c>null</c> otherwise.
|
||||
/// </summary>
|
||||
string ErrorDetails { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the exception that caused the current exception to be thrown, or <c>null</c> if one was not specified.
|
||||
/// </summary>
|
||||
Exception InnerException { get; }
|
||||
}
|
||||
}
|
|
@ -73,5 +73,5 @@ using System.Runtime.InteropServices;
|
|||
[assembly: InternalsVisibleTo("ClearScriptTest")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: AssemblyVersion("5.1.3.0")]
|
||||
[assembly: AssemblyFileVersion("5.1.3.0")]
|
||||
[assembly: AssemblyVersion("5.2.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.2.0.0")]
|
||||
|
|
|
@ -63,7 +63,6 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.ClearScript.Util;
|
||||
|
||||
namespace Microsoft.ClearScript
|
||||
|
@ -73,24 +72,36 @@ namespace Microsoft.ClearScript
|
|||
/// </summary>
|
||||
public abstract class ScriptEngine : IDisposable
|
||||
{
|
||||
#region constructors
|
||||
#region data
|
||||
|
||||
// ReSharper disable EmptyConstructor
|
||||
private readonly string name;
|
||||
private static readonly IUniqueNameManager nameManager = new UniqueNameManager();
|
||||
|
||||
#endregion
|
||||
|
||||
#region constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new script engine instance.
|
||||
/// </summary>
|
||||
protected ScriptEngine()
|
||||
/// <param name="name">A name to associate with the instance. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
|
||||
protected ScriptEngine(string name)
|
||||
{
|
||||
// the help file builder (SHFB) insists on an empty constructor here
|
||||
this.name = nameManager.GetUniqueName(name, GetType().GetRootName());
|
||||
}
|
||||
|
||||
// ReSharper restore EmptyConstructor
|
||||
|
||||
#endregion
|
||||
|
||||
#region public members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name associated with the script engine instance.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the script engine's recommended file name extension for script files.
|
||||
/// </summary>
|
||||
|
@ -710,11 +721,6 @@ namespace Microsoft.ClearScript
|
|||
return marshaledResult.ToString();
|
||||
}
|
||||
|
||||
if (marshaledResult is ScriptItem)
|
||||
{
|
||||
return "[ScriptItem]";
|
||||
}
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
|
@ -739,61 +745,14 @@ namespace Microsoft.ClearScript
|
|||
|
||||
#region host-side invocation
|
||||
|
||||
internal void HostInvoke(Action action)
|
||||
internal virtual void HostInvoke(Action action)
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
var registeredException = RegisterHostException(exception);
|
||||
if (registeredException != exception)
|
||||
{
|
||||
throw registeredException;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
action();
|
||||
}
|
||||
|
||||
internal T HostInvoke<T>(Func<T> func)
|
||||
internal virtual T HostInvoke<T>(Func<T> func)
|
||||
{
|
||||
try
|
||||
{
|
||||
return func();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
var registeredException = RegisterHostException(exception);
|
||||
if (registeredException != exception)
|
||||
{
|
||||
throw registeredException;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private Exception RegisterHostException(Exception exception)
|
||||
{
|
||||
while (exception is TargetInvocationException)
|
||||
{
|
||||
var innerException = exception.InnerException;
|
||||
if (innerException == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
exception = innerException;
|
||||
}
|
||||
|
||||
if (CurrentScriptFrame != null)
|
||||
{
|
||||
CurrentScriptFrame.SetHostException(exception);
|
||||
}
|
||||
|
||||
return exception;
|
||||
return func();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -811,16 +770,6 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
action();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
var exception = CurrentScriptFrame.Exception;
|
||||
if (exception != null)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CurrentScriptFrame = prevScriptFrame;
|
||||
|
@ -836,31 +785,30 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
return func();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
var exception = CurrentScriptFrame.Exception;
|
||||
if (exception != null)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CurrentScriptFrame = prevScriptFrame;
|
||||
}
|
||||
}
|
||||
|
||||
internal void ThrowScriptFrameException()
|
||||
internal void ThrowScriptError()
|
||||
{
|
||||
if (CurrentScriptFrame != null)
|
||||
{
|
||||
var exception = CurrentScriptFrame.ReportedException;
|
||||
if (exception != null)
|
||||
ThrowScriptError(CurrentScriptFrame.ScriptError);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ThrowScriptError(IScriptEngineException scriptError)
|
||||
{
|
||||
if (scriptError != null)
|
||||
{
|
||||
if (scriptError is ScriptInterruptedException)
|
||||
{
|
||||
throw exception;
|
||||
throw new ScriptInterruptedException(scriptError.EngineName, scriptError.Message, scriptError.ErrorDetails, scriptError.HResult, scriptError.InnerException);
|
||||
}
|
||||
|
||||
throw new ScriptEngineException(scriptError.EngineName, scriptError.Message, scriptError.ErrorDetails, scriptError.HResult, scriptError.InnerException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -965,35 +913,13 @@ namespace Microsoft.ClearScript
|
|||
|
||||
internal class ScriptFrame
|
||||
{
|
||||
public Exception HostException { get; set; }
|
||||
|
||||
public IScriptEngineException ScriptError { get; set; }
|
||||
|
||||
public IScriptEngineException PendingScriptError { get; set; }
|
||||
|
||||
public bool InterruptRequested { get; set; }
|
||||
|
||||
private Exception hostException;
|
||||
public void SetHostException(Exception value)
|
||||
{
|
||||
hostException = value;
|
||||
}
|
||||
|
||||
private Exception scriptError;
|
||||
public void SetScriptError(Exception value)
|
||||
{
|
||||
scriptError = value;
|
||||
}
|
||||
|
||||
private Exception pendingScriptError;
|
||||
public void SetPendingScriptError(Exception value)
|
||||
{
|
||||
pendingScriptError = value;
|
||||
}
|
||||
|
||||
public Exception Exception
|
||||
{
|
||||
get { return hostException ?? scriptError ?? pendingScriptError; }
|
||||
}
|
||||
|
||||
public Exception ReportedException
|
||||
{
|
||||
get { return hostException ?? scriptError; }
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
//
|
||||
// This license governs use of the accompanying software. If you use the
|
||||
// software, you accept this license. If you do not accept the license, do not
|
||||
// use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
//
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S. copyright law. A
|
||||
// "contribution" is the original software, or any additions or changes to
|
||||
// the software. A "contributor" is any person that distributes its
|
||||
// contribution under this license. "Licensed patents" are a contributor's
|
||||
// patent claims that read directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
//
|
||||
// (A) Copyright Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free copyright license
|
||||
// to reproduce its contribution, prepare derivative works of its
|
||||
// contribution, and distribute its contribution or any derivative works
|
||||
// that you create.
|
||||
//
|
||||
// (B) Patent Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free license under its
|
||||
// licensed patents to make, have made, use, sell, offer for sale,
|
||||
// import, and/or otherwise dispose of its contribution in the software
|
||||
// or derivative works of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
//
|
||||
// (A) No Trademark License- This license does not grant you rights to use
|
||||
// any contributors' name, logo, or trademarks.
|
||||
//
|
||||
// (B) If you bring a patent claim against any contributor over patents that
|
||||
// you claim are infringed by the software, your patent license from such
|
||||
// contributor to the software ends automatically.
|
||||
//
|
||||
// (C) If you distribute any portion of the software, you must retain all
|
||||
// copyright, patent, trademark, and attribution notices that are present
|
||||
// in the software.
|
||||
//
|
||||
// (D) If you distribute any portion of the software in source code form, you
|
||||
// may do so only under this license by including a complete copy of this
|
||||
// license with your distribution. If you distribute any portion of the
|
||||
// software in compiled or object code form, you may only do so under a
|
||||
// license that complies with this license.
|
||||
//
|
||||
// (E) The software is licensed "as-is." You bear the risk of using it. The
|
||||
// contributors give no express warranties, guarantees or conditions. You
|
||||
// may have additional consumer rights under your local laws which this
|
||||
// license cannot change. To the extent permitted under your local laws,
|
||||
// the contributors exclude the implied warranties of merchantability,
|
||||
// fitness for a particular purpose and non-infringement.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.ClearScript
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when an error occurs during script execution or script object access.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ScriptEngineException : InvalidOperationException, IScriptEngineException
|
||||
{
|
||||
private readonly string engineName;
|
||||
private const string engineNameItemName = "ScriptEngineName";
|
||||
|
||||
private readonly string errorDetails;
|
||||
private const string errorDetailsItemName = "ScriptErrorDetails";
|
||||
|
||||
#region constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptEngineException"/> instance.
|
||||
/// </summary>
|
||||
public ScriptEngineException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptEngineException"/> with the specified error message.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message.</param>
|
||||
public ScriptEngineException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptEngineException"/> with the specified error message and nested exception.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message.</param>
|
||||
/// <param name="innerException">The exception that caused the current exception to be thrown.</param>
|
||||
public ScriptEngineException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptEngineException"/> with serialized data.
|
||||
/// </summary>
|
||||
/// <param name="info">The object that holds the serialized data.</param>
|
||||
/// <param name="context">The contextual information about the source or destination.</param>
|
||||
protected ScriptEngineException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
engineName = info.GetString(engineNameItemName);
|
||||
errorDetails = info.GetString(errorDetailsItemName);
|
||||
}
|
||||
|
||||
internal ScriptEngineException(string engineName, string message, string errorDetails, int errorCode, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
this.engineName = engineName;
|
||||
this.errorDetails = errorDetails;
|
||||
|
||||
if (errorCode != 0)
|
||||
{
|
||||
HResult = errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IScriptEngineException implementation
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name associated with the script engine instance.
|
||||
/// </summary>
|
||||
public string EngineName
|
||||
{
|
||||
get { return engineName; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a detailed error message if one is available, <c>null</c> otherwise.
|
||||
/// </summary>
|
||||
public string ErrorDetails
|
||||
{
|
||||
get { return errorDetails; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region InvalidOperationException overrides
|
||||
|
||||
/// <summary>
|
||||
/// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object.
|
||||
/// </summary>
|
||||
/// <param name="info">The <see cref="SerializationInfo"/> to populate with data.</param>
|
||||
/// <param name="context">The destination (see <see cref="StreamingContext"/>) for this serialization.</param>
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
info.AddValue(engineNameItemName, engineName);
|
||||
info.AddValue(errorDetailsItemName, errorDetails);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
//
|
||||
// This license governs use of the accompanying software. If you use the
|
||||
// software, you accept this license. If you do not accept the license, do not
|
||||
// use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
//
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S. copyright law. A
|
||||
// "contribution" is the original software, or any additions or changes to
|
||||
// the software. A "contributor" is any person that distributes its
|
||||
// contribution under this license. "Licensed patents" are a contributor's
|
||||
// patent claims that read directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
//
|
||||
// (A) Copyright Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free copyright license
|
||||
// to reproduce its contribution, prepare derivative works of its
|
||||
// contribution, and distribute its contribution or any derivative works
|
||||
// that you create.
|
||||
//
|
||||
// (B) Patent Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free license under its
|
||||
// licensed patents to make, have made, use, sell, offer for sale,
|
||||
// import, and/or otherwise dispose of its contribution in the software
|
||||
// or derivative works of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
//
|
||||
// (A) No Trademark License- This license does not grant you rights to use
|
||||
// any contributors' name, logo, or trademarks.
|
||||
//
|
||||
// (B) If you bring a patent claim against any contributor over patents that
|
||||
// you claim are infringed by the software, your patent license from such
|
||||
// contributor to the software ends automatically.
|
||||
//
|
||||
// (C) If you distribute any portion of the software, you must retain all
|
||||
// copyright, patent, trademark, and attribution notices that are present
|
||||
// in the software.
|
||||
//
|
||||
// (D) If you distribute any portion of the software in source code form, you
|
||||
// may do so only under this license by including a complete copy of this
|
||||
// license with your distribution. If you distribute any portion of the
|
||||
// software in compiled or object code form, you may only do so under a
|
||||
// license that complies with this license.
|
||||
//
|
||||
// (E) The software is licensed "as-is." You bear the risk of using it. The
|
||||
// contributors give no express warranties, guarantees or conditions. You
|
||||
// may have additional consumer rights under your local laws which this
|
||||
// license cannot change. To the extent permitted under your local laws,
|
||||
// the contributors exclude the implied warranties of merchantability,
|
||||
// fitness for a particular purpose and non-infringement.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.ClearScript
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when script execution is interrupted by the host.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ScriptInterruptedException : OperationCanceledException, IScriptEngineException
|
||||
{
|
||||
private readonly string engineName;
|
||||
private const string engineNameItemName = "ScriptEngineName";
|
||||
|
||||
private readonly string errorDetails;
|
||||
private const string errorDetailsItemName = "ScriptErrorDetails";
|
||||
|
||||
#region constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptInterruptedException"/> instance.
|
||||
/// </summary>
|
||||
public ScriptInterruptedException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptInterruptedException"/> with the specified error message.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message.</param>
|
||||
public ScriptInterruptedException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptInterruptedException"/> with the specified error message and nested exception.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message.</param>
|
||||
/// <param name="innerException">The exception that caused the current exception to be thrown.</param>
|
||||
public ScriptInterruptedException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptInterruptedException"/> with serialized data.
|
||||
/// </summary>
|
||||
/// <param name="info">The object that holds the serialized data.</param>
|
||||
/// <param name="context">The contextual information about the source or destination.</param>
|
||||
protected ScriptInterruptedException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
engineName = info.GetString(engineNameItemName);
|
||||
errorDetails = info.GetString(errorDetailsItemName);
|
||||
}
|
||||
|
||||
internal ScriptInterruptedException(string engineName, string message, string errorDetails, int errorCode, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
this.engineName = engineName;
|
||||
this.errorDetails = errorDetails;
|
||||
|
||||
if (errorCode != 0)
|
||||
{
|
||||
HResult = errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IScriptEngineException implementation
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name associated with the script engine instance.
|
||||
/// </summary>
|
||||
public string EngineName
|
||||
{
|
||||
get { return engineName; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a detailed error message if one is available, <c>null</c> otherwise.
|
||||
/// </summary>
|
||||
public string ErrorDetails
|
||||
{
|
||||
get { return errorDetails; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OperationCanceledException overrides
|
||||
|
||||
/// <summary>
|
||||
/// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object.
|
||||
/// </summary>
|
||||
/// <param name="info">The <see cref="SerializationInfo"/> to populate with data.</param>
|
||||
/// <param name="context">The destination (see <see cref="StreamingContext"/>) for this serialization.</param>
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
info.AddValue(engineNameItemName, engineName);
|
||||
info.AddValue(errorDetailsItemName, errorDetails);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -60,8 +60,10 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Dynamic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.ClearScript.Util;
|
||||
|
@ -86,7 +88,7 @@ namespace Microsoft.ClearScript
|
|||
{
|
||||
if (!TryBindAndInvoke(binder, Engine.MarshalToScript(args), out tempResult))
|
||||
{
|
||||
Engine.ThrowScriptFrameException();
|
||||
Engine.ThrowScriptError();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -148,6 +150,11 @@ namespace Microsoft.ClearScript
|
|||
|
||||
#region DynamicObject overrides
|
||||
|
||||
public override IEnumerable<string> GetDynamicMemberNames()
|
||||
{
|
||||
return GetPropertyNames().Concat(GetPropertyIndices().Select(index => index.ToString(CultureInfo.InvariantCulture)));
|
||||
}
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
||||
{
|
||||
return TryWrappedBindAndInvoke(binder, MiscHelpers.GetEmptyArray<object>(), out result);
|
||||
|
|
|
@ -105,6 +105,50 @@ namespace Microsoft.ClearScript
|
|||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptMemberAttribute"/> instance with the specified script options.
|
||||
/// </summary>
|
||||
/// <param name="flags">The script options for the type member.</param>
|
||||
public ScriptMemberAttribute(ScriptMemberFlags flags)
|
||||
{
|
||||
Flags = flags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptMemberAttribute"/> instance with the specified name and script options.
|
||||
/// </summary>
|
||||
/// <param name="name">The name that script code will use to access the type member.</param>
|
||||
/// <param name="flags">The script options for the type member.</param>
|
||||
public ScriptMemberAttribute(string name, ScriptMemberFlags flags)
|
||||
{
|
||||
Name = name;
|
||||
Flags = flags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptMemberAttribute"/> instance with the specified script access setting and script options.
|
||||
/// </summary>
|
||||
/// <param name="access">The script access setting for the type member.</param>
|
||||
/// <param name="flags">The script options for the type member.</param>
|
||||
public ScriptMemberAttribute(ScriptAccess access, ScriptMemberFlags flags)
|
||||
: base(access)
|
||||
{
|
||||
Flags = flags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ScriptMemberAttribute"/> instance with the specified name, script access setting, and script options.
|
||||
/// </summary>
|
||||
/// <param name="name">The name that script code will use to access the type member.</param>
|
||||
/// <param name="access">The script access setting for the type member.</param>
|
||||
/// <param name="flags">The script options for the type member.</param>
|
||||
public ScriptMemberAttribute(string name, ScriptAccess access, ScriptMemberFlags flags)
|
||||
: base(access)
|
||||
{
|
||||
Name = name;
|
||||
Flags = flags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name that script code will use to access the type member.
|
||||
/// </summary>
|
||||
|
@ -115,5 +159,10 @@ namespace Microsoft.ClearScript
|
|||
/// could receive the call.
|
||||
/// </remarks>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the script options for the type member.
|
||||
/// </summary>
|
||||
public ScriptMemberFlags Flags { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
//
|
||||
// This license governs use of the accompanying software. If you use the
|
||||
// software, you accept this license. If you do not accept the license, do not
|
||||
// use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
//
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S. copyright law. A
|
||||
// "contribution" is the original software, or any additions or changes to
|
||||
// the software. A "contributor" is any person that distributes its
|
||||
// contribution under this license. "Licensed patents" are a contributor's
|
||||
// patent claims that read directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
//
|
||||
// (A) Copyright Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free copyright license
|
||||
// to reproduce its contribution, prepare derivative works of its
|
||||
// contribution, and distribute its contribution or any derivative works
|
||||
// that you create.
|
||||
//
|
||||
// (B) Patent Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free license under its
|
||||
// licensed patents to make, have made, use, sell, offer for sale,
|
||||
// import, and/or otherwise dispose of its contribution in the software
|
||||
// or derivative works of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
//
|
||||
// (A) No Trademark License- This license does not grant you rights to use
|
||||
// any contributors' name, logo, or trademarks.
|
||||
//
|
||||
// (B) If you bring a patent claim against any contributor over patents that
|
||||
// you claim are infringed by the software, your patent license from such
|
||||
// contributor to the software ends automatically.
|
||||
//
|
||||
// (C) If you distribute any portion of the software, you must retain all
|
||||
// copyright, patent, trademark, and attribution notices that are present
|
||||
// in the software.
|
||||
//
|
||||
// (D) If you distribute any portion of the software in source code form, you
|
||||
// may do so only under this license by including a complete copy of this
|
||||
// license with your distribution. If you distribute any portion of the
|
||||
// software in compiled or object code form, you may only do so under a
|
||||
// license that complies with this license.
|
||||
//
|
||||
// (E) The software is licensed "as-is." You bear the risk of using it. The
|
||||
// contributors give no express warranties, guarantees or conditions. You
|
||||
// may have additional consumer rights under your local laws which this
|
||||
// license cannot change. To the extent permitted under your local laws,
|
||||
// the contributors exclude the implied warranties of merchantability,
|
||||
// fitness for a particular purpose and non-infringement.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.ClearScript
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines options for exposing type members to script code.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum ScriptMemberFlags
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies that no options are selected.
|
||||
/// </summary>
|
||||
None = 0x00,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies that the field, property, or method return value is not to be restricted to its declared type.
|
||||
/// </summary>
|
||||
ExposeRuntimeType = 0x00000001,
|
||||
}
|
||||
}
|
|
@ -139,9 +139,9 @@ namespace Microsoft.ClearScript.Util
|
|||
result = InvokeExpression(binding.Expression);
|
||||
return true;
|
||||
}
|
||||
catch (ApplicationException)
|
||||
catch (Exception exception)
|
||||
{
|
||||
result = null;
|
||||
result = exception;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,7 +147,13 @@ namespace Microsoft.ClearScript.Util
|
|||
item.ByRefArg.Value = array.GetValue(item.Index);
|
||||
}
|
||||
|
||||
return (method.ReturnType == typeof(void)) ? VoidResult.Value : result;
|
||||
var type = method.ReturnType;
|
||||
if (type == typeof(void))
|
||||
{
|
||||
return VoidResult.Value;
|
||||
}
|
||||
|
||||
return method.IsRestrictedForScript() ? HostObject.WrapResult(result, type) : result;
|
||||
}
|
||||
|
||||
public static object InvokeDelegate(Delegate del, object[] args)
|
||||
|
|
|
@ -102,6 +102,11 @@ namespace Microsoft.ClearScript.Util
|
|||
return member.GetScriptAccess() == ScriptAccess.ReadOnly;
|
||||
}
|
||||
|
||||
public static bool IsRestrictedForScript(this MemberInfo member)
|
||||
{
|
||||
return !member.GetScriptMemberFlags().HasFlag(ScriptMemberFlags.ExposeRuntimeType);
|
||||
}
|
||||
|
||||
public static string GetShortName(this MemberInfo member)
|
||||
{
|
||||
var name = member.Name;
|
||||
|
@ -120,6 +125,12 @@ namespace Microsoft.ClearScript.Util
|
|||
return (attribute != null) ? attribute.Access : ScriptAccess.Full;
|
||||
}
|
||||
|
||||
private static ScriptMemberFlags GetScriptMemberFlags(this MemberInfo member)
|
||||
{
|
||||
var attribute = member.GetAttribute<ScriptMemberAttribute>(true);
|
||||
return (attribute != null) ? attribute.Flags : ScriptMemberFlags.None;
|
||||
}
|
||||
|
||||
private static T GetAttribute<T>(this MemberInfo member, bool inherit) where T : Attribute
|
||||
{
|
||||
return Attribute.GetCustomAttribute(member, typeof(T), inherit) as T;
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace Microsoft.ClearScript.Util
|
|||
|
||||
public static string FormatCode(string code)
|
||||
{
|
||||
var lines = code.Replace("\r\n", "\n").Split('\n');
|
||||
var lines = (code ?? string.Empty).Replace("\r\n", "\n").Split('\n');
|
||||
|
||||
lines = lines.SkipWhile(string.IsNullOrWhiteSpace).Reverse().SkipWhile(string.IsNullOrWhiteSpace).Reverse().ToArray();
|
||||
if (lines.Length > 0)
|
||||
|
@ -111,9 +111,9 @@ namespace Microsoft.ClearScript.Util
|
|||
for (var indentLength = firstLine.TakeWhile(char.IsWhiteSpace).Count(); indentLength > 0; indentLength--)
|
||||
{
|
||||
var indent = firstLine.Substring(0, indentLength);
|
||||
if (lines.Skip(1).All(line => line.StartsWith(indent, StringComparison.Ordinal)))
|
||||
if (lines.Skip(1).All(line => string.IsNullOrWhiteSpace(line) || line.StartsWith(indent, StringComparison.Ordinal)))
|
||||
{
|
||||
lines = lines.Select(line => line.Substring(indent.Length)).ToArray();
|
||||
lines = lines.Select(line => string.IsNullOrWhiteSpace(line) ? string.Empty : line.Substring(indent.Length)).ToArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +147,11 @@ namespace Microsoft.ClearScript.Util
|
|||
return BitConverter.ToInt32(BitConverter.GetBytes(value), 0);
|
||||
}
|
||||
|
||||
public static uint SignedAsUnsigned(int value)
|
||||
{
|
||||
return BitConverter.ToUInt32(BitConverter.GetBytes(value), 0);
|
||||
}
|
||||
|
||||
public static T[] GetEmptyArray<T>()
|
||||
{
|
||||
return EmptyArray<T>.Value;
|
||||
|
|
|
@ -147,12 +147,20 @@ namespace Microsoft.ClearScript.Util
|
|||
public const int FACILITY_WINDOWS = 8;
|
||||
public const int FACILITY_CONTROL = 10;
|
||||
public const int FACILITY_INTERNET = 12;
|
||||
public const int FACILITY_URT = 19;
|
||||
|
||||
public const uint S_OK = 0;
|
||||
public const uint S_FALSE = 1;
|
||||
public const uint E_NOINTERFACE = 0x80004002;
|
||||
public const uint E_ABORT = 0x80004004;
|
||||
public const uint DISP_E_MEMBERNOTFOUND = 0x80020003;
|
||||
public const int S_OK = 0;
|
||||
public const int S_FALSE = 1;
|
||||
|
||||
public static readonly int E_NOINTERFACE = MiscHelpers.UnsignedAsSigned(0x80004002U);
|
||||
public static readonly int E_ABORT = MiscHelpers.UnsignedAsSigned(0x80004004U);
|
||||
public static readonly int E_INVALIDARG = MiscHelpers.UnsignedAsSigned(0x80070057U);
|
||||
|
||||
public static readonly int DISP_E_MEMBERNOTFOUND = MiscHelpers.UnsignedAsSigned(0x80020003U);
|
||||
public static readonly int SCRIPT_E_REPORTED = MiscHelpers.UnsignedAsSigned(0x80020101U);
|
||||
|
||||
public static readonly int CLEARSCRIPT_E_HOSTEXCEPTION = MakeResult(SEVERITY_ERROR, FACILITY_URT, 0xBAFF);
|
||||
public static readonly int CLEARSCRIPT_E_SCRIPTITEMEXCEPTION = MakeResult(SEVERITY_ERROR, FACILITY_URT, 0xB0FF);
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
|
@ -195,6 +203,11 @@ namespace Microsoft.ClearScript.Util
|
|||
{
|
||||
return result & 0xFFFF;
|
||||
}
|
||||
|
||||
public static int MakeResult(int severity, int facility, int code)
|
||||
{
|
||||
return MiscHelpers.UnsignedAsSigned((uint)(code & 0xFFFF) | ((uint)(facility & 0x1FFF) << 16) | ((uint)(severity & 0x1) << 31));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -132,6 +132,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="..\ClearScriptV8.h" />
|
||||
<ClInclude Include="..\ClearScriptV8Managed.h" />
|
||||
<ClInclude Include="..\HostException.h" />
|
||||
<ClInclude Include="..\HostObjectHelpers.h" />
|
||||
<ClInclude Include="..\HostObjectHolder.h" />
|
||||
<ClInclude Include="..\HostObjectHolderImpl.h" />
|
||||
|
|
|
@ -84,6 +84,9 @@
|
|||
<ClInclude Include="..\ManagedPlatform.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\HostException.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
|
|
|
@ -132,6 +132,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="..\ClearScriptV8.h" />
|
||||
<ClInclude Include="..\ClearScriptV8Managed.h" />
|
||||
<ClInclude Include="..\HostException.h" />
|
||||
<ClInclude Include="..\HostObjectHelpers.h" />
|
||||
<ClInclude Include="..\HostObjectHolder.h" />
|
||||
<ClInclude Include="..\HostObjectHolderImpl.h" />
|
||||
|
|
|
@ -84,6 +84,9 @@
|
|||
<ClInclude Include="..\ManagedPlatform.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\HostException.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Header Files">
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
#include "V8ObjectHolder.h"
|
||||
#include "HostObjectHolder.h"
|
||||
#include "V8Value.h"
|
||||
#include "HostException.h"
|
||||
#include "V8Exception.h"
|
||||
#include "V8Context.h"
|
||||
#include "V8ContextImpl.h"
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
#include "V8ObjectHolder.h"
|
||||
#include "HostObjectHolder.h"
|
||||
#include "V8Value.h"
|
||||
#include "HostException.h"
|
||||
#include "V8Exception.h"
|
||||
#include "V8Context.h"
|
||||
#include "V8ProxyImpl.h"
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
//
|
||||
// This license governs use of the accompanying software. If you use the
|
||||
// software, you accept this license. If you do not accept the license, do not
|
||||
// use the software.
|
||||
//
|
||||
// 1. Definitions
|
||||
//
|
||||
// The terms "reproduce," "reproduction," "derivative works," and
|
||||
// "distribution" have the same meaning here as under U.S. copyright law. A
|
||||
// "contribution" is the original software, or any additions or changes to
|
||||
// the software. A "contributor" is any person that distributes its
|
||||
// contribution under this license. "Licensed patents" are a contributor's
|
||||
// patent claims that read directly on its contribution.
|
||||
//
|
||||
// 2. Grant of Rights
|
||||
//
|
||||
// (A) Copyright Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free copyright license
|
||||
// to reproduce its contribution, prepare derivative works of its
|
||||
// contribution, and distribute its contribution or any derivative works
|
||||
// that you create.
|
||||
//
|
||||
// (B) Patent Grant- Subject to the terms of this license, including the
|
||||
// license conditions and limitations in section 3, each contributor
|
||||
// grants you a non-exclusive, worldwide, royalty-free license under its
|
||||
// licensed patents to make, have made, use, sell, offer for sale,
|
||||
// import, and/or otherwise dispose of its contribution in the software
|
||||
// or derivative works of the contribution in the software.
|
||||
//
|
||||
// 3. Conditions and Limitations
|
||||
//
|
||||
// (A) No Trademark License- This license does not grant you rights to use
|
||||
// any contributors' name, logo, or trademarks.
|
||||
//
|
||||
// (B) If you bring a patent claim against any contributor over patents that
|
||||
// you claim are infringed by the software, your patent license from such
|
||||
// contributor to the software ends automatically.
|
||||
//
|
||||
// (C) If you distribute any portion of the software, you must retain all
|
||||
// copyright, patent, trademark, and attribution notices that are present
|
||||
// in the software.
|
||||
//
|
||||
// (D) If you distribute any portion of the software in source code form, you
|
||||
// may do so only under this license by including a complete copy of this
|
||||
// license with your distribution. If you distribute any portion of the
|
||||
// software in compiled or object code form, you may only do so under a
|
||||
// license that complies with this license.
|
||||
//
|
||||
// (E) The software is licensed "as-is." You bear the risk of using it. The
|
||||
// contributors give no express warranties, guarantees or conditions. You
|
||||
// may have additional consumer rights under your local laws which this
|
||||
// license cannot change. To the extent permitted under your local laws,
|
||||
// the contributors exclude the implied warranties of merchantability,
|
||||
// fitness for a particular purpose and non-infringement.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// V8Exception
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HostException
|
||||
{
|
||||
public:
|
||||
|
||||
HostException(LPCWSTR pMessage, const V8Value& exception):
|
||||
m_Exception(exception)
|
||||
{
|
||||
if (pMessage != nullptr)
|
||||
{
|
||||
m_Message = pMessage;
|
||||
}
|
||||
}
|
||||
|
||||
HostException(LPCWSTR pMessage, V8Value&& exception):
|
||||
m_Exception(exception)
|
||||
{
|
||||
if (pMessage != nullptr)
|
||||
{
|
||||
m_Message = pMessage;
|
||||
}
|
||||
}
|
||||
|
||||
LPCWSTR GetMessage() const
|
||||
{
|
||||
return m_Message.c_str();
|
||||
}
|
||||
|
||||
const V8Value& GetException() const
|
||||
{
|
||||
return m_Exception;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
wstring m_Message;
|
||||
V8Value m_Exception;
|
||||
};
|
|
@ -61,12 +61,19 @@
|
|||
|
||||
#include "ClearScriptV8Managed.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HostObjectHelpers implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
using namespace Microsoft::ClearScript::V8;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// local helper functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void __declspec(noreturn) ThrowHostException(Exception^ gcException)
|
||||
{
|
||||
throw HostException(StringToUniPtr(gcException->Message), V8ProxyImpl::ImportValue(gcException));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HostObjectHelpers implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
LPVOID HostObjectHelpers::AddRef(LPVOID pvObject)
|
||||
|
@ -91,7 +98,7 @@ V8Value HostObjectHelpers::GetProperty(LPVOID pvObject, LPCWSTR pName)
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +112,7 @@ void HostObjectHelpers::SetProperty(LPVOID pvObject, LPCWSTR pName, const V8Valu
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +126,7 @@ bool HostObjectHelpers::DeleteProperty(LPVOID pvObject, LPCWSTR pName)
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +147,7 @@ void HostObjectHelpers::GetPropertyNames(LPVOID pvObject, vector<wstring>& names
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +161,7 @@ V8Value HostObjectHelpers::GetProperty(LPVOID pvObject, int index)
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +175,7 @@ void HostObjectHelpers::SetProperty(LPVOID pvObject, int index, const V8Value& v
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,7 +189,7 @@ bool HostObjectHelpers::DeleteProperty(LPVOID pvObject, int index)
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +210,7 @@ void HostObjectHelpers::GetPropertyIndices(LPVOID pvObject, vector<int>& indices
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,7 +232,7 @@ V8Value HostObjectHelpers::Invoke(LPVOID pvObject, const vector<V8Value>& args,
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,7 +254,7 @@ V8Value HostObjectHelpers::InvokeMethod(LPVOID pvObject, LPCWSTR pName, const ve
|
|||
}
|
||||
catch (Exception^ gcException)
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, StringToUniPtr(gcException->Message), StringToUniPtr(gcException->StackTrace));
|
||||
ThrowHostException(gcException);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -98,5 +98,5 @@ using namespace Microsoft::ClearScript::Util;
|
|||
msclr::lock t_LockScope(obj);
|
||||
|
||||
#define END_LOCK_SCOPE \
|
||||
t_LockScope; \
|
||||
(void) t_LockScope; \
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ private:
|
|||
AddRef();
|
||||
}
|
||||
|
||||
template<typename U> void Move(SharedPtr<U>&& that)
|
||||
template<typename U> void Move(SharedPtr<U>& that)
|
||||
{
|
||||
m_pTarget = that.m_pTarget;
|
||||
m_pRefCount = that.m_pRefCount;
|
||||
|
|
|
@ -129,29 +129,6 @@ static LPVOID UnwrapHostObject(const Arguments& args)
|
|||
return ::GetHostObject(args.Holder());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void Verify(const TryCatch& tryCatch)
|
||||
{
|
||||
if (tryCatch.HasCaught())
|
||||
{
|
||||
if (!tryCatch.CanContinue())
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_Interrupt, L"Script execution interrupted by host", *String::Value(tryCatch.StackTrace()));
|
||||
}
|
||||
|
||||
throw V8Exception(V8Exception::Type_General, *String::Value(tryCatch.Exception()), *String::Value(tryCatch.StackTrace()));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<typename T> static T Verify(const TryCatch& tryCatch, T result)
|
||||
{
|
||||
::Verify(tryCatch);
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// V8ContextImpl implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -160,12 +137,12 @@ template<typename T> static T Verify(const TryCatch& tryCatch, T result)
|
|||
{ \
|
||||
Locker t_LockScope(m_pIsolate); \
|
||||
Isolate::Scope t_IsolateScope(m_pIsolate); \
|
||||
HandleScope t_HandleScope;
|
||||
HandleScope t_HandleScope(m_pIsolate);
|
||||
|
||||
#define END_ISOLATE_SCOPE \
|
||||
t_HandleScope; \
|
||||
t_IsolateScope; \
|
||||
t_LockScope; \
|
||||
(void) t_HandleScope; \
|
||||
(void) t_IsolateScope; \
|
||||
(void) t_LockScope; \
|
||||
}
|
||||
|
||||
#define BEGIN_CONTEXT_SCOPE \
|
||||
|
@ -173,7 +150,7 @@ template<typename T> static T Verify(const TryCatch& tryCatch, T result)
|
|||
Context::Scope t_ContextScope(m_hContext);
|
||||
|
||||
#define END_CONTEXT_SCOPE \
|
||||
t_ContextScope; \
|
||||
(void) t_ContextScope; \
|
||||
}
|
||||
|
||||
#define BEGIN_VERIFY_SCOPE \
|
||||
|
@ -181,14 +158,14 @@ template<typename T> static T Verify(const TryCatch& tryCatch, T result)
|
|||
TryCatch t_TryCatch;
|
||||
|
||||
#define END_VERIFY_SCOPE \
|
||||
t_TryCatch; \
|
||||
(void) t_TryCatch; \
|
||||
}
|
||||
|
||||
#define VERIFY(result) \
|
||||
::Verify(t_TryCatch, result)
|
||||
Verify(t_TryCatch, result)
|
||||
|
||||
#define VERIFY_CHECKPOINT() \
|
||||
::Verify(t_TryCatch)
|
||||
Verify(t_TryCatch)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -197,6 +174,11 @@ V8ContextImpl::V8ContextImpl(LPCWSTR pName, bool enableDebugging, bool disableGl
|
|||
m_DebugAgentEnabled(false),
|
||||
m_DebugMessageDispatchCount(0)
|
||||
{
|
||||
if (pName != nullptr)
|
||||
{
|
||||
m_Name = pName;
|
||||
}
|
||||
|
||||
BEGIN_ISOLATE_SCOPE
|
||||
|
||||
if (disableGlobalMembers)
|
||||
|
@ -223,9 +205,10 @@ V8ContextImpl::V8ContextImpl(LPCWSTR pName, bool enableDebugging, bool disableGl
|
|||
// Such a change will require a corresponding change in the V8ScriptEngine constructor.
|
||||
|
||||
m_hHostObjectCookieName = Persistent<String>::New(m_pIsolate, String::New(L"{c2cf47d3-916b-4a3f-be2a-6ff567425808}"));
|
||||
m_hInnerExceptionName = Persistent<String>::New(m_pIsolate, String::New(L"inner"));
|
||||
|
||||
m_hHostObjectTemplate = Persistent<FunctionTemplate>::New(m_pIsolate, FunctionTemplate::New());
|
||||
m_hHostObjectTemplate->SetClassName(String::New("HostObject"));
|
||||
m_hHostObjectTemplate->SetClassName(String::New(L"HostObject"));
|
||||
|
||||
m_hHostObjectTemplate->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
m_hHostObjectTemplate->InstanceTemplate()->SetNamedPropertyHandler(GetHostObjectProperty, SetHostObjectProperty, QueryHostObjectProperty, DeleteHostObjectProperty, GetHostObjectPropertyNames, Wrap());
|
||||
|
@ -261,7 +244,7 @@ void V8ContextImpl::SetGlobalProperty(LPCWSTR pName, const V8Value& value, bool
|
|||
BEGIN_CONTEXT_SCOPE
|
||||
|
||||
auto hValue = ImportValue(value);
|
||||
m_hContext->Global()->Set(String::New(pName), hValue);
|
||||
m_hContext->Global()->Set(String::New(pName), hValue, (PropertyAttribute)(ReadOnly | DontDelete));
|
||||
if (globalMembers && hValue->IsObject())
|
||||
{
|
||||
m_GlobalMembersStack.push_back(Persistent<Object>::New(m_pIsolate, hValue->ToObject()));
|
||||
|
@ -482,13 +465,15 @@ V8Value V8ContextImpl::InvokeV8ObjectMethod(LPVOID pvV8Object, LPCWSTR pName, co
|
|||
auto hName = String::New(pName);
|
||||
if (!hObject->Has(hName))
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, *String::Value(Exception::TypeError(String::New("Method or property not found"))), nullptr);
|
||||
auto hError = Exception::TypeError(String::New(L"Method or property not found"))->ToObject();
|
||||
throw V8Exception(V8Exception::Type_General, m_Name.c_str(), *String::Value(hError), *String::Value(hError->Get(String::New(L"stack"))), V8Value(V8Value::Undefined));
|
||||
}
|
||||
|
||||
auto hValue = hObject->Get(hName);
|
||||
if (hValue->IsUndefined() || hValue->IsNull())
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_General, *String::Value(Exception::TypeError(String::New("Property value does not support invocation"))), nullptr);
|
||||
auto hError = Exception::TypeError(String::New(L"Property value does not support invocation"))->ToObject();
|
||||
throw V8Exception(V8Exception::Type_General, m_Name.c_str(), *String::Value(hError), *String::Value(hError->Get(String::New(L"stack"))), V8Value(V8Value::Undefined));
|
||||
}
|
||||
|
||||
vector<Handle<Value>> importedArgs;
|
||||
|
@ -526,6 +511,7 @@ V8ContextImpl::~V8ContextImpl()
|
|||
}
|
||||
|
||||
m_hHostObjectTemplate.Dispose(m_pIsolate);
|
||||
m_hInnerExceptionName.Dispose(m_pIsolate);
|
||||
m_hHostObjectCookieName.Dispose(m_pIsolate);
|
||||
|
||||
END_CONTEXT_SCOPE
|
||||
|
@ -726,9 +712,9 @@ Handle<Boolean> V8ContextImpl::DeleteGlobalProperty(Local<String> hName, const A
|
|||
{
|
||||
return HostObjectHelpers::DeleteProperty(::GetHostObject(*it), *String::Value(hName)) ? True(pContextImpl->m_pIsolate) : False(pContextImpl->m_pIsolate);
|
||||
}
|
||||
catch (const V8Exception&)
|
||||
catch (const HostException&)
|
||||
{
|
||||
return False(pContextImpl->m_pIsolate) ;
|
||||
return False(pContextImpl->m_pIsolate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -745,13 +731,13 @@ Handle<Boolean> V8ContextImpl::DeleteGlobalProperty(Local<String> hName, const A
|
|||
|
||||
Handle<Array> V8ContextImpl::GetGlobalPropertyNames(const AccessorInfo& info)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto hGlobal = info.Holder();
|
||||
_ASSERTE(hGlobal->InternalFieldCount() > 0);
|
||||
auto hGlobal = info.Holder();
|
||||
_ASSERTE(hGlobal->InternalFieldCount() > 0);
|
||||
|
||||
auto pContextImpl = reinterpret_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
|
||||
if (pContextImpl != nullptr)
|
||||
auto pContextImpl = reinterpret_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
|
||||
if (pContextImpl != nullptr)
|
||||
{
|
||||
try
|
||||
{
|
||||
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
|
||||
if (stack.size() > 0)
|
||||
|
@ -785,14 +771,13 @@ Handle<Array> V8ContextImpl::GetGlobalPropertyNames(const AccessorInfo& info)
|
|||
return hImportedNames;
|
||||
}
|
||||
}
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
return Handle<Array>();
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Array>();
|
||||
}
|
||||
return Handle<Array>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -905,13 +890,13 @@ Handle<Boolean> V8ContextImpl::DeleteGlobalProperty(unsigned __int32 index, cons
|
|||
|
||||
Handle<Array> V8ContextImpl::GetGlobalPropertyIndices(const AccessorInfo& info)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto hGlobal = info.Holder();
|
||||
_ASSERTE(hGlobal->InternalFieldCount() > 0);
|
||||
auto hGlobal = info.Holder();
|
||||
_ASSERTE(hGlobal->InternalFieldCount() > 0);
|
||||
|
||||
auto pContextImpl = reinterpret_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
|
||||
if (pContextImpl != nullptr)
|
||||
auto pContextImpl = reinterpret_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
|
||||
if (pContextImpl != nullptr)
|
||||
{
|
||||
try
|
||||
{
|
||||
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
|
||||
if (stack.size() > 0)
|
||||
|
@ -945,23 +930,23 @@ Handle<Array> V8ContextImpl::GetGlobalPropertyIndices(const AccessorInfo& info)
|
|||
return hImportedIndices;
|
||||
}
|
||||
}
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
return Handle<Array>();
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Array>();
|
||||
}
|
||||
return Handle<Array>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Value> V8ContextImpl::GetHostObjectProperty(Local<String> hName, const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
if (hName->Equals(pContextImpl->m_hHostObjectCookieName))
|
||||
{
|
||||
return True(pContextImpl->m_pIsolate);
|
||||
|
@ -969,36 +954,41 @@ Handle<Value> V8ContextImpl::GetHostObjectProperty(Local<String> hName, const Ac
|
|||
|
||||
return pContextImpl->ImportValue(HostObjectHelpers::GetProperty(::UnwrapHostObject(info), *String::Value(hName)));
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Value>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Value>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Value> V8ContextImpl::SetHostObjectProperty(Local<String> hName, Local<Value> hValue, const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
HostObjectHelpers::SetProperty(::UnwrapHostObject(info), *String::Value(hName), ::UnwrapContextImpl(info)->ExportValue(hValue));
|
||||
HostObjectHelpers::SetProperty(::UnwrapHostObject(info), *String::Value(hName), pContextImpl->ExportValue(hValue));
|
||||
return hValue;
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Value>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Value>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Integer> V8ContextImpl::QueryHostObjectProperty(Local<String> hName, const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
if (hName->Equals(pContextImpl->m_hHostObjectCookieName))
|
||||
{
|
||||
return pContextImpl->GetIntegerHandle(ReadOnly | DontEnum | DontDelete);
|
||||
|
@ -1018,33 +1008,38 @@ Handle<Integer> V8ContextImpl::QueryHostObjectProperty(Local<String> hName, cons
|
|||
|
||||
return Handle<Integer>();
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Integer>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Integer>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Boolean> V8ContextImpl::DeleteHostObjectProperty(Local<String> hName, const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
return HostObjectHelpers::DeleteProperty(::UnwrapHostObject(info), *String::Value(hName)) ? True(pContextImpl->m_pIsolate) : False(pContextImpl->m_pIsolate);
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Boolean>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Boolean>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Array> V8ContextImpl::GetHostObjectPropertyNames(const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
vector<wstring> names;
|
||||
|
@ -1059,48 +1054,57 @@ Handle<Array> V8ContextImpl::GetHostObjectPropertyNames(const AccessorInfo& info
|
|||
|
||||
return hImportedNames;
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Array>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Array>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Value> V8ContextImpl::GetHostObjectProperty(unsigned __int32 index, const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
return ::UnwrapContextImpl(info)->ImportValue(HostObjectHelpers::GetProperty(::UnwrapHostObject(info), index));
|
||||
return pContextImpl->ImportValue(HostObjectHelpers::GetProperty(::UnwrapHostObject(info), index));
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Value>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Value>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Value> V8ContextImpl::SetHostObjectProperty(unsigned __int32 index, Local<Value> hValue, const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
HostObjectHelpers::SetProperty(::UnwrapHostObject(info), index, ::UnwrapContextImpl(info)->ExportValue(hValue));
|
||||
HostObjectHelpers::SetProperty(::UnwrapHostObject(info), index, pContextImpl->ExportValue(hValue));
|
||||
return hValue;
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Value>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Value>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Integer> V8ContextImpl::QueryHostObjectProperty(unsigned __int32 index, const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
vector<int> indices;
|
||||
|
@ -1110,39 +1114,44 @@ Handle<Integer> V8ContextImpl::QueryHostObjectProperty(unsigned __int32 index, c
|
|||
{
|
||||
if (*it == (int)index)
|
||||
{
|
||||
return ::UnwrapContextImpl(info)->GetIntegerHandle(None);
|
||||
return pContextImpl->GetIntegerHandle(None);
|
||||
}
|
||||
}
|
||||
|
||||
return Handle<Integer>();
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Integer>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Integer>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Boolean> V8ContextImpl::DeleteHostObjectProperty(unsigned __int32 index, const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
return HostObjectHelpers::DeleteProperty(::UnwrapHostObject(info), index) ? True(pContextImpl->m_pIsolate) : False(pContextImpl->m_pIsolate);
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Boolean>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Boolean>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Array> V8ContextImpl::GetHostObjectPropertyIndices(const AccessorInfo& info)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(info);
|
||||
|
||||
try
|
||||
{
|
||||
vector<int> indices;
|
||||
|
@ -1152,25 +1161,27 @@ Handle<Array> V8ContextImpl::GetHostObjectPropertyIndices(const AccessorInfo& in
|
|||
auto hImportedIndices = Array::New(indexCount);
|
||||
for (auto index = 0; index < indexCount; index++)
|
||||
{
|
||||
hImportedIndices->Set(index, Int32::New(indices[index], ::UnwrapContextImpl(info)->m_pIsolate));
|
||||
hImportedIndices->Set(index, Int32::New(indices[index], pContextImpl->m_pIsolate));
|
||||
}
|
||||
|
||||
return hImportedIndices;
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Array>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Array>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Handle<Value> V8ContextImpl::InvokeHostObject(const Arguments& args)
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(args);
|
||||
|
||||
try
|
||||
{
|
||||
auto pContextImpl = ::UnwrapContextImpl(args);
|
||||
auto argCount = args.Length();
|
||||
|
||||
vector<V8Value> exportedArgs;
|
||||
|
@ -1183,11 +1194,12 @@ Handle<Value> V8ContextImpl::InvokeHostObject(const Arguments& args)
|
|||
|
||||
return pContextImpl->ImportValue(HostObjectHelpers::Invoke(::UnwrapHostObject(args), exportedArgs, args.IsConstructCall()));
|
||||
}
|
||||
catch (const V8Exception& exception)
|
||||
catch (const HostException& exception)
|
||||
{
|
||||
ThrowException(String::New(exception.GetMessage()));
|
||||
return Handle<Value>();
|
||||
pContextImpl->ThrowScriptException(exception);
|
||||
}
|
||||
|
||||
return Handle<Value>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -1364,3 +1376,49 @@ void V8ContextImpl::ImportValues(const vector<V8Value>& values, vector<Handle<Va
|
|||
importedValues.push_back(ImportValue(values[index]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void V8ContextImpl::Verify(const TryCatch& tryCatch)
|
||||
{
|
||||
if (tryCatch.HasCaught())
|
||||
{
|
||||
if (!tryCatch.CanContinue())
|
||||
{
|
||||
throw V8Exception(V8Exception::Type_Interrupt, m_Name.c_str(), L"Script execution interrupted by host", *String::Value(tryCatch.StackTrace()), V8Value(V8Value::Undefined));
|
||||
}
|
||||
|
||||
V8Value innerException(V8Value::Undefined);
|
||||
|
||||
auto hException = tryCatch.Exception();
|
||||
if (hException->IsObject())
|
||||
{
|
||||
innerException = ExportValue(hException->ToObject()->Get(m_hInnerExceptionName));
|
||||
}
|
||||
|
||||
throw V8Exception(V8Exception::Type_General, m_Name.c_str(), *String::Value(tryCatch.Exception()), *String::Value(tryCatch.StackTrace()), innerException);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<typename T> T V8ContextImpl::Verify(const TryCatch& tryCatch, T result)
|
||||
{
|
||||
Verify(tryCatch);
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void V8ContextImpl::ThrowScriptException(const HostException& exception)
|
||||
{
|
||||
auto hException = Exception::Error(String::New(exception.GetMessage()))->ToObject();
|
||||
|
||||
auto hInnerException = ImportValue(exception.GetException());
|
||||
if (!hInnerException.IsEmpty() && hInnerException->IsObject())
|
||||
{
|
||||
hException->Set(m_hInnerExceptionName, hInnerException);
|
||||
}
|
||||
|
||||
ThrowException(hException);
|
||||
}
|
||||
|
|
|
@ -152,6 +152,11 @@ private:
|
|||
V8Value ExportValue(Handle<Value> hValue);
|
||||
void ImportValues(const vector<V8Value>& values, vector<Handle<Value>>& importedValues);
|
||||
|
||||
void Verify(const TryCatch& tryCatch);
|
||||
template<typename T> T Verify(const TryCatch& tryCatch, T result);
|
||||
void ThrowScriptException(const HostException& exception);
|
||||
|
||||
wstring m_Name;
|
||||
Isolate* m_pIsolate;
|
||||
bool m_DebugAgentEnabled;
|
||||
long m_DebugMessageDispatchCount;
|
||||
|
@ -159,6 +164,7 @@ private:
|
|||
Persistent<Object> m_hGlobal;
|
||||
vector<Persistent<Object>> m_GlobalMembersStack;
|
||||
Persistent<String> m_hHostObjectCookieName;
|
||||
Persistent<String> m_hInnerExceptionName;
|
||||
Persistent<FunctionTemplate> m_hHostObjectTemplate;
|
||||
hash_map<int, Persistent<Integer>> m_IntegerCache;
|
||||
};
|
||||
|
|
|
@ -75,9 +75,35 @@ public:
|
|||
Type_Interrupt
|
||||
};
|
||||
|
||||
explicit V8Exception(Type type, LPCWSTR pMessage, LPCWSTR pStackTrace):
|
||||
m_Type(type)
|
||||
V8Exception(Type type, LPCWSTR pEngineName, LPCWSTR pMessage, LPCWSTR pStackTrace, const V8Value& innerException):
|
||||
m_Type(type),
|
||||
m_InnerException(innerException)
|
||||
{
|
||||
if (pEngineName != nullptr)
|
||||
{
|
||||
m_EngineName = pEngineName;
|
||||
}
|
||||
|
||||
if (pMessage != nullptr)
|
||||
{
|
||||
m_Message = pMessage;
|
||||
}
|
||||
|
||||
if (pStackTrace != nullptr)
|
||||
{
|
||||
m_StackTrace = pStackTrace;
|
||||
}
|
||||
}
|
||||
|
||||
V8Exception(Type type, LPCWSTR pEngineName, LPCWSTR pMessage, LPCWSTR pStackTrace, V8Value&& innerException):
|
||||
m_Type(type),
|
||||
m_InnerException(innerException)
|
||||
{
|
||||
if (pEngineName != nullptr)
|
||||
{
|
||||
m_EngineName = pEngineName;
|
||||
}
|
||||
|
||||
if (pMessage != nullptr)
|
||||
{
|
||||
m_Message = pMessage;
|
||||
|
@ -94,6 +120,11 @@ public:
|
|||
return m_Type;
|
||||
}
|
||||
|
||||
LPCWSTR GetEngineName() const
|
||||
{
|
||||
return m_EngineName.c_str();
|
||||
}
|
||||
|
||||
LPCWSTR GetMessage() const
|
||||
{
|
||||
return m_Message.c_str();
|
||||
|
@ -104,9 +135,16 @@ public:
|
|||
return m_StackTrace.c_str();
|
||||
}
|
||||
|
||||
const V8Value& GetInnerException() const
|
||||
{
|
||||
return m_InnerException;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Type m_Type;
|
||||
wstring m_EngineName;
|
||||
wstring m_Message;
|
||||
wstring m_StackTrace;
|
||||
V8Value m_InnerException;
|
||||
};
|
||||
|
|
|
@ -104,7 +104,7 @@ V8Value V8ObjectHolderImpl::GetProperty(LPCWSTR pName) const
|
|||
|
||||
void V8ObjectHolderImpl::SetProperty(LPCWSTR pName, const V8Value& value) const
|
||||
{
|
||||
return m_psContextImpl->SetV8ObjectProperty(m_pvObject, pName, value);
|
||||
m_psContextImpl->SetV8ObjectProperty(m_pvObject, pName, value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -132,7 +132,7 @@ V8Value V8ObjectHolderImpl::GetProperty(int index) const
|
|||
|
||||
void V8ObjectHolderImpl::SetProperty(int index, const V8Value& value) const
|
||||
{
|
||||
return m_psContextImpl->SetV8ObjectProperty(m_pvObject, index, value);
|
||||
m_psContextImpl->SetV8ObjectProperty(m_pvObject, index, value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
V8ProxyImpl::ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,12 +126,7 @@ namespace V8 {
|
|||
}
|
||||
catch (const V8Exception& exception)
|
||||
{
|
||||
if (exception.GetType() == V8Exception::Type_Interrupt)
|
||||
{
|
||||
throw gcnew OperationCanceledException(gcnew String(exception.GetMessage()));
|
||||
}
|
||||
|
||||
throw gcnew InvalidOperationException(gcnew String(exception.GetMessage()));
|
||||
ThrowScriptEngineException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,7 +416,20 @@ namespace V8 {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void __declspec(noreturn) V8ProxyImpl::ThrowScriptEngineException(const V8Exception& exception)
|
||||
{
|
||||
if (exception.GetType() == V8Exception::Type_Interrupt)
|
||||
{
|
||||
throw gcnew ScriptInterruptedException(gcnew String(exception.GetEngineName()), gcnew String(exception.GetMessage()), gcnew String(exception.GetStackTrace()), 0, nullptr);
|
||||
}
|
||||
|
||||
auto gcInnerException = dynamic_cast<Exception^>(ExportValue(exception.GetInnerException()));
|
||||
throw gcnew ScriptEngineException(gcnew String(exception.GetEngineName()), gcnew String(exception.GetMessage()), gcnew String(exception.GetStackTrace()), 0, gcInnerException);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
SharedPtr<V8Context> V8ProxyImpl::GetContext()
|
||||
{
|
||||
|
|
|
@ -88,6 +88,7 @@ namespace V8 {
|
|||
|
||||
static V8Value ImportValue(Object^ gcObject);
|
||||
static Object^ ExportValue(const V8Value& value);
|
||||
static void __declspec(noreturn) ThrowScriptEngineException(const V8Exception& exception);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -146,6 +146,11 @@ public:
|
|||
Copy(that);
|
||||
}
|
||||
|
||||
V8Value(V8Value&& that)
|
||||
{
|
||||
Move(that);
|
||||
}
|
||||
|
||||
const V8Value& operator=(const V8Value& that)
|
||||
{
|
||||
Dispose();
|
||||
|
@ -153,6 +158,13 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
const V8Value& operator=(V8Value&& that)
|
||||
{
|
||||
Dispose();
|
||||
Move(that);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool IsNonexistent() const
|
||||
{
|
||||
return m_Type == Type_Nonexistent;
|
||||
|
@ -311,6 +323,13 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void Move(V8Value& that)
|
||||
{
|
||||
m_Type = that.m_Type;
|
||||
m_Data = that.m_Data;
|
||||
that.m_Type = Type_Undefined;
|
||||
}
|
||||
|
||||
void Dispose()
|
||||
{
|
||||
if (m_Type == Type_String)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Index: tools/gyp/v8.gyp
|
||||
===================================================================
|
||||
--- tools/gyp/v8.gyp (revision 13887)
|
||||
--- tools/gyp/v8.gyp (revision 14077)
|
||||
+++ tools/gyp/v8.gyp (working copy)
|
||||
@@ -32,6 +32,7 @@
|
||||
'targets': [
|
||||
|
|
|
@ -90,7 +90,6 @@ namespace Microsoft.ClearScript.V8
|
|||
private readonly dynamic script;
|
||||
private bool disposed;
|
||||
|
||||
private static readonly IUniqueNameManager embeddingHostNameManager = new UniqueNameManager();
|
||||
private readonly IUniqueNameManager documentNameManager = new UniqueFileNameManager();
|
||||
private readonly List<string> documentNames = new List<string>();
|
||||
|
||||
|
@ -141,11 +140,10 @@ namespace Microsoft.ClearScript.V8
|
|||
/// <param name="flags">A value that selects options for the operation.</param>
|
||||
/// <param name="debugPort">A TCP/IP port number on which to listen for a debugger connection.</param>
|
||||
public V8ScriptEngine(string name, V8ScriptEngineFlags flags, int debugPort)
|
||||
: base(name)
|
||||
{
|
||||
var uniqueName = embeddingHostNameManager.GetUniqueName(name, GetType().GetRootName());
|
||||
|
||||
engineFlags = flags;
|
||||
proxy = V8Proxy.Create(uniqueName, flags.HasFlag(V8ScriptEngineFlags.EnableDebugging), flags.HasFlag(V8ScriptEngineFlags.DisableGlobalMembers), debugPort);
|
||||
proxy = V8Proxy.Create(Name, flags.HasFlag(V8ScriptEngineFlags.EnableDebugging), flags.HasFlag(V8ScriptEngineFlags.DisableGlobalMembers), debugPort);
|
||||
script = GetRootItem();
|
||||
|
||||
var engineInternal = Evaluate(
|
||||
|
@ -347,7 +345,13 @@ namespace Microsoft.ClearScript.V8
|
|||
return obj;
|
||||
}
|
||||
|
||||
obj = hostItem.Unwrap();
|
||||
obj = hostItem.Target;
|
||||
}
|
||||
|
||||
var hostTarget = obj as HostTarget;
|
||||
if (hostTarget != null)
|
||||
{
|
||||
obj = hostTarget.Target;
|
||||
}
|
||||
|
||||
var scriptItem = obj as ScriptItem;
|
||||
|
@ -359,7 +363,7 @@ namespace Microsoft.ClearScript.V8
|
|||
}
|
||||
}
|
||||
|
||||
return HostItem.Wrap(this, obj, flags);
|
||||
return HostItem.Wrap(this, hostTarget ?? obj, flags);
|
||||
}
|
||||
|
||||
internal override object MarshalToHost(object obj, bool preserveHostTarget)
|
||||
|
@ -374,6 +378,12 @@ namespace Microsoft.ClearScript.V8
|
|||
return null;
|
||||
}
|
||||
|
||||
var hostTarget = obj as HostTarget;
|
||||
if (hostTarget != null)
|
||||
{
|
||||
return preserveHostTarget ? hostTarget : hostTarget.Target;
|
||||
}
|
||||
|
||||
var hostItem = obj as HostItem;
|
||||
if (hostItem != null)
|
||||
{
|
||||
|
|
|
@ -189,7 +189,15 @@ namespace Microsoft.ClearScript.V8
|
|||
{
|
||||
if (engine.CurrentScriptFrame != null)
|
||||
{
|
||||
engine.CurrentScriptFrame.SetScriptError(exception);
|
||||
var scriptError = exception as IScriptEngineException;
|
||||
if (scriptError != null)
|
||||
{
|
||||
engine.CurrentScriptFrame.ScriptError = scriptError;
|
||||
}
|
||||
else
|
||||
{
|
||||
engine.CurrentScriptFrame.ScriptError = new ScriptEngineException(engine.Name, exception.Message, null, RawCOMHelpers.HResult.CLEARSCRIPT_E_SCRIPTITEMEXCEPTION, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,5 +61,5 @@
|
|||
|
||||
|
||||
|
||||
#define CLEARSCRIPT_VERSION_STRING "5.1.3.0"
|
||||
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,1,3,0
|
||||
#define CLEARSCRIPT_VERSION_STRING "5.2.0.0"
|
||||
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,2,0,0
|
||||
|
|
|
@ -148,6 +148,42 @@ namespace Microsoft.ClearScript.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region structures
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DebugStackFrameDescriptor
|
||||
{
|
||||
[MarshalAs(UnmanagedType.Interface)]
|
||||
public IDebugStackFrame Frame;
|
||||
|
||||
public uint Minimum;
|
||||
public uint Limit;
|
||||
|
||||
[MarshalAs(UnmanagedType.Bool)]
|
||||
public bool IsFinal;
|
||||
|
||||
[MarshalAs(UnmanagedType.Interface)]
|
||||
public object FinalObject;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DebugStackFrameDescriptor64
|
||||
{
|
||||
[MarshalAs(UnmanagedType.Interface)]
|
||||
public IDebugStackFrame Frame;
|
||||
|
||||
public ulong Minimum;
|
||||
public ulong Limit;
|
||||
|
||||
[MarshalAs(UnmanagedType.Bool)]
|
||||
public bool final;
|
||||
|
||||
[MarshalAs(UnmanagedType.Interface)]
|
||||
public object FinalObject;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region interfaces
|
||||
|
||||
[ComImport]
|
||||
|
@ -876,6 +912,136 @@ namespace Microsoft.ClearScript.Windows
|
|||
);
|
||||
};
|
||||
|
||||
[ComImport]
|
||||
[Guid("51973c18-cb0c-11d0-b5c9-00a0244a0e7a")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IDebugStackFrameSniffer
|
||||
{
|
||||
void EnumStackFrames(
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames
|
||||
);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("51973c19-cb0c-11d0-b5c9-00a0244a0e7a")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IDebugStackFrameSnifferEx32 // : IDebugStackFrameSniffer
|
||||
{
|
||||
#region IDebugStackFrameSniffer methods
|
||||
|
||||
void EnumStackFrames(
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
void EnumStackFramesEx32(
|
||||
[In] uint minimum,
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames
|
||||
);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("8cd12af4-49c1-4d52-8d8a-c146f47581aa")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IDebugStackFrameSnifferEx64 // : IDebugStackFrameSniffer
|
||||
{
|
||||
#region IDebugStackFrameSniffer methods
|
||||
|
||||
void EnumStackFrames(
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
void EnumStackFramesEx64(
|
||||
[In] ulong minimum,
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames
|
||||
);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("51973c1e-cb0c-11d0-b5c9-00a0244a0e7a")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IEnumDebugStackFrames
|
||||
{
|
||||
void Next(
|
||||
[In] uint count,
|
||||
[Out] [MarshalAs(UnmanagedType.Struct)] out DebugStackFrameDescriptor descriptor,
|
||||
[Out] out uint countFetched
|
||||
);
|
||||
|
||||
void Skip(
|
||||
[In] uint count
|
||||
);
|
||||
|
||||
void Reset();
|
||||
|
||||
void Clone(
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames
|
||||
);
|
||||
};
|
||||
|
||||
[ComImport]
|
||||
[Guid("0dc38853-c1b0-4176-a984-b298361027af")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IEnumDebugStackFrames64 // : IEnumDebugStackFrames
|
||||
{
|
||||
#region IEnumDebugStackFrames methods
|
||||
|
||||
void Next(
|
||||
[In] uint count,
|
||||
[Out] [MarshalAs(UnmanagedType.Struct)] out DebugStackFrameDescriptor descriptor,
|
||||
[Out] out uint countFetched
|
||||
);
|
||||
|
||||
void Skip(
|
||||
[In] uint count
|
||||
);
|
||||
|
||||
void Reset();
|
||||
|
||||
void Clone(
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
void Next64(
|
||||
[In] uint count,
|
||||
[Out] [MarshalAs(UnmanagedType.Struct)] out DebugStackFrameDescriptor64 descriptor,
|
||||
[Out] out uint countFetched
|
||||
);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("51973c17-cb0c-11d0-b5c9-00a0244a0e7a")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IDebugStackFrame
|
||||
{
|
||||
void GetCodeContext(
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IDebugCodeContext context
|
||||
);
|
||||
|
||||
void GetDescriptionString(
|
||||
[In] [MarshalAs(UnmanagedType.Bool)] bool longString,
|
||||
[Out] [MarshalAs(UnmanagedType.BStr)] out string description
|
||||
);
|
||||
|
||||
void GetLanguageString(
|
||||
[In] [MarshalAs(UnmanagedType.Bool)] bool longString,
|
||||
[Out] [MarshalAs(UnmanagedType.BStr)] out string language
|
||||
);
|
||||
|
||||
void GetThread(
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IDebugApplicationThread thread
|
||||
);
|
||||
|
||||
void GetDebugProperty(
|
||||
[Out] [MarshalAs(UnmanagedType.Interface)] out IDebugProperty property
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region interface stubs
|
||||
|
@ -960,14 +1126,6 @@ namespace Microsoft.ClearScript.Windows
|
|||
// methods omitted
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("51973c18-cb0c-11d0-b5c9-00a0244a0e7a")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IDebugStackFrameSniffer
|
||||
{
|
||||
// methods omitted
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("51973c36-cb0c-11d0-b5c9-00a0244a0e7a")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
|
@ -1026,5 +1184,13 @@ namespace Microsoft.ClearScript.Windows
|
|||
// methods omitted
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("51973c50-cb0c-11d0-b5c9-00a0244a0e7a")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IDebugProperty
|
||||
{
|
||||
// methods omitted
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -98,6 +98,8 @@ namespace Microsoft.ClearScript.Windows
|
|||
|
||||
public abstract void EnumCodeContextsOfPosition(UIntPtr sourceContext, uint offset, uint length, out IEnumDebugCodeContexts enumContexts);
|
||||
|
||||
public abstract void EnumStackFrames(out IEnumDebugStackFrames enumFrames);
|
||||
|
||||
public abstract void Close();
|
||||
}
|
||||
|
||||
|
@ -105,13 +107,15 @@ namespace Microsoft.ClearScript.Windows
|
|||
{
|
||||
// ReSharper disable NotAccessedField.Local
|
||||
|
||||
private IntPtr pClearScript;
|
||||
private IntPtr pClearScriptParse;
|
||||
private IntPtr pClearScriptDebug;
|
||||
private IntPtr pActiveScript;
|
||||
private IntPtr pActiveScriptParse;
|
||||
private IntPtr pActiveScriptDebug;
|
||||
private IntPtr pDebugStackFrameSniffer;
|
||||
|
||||
private IActiveScript activeScript;
|
||||
private IActiveScriptParse32 activeScriptParse;
|
||||
private IActiveScriptDebug32 activeScriptDebug;
|
||||
private IDebugStackFrameSnifferEx32 debugStackFrameSniffer;
|
||||
|
||||
// ReSharper restore NotAccessedField.Local
|
||||
|
||||
|
@ -132,13 +136,15 @@ namespace Microsoft.ClearScript.Windows
|
|||
|
||||
public ActiveScriptWrapper32(string progID)
|
||||
{
|
||||
pClearScript = RawCOMHelpers.CreateInstance<IActiveScript>(progID);
|
||||
pClearScriptParse = RawCOMHelpers.QueryInterface<IActiveScriptParse32>(pClearScript);
|
||||
pClearScriptDebug = RawCOMHelpers.QueryInterface<IActiveScriptDebug32>(pClearScript);
|
||||
pActiveScript = RawCOMHelpers.CreateInstance<IActiveScript>(progID);
|
||||
pActiveScriptParse = RawCOMHelpers.QueryInterface<IActiveScriptParse32>(pActiveScript);
|
||||
pActiveScriptDebug = RawCOMHelpers.QueryInterface<IActiveScriptDebug32>(pActiveScript);
|
||||
pDebugStackFrameSniffer = RawCOMHelpers.QueryInterface<IDebugStackFrameSnifferEx32>(pActiveScript);
|
||||
|
||||
activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pClearScript);
|
||||
activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript);
|
||||
activeScriptParse = (IActiveScriptParse32)activeScript;
|
||||
activeScriptDebug = (IActiveScriptDebug32)activeScript;
|
||||
debugStackFrameSniffer = (IDebugStackFrameSnifferEx32)activeScript;
|
||||
}
|
||||
|
||||
public override void SetScriptSite(IActiveScriptSite site)
|
||||
|
@ -178,27 +184,34 @@ namespace Microsoft.ClearScript.Windows
|
|||
|
||||
public override void InterruptScriptThread(uint scriptThreadID, ref EXCEPINFO excepInfo, ScriptInterruptFlags flags)
|
||||
{
|
||||
var del = RawCOMHelpers.GetMethodDelegate<RawInterruptScriptThread>(pClearScript, 14);
|
||||
del(pClearScript, scriptThreadID, ref excepInfo, flags);
|
||||
var del = RawCOMHelpers.GetMethodDelegate<RawInterruptScriptThread>(pActiveScript, 14);
|
||||
del(pActiveScript, scriptThreadID, ref excepInfo, flags);
|
||||
}
|
||||
|
||||
public override void EnumCodeContextsOfPosition(UIntPtr sourceContext, uint offset, uint length, out IEnumDebugCodeContexts enumContexts)
|
||||
{
|
||||
var del = RawCOMHelpers.GetMethodDelegate<RawEnumCodeContextsOfPosition>(pClearScriptDebug, 5);
|
||||
RawCOMHelpers.HResult.Check(del(pClearScriptDebug, sourceContext.ToUInt32(), offset, length, out enumContexts));
|
||||
var del = RawCOMHelpers.GetMethodDelegate<RawEnumCodeContextsOfPosition>(pActiveScriptDebug, 5);
|
||||
RawCOMHelpers.HResult.Check(del(pActiveScriptDebug, sourceContext.ToUInt32(), offset, length, out enumContexts));
|
||||
}
|
||||
|
||||
public override void EnumStackFrames(out IEnumDebugStackFrames enumFrames)
|
||||
{
|
||||
debugStackFrameSniffer.EnumStackFrames(out enumFrames);
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
activeScript.Close();
|
||||
|
||||
debugStackFrameSniffer = null;
|
||||
activeScriptDebug = null;
|
||||
activeScriptParse = null;
|
||||
activeScript = null;
|
||||
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pClearScriptDebug);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pClearScriptParse);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pClearScript);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pDebugStackFrameSniffer);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptDebug);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptParse);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pActiveScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,13 +219,15 @@ namespace Microsoft.ClearScript.Windows
|
|||
{
|
||||
// ReSharper disable NotAccessedField.Local
|
||||
|
||||
private IntPtr pClearScript;
|
||||
private IntPtr pClearScriptParse;
|
||||
private IntPtr pClearScriptDebug;
|
||||
private IntPtr pActiveScript;
|
||||
private IntPtr pActiveScriptParse;
|
||||
private IntPtr pActiveScriptDebug;
|
||||
private IntPtr pDebugStackFrameSniffer;
|
||||
|
||||
private IActiveScript activeScript;
|
||||
private IActiveScriptParse64 activeScriptParse;
|
||||
private IActiveScriptDebug64 activeScriptDebug;
|
||||
private IDebugStackFrameSnifferEx64 debugStackFrameSniffer;
|
||||
|
||||
// ReSharper restore NotAccessedField.Local
|
||||
|
||||
|
@ -233,13 +248,15 @@ namespace Microsoft.ClearScript.Windows
|
|||
|
||||
public ActiveScriptWrapper64(string progID)
|
||||
{
|
||||
pClearScript = RawCOMHelpers.CreateInstance<IActiveScript>(progID);
|
||||
pClearScriptParse = RawCOMHelpers.QueryInterface<IActiveScriptParse64>(pClearScript);
|
||||
pClearScriptDebug = RawCOMHelpers.QueryInterface<IActiveScriptDebug64>(pClearScript);
|
||||
pActiveScript = RawCOMHelpers.CreateInstance<IActiveScript>(progID);
|
||||
pActiveScriptParse = RawCOMHelpers.QueryInterface<IActiveScriptParse64>(pActiveScript);
|
||||
pActiveScriptDebug = RawCOMHelpers.QueryInterface<IActiveScriptDebug64>(pActiveScript);
|
||||
pDebugStackFrameSniffer = RawCOMHelpers.QueryInterface<IDebugStackFrameSnifferEx64>(pActiveScript);
|
||||
|
||||
activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pClearScript);
|
||||
activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript);
|
||||
activeScriptParse = (IActiveScriptParse64)activeScript;
|
||||
activeScriptDebug = (IActiveScriptDebug64)activeScript;
|
||||
debugStackFrameSniffer = (IDebugStackFrameSnifferEx64)activeScript;
|
||||
}
|
||||
|
||||
public override void SetScriptSite(IActiveScriptSite site)
|
||||
|
@ -279,27 +296,34 @@ namespace Microsoft.ClearScript.Windows
|
|||
|
||||
public override void InterruptScriptThread(uint scriptThreadID, ref EXCEPINFO excepInfo, ScriptInterruptFlags flags)
|
||||
{
|
||||
var del = RawCOMHelpers.GetMethodDelegate<RawInterruptScriptThread>(pClearScript, 14);
|
||||
del(pClearScript, scriptThreadID, ref excepInfo, flags);
|
||||
var del = RawCOMHelpers.GetMethodDelegate<RawInterruptScriptThread>(pActiveScript, 14);
|
||||
del(pActiveScript, scriptThreadID, ref excepInfo, flags);
|
||||
}
|
||||
|
||||
public override void EnumCodeContextsOfPosition(UIntPtr sourceContext, uint offset, uint length, out IEnumDebugCodeContexts enumContexts)
|
||||
{
|
||||
var del = RawCOMHelpers.GetMethodDelegate<RawEnumCodeContextsOfPosition>(pClearScriptDebug, 5);
|
||||
RawCOMHelpers.HResult.Check(del(pClearScriptDebug, sourceContext.ToUInt64(), offset, length, out enumContexts));
|
||||
var del = RawCOMHelpers.GetMethodDelegate<RawEnumCodeContextsOfPosition>(pActiveScriptDebug, 5);
|
||||
RawCOMHelpers.HResult.Check(del(pActiveScriptDebug, sourceContext.ToUInt64(), offset, length, out enumContexts));
|
||||
}
|
||||
|
||||
public override void EnumStackFrames(out IEnumDebugStackFrames enumFrames)
|
||||
{
|
||||
debugStackFrameSniffer.EnumStackFrames(out enumFrames);
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
activeScript.Close();
|
||||
|
||||
debugStackFrameSniffer = null;
|
||||
activeScriptDebug = null;
|
||||
activeScriptParse = null;
|
||||
activeScript = null;
|
||||
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pClearScriptDebug);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pClearScriptParse);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pClearScript);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pDebugStackFrameSniffer);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptDebug);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptParse);
|
||||
RawCOMHelpers.ReleaseAndEmpty(ref pActiveScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,11 @@ namespace Microsoft.ClearScript.Windows
|
|||
node.Attach(rootNode);
|
||||
}
|
||||
|
||||
public string Code
|
||||
{
|
||||
get { return code; }
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
node.Detach();
|
||||
|
@ -118,7 +123,7 @@ namespace Microsoft.ClearScript.Windows
|
|||
{
|
||||
case DocumentNameType.URL:
|
||||
var fullName = Path.HasExtension(name) ? name : Path.ChangeExtension(name, engine.FileNameExtension);
|
||||
documentName = MiscHelpers.FormatInvariant("{0}/{1}", engine.debugApplicationName, fullName);
|
||||
documentName = MiscHelpers.FormatInvariant("{0}/{1}", engine.Name, fullName);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.ClearScript.Util;
|
||||
using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO;
|
||||
|
@ -81,6 +82,138 @@ namespace Microsoft.ClearScript.Windows
|
|||
this.engine = engine;
|
||||
}
|
||||
|
||||
private string GetDetails(object error, string message)
|
||||
{
|
||||
if (engine.engineFlags.HasFlag(WindowsScriptEngineFlags.EnableDebugging))
|
||||
{
|
||||
try
|
||||
{
|
||||
var stackTrace = GetStackTrace();
|
||||
if (!string.IsNullOrWhiteSpace(stackTrace))
|
||||
{
|
||||
return message + "\n" + stackTrace;
|
||||
}
|
||||
|
||||
var errorLocation = GetErrorLocation(error);
|
||||
if (!string.IsNullOrWhiteSpace(errorLocation))
|
||||
{
|
||||
return message + "\n" + errorLocation;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.Assert(false, "Exception caught during error processing", exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
private string GetStackTrace()
|
||||
{
|
||||
var stackTrace = string.Empty;
|
||||
|
||||
IEnumDebugStackFrames enumFrames;
|
||||
engine.activeScript.EnumStackFrames(out enumFrames);
|
||||
|
||||
while (true)
|
||||
{
|
||||
DebugStackFrameDescriptor descriptor;
|
||||
uint countFetched;
|
||||
enumFrames.Next(1, out descriptor, out countFetched);
|
||||
if (countFetched < 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string description;
|
||||
descriptor.Frame.GetDescriptionString(true, out description);
|
||||
|
||||
IDebugCodeContext codeContext;
|
||||
descriptor.Frame.GetCodeContext(out codeContext);
|
||||
|
||||
IDebugDocumentContext documentContext;
|
||||
codeContext.GetDocumentContext(out documentContext);
|
||||
|
||||
IDebugDocument document;
|
||||
documentContext.GetDocument(out document);
|
||||
var documentText = (IDebugDocumentText)document;
|
||||
|
||||
string documentName;
|
||||
document.GetName(DocumentNameType.Title, out documentName);
|
||||
|
||||
uint position;
|
||||
uint length;
|
||||
documentText.GetPositionOfContext(documentContext, out position, out length);
|
||||
|
||||
var pBuffer = Marshal.AllocCoTaskMem((int)(sizeof(char) * length));
|
||||
try
|
||||
{
|
||||
uint lengthReturned = 0;
|
||||
documentText.GetText(position, pBuffer, IntPtr.Zero, ref lengthReturned, length);
|
||||
var codeLine = Marshal.PtrToStringUni(pBuffer, (int)lengthReturned);
|
||||
|
||||
uint lineNumber;
|
||||
uint offsetInLine;
|
||||
documentText.GetLineOfPosition(position, out lineNumber, out offsetInLine);
|
||||
|
||||
stackTrace += MiscHelpers.FormatInvariant(" at {0} ({1}:{2}:{3}) -> {4}\n", description, documentName, lineNumber, offsetInLine, codeLine);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pBuffer);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (descriptor.FinalObject != null)
|
||||
{
|
||||
Marshal.ReleaseComObject(descriptor.FinalObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stackTrace;
|
||||
}
|
||||
|
||||
private string GetErrorLocation(object error)
|
||||
{
|
||||
var scriptError = error as IActiveScriptError;
|
||||
if (scriptError != null)
|
||||
{
|
||||
uint sourceContext;
|
||||
uint lineNumber;
|
||||
int offsetInLine;
|
||||
scriptError.GetSourcePosition(out sourceContext, out lineNumber, out offsetInLine);
|
||||
|
||||
DebugDocument document;
|
||||
if (engine.debugDocumentMap.TryGetValue(new UIntPtr(sourceContext), out document))
|
||||
{
|
||||
string documentName;
|
||||
document.GetName(DocumentNameType.Title, out documentName);
|
||||
|
||||
int position;
|
||||
if (lineNumber > 0)
|
||||
{
|
||||
uint linePosition;
|
||||
document.GetPositionOfLine(--lineNumber, out linePosition);
|
||||
position = (int)linePosition + offsetInLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
position = offsetInLine;
|
||||
}
|
||||
|
||||
var text = new string(document.Code.Skip(position).TakeWhile(ch => ch != '\n').ToArray());
|
||||
return MiscHelpers.FormatInvariant(" at ({0}:{1}:{2}) -> {3}", documentName, lineNumber, offsetInLine, text);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#region IActiveScriptSite implementation
|
||||
|
||||
public void GetLCID(out uint lcid)
|
||||
|
@ -122,18 +255,36 @@ namespace Microsoft.ClearScript.Windows
|
|||
{
|
||||
EXCEPINFO excepInfo;
|
||||
error.GetExceptionInfo(out excepInfo);
|
||||
if (excepInfo.scode == MiscHelpers.UnsignedAsSigned(RawCOMHelpers.HResult.E_ABORT))
|
||||
if (excepInfo.scode == RawCOMHelpers.HResult.E_ABORT)
|
||||
{
|
||||
// Script execution was interrupted explicitly. At this point the script
|
||||
// engine might be in an odd state; the following call seems to get it back
|
||||
// to normal.
|
||||
|
||||
engine.activeScript.SetScriptState(ScriptState.Started);
|
||||
engine.CurrentScriptFrame.SetScriptError(new OperationCanceledException(excepInfo.bstrDescription ?? "Script execution interrupted by host"));
|
||||
|
||||
var description = excepInfo.bstrDescription ?? "Script execution interrupted by host";
|
||||
engine.CurrentScriptFrame.ScriptError = new ScriptInterruptedException(engine.Name, description, GetDetails(error, description), excepInfo.scode, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
engine.CurrentScriptFrame.SetScriptError(new ExternalException(excepInfo.bstrDescription, excepInfo.scode));
|
||||
var description = excepInfo.bstrDescription;
|
||||
|
||||
Exception innerException;
|
||||
if (excepInfo.scode != RawCOMHelpers.HResult.CLEARSCRIPT_E_HOSTEXCEPTION)
|
||||
{
|
||||
innerException = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
innerException = engine.CurrentScriptFrame.HostException;
|
||||
if ((innerException != null) && string.IsNullOrWhiteSpace(description))
|
||||
{
|
||||
description = innerException.Message;
|
||||
}
|
||||
}
|
||||
|
||||
engine.CurrentScriptFrame.ScriptError = new ScriptEngineException(engine.Name, description, GetDetails(error, description), excepInfo.scode, innerException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +311,7 @@ namespace Microsoft.ClearScript.Windows
|
|||
keepGoing = keepGoing && !engine.CurrentScriptFrame.InterruptRequested;
|
||||
}
|
||||
|
||||
return keepGoing ? RawCOMHelpers.HResult.S_OK : RawCOMHelpers.HResult.E_ABORT;
|
||||
return keepGoing ? RawCOMHelpers.HResult.S_OK : MiscHelpers.SignedAsUnsigned(RawCOMHelpers.HResult.E_ABORT);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -193,13 +344,30 @@ namespace Microsoft.ClearScript.Windows
|
|||
{
|
||||
EXCEPINFO excepInfo;
|
||||
errorDebug.GetExceptionInfo(out excepInfo);
|
||||
if (excepInfo.scode == MiscHelpers.UnsignedAsSigned(RawCOMHelpers.HResult.E_ABORT))
|
||||
if (excepInfo.scode == RawCOMHelpers.HResult.E_ABORT)
|
||||
{
|
||||
engine.CurrentScriptFrame.SetPendingScriptError(new OperationCanceledException(excepInfo.bstrDescription ?? "Script execution interrupted by host"));
|
||||
var description = excepInfo.bstrDescription ?? "Script execution interrupted by host";
|
||||
engine.CurrentScriptFrame.PendingScriptError = new ScriptInterruptedException(engine.Name, description, GetDetails(errorDebug, description), excepInfo.scode, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
engine.CurrentScriptFrame.SetPendingScriptError(new ExternalException(excepInfo.bstrDescription, excepInfo.scode));
|
||||
var description = excepInfo.bstrDescription;
|
||||
|
||||
Exception innerException;
|
||||
if (excepInfo.scode != RawCOMHelpers.HResult.CLEARSCRIPT_E_HOSTEXCEPTION)
|
||||
{
|
||||
innerException = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
innerException = engine.CurrentScriptFrame.HostException;
|
||||
if ((innerException != null) && string.IsNullOrWhiteSpace(description))
|
||||
{
|
||||
description = innerException.Message;
|
||||
}
|
||||
}
|
||||
|
||||
engine.CurrentScriptFrame.PendingScriptError = new ScriptEngineException(engine.Name, description, GetDetails(errorDebug, description), excepInfo.scode, innerException);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,17 +90,14 @@ namespace Microsoft.ClearScript.Windows
|
|||
private readonly dynamic script;
|
||||
|
||||
private ProcessDebugManagerWrapper processDebugManager;
|
||||
private string debugApplicationName;
|
||||
private DebugApplicationWrapper debugApplication;
|
||||
private uint debugApplicationCookie;
|
||||
private readonly IUniqueNameManager debugDocumentNameManager = new UniqueFileNameManager();
|
||||
|
||||
private bool sourceManagement;
|
||||
private readonly DebugDocumentMap debugDocumentMap = new DebugDocumentMap();
|
||||
private uint nextSourceContext = 1;
|
||||
|
||||
private static readonly IUniqueNameManager debugApplicationNameManager = new UniqueNameManager();
|
||||
private readonly IUniqueNameManager debugDocumentNameManager = new UniqueFileNameManager();
|
||||
|
||||
private readonly Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
|
||||
private bool disposed;
|
||||
|
||||
|
@ -119,6 +116,7 @@ namespace Microsoft.ClearScript.Windows
|
|||
/// GUID format with braces (e.g., "{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}").
|
||||
/// </remarks>
|
||||
protected WindowsScriptEngine(string progID, string name, WindowsScriptEngineFlags flags)
|
||||
: base(name)
|
||||
{
|
||||
AccessContext = typeof(ScriptEngine);
|
||||
script = base.ScriptInvoke(() =>
|
||||
|
@ -130,8 +128,7 @@ namespace Microsoft.ClearScript.Windows
|
|||
{
|
||||
processDebugManager = ProcessDebugManagerWrapper.Create();
|
||||
processDebugManager.CreateApplication(out debugApplication);
|
||||
debugApplicationName = debugApplicationNameManager.GetUniqueName(name, GetType().GetRootName());
|
||||
debugApplication.SetName(debugApplicationName);
|
||||
debugApplication.SetName(Name);
|
||||
processDebugManager.AddApplication(debugApplication, out debugApplicationCookie);
|
||||
sourceManagement = !flags.HasFlag(WindowsScriptEngineFlags.DisableSourceManagement);
|
||||
}
|
||||
|
@ -268,7 +265,7 @@ namespace Microsoft.ClearScript.Windows
|
|||
{
|
||||
VerifyNotDisposed();
|
||||
|
||||
var excepInfo = new EXCEPINFO { scode = MiscHelpers.UnsignedAsSigned(RawCOMHelpers.HResult.E_ABORT) };
|
||||
var excepInfo = new EXCEPINFO { scode = RawCOMHelpers.HResult.E_ABORT };
|
||||
activeScript.InterruptScriptThread(ScriptThreadID.Base, ref excepInfo, ScriptInterruptFlags.None);
|
||||
}
|
||||
|
||||
|
@ -336,7 +333,13 @@ namespace Microsoft.ClearScript.Windows
|
|||
return obj;
|
||||
}
|
||||
|
||||
obj = hostItem.Unwrap();
|
||||
obj = hostItem.Target;
|
||||
}
|
||||
|
||||
var hostTarget = obj as HostTarget;
|
||||
if (hostTarget != null)
|
||||
{
|
||||
obj = hostTarget.Target;
|
||||
}
|
||||
|
||||
var scriptItem = obj as ScriptItem;
|
||||
|
@ -348,7 +351,7 @@ namespace Microsoft.ClearScript.Windows
|
|||
}
|
||||
}
|
||||
|
||||
return HostItem.Wrap(this, obj, flags);
|
||||
return HostItem.Wrap(this, hostTarget ?? obj, flags);
|
||||
}
|
||||
|
||||
internal override object MarshalToHost(object obj, bool preserveHostTarget)
|
||||
|
@ -371,6 +374,12 @@ namespace Microsoft.ClearScript.Windows
|
|||
return array;
|
||||
}
|
||||
|
||||
var hostTarget = obj as HostTarget;
|
||||
if (hostTarget != null)
|
||||
{
|
||||
return preserveHostTarget ? hostTarget : hostTarget.Target;
|
||||
}
|
||||
|
||||
var hostItem = obj as HostItem;
|
||||
if (hostItem != null)
|
||||
{
|
||||
|
@ -420,18 +429,108 @@ namespace Microsoft.ClearScript.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region ScriptEngine overrides (host-side invocation)
|
||||
|
||||
internal override void HostInvoke(Action action)
|
||||
{
|
||||
try
|
||||
{
|
||||
base.HostInvoke(action);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
ThrowHostException(exception);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal override T HostInvoke<T>(Func<T> func)
|
||||
{
|
||||
try
|
||||
{
|
||||
return base.HostInvoke(func);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
ThrowHostException(exception);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void ThrowHostException(Exception exception)
|
||||
{
|
||||
if (CurrentScriptFrame != null)
|
||||
{
|
||||
// Record the host exception in the script frame and throw an easily recognizable
|
||||
// surrogate across the COM boundary. Recording the host exception enables
|
||||
// downstream chaining. The surrogate exception indicates to the site that the
|
||||
// reported script error actually corresponds to the host exception in the frame.
|
||||
|
||||
CurrentScriptFrame.HostException = exception;
|
||||
throw new COMException(exception.Message, RawCOMHelpers.HResult.CLEARSCRIPT_E_HOSTEXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ScriptEngine overrides (script-side invocation)
|
||||
|
||||
internal override void ScriptInvoke(Action action)
|
||||
{
|
||||
VerifyAccess();
|
||||
base.ScriptInvoke(action);
|
||||
base.ScriptInvoke(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
ThrowScriptError(exception);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
internal override T ScriptInvoke<T>(Func<T> func)
|
||||
{
|
||||
VerifyAccess();
|
||||
return base.ScriptInvoke(func);
|
||||
return base.ScriptInvoke(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return func();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
ThrowScriptError(exception);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void ThrowScriptError(Exception exception)
|
||||
{
|
||||
if (exception is COMException)
|
||||
{
|
||||
if (exception.HResult == RawCOMHelpers.HResult.SCRIPT_E_REPORTED)
|
||||
{
|
||||
// a script error was reported; the corresponding exception should be in the script frame
|
||||
ThrowScriptError(CurrentScriptFrame.ScriptError ?? CurrentScriptFrame.PendingScriptError);
|
||||
}
|
||||
else if (exception.HResult == RawCOMHelpers.HResult.CLEARSCRIPT_E_HOSTEXCEPTION)
|
||||
{
|
||||
// A host exception surrogate passed through the COM boundary; this happens
|
||||
// when some script engines are invoked via script item access rather than
|
||||
// script execution. Chain the host exception to a new script exception.
|
||||
|
||||
var hostException = CurrentScriptFrame.HostException;
|
||||
if (hostException != null)
|
||||
{
|
||||
throw new ScriptEngineException(Name, hostException.Message, null, RawCOMHelpers.HResult.CLEARSCRIPT_E_SCRIPTITEMEXCEPTION, hostException);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -65,7 +65,6 @@ using System.Dynamic;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Expando;
|
||||
using Microsoft.ClearScript.Util;
|
||||
|
||||
|
@ -101,6 +100,77 @@ namespace Microsoft.ClearScript.Windows
|
|||
return obj;
|
||||
}
|
||||
|
||||
private IScriptEngineException GetScriptError(Exception exception)
|
||||
{
|
||||
IScriptEngineException scriptError;
|
||||
if (TryGetScriptError(exception, out scriptError))
|
||||
{
|
||||
return scriptError;
|
||||
}
|
||||
|
||||
return new ScriptEngineException(engine.Name, exception.Message, null, RawCOMHelpers.HResult.CLEARSCRIPT_E_SCRIPTITEMEXCEPTION, exception);
|
||||
}
|
||||
|
||||
private bool TryGetScriptError(Exception exception, out IScriptEngineException scriptError)
|
||||
{
|
||||
// WORKAROUND: Windows Script items often throw ugly exceptions. The code here
|
||||
// attempts to clean up specific cases.
|
||||
|
||||
while (exception is TargetInvocationException)
|
||||
{
|
||||
exception = exception.InnerException;
|
||||
}
|
||||
|
||||
scriptError = exception as IScriptEngineException;
|
||||
if (scriptError != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
var hr = exception.HResult;
|
||||
if ((hr == RawCOMHelpers.HResult.SCRIPT_E_REPORTED) && (engine.CurrentScriptFrame != null))
|
||||
{
|
||||
scriptError = engine.CurrentScriptFrame.ScriptError ?? engine.CurrentScriptFrame.PendingScriptError;
|
||||
if (scriptError != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (RawCOMHelpers.HResult.GetFacility(hr) == RawCOMHelpers.HResult.FACILITY_CONTROL)
|
||||
{
|
||||
// These exceptions often have awful messages that include COM error codes.
|
||||
// The engine itself may be able to provide a better message.
|
||||
|
||||
string message;
|
||||
if (engine.RuntimeErrorMap.TryGetValue(RawCOMHelpers.HResult.GetCode(hr), out message) && (message != exception.Message))
|
||||
{
|
||||
scriptError = new ScriptEngineException(engine.Name, message, null, RawCOMHelpers.HResult.CLEARSCRIPT_E_SCRIPTITEMEXCEPTION, exception.InnerException);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (hr == RawCOMHelpers.HResult.DISP_E_MEMBERNOTFOUND)
|
||||
{
|
||||
// this usually indicates invalid object or property access in JScript
|
||||
scriptError = new ScriptEngineException(engine.Name, "Invalid object or property access", null, RawCOMHelpers.HResult.CLEARSCRIPT_E_SCRIPTITEMEXCEPTION, exception.InnerException);
|
||||
return true;
|
||||
}
|
||||
else if (hr == RawCOMHelpers.HResult.E_INVALIDARG)
|
||||
{
|
||||
var argumentException = exception as ArgumentException;
|
||||
if ((argumentException != null) && (argumentException.ParamName == null))
|
||||
{
|
||||
// this usually indicates invalid object or property access in VBScript
|
||||
scriptError = new ScriptEngineException(engine.Name, "Invalid object or property access", null, RawCOMHelpers.HResult.CLEARSCRIPT_E_SCRIPTITEMEXCEPTION, exception.InnerException);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#region ScriptItem overrides
|
||||
|
||||
public override ScriptEngine Engine
|
||||
|
@ -110,7 +180,28 @@ namespace Microsoft.ClearScript.Windows
|
|||
|
||||
protected override bool TryBindAndInvoke(DynamicMetaObjectBinder binder, object[] args, out object result)
|
||||
{
|
||||
return DynamicHelpers.TryBindAndInvoke(binder, target, args, out result);
|
||||
var succeeded = DynamicHelpers.TryBindAndInvoke(binder, target, args, out result);
|
||||
if (!succeeded)
|
||||
{
|
||||
var exception = result as Exception;
|
||||
if ((exception != null) && (engine.CurrentScriptFrame != null))
|
||||
{
|
||||
var scriptError = exception as IScriptEngineException;
|
||||
if (scriptError != null)
|
||||
{
|
||||
engine.CurrentScriptFrame.ScriptError = scriptError;
|
||||
}
|
||||
else
|
||||
{
|
||||
engine.CurrentScriptFrame.ScriptError = GetScriptError(exception);
|
||||
}
|
||||
}
|
||||
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override object[] AdjustInvokeArgs(object[] args)
|
||||
|
@ -131,22 +222,17 @@ namespace Microsoft.ClearScript.Windows
|
|||
{
|
||||
return target.InvokeMember(name, BindingFlags.GetProperty, null, target, MiscHelpers.GetEmptyArray<object>(), null, CultureInfo.InvariantCulture, null);
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch (Exception)
|
||||
{
|
||||
if ((exception is MissingMemberException) || (exception is ArgumentException) || (exception is ExternalException))
|
||||
if (target.GetMethod(name, BindingFlags.GetProperty) != null)
|
||||
{
|
||||
if (target.GetMethod(name, BindingFlags.GetProperty) != null)
|
||||
{
|
||||
// Property retrieval failed, but a method with the given name exists;
|
||||
// create a tear-off method. This currently applies only to VBScript.
|
||||
// Property retrieval failed, but a method with the given name exists;
|
||||
// create a tear-off method. This currently applies only to VBScript.
|
||||
|
||||
return new ScriptMethod(this, name);
|
||||
}
|
||||
|
||||
return Nonexistent.Value;
|
||||
return new ScriptMethod(this, name);
|
||||
}
|
||||
|
||||
throw;
|
||||
return Nonexistent.Value;
|
||||
}
|
||||
}), false);
|
||||
|
||||
|
@ -241,25 +327,10 @@ namespace Microsoft.ClearScript.Windows
|
|||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
if ((exception is MissingMemberException) || (exception is ArgumentException) || (exception is ExternalException))
|
||||
IScriptEngineException scriptError;
|
||||
if (TryGetScriptError(exception, out scriptError))
|
||||
{
|
||||
// These exceptions tend to have awful messages that include COM error codes.
|
||||
// The engine may be able to provide a better message.
|
||||
|
||||
var hr = Marshal.GetHRForException(exception);
|
||||
if (RawCOMHelpers.HResult.GetFacility(hr) == RawCOMHelpers.HResult.FACILITY_CONTROL)
|
||||
{
|
||||
string message;
|
||||
if (engine.RuntimeErrorMap.TryGetValue(RawCOMHelpers.HResult.GetCode(hr), out message))
|
||||
{
|
||||
throw (Exception)typeof(Exception).CreateInstance(message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
if (hr == MiscHelpers.UnsignedAsSigned(RawCOMHelpers.HResult.DISP_E_MEMBERNOTFOUND))
|
||||
{
|
||||
throw new MissingMemberException(MiscHelpers.FormatInvariant("Object has no method named '{0}'", name));
|
||||
}
|
||||
throw (Exception)scriptError;
|
||||
}
|
||||
|
||||
throw;
|
||||
|
|
Двоичные данные
ClearScript/doc/Reference.chm
Двоичные данные
ClearScript/doc/Reference.chm
Двоичный файл не отображается.
|
@ -39,7 +39,7 @@
|
|||
<SyntaxFilters>Standard</SyntaxFilters>
|
||||
<SdkLinkTarget>Blank</SdkLinkTarget>
|
||||
<RootNamespaceContainer>True</RootNamespaceContainer>
|
||||
<NamingMethod>Guid</NamingMethod>
|
||||
<NamingMethod>MemberName</NamingMethod>
|
||||
<ContentPlacement>AboveNamespaces</ContentPlacement>
|
||||
<CopyrightText>Copyright &#169%3b Microsoft Corporation. All rights reserved.</CopyrightText>
|
||||
<NamespaceSummaries>
|
||||
|
|
|
@ -69,5 +69,5 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("© Microsoft Corporation")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: AssemblyVersion("5.1.3.0")]
|
||||
[assembly: AssemblyFileVersion("5.1.3.0")]
|
||||
[assembly: AssemblyVersion("5.2.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.2.0.0")]
|
||||
|
|
|
@ -73,6 +73,8 @@ namespace Microsoft.ClearScript.Test
|
|||
using (var engine = new V8ScriptEngine(typeof(ClearScriptConsole).Name, V8ScriptEngineFlags.EnableDebugging))
|
||||
{
|
||||
engine.AddHostObject("host", new ExtendedHostFunctions());
|
||||
engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib", "System", "System.Core", "ClearScript"));
|
||||
engine.AllowReflection = true;
|
||||
RunStartupFile(engine);
|
||||
RunConsole(engine);
|
||||
}
|
||||
|
@ -95,7 +97,7 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Console.WriteLine("Error: {0}", exception.Message);
|
||||
Console.WriteLine("Error: {0}", exception.GetBaseException().Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +128,7 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Console.WriteLine("Error: {0}", exception.Message);
|
||||
Console.WriteLine("Error: {0}", exception.GetBaseException().Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,5 +69,5 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("© Microsoft Corporation")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: AssemblyVersion("5.1.3.0")]
|
||||
[assembly: AssemblyFileVersion("5.1.3.0")]
|
||||
[assembly: AssemblyVersion("5.2.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.2.0.0")]
|
||||
|
|
|
@ -117,10 +117,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseInterfaceMemberAccess_Property_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceProperty = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseInterfaceProperty = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -133,17 +132,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void BaseInterfaceMemberAccess_Property_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceScalarProperty = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("testObject.BaseInterfaceScalarProperty = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseInterfaceMemberAccess_Property_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceScalarProperty = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseInterfaceScalarProperty = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -163,10 +160,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseInterfaceMemberAccess_Property_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceEnumProperty = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseInterfaceEnumProperty = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -179,10 +175,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseInterfaceMemberAccess_Property_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceStructProperty = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseInterfaceStructProperty = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -192,10 +187,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseInterfaceMemberAccess_ReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceReadOnlyProperty = 2");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseInterfaceReadOnlyProperty = 2"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -216,10 +210,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseInterfaceMemberAccess_Method_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseInterfaceMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -229,10 +222,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseInterfaceMemberAccess_Method_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseInterfaceMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -242,10 +234,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseInterfaceMemberAccess_Method_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseInterfaceMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -255,10 +246,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseInterfaceMemberAccess_Method_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseInterfaceMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -284,10 +274,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseInterfaceMemberAccess_ExtensionMethod_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceExtensionMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseInterfaceExtensionMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -297,10 +286,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseInterfaceMemberAccess_ExtensionMethod_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceExtensionMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseInterfaceExtensionMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -310,10 +298,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseInterfaceMemberAccess_ExtensionMethod_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
@ -323,10 +310,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseInterfaceMemberAccess_ExtensionMethod_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.BaseInterfaceExtensionMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseInterfaceExtensionMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseInterfaceMemberAccess")]
|
||||
|
|
|
@ -121,10 +121,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_Field_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseField = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseField = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -137,17 +136,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void BaseMemberAccess_Field_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("testObject.BaseScalarField = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("testObject.BaseScalarField = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_Field_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseScalarField = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseScalarField = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -167,10 +164,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_Field_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseEnumField = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseEnumField = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -183,10 +179,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_Field_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseStructField = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseStructField = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -206,10 +201,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_Property_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseProperty = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseProperty = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -222,17 +216,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void BaseMemberAccess_Property_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("testObject.BaseScalarProperty = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("testObject.BaseScalarProperty = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_Property_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseScalarProperty = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseScalarProperty = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -252,10 +244,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_Property_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseEnumProperty = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseEnumProperty = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -268,10 +259,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_Property_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.BaseStructProperty = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseStructProperty = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -281,10 +271,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void BaseMemberAccess_ReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("testObject.BaseReadOnlyProperty = 2");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.BaseReadOnlyProperty = 2"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -305,10 +294,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseMemberAccess_Method_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testObject.BaseMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -318,10 +306,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseMemberAccess_Method_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testObject.BaseMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -331,10 +318,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseMemberAccess_Method_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.BaseMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -344,10 +330,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseMemberAccess_Method_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.BaseMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -373,10 +358,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseMemberAccess_ExtensionMethod_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testObject.BaseExtensionMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseExtensionMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -386,10 +370,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseMemberAccess_ExtensionMethod_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testObject.BaseExtensionMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseExtensionMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -399,10 +382,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseMemberAccess_ExtensionMethod_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.BaseExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
@ -412,10 +394,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BaseMemberAccess_ExtensionMethod_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.BaseExtensionMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.BaseExtensionMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BaseMemberAccess")]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
|
@ -61,7 +61,6 @@
|
|||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.ClearScript.Test
|
||||
{
|
||||
|
@ -91,28 +90,24 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BaseMethod(string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("d5114f53-ca6a-4993-8117-7f8194088c08"), this, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BaseMethod<T>(string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("d18ddd76-a035-44b4-b18b-7c4c7d313c4f"), this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BaseMethod<T>(int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("53b0fe2a-6b7c-4516-93de-db706b1bf1bb"), this, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BaseBindTestMethod<T>(T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("c0f52143-a775-4b71-b206-a759285a35a5"), this, typeof(T), arg);
|
||||
}
|
||||
|
||||
#region Implementation of IBaseTestInterface
|
||||
|
@ -136,28 +131,24 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BaseInterfaceMethod(string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("f58f24cd-1d08-4224-bf78-7dcdb01b733f"), this, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BaseInterfaceMethod<T>(string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("73cd3acf-3c94-4993-8786-70ba0f86f1a7"), this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BaseInterfaceMethod<T>(int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("28cf53e3-6422-4ac8-82d6-0d3d00e7bc1d"), this, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BaseInterfaceBindTestMethod<T>(T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("302f0d74-7ee8-4e0c-b383-7816d79a889b"), this, typeof(T), arg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -199,32 +190,28 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "This member requires explicit implementation for testing purposes.")]
|
||||
double IExplicitBaseTestInterface.ExplicitBaseInterfaceMethod(string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("354a43bc-7d15-4aeb-b4c9-c6e03893c5f2"), this, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "This member requires explicit implementation for testing purposes.")]
|
||||
double IExplicitBaseTestInterface.ExplicitBaseInterfaceMethod<T>(string arg1, int arg2, T arg3)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("b6496578-af16-4424-b16b-808de442d9e3"), this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "This member requires explicit implementation for testing purposes.")]
|
||||
double IExplicitBaseTestInterface.ExplicitBaseInterfaceMethod<T>(int arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("b9810875-3ccf-400f-b106-d2869905f9bc"), this, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "This member requires explicit implementation for testing purposes.")]
|
||||
double IExplicitBaseTestInterface.ExplicitBaseInterfaceBindTestMethod<T>(T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("5937707d-9158-4d72-986b-8eb13da5c079"), this, typeof(T), arg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -232,28 +219,24 @@ namespace Microsoft.ClearScript.Test
|
|||
|
||||
public static class BaseTestObjectExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double BaseExtensionMethod(this BaseTestObject self, string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("ffac885b-0e3b-4438-99e1-64f4d2c6f769"), self, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double BaseExtensionMethod<T>(this BaseTestObject self, string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("6ee07aa3-4548-4d59-b7d6-77725bb2c900"), self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double BaseExtensionMethod<T>(this BaseTestObject self, int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("2db0feaf-8618-4676-a7ba-552a20853fcd"), self, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double BaseExtensionBindTestMethod<T>(this BaseTestObject self, T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("fdef26a4-2155-4be5-a245-4810ae66c491"), self, typeof(T), arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,11 +106,10 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("BugFix")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void BugFix_NullArgBinding_Ambiguous()
|
||||
{
|
||||
engine.AddHostObject("lib", new HostTypeCollection("mscorlib"));
|
||||
engine.Execute("lib.System.Console.WriteLine(null)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("lib.System.Console.WriteLine(null)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("BugFix")]
|
||||
|
|
|
@ -123,10 +123,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Property_BadAssignment()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceProperty = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceProperty = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -139,17 +138,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Property_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceScalarProperty = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceScalarProperty = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Property_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceScalarProperty = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceScalarProperty = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -169,10 +166,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Property_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceEnumProperty = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceEnumProperty = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -185,10 +181,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Property_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceStructProperty = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceStructProperty = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -198,10 +193,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceReadOnlyProperty = 2");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceReadOnlyProperty = 2"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -222,10 +216,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Method_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -235,10 +228,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Method_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceMethod('foo', 4, testInterface)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceMethod('foo', 4, testInterface)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -248,10 +240,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Method_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -261,10 +252,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_Method_GenericExplicitBase_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -290,10 +280,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ExtensionMethod_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceExtensionMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceExtensionMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -303,10 +292,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ExtensionMethod_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceExtensionMethod('foo', 4, testInterface)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceExtensionMethod('foo', 4, testInterface)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -316,10 +304,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ExtensionMethod_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -329,10 +316,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ExtensionMethod_GenericExplicitBase_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitBaseInterfaceExtensionMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitBaseInterfaceExtensionMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -384,10 +370,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ExtensionMethod_NoMatchingOverload_OnObject()
|
||||
{
|
||||
engine.Execute("testObject.ExplicitBaseInterfaceExtensionMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExplicitBaseInterfaceExtensionMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -397,10 +382,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ExtensionMethod_Generic_TypeArgConstraintFailure_OnObject()
|
||||
{
|
||||
engine.Execute("testObject.ExplicitBaseInterfaceExtensionMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExplicitBaseInterfaceExtensionMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -410,10 +394,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ExtensionMethod_GenericRedundant_MismatchedTypeArg_OnObject()
|
||||
{
|
||||
engine.Execute("testObject.ExplicitBaseInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExplicitBaseInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
@ -423,10 +406,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitBaseInterfaceMemberAccess_ExtensionMethod_GenericExplicitBase_MissingTypeArg_OnObject()
|
||||
{
|
||||
engine.Execute("testObject.ExplicitBaseInterfaceExtensionMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExplicitBaseInterfaceExtensionMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitBaseInterfaceMemberAccess")]
|
||||
|
|
|
@ -119,10 +119,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitInterfaceMemberAccess_Property_BadAssignment()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceProperty = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitInterfaceProperty = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -135,17 +134,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void ExplicitInterfaceMemberAccess_Property_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceScalarProperty = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("testInterface.ExplicitInterfaceScalarProperty = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitInterfaceMemberAccess_Property_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceScalarProperty = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitInterfaceScalarProperty = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -165,10 +162,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitInterfaceMemberAccess_Property_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceEnumProperty = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitInterfaceEnumProperty = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -181,10 +177,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitInterfaceMemberAccess_Property_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceStructProperty = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitInterfaceStructProperty = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -194,10 +189,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void ExplicitInterfaceMemberAccess_ReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceReadOnlyProperty = 2");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testInterface.ExplicitInterfaceReadOnlyProperty = 2"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -218,10 +212,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_Method_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitInterfaceMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -231,10 +224,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_Method_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceMethod('foo', 4, testInterface)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitInterfaceMethod('foo', 4, testInterface)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -244,10 +236,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_Method_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitInterfaceMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -257,10 +248,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_Method_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitInterfaceMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -286,10 +276,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_ExtensionMethod_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceExtensionMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitInterfaceExtensionMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -299,10 +288,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_ExtensionMethod_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceExtensionMethod('foo', 4, testInterface)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitInterfaceExtensionMethod('foo', 4, testInterface)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -312,10 +300,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_ExtensionMethod_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -325,10 +312,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_ExtensionMethod_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testInterface.ExplicitInterfaceExtensionMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testInterface.ExplicitInterfaceExtensionMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -380,10 +366,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_ExtensionMethod_NoMatchingOverload_OnObject()
|
||||
{
|
||||
engine.Execute("testObject.ExplicitInterfaceExtensionMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExplicitInterfaceExtensionMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -393,10 +378,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_ExtensionMethod_Generic_TypeArgConstraintFailure_OnObject()
|
||||
{
|
||||
engine.Execute("testObject.ExplicitInterfaceExtensionMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExplicitInterfaceExtensionMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -406,10 +390,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_ExtensionMethod_GenericRedundant_MismatchedTypeArg_OnObject()
|
||||
{
|
||||
engine.Execute("testObject.ExplicitInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExplicitInterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
@ -419,10 +402,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void ExplicitInterfaceMemberAccess_ExtensionMethod_GenericExplicit_MissingTypeArg_OnObject()
|
||||
{
|
||||
engine.Execute("testObject.ExplicitInterfaceExtensionMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExplicitInterfaceExtensionMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ExplicitInterfaceMemberAccess")]
|
||||
|
|
|
@ -568,27 +568,24 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("HostFunctions")]
|
||||
[ExpectedException(typeof(UnauthorizedAccessException))]
|
||||
public void HostFunctions_typeOf_TypeArg_Blocked()
|
||||
{
|
||||
engine.AddHostType("Int32", typeof(int));
|
||||
engine.Execute("host.typeOf(Int32)");
|
||||
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Execute("host.typeOf(Int32)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("HostFunctions")]
|
||||
[ExpectedException(typeof(UnauthorizedAccessException))]
|
||||
public void HostFunctions_typeOf_NonTypeArg_Blocked()
|
||||
{
|
||||
engine.AddHostType("Console", typeof(Console));
|
||||
engine.Execute("host.typeOf(Console)");
|
||||
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Execute("host.typeOf(Console)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("HostFunctions")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void HostFunctions_typeOf_NonType()
|
||||
{
|
||||
engine.AllowReflection = true;
|
||||
engine.Execute("host.typeOf(5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("host.typeOf(5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("HostFunctions")]
|
||||
|
@ -609,20 +606,18 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("HostFunctions")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void HostFunctions_flags_Mismatch()
|
||||
{
|
||||
engine.AddHostType("UnsignedFlags", HostItemFlags.PrivateAccess, typeof(UnsignedFlags));
|
||||
engine.AddHostType("SignedFlags", HostItemFlags.PrivateAccess, typeof(SignedFlags));
|
||||
engine.Execute("host.flags(SignedFlags.Second, SignedFlags.Fourth, UnsignedFlags.Sixth, UnsignedFlags.Eighth)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("host.flags(SignedFlags.Second, SignedFlags.Fourth, UnsignedFlags.Sixth, UnsignedFlags.Eighth)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("HostFunctions")]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void HostFunctions_flags_NonFlags()
|
||||
{
|
||||
engine.AddHostType("NonFlags", HostItemFlags.PrivateAccess, typeof(NonFlags));
|
||||
engine.Execute("host.flags(NonFlags.Second, NonFlags.Fourth, NonFlags.Sixth, NonFlags.Eighth)");
|
||||
TestUtil.AssertException<InvalidOperationException>(() => engine.Execute("host.flags(NonFlags.Second, NonFlags.Fourth, NonFlags.Sixth, NonFlags.Eighth)"));
|
||||
}
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
@ -641,7 +636,7 @@ namespace Microsoft.ClearScript.Test
|
|||
|
||||
private void VerifyNewArr<T>(params int[] lengths)
|
||||
{
|
||||
var value = host.newArr<T>(lengths);
|
||||
var value = (Array)host.newArr<T>(lengths);
|
||||
Assert.IsInstanceOfType(value, typeof(T).MakeArrayType(lengths.Length));
|
||||
lengths.ForEach((length, index) => Assert.AreEqual(lengths[index], value.GetLength(index)));
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
|
@ -60,7 +60,6 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.ClearScript.Test
|
||||
{
|
||||
|
@ -83,28 +82,24 @@ namespace Microsoft.ClearScript.Test
|
|||
|
||||
public static class BaseTestInterfaceExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double BaseInterfaceExtensionMethod(this IBaseTestInterface self, string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("4b62c135-85fe-40fd-94f3-b97a8961bd7e"), self, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double BaseInterfaceExtensionMethod<T>(this IBaseTestInterface self, string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("25091ed2-88a2-4efb-aceb-b8c1c6aeb66e"), self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double BaseInterfaceExtensionMethod<T>(this IBaseTestInterface self, int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("589b2ea2-cec8-4ee2-9d25-684d8e3b8e2a"), self, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double BaseInterfaceExtensionBindTestMethod<T>(this IBaseTestInterface self, T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("5fb43a52-2268-430c-9f90-5dfa06d98603"), self, typeof(T), arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
|
@ -60,7 +60,6 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.ClearScript.Test
|
||||
{
|
||||
|
@ -83,28 +82,24 @@ namespace Microsoft.ClearScript.Test
|
|||
|
||||
public static class ExplicitBaseTestInterfaceExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExplicitBaseInterfaceExtensionMethod(this IExplicitBaseTestInterface self, string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("7cc1fa3e-6193-4914-9e0e-cff8a84e9beb"), self, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExplicitBaseInterfaceExtensionMethod<T>(this IExplicitBaseTestInterface self, string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("5db749b9-bc1a-408c-a630-4c3aaa177a26"), self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExplicitBaseInterfaceExtensionMethod<T>(this IExplicitBaseTestInterface self, int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("ee25eedb-4a80-4db6-9c5e-5fe79178b9be"), self, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExplicitBaseInterfaceExtensionBindTestMethod<T>(this IExplicitBaseTestInterface self, T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("a6815002-5517-43c3-94bc-282d53c32cb3"), self, typeof(T), arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
|
@ -60,7 +60,6 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.ClearScript.Test
|
||||
{
|
||||
|
@ -83,28 +82,24 @@ namespace Microsoft.ClearScript.Test
|
|||
|
||||
public static class ExplicitTestInterfaceExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExplicitInterfaceExtensionMethod(this IExplicitTestInterface self, string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("d758e3b9-52e3-46b5-ae5c-4d0b89bddc78"), self, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExplicitInterfaceExtensionMethod<T>(this IExplicitTestInterface self, string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("185c7082-c55d-435f-b3eb-418f1c27617c"), self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExplicitInterfaceExtensionMethod<T>(this IExplicitTestInterface self, int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("768b93c3-0a86-4e45-92ab-4d37613d4e09"), self, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExplicitInterfaceExtensionBindTestMethod<T>(this IExplicitTestInterface self, T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("35c244d4-1473-46ce-a9cf-d633034c967d"), self, typeof(T), arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
|
@ -60,7 +60,6 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.ClearScript.Test
|
||||
{
|
||||
|
@ -83,28 +82,24 @@ namespace Microsoft.ClearScript.Test
|
|||
|
||||
public static class TestInterfaceExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double InterfaceExtensionMethod(this ITestInterface self, string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("59c058fc-86c0-49ec-a686-1eda84a902a2"), self, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double InterfaceExtensionMethod<T>(this ITestInterface self, string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("b7de0341-a6ed-475f-83b8-9ce3fa3cbe38"), self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double InterfaceExtensionMethod<T>(this ITestInterface self, int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("9101e026-40d9-43cc-a52d-c5264f168e28"), self, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double InterfaceExtensionBindTestMethod<T>(this ITestInterface self, T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("84e8f577-58c3-42c5-aed3-ca0f62ccb291"), self, typeof(T), arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,10 +117,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void InterfaceMemberAccess_Property_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceProperty = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.InterfaceProperty = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -133,17 +132,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void InterfaceMemberAccess_Property_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceScalarProperty = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("testObject.InterfaceScalarProperty = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void InterfaceMemberAccess_Property_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceScalarProperty = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.InterfaceScalarProperty = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -163,10 +160,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void InterfaceMemberAccess_Property_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceEnumProperty = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.InterfaceEnumProperty = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -179,10 +175,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void InterfaceMemberAccess_Property_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceStructProperty = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.InterfaceStructProperty = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -192,10 +187,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void InterfaceMemberAccess_ReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceReadOnlyProperty = 2");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.InterfaceReadOnlyProperty = 2"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -216,10 +210,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void InterfaceMemberAccess_Method_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.InterfaceMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -229,10 +222,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void InterfaceMemberAccess_Method_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.InterfaceMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -242,10 +234,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void InterfaceMemberAccess_Method_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.InterfaceMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -255,10 +246,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void InterfaceMemberAccess_Method_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.InterfaceMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -284,10 +274,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void InterfaceMemberAccess_ExtensionMethod_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceExtensionMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.InterfaceExtensionMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -297,10 +286,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void InterfaceMemberAccess_ExtensionMethod_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceExtensionMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.InterfaceExtensionMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -310,10 +298,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void InterfaceMemberAccess_ExtensionMethod_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.InterfaceExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
@ -323,10 +310,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void InterfaceMemberAccess_ExtensionMethod_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.InterfaceExtensionMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.InterfaceExtensionMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("InterfaceMemberAccess")]
|
||||
|
|
|
@ -65,8 +65,9 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using Microsoft.ClearScript.Util;
|
||||
using Microsoft.ClearScript.Windows;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
@ -143,7 +144,7 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
[ExpectedException(typeof(ExternalException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void JScriptEngine_AddHostObject_DefaultAccess()
|
||||
{
|
||||
engine.AddHostObject("test", this);
|
||||
|
@ -163,7 +164,7 @@ namespace Microsoft.ClearScript.Test
|
|||
var host = new ExtendedHostFunctions() as HostFunctions;
|
||||
engine.AddRestrictedHostObject("host", host);
|
||||
Assert.IsInstanceOfType(engine.Evaluate("host.newObj()"), typeof(PropertyBag));
|
||||
TestUtil.AssertException<ExternalException>(() => engine.Evaluate("host.type('System.Int32')"));
|
||||
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate("host.type('System.Int32')"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
|
@ -195,7 +196,7 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
[ExpectedException(typeof(ExternalException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void JScriptEngine_AddHostType_DefaultAccess()
|
||||
{
|
||||
engine.AddHostType("Test", GetType());
|
||||
|
@ -351,23 +352,12 @@ namespace Microsoft.ClearScript.Test
|
|||
});
|
||||
|
||||
engine.AddHostObject("checkpoint", checkpoint);
|
||||
|
||||
var gotException = false;
|
||||
try
|
||||
{
|
||||
engine.Execute("checkpoint.Set(); while (true) { var foo = 'hello'; }");
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
|
||||
Assert.IsTrue(gotException);
|
||||
TestUtil.AssertException<OperationCanceledException>(() => engine.Execute("checkpoint.Set(); while (true) { var foo = 'hello'; }"));
|
||||
Assert.AreEqual(Math.E * Math.PI, engine.Evaluate("Math.E * Math.PI"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
[ExpectedException(typeof(ExternalException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void JScriptEngine_AccessContext_Default()
|
||||
{
|
||||
engine.AddHostObject("test", this);
|
||||
|
@ -386,19 +376,7 @@ namespace Microsoft.ClearScript.Test
|
|||
public void JScriptEngine_ContinuationCallback()
|
||||
{
|
||||
engine.ContinuationCallback = () => false;
|
||||
|
||||
var gotException = false;
|
||||
try
|
||||
{
|
||||
engine.Execute("while (true) { var foo = 'hello'; }");
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
|
||||
Assert.IsTrue(gotException);
|
||||
|
||||
TestUtil.AssertException<OperationCanceledException>(() => engine.Execute("while (true) { var foo = 'hello'; }"));
|
||||
engine.ContinuationCallback = null;
|
||||
Assert.AreEqual(Math.E * Math.PI, engine.Evaluate("Math.E * Math.PI"));
|
||||
}
|
||||
|
@ -527,11 +505,10 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
[ExpectedException(typeof(MissingMemberException), AllowDerivedTypes = true)]
|
||||
public void JScriptEngine_new_NoMatch()
|
||||
{
|
||||
engine.AddHostObject("clr", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib"));
|
||||
engine.Execute("new System.Random('a')");
|
||||
TestUtil.AssertException<MissingMemberException>(() => engine.Execute("new System.Random('a')"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
|
@ -550,6 +527,144 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
public void JScriptEngine_ErrorHandling_ScriptError()
|
||||
{
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("foo = {}; foo();");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNull(exception.InnerException);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
public void JScriptEngine_ErrorHandling_HostException()
|
||||
{
|
||||
engine.AddHostObject("host", new HostFunctions());
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Evaluate("host.newObj(null)");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(RuntimeBinderException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNull(hostException.InnerException);
|
||||
|
||||
Assert.AreEqual(hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
public void JScriptEngine_ErrorHandling_IgnoredHostException()
|
||||
{
|
||||
engine.AddHostObject("host", new HostFunctions());
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("try { host.newObj(null); } catch(ex) {} foo = {}; foo();");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNull(exception.InnerException);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
public void JScriptEngine_ErrorHandling_NestedScriptError()
|
||||
{
|
||||
var innerEngine = new JScriptEngine("inner", WindowsScriptEngineFlags.EnableDebugging);
|
||||
engine.AddHostObject("engine", innerEngine);
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("engine.Execute('foo = {}; foo();')");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(TargetInvocationException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNotNull(hostException.InnerException);
|
||||
|
||||
var nestedException = hostException.InnerException as ScriptEngineException;
|
||||
Assert.IsNotNull(nestedException);
|
||||
TestUtil.AssertValidException(innerEngine, nestedException);
|
||||
Assert.IsNull(nestedException.InnerException);
|
||||
|
||||
Assert.AreEqual(hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("JScriptEngine")]
|
||||
public void JScriptEngine_ErrorHandling_NestedHostException()
|
||||
{
|
||||
var innerEngine = new JScriptEngine("inner", WindowsScriptEngineFlags.EnableDebugging);
|
||||
innerEngine.AddHostObject("host", new HostFunctions());
|
||||
engine.AddHostObject("engine", innerEngine);
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("engine.Evaluate('host.newObj(null)')");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(TargetInvocationException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNotNull(hostException.InnerException);
|
||||
|
||||
var nestedException = hostException.InnerException as ScriptEngineException;
|
||||
Assert.IsNotNull(nestedException);
|
||||
TestUtil.AssertValidException(innerEngine, nestedException);
|
||||
Assert.IsNotNull(nestedException.InnerException);
|
||||
|
||||
var nestedHostException = nestedException.InnerException;
|
||||
Assert.IsInstanceOfType(nestedHostException, typeof(RuntimeBinderException));
|
||||
TestUtil.AssertValidException(nestedHostException);
|
||||
Assert.IsNull(nestedHostException.InnerException);
|
||||
|
||||
Assert.AreEqual(nestedHostException.Message, nestedException.Message);
|
||||
Assert.AreEqual(hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -121,10 +121,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_Field_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.Field = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.Field = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -137,17 +136,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void MemberAccess_Field_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("testObject.ScalarField = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("testObject.ScalarField = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_Field_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.ScalarField = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.ScalarField = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -167,10 +164,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_Field_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.EnumField = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.EnumField = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -183,10 +179,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_Field_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.StructField = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.StructField = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -206,10 +201,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_Property_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.Property = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.Property = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -222,17 +216,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void MemberAccess_Property_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("testObject.ScalarProperty = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("testObject.ScalarProperty = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_Property_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.ScalarProperty = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.ScalarProperty = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -252,10 +244,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_Property_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.EnumProperty = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.EnumProperty = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -268,10 +259,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_Property_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("testObject.StructProperty = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.StructProperty = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -281,10 +271,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void MemberAccess_ReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("testObject.ReadOnlyProperty = 2");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("testObject.ReadOnlyProperty = 2"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -305,10 +294,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void MemberAccess_Method_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testObject.Method('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.Method('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -318,10 +306,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void MemberAccess_Method_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testObject.Method('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.Method('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -331,10 +318,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void MemberAccess_Method_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.Method(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.Method(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -344,10 +330,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void MemberAccess_Method_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.Method(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.Method(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -358,10 +343,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(UnauthorizedAccessException))]
|
||||
public void MemberAccess_Method_GetType_Blocked()
|
||||
{
|
||||
engine.Execute("testObject.GetType()");
|
||||
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Execute("testObject.GetType()"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -387,10 +371,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void MemberAccess_ExtensionMethod_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("testObject.ExtensionMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExtensionMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -400,10 +383,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void MemberAccess_ExtensionMethod_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("testObject.ExtensionMethod('foo', 4, testObject)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExtensionMethod('foo', 4, testObject)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -413,10 +395,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void MemberAccess_ExtensionMethod_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.ExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExtensionMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
@ -426,10 +407,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void MemberAccess_ExtensionMethod_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("testObject.ExtensionMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("testObject.ExtensionMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("MemberAccess")]
|
||||
|
|
|
@ -60,9 +60,8 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.ClearScript.Util;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.ClearScript.Test
|
||||
|
@ -95,14 +94,9 @@ namespace Microsoft.ClearScript.Test
|
|||
|
||||
public static class TestUtil
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double CalcTestValue(params object[] args)
|
||||
public static double CalcTestValue(Guid callerGuid, params object[] args)
|
||||
{
|
||||
// ReSharper disable PossibleNullReferenceException
|
||||
var method = new StackTrace(false).GetFrames()[1].GetMethod();
|
||||
// ReSharper restore PossibleNullReferenceException
|
||||
|
||||
var hashCode = args.Aggregate(method.GetHashCode(), (currentHashCode, value) => unchecked((currentHashCode * 31) + ((value != null) ? value.GetHashCode() : 0)));
|
||||
var hashCode = args.Aggregate(callerGuid.GetHashCode(), (currentHashCode, value) => unchecked((currentHashCode * 31) + ((value != null) ? value.GetHashCode() : 0)));
|
||||
return hashCode * Math.E / Math.PI;
|
||||
}
|
||||
|
||||
|
@ -114,12 +108,61 @@ namespace Microsoft.ClearScript.Test
|
|||
{
|
||||
action();
|
||||
}
|
||||
catch (T)
|
||||
catch (T exception)
|
||||
{
|
||||
gotException = true;
|
||||
AssertValidExceptionChain(exception);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
gotException = exception.GetBaseException() is T;
|
||||
AssertValidExceptionChain(exception);
|
||||
}
|
||||
|
||||
Assert.IsTrue(gotException);
|
||||
Assert.IsTrue(gotException, "Expected " + typeof(T).Name + " was not thrown.");
|
||||
}
|
||||
|
||||
public static void AssertValidException(Exception exception)
|
||||
{
|
||||
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
|
||||
Assert.IsFalse(exception.Message.Contains("COM"));
|
||||
Assert.IsFalse(exception.Message.Contains("HRESULT"));
|
||||
Assert.IsFalse(exception.Message.Contains("0x"));
|
||||
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.StackTrace));
|
||||
}
|
||||
|
||||
public static void AssertValidException(IScriptEngineException exception)
|
||||
{
|
||||
AssertValidException((Exception)exception);
|
||||
if ((exception is ScriptEngineException) && (exception.HResult != RawCOMHelpers.HResult.CLEARSCRIPT_E_SCRIPTITEMEXCEPTION))
|
||||
{
|
||||
Assert.IsTrue(exception.ErrorDetails.StartsWith(exception.Message, StringComparison.Ordinal));
|
||||
Assert.IsTrue(exception.ErrorDetails.Contains("\n at "));
|
||||
}
|
||||
}
|
||||
|
||||
public static void AssertValidException(ScriptEngine engine, IScriptEngineException exception)
|
||||
{
|
||||
AssertValidException(exception);
|
||||
Assert.AreEqual(engine.Name, exception.EngineName);
|
||||
}
|
||||
|
||||
private static void AssertValidExceptionChain(Exception exception)
|
||||
{
|
||||
while (exception != null)
|
||||
{
|
||||
var scriptError = exception as IScriptEngineException;
|
||||
if (scriptError != null)
|
||||
{
|
||||
AssertValidException(scriptError);
|
||||
}
|
||||
else
|
||||
{
|
||||
AssertValidException(exception);
|
||||
}
|
||||
|
||||
exception = exception.InnerException;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,5 +69,5 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("© Microsoft Corporation")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: AssemblyVersion("5.1.3.0")]
|
||||
[assembly: AssemblyFileVersion("5.1.3.0")]
|
||||
[assembly: AssemblyVersion("5.2.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.2.0.0")]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
|
@ -63,7 +63,6 @@ using System;
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.ClearScript.Util;
|
||||
using Microsoft.ClearScript.V8;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
@ -240,10 +239,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ScriptAccess")]
|
||||
[ExpectedException(typeof(UnauthorizedAccessException))]
|
||||
public void ScriptAccess_ReadOnlyField_Write()
|
||||
{
|
||||
engine.Execute("testObject.ReadOnlyField = 7");
|
||||
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Execute("testObject.ReadOnlyField = 7"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ScriptAccess")]
|
||||
|
@ -253,10 +251,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ScriptAccess")]
|
||||
[ExpectedException(typeof(UnauthorizedAccessException))]
|
||||
public void ScriptAccess_ReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("testObject.ReadOnlyProperty = Guid.NewGuid()");
|
||||
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Execute("testObject.ReadOnlyProperty = Guid.NewGuid()"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ScriptAccess")]
|
||||
|
@ -385,10 +382,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ScriptAccess")]
|
||||
[ExpectedException(typeof(UnauthorizedAccessException))]
|
||||
public void ScriptAccess_RenamedReadOnlyField_Write()
|
||||
{
|
||||
engine.Execute("testObject.renamedReadOnlyField = 7");
|
||||
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Execute("testObject.renamedReadOnlyField = 7"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("ScriptAccess")]
|
||||
|
@ -398,10 +394,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("ScriptAccess")]
|
||||
[ExpectedException(typeof(UnauthorizedAccessException))]
|
||||
public void ScriptAccess_RenamedReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("testObject.renamedReadOnlyProperty = Guid.NewGuid()");
|
||||
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Execute("testObject.renamedReadOnlyProperty = Guid.NewGuid()"));
|
||||
}
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
@ -422,8 +417,8 @@ namespace Microsoft.ClearScript.Test
|
|||
[NoScriptAccess] public Guid BlockedBaseProperty { get { return guids[0]; } set { } }
|
||||
[NoScriptAccess] public virtual Guid BlockedOverriddenProperty { get { return guids[1]; } set { } }
|
||||
|
||||
[NoScriptAccess, MethodImpl(MethodImplOptions.NoInlining)] public double BlockedBaseMethod(object arg) { return TestUtil.CalcTestValue("BlockedBaseMethod", arg); }
|
||||
[NoScriptAccess, MethodImpl(MethodImplOptions.NoInlining)] public virtual double BlockedOverriddenMethod(object arg) { return TestUtil.CalcTestValue("BlockedOverriddenMethod", arg); }
|
||||
[NoScriptAccess] public double BlockedBaseMethod(object arg) { return TestUtil.CalcTestValue(new Guid("9bf4c32d-1394-4546-a150-eb162b3bbb5f"), "BlockedBaseMethod", arg); }
|
||||
[NoScriptAccess] public virtual double BlockedOverriddenMethod(object arg) { return TestUtil.CalcTestValue(new Guid("83aa905a-e17d-47fe-bd0f-d2350cfb92d6"), "BlockedOverriddenMethod", arg); }
|
||||
|
||||
[ScriptMember("renamedBaseEvent")] public event EventHandler RenamedBaseEvent { add { } remove { } }
|
||||
[ScriptMember("renamedOverriddenEvent")] public virtual event EventHandler RenamedOverriddenEvent { add { } remove { } }
|
||||
|
@ -433,8 +428,8 @@ namespace Microsoft.ClearScript.Test
|
|||
[ScriptMember("renamedBaseProperty")] public Guid RenamedBaseProperty { get { return guids[2]; } set { } }
|
||||
[ScriptMember("renamedOverriddenProperty")] public virtual Guid RenamedOverriddenProperty { get { return guids[3]; } set { } }
|
||||
|
||||
[ScriptMember("renamedBaseMethod"), MethodImpl(MethodImplOptions.NoInlining)] public double RenamedBaseMethod(object arg) { return TestUtil.CalcTestValue("RenamedBaseMethod", arg); }
|
||||
[ScriptMember("renamedOverriddenMethod"), MethodImpl(MethodImplOptions.NoInlining)] public virtual double RenamedOverriddenMethod(object arg) { return TestUtil.CalcTestValue("RenamedOverriddenMethod", arg); }
|
||||
[ScriptMember("renamedBaseMethod")] public double RenamedBaseMethod(object arg) { return TestUtil.CalcTestValue(new Guid("460c0b65-56e6-4174-9331-905d417df885"), "RenamedBaseMethod", arg); }
|
||||
[ScriptMember("renamedOverriddenMethod")] public virtual double RenamedOverriddenMethod(object arg) { return TestUtil.CalcTestValue(new Guid("051b3239-df62-4a14-967c-0291e02ad48f"), "RenamedOverriddenMethod", arg); }
|
||||
}
|
||||
|
||||
public interface ITestInterface
|
||||
|
@ -474,12 +469,12 @@ namespace Microsoft.ClearScript.Test
|
|||
Guid ITestInterface.BlockedExplicitInterfaceProperty { get { return guids[7]; } set { } }
|
||||
[ScriptMember(ScriptAccess.ReadOnly)] public Guid ReadOnlyProperty { get { return guids[8]; } set { } }
|
||||
|
||||
[NoScriptAccess, MethodImpl(MethodImplOptions.NoInlining)] public double BlockedMethod(object arg) { return TestUtil.CalcTestValue("BlockedMethod", arg); }
|
||||
[MethodImpl(MethodImplOptions.NoInlining)] public override double BlockedOverriddenMethod(object arg) { return TestUtil.CalcTestValue("BlockedOverriddenMethod", arg); }
|
||||
[MethodImpl(MethodImplOptions.NoInlining)] public double BlockedInterfaceMethod(object arg) { return TestUtil.CalcTestValue("BlockedInterfaceMethod", arg); }
|
||||
[MethodImpl(MethodImplOptions.NoInlining)] double ITestInterface.BlockedExplicitInterfaceMethod(object arg) { return TestUtil.CalcTestValue("BlockedExplicitInterfaceMethod", arg); }
|
||||
[MethodImpl(MethodImplOptions.NoInlining)] public double BlockedOverloadedMethod(object arg) { return TestUtil.CalcTestValue("BlockedOverloadedMethod 1", arg); }
|
||||
[NoScriptAccess, MethodImpl(MethodImplOptions.NoInlining)] public double BlockedOverloadedMethod<T>(T arg) { return TestUtil.CalcTestValue("BlockedOverloadedMethod 2", arg); }
|
||||
[NoScriptAccess] public double BlockedMethod(object arg) { return TestUtil.CalcTestValue(new Guid("9e890478-709c-4e42-be5f-c4e291572a17"), "BlockedMethod", arg); }
|
||||
public override double BlockedOverriddenMethod(object arg) { return TestUtil.CalcTestValue(new Guid("7ff033f5-f6f2-46cf-aba5-5adec6e210fd"), "BlockedOverriddenMethod", arg); }
|
||||
public double BlockedInterfaceMethod(object arg) { return TestUtil.CalcTestValue(new Guid("0eb4c085-808d-40ec-9117-214084222b75"), "BlockedInterfaceMethod", arg); }
|
||||
double ITestInterface.BlockedExplicitInterfaceMethod(object arg) { return TestUtil.CalcTestValue(new Guid("28318787-2195-46cf-8b57-a993c30b131f"), "BlockedExplicitInterfaceMethod", arg); }
|
||||
public double BlockedOverloadedMethod(object arg) { return TestUtil.CalcTestValue(new Guid("47a9e14b-65f6-4202-9e6c-528f05d2fd08"), "BlockedOverloadedMethod 1", arg); }
|
||||
[NoScriptAccess] public double BlockedOverloadedMethod<T>(T arg) { return TestUtil.CalcTestValue(new Guid("60e54acc-0b47-4d0a-a29e-b6f420079095"), "BlockedOverloadedMethod 2", arg); }
|
||||
|
||||
[ScriptMember("renamedEvent")] public event EventHandler RenamedEvent { add { } remove { } }
|
||||
public override event EventHandler RenamedOverriddenEvent { add { } remove { } }
|
||||
|
@ -495,12 +490,12 @@ namespace Microsoft.ClearScript.Test
|
|||
Guid ITestInterface.RenamedExplicitInterfaceProperty { get { return guids[12]; } set { } }
|
||||
[ScriptMember("renamedReadOnlyProperty", ScriptAccess.ReadOnly)] public Guid RenamedReadOnlyProperty { get { return guids[13]; } set { } }
|
||||
|
||||
[ScriptMember("renamedMethod"), MethodImpl(MethodImplOptions.NoInlining)] public double RenamedMethod(object arg) { return TestUtil.CalcTestValue("RenamedMethod", arg); }
|
||||
[MethodImpl(MethodImplOptions.NoInlining)] public override double RenamedOverriddenMethod(object arg) { return TestUtil.CalcTestValue("RenamedOverriddenMethod", arg); }
|
||||
[MethodImpl(MethodImplOptions.NoInlining)] public double RenamedInterfaceMethod(object arg) { return TestUtil.CalcTestValue("RenamedInterfaceMethod", arg); }
|
||||
[MethodImpl(MethodImplOptions.NoInlining)] double ITestInterface.RenamedExplicitInterfaceMethod(object arg) { return TestUtil.CalcTestValue("RenamedExplicitInterfaceMethod", arg); }
|
||||
[MethodImpl(MethodImplOptions.NoInlining)] public double RenamedOverloadedMethod(object arg) { return TestUtil.CalcTestValue("RenamedOverloadedMethod 1", arg); }
|
||||
[ScriptMember("renamedOverloadedMethod"), MethodImpl(MethodImplOptions.NoInlining)] public double RenamedOverloadedMethod<T>(T arg) { return TestUtil.CalcTestValue("RenamedOverloadedMethod 2", arg); }
|
||||
[ScriptMember("renamedMethod")] public double RenamedMethod(object arg) { return TestUtil.CalcTestValue(new Guid("d6c05624-6357-4ef1-b54a-d7a03864a034"), "RenamedMethod", arg); }
|
||||
public override double RenamedOverriddenMethod(object arg) { return TestUtil.CalcTestValue(new Guid("77382ed3-feec-4d49-bd6e-d1d590827c35"), "RenamedOverriddenMethod", arg); }
|
||||
public double RenamedInterfaceMethod(object arg) { return TestUtil.CalcTestValue(new Guid("d3a7c549-1ee3-4890-b933-6b8ab6988e49"), "RenamedInterfaceMethod", arg); }
|
||||
double ITestInterface.RenamedExplicitInterfaceMethod(object arg) { return TestUtil.CalcTestValue(new Guid("d0505e09-e152-40e2-b279-59e980109d9c"), "RenamedExplicitInterfaceMethod", arg); }
|
||||
public double RenamedOverloadedMethod(object arg) { return TestUtil.CalcTestValue(new Guid("c3b7cfd5-c870-422e-9bce-c361429c8c74"), "RenamedOverloadedMethod 1", arg); }
|
||||
[ScriptMember("renamedOverloadedMethod")] public double RenamedOverloadedMethod<T>(T arg) { return TestUtil.CalcTestValue(new Guid("8b79b6b1-8e54-4fff-9054-bfba76e092b7"), "RenamedOverloadedMethod 2", arg); }
|
||||
}
|
||||
|
||||
private void AssertBlockedMember(string objectName, string memberName)
|
||||
|
|
|
@ -118,10 +118,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_Field_BadAssignment()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticField = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticField = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -134,17 +133,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void StaticMemberAccess_Field_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticScalarField = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("StaticTestClass.StaticScalarField = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_Field_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticScalarField = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticScalarField = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -164,10 +161,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_Field_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticEnumField = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticEnumField = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -180,10 +176,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_Field_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticStructField = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticStructField = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -203,10 +198,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_Property_BadAssignment()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticProperty = host.newArr(System.Double, 5)");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticProperty = host.newArr(System.Double, 5)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -219,17 +213,15 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(OverflowException))]
|
||||
public void StaticMemberAccess_Property_Scalar_Overflow()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticScalarProperty = 54321");
|
||||
TestUtil.AssertException<OverflowException>(() => engine.Execute("StaticTestClass.StaticScalarProperty = 54321"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_Property_Scalar_BadAssignment()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticScalarProperty = TestEnum.Second");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticScalarProperty = TestEnum.Second"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -249,10 +241,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_Property_Enum_BadAssignment()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticEnumProperty = 1");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticEnumProperty = 1"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -265,10 +256,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_Property_Struct_BadAssignment()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticStructProperty = System.DateTime.Now");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticStructProperty = System.DateTime.Now"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -278,10 +268,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void StaticMemberAccess_ReadOnlyProperty_Write()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticReadOnlyProperty = 2");
|
||||
TestUtil.AssertException<ArgumentException>(() => engine.Execute("StaticTestClass.StaticReadOnlyProperty = 2"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -302,10 +291,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void StaticMemberAccess_Method_NoMatchingOverload()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticMethod('foo', TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("StaticTestClass.StaticMethod('foo', TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -315,10 +303,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void StaticMemberAccess_Method_Generic_TypeArgConstraintFailure()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticMethod('foo', 4, StaticTestClass)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("StaticTestClass.StaticMethod('foo', 4, StaticTestClass)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -328,10 +315,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void StaticMemberAccess_Method_GenericRedundant_MismatchedTypeArg()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticMethod(System.Int32, 'foo', 4, TestEnum.Second)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("StaticTestClass.StaticMethod(System.Int32, 'foo', 4, TestEnum.Second)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
@ -341,10 +327,9 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
[ExpectedException(typeof(RuntimeBinderException))]
|
||||
public void StaticMemberAccess_Method_GenericExplicit_MissingTypeArg()
|
||||
{
|
||||
engine.Execute("StaticTestClass.StaticMethod(4)");
|
||||
TestUtil.AssertException<RuntimeBinderException>(() => engine.Execute("StaticTestClass.StaticMethod(4)"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("StaticMemberAccess")]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
|
@ -60,7 +60,6 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.ClearScript.Test
|
||||
{
|
||||
|
@ -90,28 +89,24 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double StaticMethod(string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(typeof(StaticTestClass), arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("e9bc20b4-3f24-4c99-b2dd-34d7e533bc10"), typeof(StaticTestClass), arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double StaticMethod<T>(string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(typeof(StaticTestClass), arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("1f78dcb0-ecd9-4497-b67a-88684a5b3352"), typeof(StaticTestClass), arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double StaticMethod<T>(int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(typeof(StaticTestClass), typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("6298f0a4-01c7-4600-870b-99917b92a4de"), typeof(StaticTestClass), typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double StaticBindTestMethod<T>(T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(typeof(StaticTestClass), typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("d1e979f2-47cd-44fa-a21a-7b215f18bd67"), typeof(StaticTestClass), typeof(T), arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Copyright © Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Microsoft Public License (MS-PL)
|
||||
|
@ -60,7 +60,6 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.ClearScript.Test
|
||||
{
|
||||
|
@ -90,28 +89,24 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double Method(string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("f5b75d68-253b-4597-9464-8574f74750f5"), this, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double Method<T>(string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("823eeeea-48b3-4650-ba3c-077e47622b57"), this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double Method<T>(int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("ef3fafb5-680b-40ba-b9be-a0bb5ea0cba4"), this, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double BindTestMethod<T>(T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("06407870-c4dc-40f8-95ec-8d743c77c8b2"), this, typeof(T), arg);
|
||||
}
|
||||
|
||||
#region Implementation of ITestInterface
|
||||
|
@ -135,28 +130,24 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double InterfaceMethod(string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("a545f94c-a791-47de-a292-b687fe6d0fc3"), this, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double InterfaceMethod<T>(string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("216ef56a-aa88-46e2-93d9-bc5153ad2c9e"), this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double InterfaceMethod<T>(int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("62a17d8c-2c9e-4dcd-b14f-c027c773c593"), this, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public double InterfaceBindTestMethod<T>(T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("43ce378d-5319-419c-bd62-908cd56dfd85"), this, typeof(T), arg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -188,28 +179,24 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
double IExplicitTestInterface.ExplicitInterfaceMethod(string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("3f9634ff-d044-4ad5-96d7-bb2a42aa6aa5"), this, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
double IExplicitTestInterface.ExplicitInterfaceMethod<T>(string arg1, int arg2, T arg3)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("7b46c24f-8bfa-4fc6-ae57-fcb136f9332e"), this, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
double IExplicitTestInterface.ExplicitInterfaceMethod<T>(int arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("d6aaecfe-952f-459b-9355-14a17cc66010"), this, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
double IExplicitTestInterface.ExplicitInterfaceBindTestMethod<T>(T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(this, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("353d275f-aead-4f92-8035-1fd620a4a12e"), this, typeof(T), arg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -217,28 +204,24 @@ namespace Microsoft.ClearScript.Test
|
|||
|
||||
public static class TestObjectExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExtensionMethod(this TestObject self, string arg1, int arg2)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2);
|
||||
return TestUtil.CalcTestValue(new Guid("d78a86ce-310f-4d9e-bc3a-9f07dfa1d8e1"), self, arg1.Length, arg2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExtensionMethod<T>(this TestObject self, string arg1, int arg2, T arg3) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
return TestUtil.CalcTestValue(new Guid("b3fad7c5-69fa-49d6-829f-16beb738352d"), self, arg1.Length, arg2, arg3.ToString().Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExtensionMethod<T>(this TestObject self, int arg) where T : struct
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T).Name.Length, arg);
|
||||
return TestUtil.CalcTestValue(new Guid("f1d7d8ec-998e-413c-9b65-06c396676a4b"), self, typeof(T).Name.Length, arg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static double ExtensionBindTestMethod<T>(this TestObject self, T arg)
|
||||
{
|
||||
return TestUtil.CalcTestValue(self, typeof(T), arg);
|
||||
return TestUtil.CalcTestValue(new Guid("613ce819-bc84-41c3-a3d6-4efa9a2a3b65"), self, typeof(T), arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,9 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using Microsoft.ClearScript.Util;
|
||||
using Microsoft.ClearScript.V8;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
@ -146,7 +148,7 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void V8ScriptEngine_AddHostObject_DefaultAccess()
|
||||
{
|
||||
engine.AddHostObject("test", this);
|
||||
|
@ -166,7 +168,7 @@ namespace Microsoft.ClearScript.Test
|
|||
var host = new ExtendedHostFunctions() as HostFunctions;
|
||||
engine.AddRestrictedHostObject("host", host);
|
||||
Assert.IsInstanceOfType(engine.Evaluate("host.newObj()"), typeof(PropertyBag));
|
||||
TestUtil.AssertException<InvalidOperationException>(() => engine.Evaluate("host.type('System.Int32')"));
|
||||
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate("host.type('System.Int32')"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
|
@ -198,7 +200,7 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void V8ScriptEngine_AddHostType_DefaultAccess()
|
||||
{
|
||||
engine.AddHostType("Test", GetType());
|
||||
|
@ -358,22 +360,12 @@ namespace Microsoft.ClearScript.Test
|
|||
// V8 can't interrupt code that accesses only native data
|
||||
engine.AddHostObject("test", new { foo = "bar" });
|
||||
|
||||
var gotException = false;
|
||||
try
|
||||
{
|
||||
engine.Execute("checkpoint.Set(); while (true) { var foo = test.foo; }");
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
|
||||
Assert.IsTrue(gotException);
|
||||
TestUtil.AssertException<OperationCanceledException>(() => engine.Execute("checkpoint.Set(); while (true) { var foo = test.foo; }"));
|
||||
Assert.AreEqual(Math.E * Math.PI, engine.Evaluate("Math.E * Math.PI"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void V8ScriptEngine_AccessContext_Default()
|
||||
{
|
||||
engine.AddHostObject("test", this);
|
||||
|
@ -391,23 +383,11 @@ namespace Microsoft.ClearScript.Test
|
|||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
public void V8ScriptEngine_ContinuationCallback()
|
||||
{
|
||||
engine.ContinuationCallback = () => false;
|
||||
|
||||
// V8 can't interrupt code that accesses only native data
|
||||
engine.AddHostObject("test", new { foo = "bar" });
|
||||
|
||||
var gotException = false;
|
||||
try
|
||||
{
|
||||
engine.Execute("while (true) { var foo = test.foo; }");
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
|
||||
Assert.IsTrue(gotException);
|
||||
|
||||
engine.ContinuationCallback = () => false;
|
||||
TestUtil.AssertException<OperationCanceledException>(() => engine.Execute("while (true) { var foo = test.foo; }"));
|
||||
engine.ContinuationCallback = null;
|
||||
Assert.AreEqual(Math.E * Math.PI, engine.Evaluate("Math.E * Math.PI"));
|
||||
}
|
||||
|
@ -572,11 +552,10 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
[ExpectedException(typeof(MissingMemberException), AllowDerivedTypes = true)]
|
||||
public void V8ScriptEngine_new_NoMatch()
|
||||
{
|
||||
engine.AddHostObject("clr", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib"));
|
||||
engine.Execute("new System.Random('a')");
|
||||
TestUtil.AssertException<MissingMemberException>(() => engine.Execute("new System.Random('a')"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
|
@ -595,6 +574,144 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
public void V8ScriptEngine_ErrorHandling_ScriptError()
|
||||
{
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("foo = {}; foo();");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNull(exception.InnerException);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
public void V8ScriptEngine_ErrorHandling_HostException()
|
||||
{
|
||||
engine.AddHostObject("host", new HostFunctions());
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Evaluate("host.newObj(null)");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(RuntimeBinderException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNull(hostException.InnerException);
|
||||
|
||||
Assert.AreEqual("Error: " + hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
public void V8ScriptEngine_ErrorHandling_IgnoredHostException()
|
||||
{
|
||||
engine.AddHostObject("host", new HostFunctions());
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("try { host.newObj(null); } catch(ex) {} foo = {}; foo();");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNull(exception.InnerException);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
public void V8ScriptEngine_ErrorHandling_NestedScriptError()
|
||||
{
|
||||
var innerEngine = new V8ScriptEngine("inner", V8ScriptEngineFlags.EnableDebugging);
|
||||
engine.AddHostObject("engine", innerEngine);
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("engine.Execute('foo = {}; foo();')");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(TargetInvocationException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNotNull(hostException.InnerException);
|
||||
|
||||
var nestedException = hostException.InnerException as ScriptEngineException;
|
||||
Assert.IsNotNull(nestedException);
|
||||
TestUtil.AssertValidException(innerEngine, nestedException);
|
||||
Assert.IsNull(nestedException.InnerException);
|
||||
|
||||
Assert.AreEqual("Error: " + hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("V8ScriptEngine")]
|
||||
public void V8ScriptEngine_ErrorHandling_NestedHostException()
|
||||
{
|
||||
var innerEngine = new V8ScriptEngine("inner", V8ScriptEngineFlags.EnableDebugging);
|
||||
innerEngine.AddHostObject("host", new HostFunctions());
|
||||
engine.AddHostObject("engine", innerEngine);
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("engine.Evaluate('host.newObj(null)')");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(TargetInvocationException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNotNull(hostException.InnerException);
|
||||
|
||||
var nestedException = hostException.InnerException as ScriptEngineException;
|
||||
Assert.IsNotNull(nestedException);
|
||||
TestUtil.AssertValidException(innerEngine, nestedException);
|
||||
Assert.IsNotNull(nestedException.InnerException);
|
||||
|
||||
var nestedHostException = nestedException.InnerException;
|
||||
Assert.IsInstanceOfType(nestedHostException, typeof(RuntimeBinderException));
|
||||
TestUtil.AssertValidException(nestedHostException);
|
||||
Assert.IsNull(nestedHostException.InnerException);
|
||||
|
||||
Assert.AreEqual("Error: " + nestedHostException.Message, nestedException.Message);
|
||||
Assert.AreEqual("Error: " + hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -65,8 +65,9 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using Microsoft.ClearScript.Util;
|
||||
using Microsoft.ClearScript.Windows;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
@ -145,7 +146,7 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
[ExpectedException(typeof(ExternalException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void VBScriptEngine_AddHostObject_DefaultAccess()
|
||||
{
|
||||
engine.AddHostObject("test", this);
|
||||
|
@ -165,7 +166,7 @@ namespace Microsoft.ClearScript.Test
|
|||
var host = new ExtendedHostFunctions() as HostFunctions;
|
||||
engine.AddRestrictedHostObject("host", host);
|
||||
Assert.IsInstanceOfType(engine.Evaluate("host.newObj()"), typeof(PropertyBag));
|
||||
TestUtil.AssertException<ExternalException>(() => engine.Evaluate("host.type(\"System.Int32\")"));
|
||||
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate("host.type(\"System.Int32\")"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
|
@ -197,7 +198,7 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
[ExpectedException(typeof(ExternalException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void VBScriptEngine_AddHostType_DefaultAccess()
|
||||
{
|
||||
engine.AddHostType("Test", GetType());
|
||||
|
@ -370,23 +371,12 @@ namespace Microsoft.ClearScript.Test
|
|||
});
|
||||
|
||||
engine.AddHostObject("checkpoint", checkpoint);
|
||||
|
||||
var gotException = false;
|
||||
try
|
||||
{
|
||||
engine.Execute("call checkpoint.Set() : while true : foo = \"hello\" : wend");
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
|
||||
Assert.IsTrue(gotException);
|
||||
TestUtil.AssertException<OperationCanceledException>(() => engine.Execute("call checkpoint.Set() : while true : foo = \"hello\" : wend"));
|
||||
Assert.AreEqual(Math.E * Math.PI, engine.Evaluate("e * pi"));
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
[ExpectedException(typeof(ExternalException))]
|
||||
[ExpectedException(typeof(ScriptEngineException))]
|
||||
public void VBScriptEngine_AccessContext_Default()
|
||||
{
|
||||
engine.AddHostObject("test", this);
|
||||
|
@ -405,19 +395,7 @@ namespace Microsoft.ClearScript.Test
|
|||
public void VBScriptEngine_ContinuationCallback()
|
||||
{
|
||||
engine.ContinuationCallback = () => false;
|
||||
|
||||
var gotException = false;
|
||||
try
|
||||
{
|
||||
engine.Execute("while true : foo = \"hello\" : wend");
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
gotException = true;
|
||||
}
|
||||
|
||||
Assert.IsTrue(gotException);
|
||||
|
||||
TestUtil.AssertException<OperationCanceledException>(() => engine.Execute("while true : foo = \"hello\" : wend"));
|
||||
engine.ContinuationCallback = null;
|
||||
Assert.AreEqual(Math.E * Math.PI, engine.Evaluate("e * pi"));
|
||||
}
|
||||
|
@ -517,6 +495,144 @@ namespace Microsoft.ClearScript.Test
|
|||
}
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
public void VBScriptEngine_ErrorHandling_ScriptError()
|
||||
{
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("foo = {}; foo();");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNull(exception.InnerException);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
public void VBScriptEngine_ErrorHandling_HostException()
|
||||
{
|
||||
engine.AddHostObject("host", new HostFunctions());
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Evaluate("host.newObj(null)");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(RuntimeBinderException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNull(hostException.InnerException);
|
||||
|
||||
Assert.AreEqual(hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
public void VBScriptEngine_ErrorHandling_IgnoredHostException()
|
||||
{
|
||||
engine.AddHostObject("host", new HostFunctions());
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("on error resume next : host.newObj(null) : on error goto 0 : foo = \"foo\" : foo()");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNull(exception.InnerException);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
public void VBScriptEngine_ErrorHandling_NestedScriptError()
|
||||
{
|
||||
var innerEngine = new JScriptEngine("inner", WindowsScriptEngineFlags.EnableDebugging);
|
||||
engine.AddHostObject("engine", innerEngine);
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("engine.Execute(\"foo = {}; foo();\")");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(TargetInvocationException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNotNull(hostException.InnerException);
|
||||
|
||||
var nestedException = hostException.InnerException as ScriptEngineException;
|
||||
Assert.IsNotNull(nestedException);
|
||||
TestUtil.AssertValidException(innerEngine, nestedException);
|
||||
Assert.IsNull(nestedException.InnerException);
|
||||
|
||||
Assert.AreEqual(hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod, TestCategory("VBScriptEngine")]
|
||||
public void VBScriptEngine_ErrorHandling_NestedHostException()
|
||||
{
|
||||
var innerEngine = new JScriptEngine("inner", WindowsScriptEngineFlags.EnableDebugging);
|
||||
innerEngine.AddHostObject("host", new HostFunctions());
|
||||
engine.AddHostObject("engine", innerEngine);
|
||||
|
||||
TestUtil.AssertException<ScriptEngineException>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
engine.Execute("engine.Evaluate(\"host.newObj(null)\")");
|
||||
}
|
||||
catch (ScriptEngineException exception)
|
||||
{
|
||||
TestUtil.AssertValidException(engine, exception);
|
||||
Assert.IsNotNull(exception.InnerException);
|
||||
|
||||
var hostException = exception.InnerException;
|
||||
Assert.IsInstanceOfType(hostException, typeof(TargetInvocationException));
|
||||
TestUtil.AssertValidException(hostException);
|
||||
Assert.IsNotNull(hostException.InnerException);
|
||||
|
||||
var nestedException = hostException.InnerException as ScriptEngineException;
|
||||
Assert.IsNotNull(nestedException);
|
||||
TestUtil.AssertValidException(innerEngine, nestedException);
|
||||
Assert.IsNotNull(nestedException.InnerException);
|
||||
|
||||
var nestedHostException = nestedException.InnerException;
|
||||
Assert.IsInstanceOfType(nestedHostException, typeof(RuntimeBinderException));
|
||||
TestUtil.AssertValidException(nestedHostException);
|
||||
Assert.IsNull(nestedHostException.InnerException);
|
||||
|
||||
Assert.AreEqual(nestedHostException.Message, nestedException.Message);
|
||||
Assert.AreEqual(hostException.Message, exception.Message);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -140,6 +140,7 @@ cd ..
|
|||
:Build
|
||||
|
||||
set GYP_MSVS_VERSION=2012
|
||||
set PYTHONHOME=
|
||||
|
||||
:Copy32Bit
|
||||
echo Building 32-bit V8 ...
|
||||
|
@ -154,7 +155,7 @@ if errorlevel 1 goto Error1
|
|||
cd v8-ia32
|
||||
third_party\python_26\python build\gyp_v8 -Dtarget_arch=ia32 -Dcomponent=shared_library -Dv8_use_snapshot=false >gyp.log
|
||||
if errorlevel 1 goto Error2
|
||||
msbuild /p:Configuration=%mode% /p:Platform=Win32 tools\gyp\v8.sln >build.log
|
||||
msbuild /p:Configuration=%mode% /p:Platform=Win32 /t:v8 tools\gyp\v8.sln >build.log
|
||||
if errorlevel 1 goto Error2
|
||||
cd ..
|
||||
:Build32BitDone
|
||||
|
@ -172,7 +173,7 @@ if errorlevel 1 goto Error1
|
|||
cd v8-x64
|
||||
third_party\python_26\python build\gyp_v8 -Dtarget_arch=x64 -Dcomponent=shared_library -Dv8_use_snapshot=false >gyp.log
|
||||
if errorlevel 1 goto Error2
|
||||
msbuild /p:Configuration=%mode% /p:Platform=x64 tools\gyp\v8.sln >build.log
|
||||
msbuild /p:Configuration=%mode% /p:Platform=x64 /t:v8 tools\gyp\v8.sln >build.log
|
||||
if errorlevel 1 goto Error2
|
||||
cd ..
|
||||
:Build64BitDone
|
||||
|
|
|
@ -1 +1 @@
|
|||
<# var version = new Version(5, 1, 3, 0); #>
|
||||
<# var version = new Version(5, 2, 0, 0); #>
|
||||
|
|
Загрузка…
Ссылка в новой задаче