Permalink
Browse files

upgrade Esprima and other libs, and include iterator test (#550)

  • Loading branch information...
lahma authored and sebastienros committed Nov 3, 2018
1 parent ce69f30 commit c1a42a9da0f8d91813b7cddfe3f001870410fb35
@@ -19,7 +19,7 @@
<None Include="..\Jint.Tests.CommonScripts\Scripts\**" CopyToOutputDirectory="PreserveNewest" LinkBase="SunSpider" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.2" />
<ProjectReference Include="..\Jint\Jint.csproj" />
<PackageReference Include="Jurassic" Version="3.0.0-alpha2" />
<PackageReference Include="NiL.JS.NetCore" Version="2.5.1200" />
@@ -9,11 +9,11 @@
<ProjectReference Include="..\Jint\Jint.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
</Project>
@@ -6,11 +6,11 @@
<ProjectReference Include="..\Jint\Jint.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
</Project>
@@ -6,11 +6,11 @@
<ProjectReference Include="..\Jint\Jint.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
</Project>
@@ -1,8 +1,4 @@
[
{
"source": "built-ins/Map/iterator-is-undefined-throws.js",
"reason": "Esprima problem"
},
{
"source": "built-ins/Boolean/proto-from-ctor-realm.js",
"reason": "realms not implemented"
@@ -12,11 +12,11 @@
<Reference Include="Microsoft.CSharp" Condition=" '$(TargetFramework)' == 'net452' " />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
</Project>
@@ -0,0 +1,36 @@
using System;
using Esprima.Ast;
using Jint.Native.Symbol;
using Jint.Runtime;
namespace Jint
{
internal static class EsprimaExtensions
{
public static string GetKey<T>(this T expression) where T : Expression
{
if (expression is Literal literal)
{
return literal.Value as string ?? Convert.ToString(literal.Value, provider: null);
}
if (expression is Identifier identifier)
{
return identifier.Name;
}
if (expression is StaticMemberExpression staticMemberExpression)
{
var obj = staticMemberExpression.Object.GetKey();
var property = staticMemberExpression.Property.GetKey();
if (obj == "Symbol" && property == "iterator")
{
return GlobalSymbolRegistry.Iterator._value;
}
}
return ExceptionHelper.ThrowArgumentException<string>("Unable to extract correct key");
}
}
}
@@ -7,6 +7,6 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Esprima" Version="1.0.0-beta-1051" />
<PackageReference Include="Esprima" Version="1.0.0-beta-1066" />
</ItemGroup>
</Project>
@@ -147,24 +147,13 @@ public ArrayInstance AsArray()
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal IIterator GetIterator()
internal IIterator GetIterator(Engine engine)
{
if (!(this is ObjectInstance oi))
if (!(this is ObjectInstance oi)
|| !oi.TryGetValue(GlobalSymbolRegistry.Iterator._value, out var value)
|| !(value is ICallable callable))
{
ExceptionHelper.ThrowArgumentException("The value is not iterable");
return null;
}
// TODO
if (!oi.TryGetValue(GlobalSymbolRegistry.Iterator._value, out var value))
{
ExceptionHelper.ThrowArgumentException("The value is not iterable");
return null;
}
if (!(value is ICallable callable))
{
ExceptionHelper.ThrowArgumentException("The value is not iterable");
ExceptionHelper.ThrowTypeError(engine, "The value is not iterable");
return null;
}
@@ -76,7 +76,7 @@ public ObjectInstance Construct(JsValue[] arguments)
&& !arguments[0].IsUndefined()
&& !arguments[0].IsNull())
{
var iterator = arguments.At(0).GetIterator();
var iterator = arguments.At(0).GetIterator(_engine);
if (iterator != null)
{
var setterProperty = instance.GetProperty("set");
@@ -76,12 +76,12 @@ public ObjectInstance Construct(JsValue[] arguments)
&& !arguments[0].IsUndefined()
&& !arguments[0].IsNull())
{
var iterator = arguments.At(0).GetIterator();
var iterator = arguments.At(0).GetIterator(_engine);
if (iterator != null)
{
var setterProperty = instance.GetProperty("add");
ICallable adder = null;
ICallable adder;
if (setterProperty == null
|| !setterProperty.TryGetValue(instance, out var setterValue)
|| (adder = setterValue as ICallable) == null)
@@ -49,7 +49,7 @@ public JavaScriptException SetCallstack(Engine engine, Location location = null)
if (index != 0)
sb.Append(", ");
var arg = cse.CallExpression.Arguments[index];
if (arg is PropertyKey pke)
if (arg is Expression pke)
sb.Append(pke.GetKey());
else
sb.Append(arg);

0 comments on commit c1a42a9

Please sign in to comment.