Skip to content

Commit

Permalink
Introduce EvaluationContext for statement and expression evaluation (#…
Browse files Browse the repository at this point in the history
…979)

* Introduce EvaluationContext parameter to evaluation process

* Introduce ExpressionResult and Completion as results in evaluation
  • Loading branch information
lahma committed Oct 22, 2021
1 parent 412922c commit bf140bf
Show file tree
Hide file tree
Showing 99 changed files with 1,567 additions and 1,191 deletions.
4 changes: 3 additions & 1 deletion Jint.Tests/Runtime/Debugger/DebugHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Jint.Runtime.Debugger;
using Xunit;

#pragma warning disable 618

namespace Jint.Tests.Runtime.Debugger
{
public class DebugHandlerTests
Expand Down Expand Up @@ -33,7 +35,7 @@ public void AvoidsPauseRecursion()
var obj = info.CurrentScopeChain.Global.GetBindingValue("obj") as ObjectInstance;
var prop = obj.GetOwnProperty("name");
// This is where reentrance would occur:
var value = prop.Get.Invoke();
var value = prop.Get.Invoke(engine);
didPropertyAccess = true;
}
return StepMode.Into;
Expand Down
5 changes: 2 additions & 3 deletions Jint.Tests/Runtime/Debugger/ScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,13 @@ public void BlockScopedConstIsVisibleInsideBlock()
string script = @"
'dummy statement';
{
debugger; // const is initialized (as undefined) at beginning of block
const blockConst = 'block';
debugger; // const isn't initialized until declaration
}";

TestHelpers.TestAtBreak(script, info =>
{
var value = AssertOnlyScopeContains(info.CurrentScopeChain, "blockConst", DebugScopeType.Block);
Assert.Equal(JsUndefined.Undefined, value);
AssertOnlyScopeContains(info.CurrentScopeChain, "blockConst", DebugScopeType.Block);
});
}

Expand Down
26 changes: 9 additions & 17 deletions Jint.Tests/Runtime/EngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Reflection;
using Esprima;
using Esprima.Ast;
using Jint.Native;
using Jint.Native.Array;
using Jint.Native.Object;
Expand All @@ -12,6 +11,8 @@
using Xunit;
using Xunit.Abstractions;

#pragma warning disable 618

namespace Jint.Tests.Runtime
{
public class EngineTests : IDisposable
Expand Down Expand Up @@ -816,7 +817,7 @@ public void ShouldInvokeAFunctionValue()

var add = _engine.GetValue("add");

Assert.Equal(3, add.Invoke(1, 2));
Assert.Equal(3, add.Invoke(_engine, 1, 2));
}

[Fact]
Expand All @@ -828,7 +829,7 @@ public void ShouldAllowInvokeAFunctionValueWithNullValueAsArgument()

var add = _engine.GetValue("get");
string str = null;
Assert.Equal(Native.JsValue.Null, add.Invoke(str));
Assert.Equal(Native.JsValue.Null, add.Invoke(_engine, str));
}


Expand All @@ -841,7 +842,8 @@ public void ShouldNotInvokeNonFunctionValue()

var x = _engine.GetValue("x");

Assert.Throws<TypeErrorException>(() => x.Invoke(1, 2));
var exception = Assert.Throws<JavaScriptException>(() => x.Invoke(_engine, 1, 2));
Assert.Equal("Can only invoke functions", exception.Message);
}

[Fact]
Expand Down Expand Up @@ -1022,16 +1024,6 @@ public void ShouldBeCultureInvariant()
Assert.Equal(3.3d, result);
}

[Fact]
public void ShouldGetTheLastSyntaxNode()
{
var engine = new Engine();
engine.Evaluate("1.2");

var result = engine.GetLastSyntaxNode();
Assert.Equal(Nodes.Literal, result.Type);
}

[Fact]
public void ShouldGetParseErrorLocation()
{
Expand Down Expand Up @@ -2509,7 +2501,7 @@ public void ShouldReturnCorrectConcatenatedStrings()
}");

var concat = _engine.GetValue("concat");
var result = concat.Invoke("concat", "well", "done").ToObject() as string;
var result = concat.Invoke(_engine, "concat", "well", "done").ToObject() as string;
Assert.Equal("concatwelldone", result);
}

Expand Down Expand Up @@ -2643,10 +2635,10 @@ public void ShouldSupportDefaultsInFunctionParameters()
");

var function = _engine.GetValue("f");
var result = function.Invoke(3).ToString();
var result = function.Invoke(_engine, 3).ToString();
Assert.Equal("15", result);

result = function.Invoke(3, JsValue.Undefined).ToString();
result = function.Invoke(_engine, 3, JsValue.Undefined).ToString();
Assert.Equal("15", result);
}

Expand Down
2 changes: 1 addition & 1 deletion Jint/Collections/ListDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void Dispose()
object IEnumerator.Current => _current;
}

internal class DictionaryNode
internal sealed class DictionaryNode
{
public Key Key;
public TValue Value;
Expand Down

0 comments on commit bf140bf

Please sign in to comment.