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 harness and fix issues #2029

Merged
merged 1 commit into from
Jan 18, 2025
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
15 changes: 14 additions & 1 deletion Jint.Tests.Test262/Test262Harness.settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SuiteGitSha": "d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60",
"SuiteGitSha": "b0f03cb22d8b9233347782d166e7793d4d4c757f",
//"SuiteDirectory": "//mnt/c/work/test262",
"TargetPath": "./Generated",
"Namespace": "Jint.Tests.Test262",
Expand All @@ -9,8 +9,12 @@
"async-iteration",
"Atomics",
"decorators",
"Error.isError",
"explicit-resource-management",
"import-defer",
"iterator-helpers",
"iterator-sequencing",
"json-parse-with-source",
"regexp-lookbehind",
"regexp-modifiers",
"regexp-unicode-property-escapes",
Expand All @@ -29,6 +33,14 @@
],
"ExcludedFiles": [

// requires rewrite of destructing towards spec
"language/destructuring/binding/keyed-destructuring-property-reference-target-evaluation-order-with-bindings.js",
"language/expressions/assignment/destructuring/keyed-destructuring-property-reference-target-evaluation-order-with-bindings.js",

// Acornima doesn't implement unicode 15/16 yet
"language/identifiers/*-unicode-15.*.js",
"language/identifiers/*-unicode-16.*.js",

// Currently quite impossible to detect if assignment target is CoverParenthesizedExpression
"language/expressions/assignment/fn-name-lhs-cover.js",

Expand Down Expand Up @@ -106,6 +118,7 @@
"built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-after-nested.js",
"built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-before-nested.js",
"built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-before-nested.js",
"built-ins/GeneratorPrototype/return/try-finally-set-property-within-try.js",
"built-ins/GeneratorPrototype/return/try-finally-within-finally.js",
"built-ins/GeneratorPrototype/return/try-finally-within-finally.js",
"built-ins/GeneratorPrototype/return/try-finally-within-try.js",
Expand Down
2 changes: 1 addition & 1 deletion Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Jint.Tests.Test262;

public abstract partial class Test262Test
{
private Engine BuildTestExecutor(Test262File file)
private static Engine BuildTestExecutor(Test262File file)
{
var engine = new Engine(cfg =>
{
Expand Down
23 changes: 13 additions & 10 deletions Jint/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ internal void PutValue(Reference reference, JsValue value)
var succeeded = baseObject.Set(reference.ReferencedName, value, reference.ThisValue);
if (!succeeded && reference.Strict)
{
ExceptionHelper.ThrowTypeError(Realm, "Cannot assign to read only property '" + property + "' of " + baseObject);
ExceptionHelper.ThrowTypeError(Realm, $"Cannot assign to read only property '{property}' of {baseObject}");
}
}
else
Expand Down Expand Up @@ -906,18 +906,21 @@ internal Reference ResolveBinding(string name, Environment? env = null)

private static Reference GetIdentifierReference(Environment? env, string name, bool strict)
{
if (env is null)
Key key = name;
while (true)
{
return new Reference(JsValue.Undefined, name, strict);
}
if (env is null)
{
return new Reference(JsValue.Undefined, name, strict);
}

var envRec = env;
if (envRec.HasBinding(name))
{
return new Reference(envRec, name, strict);
}
if (env.HasBinding(key))
{
return new Reference(env, name, strict);
}

return GetIdentifierReference(env._outerEnv, name, strict);
env = env._outerEnv;
}
}

/// <summary>
Expand Down
19 changes: 3 additions & 16 deletions Jint/Native/FinalizationRegistry/FinalizationRegistryPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ protected override void Initialize()
const PropertyFlag PropertyFlags = PropertyFlag.NonEnumerable;
var properties = new PropertyDictionary(4, checkExistingKeys: false)
{
[KnownKeys.Constructor] = new(_constructor, PropertyFlag.NonEnumerable), ["register"] = new(new ClrFunction(Engine, "register", Register, 2, PropertyFlag.Configurable), PropertyFlags), ["unregister"] = new(new ClrFunction(Engine, "unregister", Unregister, 1, PropertyFlag.Configurable), PropertyFlags), ["cleanupSome"] = new(new ClrFunction(Engine, "cleanupSome", CleanupSome, 0, PropertyFlag.Configurable), PropertyFlags),
[KnownKeys.Constructor] = new PropertyDescriptor(_constructor, PropertyFlag.NonEnumerable),
["register"] = new PropertyDescriptor(new ClrFunction(Engine, "register", Register, 2, PropertyFlag.Configurable), PropertyFlags),
["unregister"] = new PropertyDescriptor(new ClrFunction(Engine, "unregister", Unregister, 1, PropertyFlag.Configurable), PropertyFlags),
};
SetProperties(properties);

Expand Down Expand Up @@ -88,21 +90,6 @@ private JsValue Unregister(JsValue thisObject, JsValue[] arguments)
return finalizationRegistry.Remove(unregisterToken);
}

private JsValue CleanupSome(JsValue thisObject, JsValue[] arguments)
{
var finalizationRegistry = AssertFinalizationRegistryInstance(thisObject);
var callback = arguments.At(0);

if (!callback.IsUndefined() && callback is not ICallable)
{
ExceptionHelper.ThrowTypeError(_realm, callback + " must be callable");
}

FinalizationRegistryInstance.CleanupFinalizationRegistry(callback as ICallable);

return Undefined;
}

private FinalizationRegistryInstance AssertFinalizationRegistryInstance(JsValue thisObject)
{
if (thisObject is FinalizationRegistryInstance finalizationRegistryInstance)
Expand Down
32 changes: 32 additions & 0 deletions Jint/Native/JsTypedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@ internal override uint GetLength()
return record.IsTypedArrayOutOfBounds ? 0 : record.TypedArrayLength;
}

public override bool PreventExtensions()
{
if (!IsTypedArrayFixedLength)
{
return false;
}

return base.PreventExtensions();
}

/// <summary>
/// https://tc39.es/ecma262/#sec-istypedarrayfixedlength
/// </summary>
private bool IsTypedArrayFixedLength
{
get
{
if (_arrayLength == LengthAuto)
{
return false;
}

var buffer = _viewedArrayBuffer;
if (!buffer.IsFixedLengthArrayBuffer && !buffer.IsSharedArrayBuffer)
{
return false;
}

return true;
}
}

internal override bool IsArrayLike => true;

internal override bool IsIntegerIndexedArray => true;
Expand Down
6 changes: 3 additions & 3 deletions Jint/Native/Object/ObjectConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private JsValue Entries(JsValue thisObject, JsValue[] arguments)
private JsValue FromEntries(JsValue thisObject, JsValue[] arguments)
{
var iterable = arguments.At(0);
TypeConverter.CheckObjectCoercible(_engine, iterable);
TypeConverter.RequireObjectCoercible(_engine, iterable);

var obj = _realm.Intrinsics.Object.Construct(0);

Expand Down Expand Up @@ -206,15 +206,15 @@ public JsValue GetPrototypeOf(JsValue thisObject, JsValue[] arguments)
private JsValue SetPrototypeOf(JsValue thisObject, JsValue[] arguments)
{
var oArg = arguments.At(0);
TypeConverter.CheckObjectCoercible(_engine, oArg);
TypeConverter.RequireObjectCoercible(_engine, oArg);

var prototype = arguments.At(1);
if (!prototype.IsObject() && !prototype.IsNull())
{
ExceptionHelper.ThrowTypeError(_realm, $"Object prototype may only be an Object or null: {prototype}");
}

if (!(oArg is ObjectInstance o))
if (oArg is not ObjectInstance o)
{
return oArg;
}
Expand Down
3 changes: 3 additions & 0 deletions Jint/Native/Object/ObjectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,9 @@ internal bool IsConcatSpreadable

internal virtual uint GetLength() => (uint) TypeConverter.ToLength(Get(CommonProperties.Length));

/// <summary>
/// https://tc39.es/ecma262/#sec-ordinarypreventextensions
/// </summary>
public virtual bool PreventExtensions()
{
Extensible = false;
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Object/ObjectPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void Initialize()
new ClrFunction(Engine, "get __proto__", (thisObject, _) => TypeConverter.ToObject(_realm, thisObject).GetPrototypeOf() ?? Null, 0, LengthFlags),
new ClrFunction(Engine, "set __proto__", (thisObject, arguments) =>
{
TypeConverter.CheckObjectCoercible(_engine, thisObject);
TypeConverter.RequireObjectCoercible(_engine, thisObject);

var proto = arguments.At(0);
if (!proto.IsObject() && !proto.IsNull() || thisObject is not ObjectInstance objectInstance)
Expand Down
Loading
Loading