Skip to content

Commit

Permalink
Enable more tests (#932)
Browse files Browse the repository at this point in the history
* small tweaks and fixes to make tests pass
  • Loading branch information
lahma authored Jul 18, 2021
1 parent 1a9cd0e commit e0589fe
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 21 deletions.
15 changes: 15 additions & 0 deletions Jint.Tests.Test262/Language/ArgumentsObjectTests.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions Jint.Tests.Test262/Language/ComputedPropertyNamesTests.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions Jint.Tests.Test262/Language/Expressions/SuperTests.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions Jint.Tests.Test262/test/skipped.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,28 @@
"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

{
Expand Down
11 changes: 6 additions & 5 deletions Jint/EsprimaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public static JsValue GetKey(this Expression expression, Engine engine, bool res
private static bool TryGetComputedPropertyKey<T>(T expression, Engine engine, out JsValue propertyKey)
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)
{
propertyKey = TypeConverter.ToPropertyKey(JintExpression.Build(engine, expression).GetValue());
Expand Down
2 changes: 1 addition & 1 deletion Jint/Jint.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<IsPackable>true</IsPackable>
</PropertyGroup>
<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="Nullable" Version="1.3.0" PrivateAssets="all" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Array/ArrayInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ protected override bool TryGetProperty(JsValue property, out PropertyDescriptor
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);
if (_dense != null)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Function/EvalFunctionInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public JsValue PerformEval(JsValue x, Realm callerRealm, bool strictCaller, bool
}
else
{
ExceptionHelper.ThrowSyntaxError(callerRealm);
ExceptionHelper.ThrowSyntaxError(callerRealm, e.Message);
}
}

Expand Down
31 changes: 22 additions & 9 deletions Jint/Native/Function/FunctionInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,36 @@ public override IEnumerable<KeyValuePair<JsValue, PropertyDescriptor>> GetOwnPro

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)
{
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)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Function/ScriptFunctionInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Jint.Native.Function
{
public sealed class ScriptFunctionInstance : FunctionInstance, IConstructor
{
private bool _isClassConstructor;
internal bool _isClassConstructor;

/// <summary>
/// http://www.ecma-international.org/ecma-262/5.1/#sec-13.2
Expand Down
10 changes: 9 additions & 1 deletion Jint/Native/Object/ObjectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Runtime.CompilerServices;
using Jint.Collections;
using Jint.Native.Array;
Expand Down Expand Up @@ -217,8 +218,13 @@ public virtual List<JsValue> GetOwnPropertyKeys(Types types = Types.String | Typ
{
EnsureInitialized();

var keys = new List<JsValue>(_properties?.Count ?? 0 + _symbols?.Count ?? 0);
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;

if ((types & Types.String) != 0 && _properties != null)
Expand Down Expand Up @@ -257,6 +263,8 @@ public virtual List<JsValue> GetOwnPropertyKeys(Types types = Types.String | Typ
return keys;
}

internal virtual IEnumerable<JsValue> GetInitialOwnStringPropertyKeys() => Enumerable.Empty<JsValue>();

protected virtual void AddProperty(JsValue property, PropertyDescriptor descriptor)
{
SetProperty(property, descriptor);
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Proxy/ProxyInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override JsValue Get(JsValue property, JsValue receiver)
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))
{
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Environments/FunctionEnvironmentRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public JsValue GetSuperBase()
var home = _functionObject._homeObject;
return home.IsUndefined()
? Undefined
: ((ObjectInstance) home).GetPrototypeOf();
: ((ObjectInstance) home).GetPrototypeOf() ?? Null;
}

// optimization to have logic near record internal structures.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ private object BuildObjectNormal()
isStrictModeCode);

closure.SetFunctionName(propName, property.Kind == PropertyKind.Get ? "get" : "set");
closure.MakeMethod(obj);

var propDesc = new GetSetPropertyDescriptor(
get: property.Kind == PropertyKind.Get ? closure : null,
Expand Down

0 comments on commit e0589fe

Please sign in to comment.