Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup fill/dup, add tests for fill
- Loading branch information
Showing
6 changed files
with
76 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
// @flow | ||
|
||
import type { Pointer } from '../../types'; | ||
import type { Memory } from './types'; | ||
|
||
module.exports = function dup (memory: Memory, ptr: Pointer, len: number): Uint8Array { | ||
return memory.uint8.slice(ptr, ptr + len); | ||
}; |
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,11 @@ | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
// @flow | ||
|
||
import type { Pointer } from '../../types'; | ||
import type { Memory } from './types'; | ||
|
||
module.exports = function fill (memory: Memory, ptr: Pointer, value: number, len: number): Uint8Array { | ||
return memory.uint8.fill(value, ptr, ptr + len); | ||
}; |
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,24 @@ | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
|
||
const envHeap = require('./index'); | ||
|
||
describe('fill', () => { | ||
let heap; | ||
|
||
beforeEach(() => { | ||
const buffer = [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]; | ||
|
||
heap = envHeap(); | ||
heap.setWasmMemory({ buffer }); | ||
}); | ||
|
||
it('uses fill to set values', () => { | ||
expect( | ||
heap.fill(2, 5, 4) | ||
).toEqual( | ||
new Uint8Array([0x0, 0x0, 0x5, 0x5, 0x5, 0x5, 0x0, 0x0]) | ||
); | ||
}); | ||
}); |
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,11 @@ | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
// @flow | ||
|
||
import type { Pointer } from '../../types'; | ||
import type { Memory } from './types'; | ||
|
||
module.exports = function get (memory: Memory, ptr: Pointer, len: number): Uint8Array { | ||
return memory.uint8.subarray(ptr, ptr + len); | ||
}; |
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,11 @@ | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
// @flow | ||
|
||
import type { Pointer } from '../../types'; | ||
import type { Memory } from './types'; | ||
|
||
module.exports = function getU32 (memory: Memory, ptr: Pointer): number { | ||
return memory.view.getUint32(ptr, true); | ||
}; |
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