[browser][bindings] Fix error with SharedArrayBuffer when used as a backing view.#46625
Merged
kjpou1 merged 12 commits intodotnet:masterfrom Jan 8, 2021
kjpou1:wasm-fix-sharedarraybuffer
Merged
[browser][bindings] Fix error with SharedArrayBuffer when used as a backing view.#46625kjpou1 merged 12 commits intodotnet:masterfrom kjpou1:wasm-fix-sharedarraybuffer
kjpou1 merged 12 commits intodotnet:masterfrom
kjpou1:wasm-fix-sharedarraybuffer
Conversation
…edBuffer. - Resolves the error `"Object '...' is not a typed array"`
|
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsFails with "Object '...' is not a typed array" when used as a backing view for TypedArrays. public static int TestSum(SharedArrayBuffer sharedArrayBuffer)
{
Int32Array array = new Int32Array(sharedArrayBuffer);
Span<int> nativeArray = array; // error
int sum = 0;
for (int i = 0; i < nativeArray.Length; i++)
{
sum += nativeArray[i];
}
return sum;
}Fixes #46624
|
benaadams
reviewed
Jan 6, 2021
radical
requested changes
Jan 6, 2021
...ervices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
Outdated
Show resolved
Hide resolved
...ervices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
Outdated
Show resolved
Hide resolved
...nteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/SharedArrayBuffer.cs
Outdated
Show resolved
Hide resolved
...eropServices.JavaScript/tests/System.Private.Runtime.InteropServices.JavaScript.Tests.csproj
Outdated
Show resolved
Hide resolved
...eropServices.JavaScript/tests/System.Private.Runtime.InteropServices.JavaScript.Tests.csproj
Outdated
Show resolved
Hide resolved
...ervices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
Outdated
Show resolved
Hide resolved
...ervices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
Outdated
Show resolved
Hide resolved
...ervices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
Outdated
Show resolved
Hide resolved
...ervices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
Outdated
Show resolved
Hide resolved
...ervices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
Outdated
Show resolved
Hide resolved
Member
|
These might be useful: private static TheoryData<SharedArrayBuffer> GetTestData(int length)
{
// create a SharedArrayBuffer with a size in bytes
SharedArrayBuffer buffer = new SharedArrayBuffer(length);
Int32Array int32View = new Int32Array(buffer); // create view
for (int i = 0; i < int32View.Length; i ++)
int32View[i] = i + 10;
int32View[1] = 42;
return new TheoryData<SharedArrayBuffer> { buffer };
}
[Theory]
[MemberData(nameof(GetTestData), 16)]
public static void SharedArrayBufferSliceAndDice3_Subset(SharedArrayBuffer buffer)
{
Int32Array sliced = new Int32Array(buffer.Slice(4,12));
Assert.Equal(2, sliced.Length);
Assert.Equal(42, sliced[0]);
Assert.Equal(12, sliced[1]);
}
[Theory]
[MemberData(nameof(GetTestData), 16)]
public static void SharedArrayBufferSliceAndDice3_SubsetFromTheBack(SharedArrayBuffer buffer)
{
Int32Array sliced = new Int32Array(buffer.Slice(-4));
Assert.Equal(1, sliced.Length);
Assert.Equal(13, sliced[0]);
}
[Theory]
[MemberData(nameof(GetTestData), 16)]
public static void SharedArrayBufferSliceAndDice3_SubsetFromTheBackWithEnd(SharedArrayBuffer buffer)
{
Int32Array sliced = new Int32Array(buffer.Slice(-12, -4));
Assert.Equal(2, sliced.Length);
Assert.Equal(42, sliced[0]);
Assert.Equal(12, sliced[1]);
} |
…fix-sharedarraybuffer
Contributor
Author
|
Thanks Ankit. Will incorporate |
benaadams
reviewed
Jan 7, 2021
…ox." This reverts commit f817638.
…out all the whitespace changes.
benaadams
approved these changes
Jan 7, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fails with "Object '...' is not a typed array" when used as a backing view for TypedArrays.
Fixes #46624
Thanks @benaadams for the firefox support !!!