Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test262 test suite and fix issues #1958

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Jint.Tests.Test262/Test262Harness.settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SuiteGitSha": "941813e1f0e64ae9a5c4c5c8075f49ff89b0c642",
"SuiteGitSha": "d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60",
//"SuiteDirectory": "//mnt/c/work/test262",
"TargetPath": "./Generated",
"Namespace": "Jint.Tests.Test262",
Expand All @@ -10,7 +10,6 @@
"Atomics",
"decorators",
"explicit-resource-management",
"import-assertions",
"iterator-helpers",
"Math.sumPrecise",
"regexp-lookbehind",
Expand Down
8 changes: 5 additions & 3 deletions Jint/Native/Array/ArrayOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static ArrayOperations For(ObjectInstance instance, bool forWrite)
public abstract JsValue Get(ulong index);

public virtual JsValue[] GetAll(
Types elementTypes = Types.Undefined | Types.Null | Types.Boolean | Types.String | Types.Symbol | Types.Number | Types.Object,
Types elementTypes = Types.Undefined | Types.Null | Types.Boolean | Types.String | Types.Symbol | Types.Number | Types.BigInt | Types.Object,
bool skipHoles = false)
{
uint writeIndex = 0;
Expand Down Expand Up @@ -265,13 +265,15 @@ public override bool TryGetValue(ulong index, out JsValue value)

public override JsValue Get(ulong index) => _target.Get((uint) index);

public override JsValue[] GetAll(Types elementTypes = Types.Undefined | Types.Null | Types.Boolean | Types.String | Types.Symbol | Types.Number | Types.Object, bool skipHoles = false)
public override JsValue[] GetAll(
Types elementTypes = Types.Empty | Types.Undefined | Types.Null | Types.Boolean | Types.String | Types.Number | Types.Symbol | Types.BigInt | Types.Object,
bool skipHoles = false)
{
var n = _target.GetLength();

if (_target._dense == null || _target._dense.Length < n)
{
return base.GetAll(elementTypes);
return base.GetAll(elementTypes, skipHoles);
}

// optimized
Expand Down
58 changes: 26 additions & 32 deletions Jint/Native/JsTypedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,10 @@ internal bool HasProperty(long numericIndex)
/// </summary>
public override bool HasProperty(JsValue property)
{
if (property.IsString())
var numericIndex = TypeConverter.CanonicalNumericIndexString(property);
if (numericIndex is not null)
{
var numericIndex = TypeConverter.CanonicalNumericIndexString(property);
if (numericIndex is not null)
{
return IsValidIntegerIndex(numericIndex.Value);
}
return IsValidIntegerIndex(numericIndex.Value);
}

return base.HasProperty(property);
Expand Down Expand Up @@ -162,39 +159,36 @@ public override bool Set(JsValue property, JsValue value, JsValue receiver)
/// </summary>
public override bool DefineOwnProperty(JsValue property, PropertyDescriptor desc)
{
if (property.IsString())
var numericIndex = TypeConverter.CanonicalNumericIndexString(property);
if (numericIndex is not null)
{
var numericIndex = TypeConverter.CanonicalNumericIndexString(property);
if (numericIndex is not null)
if (!IsValidIntegerIndex(numericIndex.Value))
{
if (!IsValidIntegerIndex(numericIndex.Value))
{
return false;
}

if (desc.ConfigurableSet && !desc.Configurable)
{
return false;
}
return false;
}

if (desc.EnumerableSet && !desc.Enumerable)
{
return false;
}
if (desc is { ConfigurableSet: true, Configurable: false })
{
return false;
}

if (desc.IsAccessorDescriptor())
{
return false;
}
if (desc is { EnumerableSet: true, Enumerable: false })
{
return false;
}

if (desc.WritableSet && !desc.Writable)
{
return false;
}
if (desc.IsAccessorDescriptor())
{
return false;
}

IntegerIndexedElementSet(numericIndex.Value, desc.Value);
return true;
if (desc is { WritableSet: true, Writable: false })
{
return false;
}

IntegerIndexedElementSet(numericIndex.Value, desc.Value);
return true;
}

return base.DefineOwnProperty(property, desc);
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Debugger/DebugScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal DebugScope(DebugScopeType type, Environment record, bool isTopLevel)
/// <returns>Value of the binding</returns>
public JsValue? GetBindingValue(string name)
{
_record.TryGetBinding(new Environment.BindingName(name), out var result);
_record.TryGetBinding(new Environment.BindingName(name), strict: false, out var result);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ClrAccessDescriptor(

private JsValue DoGet(JsValue n)
{
return _env.TryGetBinding(_name, out var value)
return _env.TryGetBinding(_name, strict: true, out var value)
? value
: JsValue.Undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Environments/DeclarativeEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DeclarativeEnvironment(Engine engine, bool catchEnvironment = false) : ba

internal sealed override bool HasBinding(Key name) => _dictionary is not null && _dictionary.ContainsKey(name);

internal override bool TryGetBinding(BindingName name, [NotNullWhen(true)] out JsValue? value)
internal override bool TryGetBinding(BindingName name, bool strict, [NotNullWhen(true)] out JsValue? value)
{
if (_dictionary?.TryGetValue(name.Key, out var binding) == true)
{
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Environments/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected Environment(Engine engine) : base(InternalTypes.ObjectEnvironmentRecor

internal abstract bool HasBinding(BindingName name);

internal abstract bool TryGetBinding(BindingName name, [NotNullWhen(true)] out JsValue? value);
internal abstract bool TryGetBinding(BindingName name, bool strict, [NotNullWhen(true)] out JsValue? value);

/// <summary>
/// Creates a new mutable binding in an environment record.
Expand Down
4 changes: 2 additions & 2 deletions Jint/Runtime/Environments/GlobalEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ internal override bool HasBinding(BindingName name)
return _global.HasProperty(name.Value);
}

internal override bool TryGetBinding(BindingName name, [NotNullWhen(true)] out JsValue? value)
internal override bool TryGetBinding(BindingName name, bool strict, [NotNullWhen(true)] out JsValue? value)
{
if (_declarativeRecord._dictionary is not null && _declarativeRecord.TryGetBinding(name, out value))
if (_declarativeRecord._dictionary is not null && _declarativeRecord.TryGetBinding(name, strict, out value))
{
return true;
}
Expand Down
5 changes: 3 additions & 2 deletions Jint/Runtime/Environments/JintEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ record = record._outerEnv;
internal static bool TryGetIdentifierEnvironmentWithBindingValue(
Environment env,
Environment.BindingName name,
bool strict,
[NotNullWhen(true)] out Environment? record,
[NotNullWhen(true)] out JsValue? value)
{
Expand All @@ -43,12 +44,12 @@ record = env;

if (env._outerEnv is null)
{
return ((GlobalEnvironment) env).TryGetBinding(name, out value);
return ((GlobalEnvironment) env).TryGetBinding(name, strict, out value);
}

while (record is not null)
{
if (record.TryGetBinding(name, out value))
if (record.TryGetBinding(name, strict, out value))
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions Jint/Runtime/Environments/ModuleEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ internal override JsValue GetBindingValue(Key name, bool strict)
return base.GetBindingValue(name, strict);
}

internal override bool TryGetBinding(BindingName name, [NotNullWhen(true)] out JsValue? value)
internal override bool TryGetBinding(BindingName name, bool strict, [NotNullWhen(true)] out JsValue? value)
{
if (_importBindings.TryGetValue(name.Key, out var indirectBinding))
{
value = indirectBinding.Module._environment.GetBindingValue(indirectBinding.BindingName, strict: true);
return true;
}

return base.TryGetBinding(name, out value);
return base.TryGetBinding(name, strict, out value);
}

/// <summary>
Expand Down
20 changes: 11 additions & 9 deletions Jint/Runtime/Environments/ObjectEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ObjectEnvironment(
internal override bool HasBinding(Key name)
{
var property = new JsString(name.Name);
var foundBinding = HasProperty(property);
var foundBinding = _bindingObject.HasProperty(property);

if (!foundBinding)
{
Expand All @@ -47,7 +47,7 @@ internal override bool HasBinding(Key name)

internal override bool HasBinding(BindingName name)
{
var foundBinding = HasProperty(name.Value);
var foundBinding = _bindingObject.HasProperty(name.Value);

if (!foundBinding)
{
Expand All @@ -62,15 +62,10 @@ internal override bool HasBinding(BindingName name)
return !IsBlocked(name.Value);
}

private bool HasProperty(JsValue property)
{
return _bindingObject.HasProperty(property);
}

internal override bool TryGetBinding(BindingName name, [NotNullWhen(true)] out JsValue? value)
internal override bool TryGetBinding(BindingName name, bool strict, [NotNullWhen(true)] out JsValue? value)
{
// we unwrap by name
if (!HasProperty(name.Value))
if (!_bindingObject.HasProperty(name.Value))
{
value = default;
return false;
Expand All @@ -83,6 +78,13 @@ internal override bool TryGetBinding(BindingName name, [NotNullWhen(true)] out J
}

value = _bindingObject.Get(name.Value);

if (strict && value.IsUndefined() && !_bindingObject.HasProperty(name.Value))
{
// data was deleted during reading of unscopable information, of course...
ExceptionHelper.ThrowReferenceNameError(_engine.Realm, name.Key);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ internal static JintExpression Build(AssignmentExpression expression)
protected override object EvaluateInternal(EvaluationContext context)
{
var engine = context.Engine;
var strict = StrictModeScope.IsStrictModeCode;

JsValue originalLeftValue;
Reference lref;
if (_leftIdentifier is not null && JintEnvironment.TryGetIdentifierEnvironmentWithBindingValue(
engine.ExecutionContext.LexicalEnvironment,
_leftIdentifier.Identifier,
strict,
out var identifierEnvironment,
out var temp))
{
originalLeftValue = temp;
lref = engine._referencePool.Rent(identifierEnvironment, _leftIdentifier.Identifier.Value, StrictModeScope.IsStrictModeCode, thisValue: null);
lref = engine._referencePool.Rent(identifierEnvironment, _leftIdentifier.Identifier.Value, strict, thisValue: null);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public override JsValue GetValue(EvaluationContext context)

var engine = context.Engine;
var env = engine.ExecutionContext.LexicalEnvironment;
var strict = StrictModeScope.IsStrictModeCode;

if (JintEnvironment.TryGetIdentifierEnvironmentWithBindingValue(
env,
identifier,
strict,
out _,
out var value))
{
Expand All @@ -70,7 +72,7 @@ public override JsValue GetValue(EvaluationContext context)
}
else
{
var reference = engine._referencePool.Rent(JsValue.Undefined, identifier.Value, StrictModeScope.IsStrictModeCode, thisValue: null);
var reference = engine._referencePool.Rent(JsValue.Undefined, identifier.Value, strict, thisValue: null);
value = engine.GetValue(reference, returnReferenceToPool: true);
}

Expand Down
4 changes: 3 additions & 1 deletion Jint/Runtime/Interpreter/Expressions/JintMemberExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected override object EvaluateInternal(EvaluationContext context)
JsValue? baseValue = null;

var engine = context.Engine;
var strict = StrictModeScope.IsStrictModeCode;
if (_objectExpression is JintIdentifierExpression identifierExpression)
{
var identifier = identifierExpression.Identifier;
Expand All @@ -69,6 +70,7 @@ protected override object EvaluateInternal(EvaluationContext context)
JintEnvironment.TryGetIdentifierEnvironmentWithBindingValue(
env,
identifier,
strict,
out _,
out baseValue);
}
Expand Down Expand Up @@ -135,4 +137,4 @@ private static Reference MakePrivateReference(Engine engine, JsValue baseValue,
var privateName = privEnv!.ResolvePrivateIdentifier(privateIdentifier.ToString());
return engine._referencePool.Rent(baseValue, privateName!, strict: true, thisValue: null);
}
}
}
9 changes: 6 additions & 3 deletions Jint/Runtime/Interpreter/Expressions/JintUpdateExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ private JsValue UpdateNonIdentifier(EvaluationContext context)
private JsValue? UpdateIdentifier(EvaluationContext context)
{
var name = _leftIdentifier!.Identifier;
var strict = StrictModeScope.IsStrictModeCode;

if (JintEnvironment.TryGetIdentifierEnvironmentWithBindingValue(
context.Engine.ExecutionContext.LexicalEnvironment,
name,
strict,
out var environmentRecord,
out var value))
{
if (_evalOrArguments && StrictModeScope.IsStrictModeCode)
if (_evalOrArguments && strict)
{
ExceptionHelper.ThrowSyntaxError(context.Engine.Realm);
}
Expand Down Expand Up @@ -163,7 +166,7 @@ private JsValue UpdateNonIdentifier(EvaluationContext context)
}
}

environmentRecord.SetMutableBinding(name.Key, newValue!, StrictModeScope.IsStrictModeCode);
environmentRecord.SetMutableBinding(name.Key, newValue!, strict);
if (_prefix)
{
return newValue;
Expand All @@ -179,4 +182,4 @@ private JsValue UpdateNonIdentifier(EvaluationContext context)

return null;
}
}
}