diff --git a/ClearScript/V8/V8/V8Patch.txt b/ClearScript/V8/V8/V8Patch.txt index d01c28e1..3fcc54a8 100644 --- a/ClearScript/V8/V8/V8Patch.txt +++ b/ClearScript/V8/V8/V8Patch.txt @@ -1,6 +1,6 @@ Index: tools/gyp/v8.gyp =================================================================== ---- tools/gyp/v8.gyp (revision 13599) +--- tools/gyp/v8.gyp (revision 13624) +++ tools/gyp/v8.gyp (working copy) @@ -32,6 +32,7 @@ 'targets': [ diff --git a/ClearScript/V8/V8ScriptEngine.cs b/ClearScript/V8/V8ScriptEngine.cs index 2651e28b..3db5d245 100644 --- a/ClearScript/V8/V8ScriptEngine.cs +++ b/ClearScript/V8/V8ScriptEngine.cs @@ -277,7 +277,11 @@ namespace Microsoft.ClearScript.V8 /// public override string ExecuteCommand(string command) { - return base.ExecuteCommand(MiscHelpers.FormatInvariant("EngineInternal.getCommandResult({0})", command)); + return ScriptInvoke(() => + { + Script.EngineInternal.command = command; + return base.ExecuteCommand("EngineInternal.getCommandResult(eval(EngineInternal.command))"); + }); } /// diff --git a/ClearScript/Windows/JScriptEngine.cs b/ClearScript/Windows/JScriptEngine.cs index 04d37136..e3a23492 100644 --- a/ClearScript/Windows/JScriptEngine.cs +++ b/ClearScript/Windows/JScriptEngine.cs @@ -244,7 +244,8 @@ namespace Microsoft.ClearScript.Windows /// public override string ExecuteCommand(string command) { - return base.ExecuteCommand(MiscHelpers.FormatInvariant("EngineInternal.getCommandResult({0})", command)); + Script.EngineInternal.command = command; + return base.ExecuteCommand("EngineInternal.getCommandResult(eval(EngineInternal.command))"); } internal override IDictionary RuntimeErrorMap diff --git a/ClearScript/Windows/VBScriptEngine.cs b/ClearScript/Windows/VBScriptEngine.cs index 04f3f776..4b5c19ac 100644 --- a/ClearScript/Windows/VBScriptEngine.cs +++ b/ClearScript/Windows/VBScriptEngine.cs @@ -121,6 +121,7 @@ namespace Microsoft.ClearScript.Windows }; #endregion + #region constructors /// diff --git a/ClearScriptTest/JScriptEngineTest.cs b/ClearScriptTest/JScriptEngineTest.cs index e1939968..9c0bbbc2 100644 --- a/ClearScriptTest/JScriptEngineTest.cs +++ b/ClearScriptTest/JScriptEngineTest.cs @@ -299,6 +299,20 @@ namespace Microsoft.ClearScript.Test Assert.AreEqual(dateHostItem.ToString(), engine.ExecuteCommand("date")); } + [TestMethod, TestCategory("JScriptEngine")] + public void JScriptEngine_ExecuteCommand_var() + { + Assert.AreEqual("[undefined]", engine.ExecuteCommand("var x = 'foo'")); + Assert.AreEqual("foo", engine.Script.x); + } + + [TestMethod, TestCategory("JScriptEngine")] + public void JScriptEngine_ExecuteCommand_HostVariable() + { + engine.Script.host = new HostFunctions(); + Assert.AreEqual("[HostVariable:String]", engine.ExecuteCommand("host.newVar('foo')")); + } + [TestMethod, TestCategory("JScriptEngine")] public void JScriptEngine_Interrupt() { diff --git a/ClearScriptTest/V8ScriptEngineTest.cs b/ClearScriptTest/V8ScriptEngineTest.cs index aff6fa07..5ac61989 100644 --- a/ClearScriptTest/V8ScriptEngineTest.cs +++ b/ClearScriptTest/V8ScriptEngineTest.cs @@ -302,6 +302,20 @@ namespace Microsoft.ClearScript.Test Assert.AreEqual(dateHostItem.ToString(), engine.ExecuteCommand("date")); } + [TestMethod, TestCategory("V8ScriptEngine")] + public void V8ScriptEngine_ExecuteCommand_var() + { + Assert.AreEqual("[undefined]", engine.ExecuteCommand("var x = 'foo'")); + Assert.AreEqual("foo", engine.Script.x); + } + + [TestMethod, TestCategory("V8ScriptEngine")] + public void V8ScriptEngine_ExecuteCommand_HostVariable() + { + engine.Script.host = new HostFunctions(); + Assert.AreEqual("[HostVariable:String]", engine.ExecuteCommand("host.newVar('foo')")); + } + [TestMethod, TestCategory("V8ScriptEngine")] public void V8ScriptEngine_Interrupt() { @@ -314,10 +328,13 @@ namespace Microsoft.ClearScript.Test engine.AddHostObject("checkpoint", checkpoint); + // 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 = 'hello'; }"); + engine.Execute("checkpoint.Set(); while (true) { var foo = test.foo; }"); } catch (OperationCanceledException) { diff --git a/ClearScriptTest/VBScriptEngineTest.cs b/ClearScriptTest/VBScriptEngineTest.cs index 42bca7a5..fbd4386c 100644 --- a/ClearScriptTest/VBScriptEngineTest.cs +++ b/ClearScriptTest/VBScriptEngineTest.cs @@ -325,6 +325,13 @@ namespace Microsoft.ClearScript.Test Assert.AreEqual(dateHostItem.ToString(), engine.ExecuteCommand("eval date")); } + [TestMethod, TestCategory("VBScriptEngine")] + public void VBScriptEngine_ExecuteCommand_HostVariable() + { + engine.Script.host = new HostFunctions(); + Assert.AreEqual("[HostVariable:String]", engine.ExecuteCommand("eval host.newVar(\"foo\")")); + } + [TestMethod, TestCategory("VBScriptEngine")] public void VBScriptEngine_Interrupt() {