Pārlūkot izejas kodu

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

Marko Lahma 6 gadi atpakaļ
vecāks
revīzija
c1a42a9da0

+ 1 - 1
Jint.Benchmark/Jint.Benchmark.csproj

@@ -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" />

+ 4 - 4
Jint.Tests.CommonScripts/Jint.Tests.CommonScripts.csproj

@@ -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>

+ 4 - 4
Jint.Tests.Ecma/Jint.Tests.Ecma.csproj

@@ -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>

+ 4 - 4
Jint.Tests.Test262/Jint.Tests.Test262.csproj

@@ -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>

+ 0 - 4
Jint.Tests.Test262/test/skipped.json

@@ -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"

+ 4 - 4
Jint.Tests/Jint.Tests.csproj

@@ -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>

+ 36 - 0
Jint/EsprimaExtensions.cs

@@ -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");
+        }
+    }
+}

+ 1 - 1
Jint/Jint.csproj

@@ -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>

+ 5 - 16
Jint/Native/JsValue.cs

@@ -147,24 +147,13 @@ namespace Jint.Native
         
         [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;
             }
 

+ 1 - 1
Jint/Native/Map/MapConstructor.cs

@@ -76,7 +76,7 @@ namespace Jint.Native.Map
                 && !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");

+ 2 - 2
Jint/Native/Set/SetConstructor.cs

@@ -76,12 +76,12 @@ namespace Jint.Native.Set
                 && !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)

+ 1 - 1
Jint/Runtime/JavaScriptException.cs

@@ -49,7 +49,7 @@ namespace Jint.Runtime
                     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);