Browse Source

Enable more tests (#932)

* small tweaks and fixes to make tests pass
Marko Lahma 4 years ago
parent
commit
e0589fe4af

+ 15 - 0
Jint.Tests.Test262/Language/ArgumentsObjectTests.cs

@@ -0,0 +1,15 @@
+using Xunit;
+
+namespace Jint.Tests.Test262.Language
+{
+    public class ArgumentsObjectTests : Test262Test
+    {
+        [Theory(DisplayName = "language\\arguments-object")]
+        [MemberData(nameof(SourceFiles), "language\\arguments-object", false)]
+        [MemberData(nameof(SourceFiles), "language\\arguments-object", true, Skip = "Skipped")]
+        protected void ArgumentsObject(SourceFile sourceFile)
+        {
+            RunTestInternal(sourceFile);
+        }
+    }
+}

+ 15 - 0
Jint.Tests.Test262/Language/ComputedPropertyNamesTests.cs

@@ -0,0 +1,15 @@
+using Xunit;
+
+namespace Jint.Tests.Test262.Language
+{
+    public class ComputedPropertyNamesTests : Test262Test
+    {
+        [Theory(DisplayName = "language\\computed-property-names")]
+        [MemberData(nameof(SourceFiles), "language\\computed-property-names", false)]
+        [MemberData(nameof(SourceFiles), "language\\computed-property-names", true, Skip = "Skipped")]
+        protected void ComputedPropertyNames(SourceFile sourceFile)
+        {
+            RunTestInternal(sourceFile);
+        }
+    }
+}

+ 15 - 0
Jint.Tests.Test262/Language/Expressions/SuperTests.cs

@@ -0,0 +1,15 @@
+using Xunit;
+
+namespace Jint.Tests.Test262.Language.Expressions
+{
+    public class SuperTests : Test262Test
+    {
+        [Theory(DisplayName = "language\\expressions\\super")]
+        [MemberData(nameof(SourceFiles), "language\\expressions\\super", false)]
+        [MemberData(nameof(SourceFiles), "language\\expressions\\super", true, Skip = "Skipped")]
+        protected void Super(SourceFile sourceFile)
+        {
+            RunTestInternal(sourceFile);
+        }
+    }
+}

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

@@ -268,6 +268,28 @@
     "reason": "generators not implemented"
     "reason": "generators not implemented"
   },
   },
 
 
