Skip to content

Commit a70d603

Browse files
authored
fix(uint32ArrayFrom): increment index & polyfill for Uint32Array (#270)
increment index and polyfill for Uint32Array instead of Array
1 parent c63b577 commit a70d603

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/util/src/uint32ArrayFrom.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
// IE 11 does not support Array.from, so we do it manually
55
export function uint32ArrayFrom(a_lookUpTable: Array<number>): Uint32Array {
6-
if (!Array.from) {
6+
if (!Uint32Array.from) {
77
const return_array = new Uint32Array(a_lookUpTable.length)
88
let a_index = 0
99
while (a_index < a_lookUpTable.length) {
1010
return_array[a_index] = a_lookUpTable[a_index]
11+
a_index += 1
1112
}
1213
return return_array
1314
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { expect } from "chai";
5+
import "mocha";
6+
import { uint32ArrayFrom } from "../src/uint32ArrayFrom";
7+
8+
describe("uint32ArrayFrom", () =>{
9+
it("When given an empty array, should return an empty array", () => {
10+
expect(uint32ArrayFrom(Array.of(0)))
11+
.to
12+
.eql(Uint32Array.of(0))
13+
})
14+
15+
it("Given a populated array, returns a valid Uint32 Array", () => {
16+
expect(uint32ArrayFrom(Array.of(0x00000000, 0xF26B8303, 0xE13B70F7)))
17+
.to
18+
.eql(Uint32Array.of(0, 4067132163, 3778769143))
19+
})
20+
})

0 commit comments

Comments
 (0)