-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #798 from glimmerjs/fix-array-growth
[BUGFIX] Grow the Uint16Array if the page size overflows 1MB
- Loading branch information
Showing
2 changed files
with
66 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Heap } from '@glimmer/program'; | ||
|
||
QUnit.module('Heap'); | ||
|
||
QUnit.test('Can grow', (assert) => { | ||
let size = 0x100000; | ||
let heap = new Heap(); | ||
|
||
let i = 0; | ||
|
||
while (i !== (size - 1)) { | ||
heap.push(1); | ||
i++; | ||
} | ||
|
||
// Should grow here | ||
heap.push(10); | ||
|
||
// Slices the buffer. Passing MAX_SAFE_INTEGER ensures | ||
// we get the whole thing out | ||
let serialized = heap.capture(Number.MAX_SAFE_INTEGER); | ||
let serializedHeap = new Uint16Array(serialized.buffer); | ||
assert.equal(serializedHeap.length, size); | ||
assert.equal(serializedHeap[size - 1], 10); | ||
|
||
heap.push(11); | ||
|
||
serialized = heap.capture(Number.MAX_SAFE_INTEGER); | ||
serializedHeap = new Uint16Array(serialized.buffer); | ||
|
||
if (serializedHeap.slice) { | ||
assert.equal(serializedHeap.length, size * 2); | ||
} else { | ||
// IE11 only gives you a buffer with residents in the slots | ||
assert.equal(serializedHeap.length, size + 1); | ||
} | ||
assert.equal(serializedHeap[size], 11); | ||
}); |