+  // Eval problems
+
+  {
+    "source": "language/expressions/super/prop-dot-cls-val-from-eval.js",
+    "reason": "JavaScriptParser cannot handle direct 'super.property' script code"
+  },
+
+  {
+    "source": "language/expressions/super/prop-dot-obj-val-from-eval.js",
+    "reason": "JavaScriptParser cannot handle direct 'super.property' script code"
+  },
+
+  {
+    "source": "language/expressions/super/prop-expr-cls-val-from-eval.js",
+    "reason": "JavaScriptParser cannot handle direct 'super.property' script code"
+  },
+
+  {
+    "source": "language/expressions/super/prop-expr-obj-val-from-eval.js",
+    "reason": "JavaScriptParser cannot handle direct 'super.property' script code"
+  },
+
   // Esprima problems
   // Esprima problems
 
 
   {
   {

+ 6 - 5
Jint/EsprimaExtensions.cs

@@ -42,11 +42,12 @@ namespace Jint
         private static bool TryGetComputedPropertyKey<T>(T expression, Engine engine, out JsValue propertyKey)
         private static bool TryGetComputedPropertyKey<T>(T expression, Engine engine, out JsValue propertyKey)
             where T : Expression
             where T : Expression
         {
         {
-            if (expression.Type == Nodes.Identifier
-                || expression.Type == Nodes.CallExpression
-                || expression.Type == Nodes.BinaryExpression
-                || expression.Type == Nodes.UpdateExpression
-                || expression.Type == Nodes.AssignmentExpression
+            if (expression.Type is Nodes.Identifier
+                or Nodes.CallExpression
+                or Nodes.BinaryExpression
+                or Nodes.UpdateExpression
+                or Nodes.AssignmentExpression
+                or Nodes.UnaryExpression
                 || expression is StaticMemberExpression)
                 || expression is StaticMemberExpression)
             {
             {
                 propertyKey = TypeConverter.ToPropertyKey(JintExpression.Build(engine, expression).GetValue());
                 propertyKey = TypeConverter.ToPropertyKey(JintExpression.Build(engine, expression).GetValue());

+ 1 - 1
Jint/Jint.csproj

@@ -8,7 +8,7 @@
     <IsPackable>true</IsPackable>
     <IsPackable>true</IsPackable>
   </PropertyGroup>
   </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Esprima" Version="2.0.0" />
+    <PackageReference Include="Esprima" Version="2.0.2" />
     <PackageReference Include="IsExternalInit" Version="1.0.1" PrivateAssets="all" />
     <PackageReference Include="IsExternalInit" Version="1.0.1" PrivateAssets="all" />
     <PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
     <PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
   </ItemGroup>
   </ItemGroup>

+ 1 - 1
Jint/Native/Array/ArrayInstance.cs

@@ -258,7 +258,7 @@ namespace Jint.Native.Array
             return base.TryGetProperty(property, out descriptor);
             return base.TryGetProperty(property, out descriptor);
         }
         }
 
 
-        public override List<JsValue> GetOwnPropertyKeys(Types types)
+        public override List<JsValue> GetOwnPropertyKeys(Types types = Types.None | Types.String | Types.Symbol)
         {
         {
             var properties = new List<JsValue>(_dense?.Length ?? 0 + 1);
             var properties = new List<JsValue>(_dense?.Length ?? 0 + 1);
             if (_dense != null)
             if (_dense != null)

+ 1 - 1
Jint/Native/Function/EvalFunctionInstance.cs

@@ -80,7 +80,7 @@ namespace Jint.Native.Function
                 }
                 }
                 else
                 else
                 {
                 {
-                    ExceptionHelper.ThrowSyntaxError(callerRealm);
+                    ExceptionHelper.ThrowSyntaxError(callerRealm, e.Message);
                 }
                 }
             }
             }
 
 

+ 22 - 9
Jint/Native/Function/FunctionInstance.cs

@@ -105,23 +105,36 @@ namespace Jint.Native.Function
 
 
         public override List<JsValue> GetOwnPropertyKeys(Types types)
         public override List<JsValue> GetOwnPropertyKeys(Types types)
         {
         {
-            var keys = new List<JsValue>();
-            if (_prototypeDescriptor != null)
+            var keys = base.GetOwnPropertyKeys(types);
+
+            // works around a problem where we don't use property for function names and classes should report it last
+            // as it's the last operation when creating a class constructor
+            if ((types & Types.String) != 0 && _nameDescriptor != null && this is ScriptFunctionInstance { _isClassConstructor: true })
             {
             {
-                keys.Add(CommonProperties.Prototype);
+                keys.Add(CommonProperties.Name);
             }
             }
+
+            return keys;
+        }
+
+        internal override IEnumerable<JsValue> GetInitialOwnStringPropertyKeys()
+        {
             if (_length != null)
             if (_length != null)
             {
             {
-                keys.Add(CommonProperties.Length);
+                yield return CommonProperties.Length;
             }
             }
-            if (_nameDescriptor != null)
+
+            // works around a problem where we don't use property for function names and classes should report it last
+            // as it's the last operation when creating a class constructor
+            if (_nameDescriptor != null && this is not ScriptFunctionInstance { _isClassConstructor: true })
             {
             {
-                keys.Add(CommonProperties.Name);
+                yield return CommonProperties.Name;
             }
             }
 
 
-            keys.AddRange(base.GetOwnPropertyKeys(types));
-
-            return keys;
+            if (_prototypeDescriptor != null)
+            {
+                yield return CommonProperties.Prototype;
+            }
         }
         }
 
 
         public override PropertyDescriptor GetOwnProperty(JsValue property)
         public override PropertyDescriptor GetOwnProperty(JsValue property)

+ 1 - 1
Jint/Native/Function/ScriptFunctionInstance.cs

@@ -11,7 +11,7 @@ namespace Jint.Native.Function
 {
 {
     public sealed class ScriptFunctionInstance : FunctionInstance, IConstructor
     public sealed class ScriptFunctionInstance : FunctionInstance, IConstructor
     {
     {
-        private bool _isClassConstructor;
+        internal bool _isClassConstructor;
 
 
         /// <summary>
         /// <summary>
         /// http://www.ecma-international.org/ecma-262/5.1/#sec-13.2
         /// http://www.ecma-international.org/ecma-262/5.1/#sec-13.2

+ 9 - 1
Jint/Native/Object/ObjectInstance.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Dynamic;
 using System.Dynamic;
+using System.Linq;
 using System.Runtime.CompilerServices;
 using System.Runtime.CompilerServices;
 using Jint.Collections;
 using Jint.Collections;
 using Jint.Native.Array;
 using Jint.Native.Array;
@@ -217,8 +218,13 @@ namespace Jint.Native.Object
         {
         {
             EnsureInitialized();
             EnsureInitialized();
 
 
-            var keys = new List<JsValue>(_properties?.Count ?? 0 + _symbols?.Count ?? 0);
             var propertyKeys = new List<JsValue>();
             var propertyKeys = new List<JsValue>();
+            if ((types & Types.String) != 0)
+            {
+                propertyKeys.AddRange(GetInitialOwnStringPropertyKeys());
+            }
+
+            var keys = new List<JsValue>(_properties?.Count ?? 0 + _symbols?.Count ?? 0 + propertyKeys.Count);
             List<JsValue> symbolKeys = null;
             List<JsValue> symbolKeys = null;
 
 
             if ((types & Types.String) != 0 && _properties != null)
             if ((types & Types.String) != 0 && _properties != null)
@@ -257,6 +263,8 @@ namespace Jint.Native.Object
             return keys;
             return keys;
         }
         }
 
 
+        internal virtual IEnumerable<JsValue> GetInitialOwnStringPropertyKeys() => Enumerable.Empty<JsValue>();
+
         protected virtual void AddProperty(JsValue property, PropertyDescriptor descriptor)
         protected virtual void AddProperty(JsValue property, PropertyDescriptor descriptor)
         {
         {
             SetProperty(property, descriptor);
             SetProperty(property, descriptor);

+ 1 - 1
Jint/Native/Proxy/ProxyInstance.cs

@@ -115,7 +115,7 @@ namespace Jint.Native.Proxy
             return result;
             return result;
         }
         }
 
 
-        public override List<JsValue> GetOwnPropertyKeys(Types types)
+        public override List<JsValue> GetOwnPropertyKeys(Types types = Types.None | Types.String | Types.Symbol)
         {
         {
             if (!TryCallHandler(TrapOwnKeys, new JsValue[] {_target }, out var result))
             if (!TryCallHandler(TrapOwnKeys, new JsValue[] {_target }, out var result))
             {
             {

+ 1 - 1
Jint/Runtime/Environments/FunctionEnvironmentRecord.cs

@@ -76,7 +76,7 @@ namespace Jint.Runtime.Environments
             var home = _functionObject._homeObject;
             var home = _functionObject._homeObject;
             return home.IsUndefined()
             return home.IsUndefined()
                 ? Undefined
                 ? Undefined
-                : ((ObjectInstance) home).GetPrototypeOf();
+                : ((ObjectInstance) home).GetPrototypeOf() ?? Null;
         }
         }
 
 
         // optimization to have logic near record internal structures.
         // optimization to have logic near record internal structures.

+ 1 - 0
Jint/Runtime/Interpreter/Expressions/JintObjectExpression.cs

@@ -190,6 +190,7 @@ namespace Jint.Runtime.Interpreter.Expressions
                         isStrictModeCode);
                         isStrictModeCode);
 
 
                     closure.SetFunctionName(propName, property.Kind == PropertyKind.Get ? "get" : "set");
                     closure.SetFunctionName(propName, property.Kind == PropertyKind.Get ? "get" : "set");
+                    closure.MakeMethod(obj);
 
 
                     var propDesc = new GetSetPropertyDescriptor(
                     var propDesc = new GetSetPropertyDescriptor(
                         get: property.Kind == PropertyKind.Get ? closure : null,
                         get: property.Kind == PropertyKind.Get ? closure : null,