Skip to content

Commit

Permalink
Backport typed array related fixes (#1913)
Browse files Browse the repository at this point in the history
* resizable array buffer length checks should obey bounds checks
* fix async function expression prototype
* upgrade System.Text.Json to version 8.0.4
  • Loading branch information
lahma authored Jul 13, 2024
1 parent a2bd553 commit 376a332
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.0" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.45.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.3" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="Test262Harness" Version="1.0.0" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" PrivateAssets="all" />
Expand Down
8 changes: 6 additions & 2 deletions Jint.Tests.Test262/Test262Harness.settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SuiteGitSha": "c3a326ace810e7c80a4e1b8df8c8b704ed223c28",
"SuiteGitSha": "694fae5b10fa760951dbc9c2fe22a2fa38383c66",
//"SuiteDirectory": "//mnt/c/work/test262",
"TargetPath": "./Generated",
"Namespace": "Jint.Tests.Test262",
Expand All @@ -8,18 +8,22 @@
"Array.fromAsync",
"async-iteration",
"Atomics",
"Atomics.pause",
"Float16Array",
"import-assertions",
"iterator-helpers",
"Math.sumPrecise",
"promise-try",
"regexp-duplicate-named-groups",
"regexp-lookbehind",
"regexp-modifiers",
"regexp-unicode-property-escapes",
"regexp-v-flag",
"source-phase-imports",
"tail-call-optimization",
"Temporal",
"u180e"
"u180e",
"uint8array-base64"
],
"ExcludedFlags": [
],
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Array/ArrayOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public override void EnsureCapacity(ulong capacity)

public override bool TryGetValue(ulong index, out JsValue value)
{
if (index < _target.GetLength())
if (_target.IsValidIntegerIndex(index))
{
value = _target[(int) index];
return true;
Expand Down
6 changes: 5 additions & 1 deletion Jint/Native/JsTypedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public JsValue this[uint index]

public uint Length => GetLength();

internal override uint GetLength() => IntrinsicTypedArrayPrototype.MakeTypedArrayWithBufferWitnessRecord(this, ArrayBufferOrder.Unordered).TypedArrayLength;
internal override uint GetLength()
{
var record = IntrinsicTypedArrayPrototype.MakeTypedArrayWithBufferWitnessRecord(this, ArrayBufferOrder.Unordered);
return record.IsTypedArrayOutOfBounds ? 0 : record.TypedArrayLength;
}

internal override bool IsArrayLike => true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Jint.Native;
using Jint.Native.Function;
using Jint.Native.Object;

namespace Jint.Runtime.Interpreter.Expressions;

Expand All @@ -18,8 +19,12 @@ protected override object EvaluateInternal(EvaluationContext context)
var env = engine.ExecutionContext.LexicalEnvironment;
var privateEnv = engine.ExecutionContext.PrivateEnvironment;

ObjectInstance prototype = _function.Function.Async
? engine.Realm.Intrinsics.AsyncFunction.PrototypeObject
: engine.Realm.Intrinsics.Function.PrototypeObject;

var closure = engine.Realm.Intrinsics.Function.OrdinaryFunctionCreate(
engine.Realm.Intrinsics.Function.PrototypeObject,
prototype,
_function,
FunctionThisMode.Lexical,
env,
Expand Down

0 comments on commit 376a332

Please sign in to comment.