mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-16 16:31:32 +00:00
Add initial newArray and getArray helpers to loader
Essentially creates an unmanaged typed array in memory that one can work with and free again respectively obtain from the AS side. No support for GC or generic arrays yet, and is likely to change substentially once WASM GC becomes a thing.
This commit is contained in:
@ -33,3 +33,16 @@ var str = "Hello world!𤭢";
|
||||
var ptr = module.newString(str);
|
||||
assert.strictEqual(module.getString(ptr), str);
|
||||
assert.strictEqual(module.strlen(ptr), str.length);
|
||||
|
||||
// should be able to allocate a typed array and sum up its values
|
||||
var arr = [1, 2, 3, 4, 5, 0x7fffffff];
|
||||
ptr = module.newArray(new Int32Array(arr));
|
||||
assert.strictEqual(module.sum(ptr), arr.reduce((a, b) => a + b, 0) | 0);
|
||||
|
||||
// should be able to get a view on an internal typed array
|
||||
assert.deepEqual(module.getArray(Int32Array, ptr), arr);
|
||||
|
||||
// should be able to free and reuse the space of an internal typed array
|
||||
module.freeArray(ptr);
|
||||
var ptr2 = module.newArray(new Int32Array(arr));
|
||||
assert.strictEqual(ptr, ptr2);
|
||||
|
Reference in New Issue
Block a user