Make ExecuteCommand() work with JavaScript var statements. Add unit tests.
This commit is contained in:
Родитель
d9c1a5a6eb
Коммит
8a551a167c
|
@ -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': [
|
||||
|
|
|
@ -277,7 +277,11 @@ namespace Microsoft.ClearScript.V8
|
|||
/// </remarks>
|
||||
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))");
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -244,7 +244,8 @@ namespace Microsoft.ClearScript.Windows
|
|||
/// </remarks>
|
||||
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<int, string> RuntimeErrorMap
|
||||
|
|
|
@ -121,6 +121,7 @@ namespace Microsoft.ClearScript.Windows
|
|||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region constructors
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче