|
| 1 | +// |
| 2 | +// Copyright © Microsoft Corporation. All rights reserved. |
| 3 | +// |
| 4 | +// Microsoft Public License (MS-PL) |
| 5 | +// |
| 6 | +// This license governs use of the accompanying software. If you use the |
| 7 | +// software, you accept this license. If you do not accept the license, do not |
| 8 | +// use the software. |
| 9 | +// |
| 10 | +// 1. Definitions |
| 11 | +// |
| 12 | +// The terms "reproduce," "reproduction," "derivative works," and |
| 13 | +// "distribution" have the same meaning here as under U.S. copyright law. A |
| 14 | +// "contribution" is the original software, or any additions or changes to |
| 15 | +// the software. A "contributor" is any person that distributes its |
| 16 | +// contribution under this license. "Licensed patents" are a contributor's |
| 17 | +// patent claims that read directly on its contribution. |
| 18 | +// |
| 19 | +// 2. Grant of Rights |
| 20 | +// |
| 21 | +// (A) Copyright Grant- Subject to the terms of this license, including the |
| 22 | +// license conditions and limitations in section 3, each contributor |
| 23 | +// grants you a non-exclusive, worldwide, royalty-free copyright license |
| 24 | +// to reproduce its contribution, prepare derivative works of its |
| 25 | +// contribution, and distribute its contribution or any derivative works |
| 26 | +// that you create. |
| 27 | +// |
| 28 | +// (B) Patent Grant- Subject to the terms of this license, including the |
| 29 | +// license conditions and limitations in section 3, each contributor |
| 30 | +// grants you a non-exclusive, worldwide, royalty-free license under its |
| 31 | +// licensed patents to make, have made, use, sell, offer for sale, |
| 32 | +// import, and/or otherwise dispose of its contribution in the software |
| 33 | +// or derivative works of the contribution in the software. |
| 34 | +// |
| 35 | +// 3. Conditions and Limitations |
| 36 | +// |
| 37 | +// (A) No Trademark License- This license does not grant you rights to use |
| 38 | +// any contributors' name, logo, or trademarks. |
| 39 | +// |
| 40 | +// (B) If you bring a patent claim against any contributor over patents that |
| 41 | +// you claim are infringed by the software, your patent license from such |
| 42 | +// contributor to the software ends automatically. |
| 43 | +// |
| 44 | +// (C) If you distribute any portion of the software, you must retain all |
| 45 | +// copyright, patent, trademark, and attribution notices that are present |
| 46 | +// in the software. |
| 47 | +// |
| 48 | +// (D) If you distribute any portion of the software in source code form, you |
| 49 | +// may do so only under this license by including a complete copy of this |
| 50 | +// license with your distribution. If you distribute any portion of the |
| 51 | +// software in compiled or object code form, you may only do so under a |
| 52 | +// license that complies with this license. |
| 53 | +// |
| 54 | +// (E) The software is licensed "as-is." You bear the risk of using it. The |
| 55 | +// contributors give no express warranties, guarantees or conditions. You |
| 56 | +// may have additional consumer rights under your local laws which this |
| 57 | +// license cannot change. To the extent permitted under your local laws, |
| 58 | +// the contributors exclude the implied warranties of merchantability, |
| 59 | +// fitness for a particular purpose and non-infringement. |
| 60 | +// |
| 61 | + |
| 62 | +using System; |
| 63 | +using System.Diagnostics.CodeAnalysis; |
| 64 | +using Microsoft.CSharp.RuntimeBinder; |
| 65 | +using Microsoft.ClearScript.V8; |
| 66 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 67 | + |
| 68 | +namespace Microsoft.ClearScript.Test |
| 69 | +{ |
| 70 | + [TestClass] |
| 71 | + [DeploymentItem("ClearScriptV8-64.dll")] |
| 72 | + [DeploymentItem("ClearScriptV8-32.dll")] |
| 73 | + [DeploymentItem("v8-x64.dll")] |
| 74 | + [DeploymentItem("v8-ia32.dll")] |
| 75 | + [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Test classes use TestCleanupAttribute for deterministic teardown.")] |
| 76 | + public class BugFixTest : ClearScriptTest |
| 77 | + { |
| 78 | + #region setup / teardown |
| 79 | + |
| 80 | + private ScriptEngine engine; |
| 81 | + |
| 82 | + [TestInitialize] |
| 83 | + public void TestInitialize() |
| 84 | + { |
| 85 | + engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging); |
| 86 | + } |
| 87 | + |
| 88 | + [TestCleanup] |
| 89 | + public void TestCleanup() |
| 90 | + { |
| 91 | + engine.Dispose(); |
| 92 | + } |
| 93 | + |
| 94 | + #endregion |
| 95 | + |
| 96 | + #region test methods |
| 97 | + |
| 98 | + // ReSharper disable InconsistentNaming |
| 99 | + |
| 100 | + [TestMethod, TestCategory("BugFix")] |
| 101 | + public void BugFix_NullArgumentBinding() |
| 102 | + { |
| 103 | + var value = 123.456 as IConvertible; |
| 104 | + engine.AddRestrictedHostObject("value", value); |
| 105 | + Assert.AreEqual(value.ToString(null), engine.Evaluate("value.ToString(null)")); |
| 106 | + } |
| 107 | + |
| 108 | + [TestMethod, TestCategory("BugFix")] |
| 109 | + [ExpectedException(typeof(RuntimeBinderException))] |
| 110 | + public void BugFix_NullArgumentBinding_Ambiguous() |
| 111 | + { |
| 112 | + engine.AddHostObject("lib", new HostTypeCollection("mscorlib")); |
| 113 | + engine.Execute("lib.System.Console.WriteLine(null)"); |
| 114 | + } |
| 115 | + |
| 116 | + // ReSharper restore InconsistentNaming |
| 117 | + |
| 118 | + #endregion |
| 119 | + } |
| 120 | +} |
0 commit comments