mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-20 02:11:31 +00:00
Implement a mechanism to realloc array buffers; Trap when trying to allocate more than max size; Test allocators in CI
This commit is contained in:
.travis.yml
bin
dist
std/assembly
tests
allocators
compiler.jscompiler
std
allocator_arena.optimized.watallocator_arena.untouched.watarray.optimized.watarray.untouched.watarraybuffer.optimized.watarraybuffer.untouched.watconstructor.optimized.watconstructor.untouched.watnew.optimized.watnew.untouched.watoperator-overloading.optimized.watoperator-overloading.untouched.watset.optimized.watset.untouched.watstatic-array.optimized.watstatic-array.untouched.watstring.optimized.watstring.untouched.wattypedarray.optimized.wattypedarray.untouched.wat
@ -1,7 +1,7 @@
|
||||
import {
|
||||
HEADER_SIZE,
|
||||
MAX_BLENGTH,
|
||||
allocate
|
||||
allocUnsafe
|
||||
} from "./internal/arraybuffer";
|
||||
|
||||
@sealed
|
||||
@ -11,7 +11,7 @@ export class ArrayBuffer {
|
||||
|
||||
constructor(length: i32) {
|
||||
if (<u32>length > <u32>MAX_BLENGTH) throw new RangeError("Invalid array buffer length");
|
||||
var buffer = allocate(length);
|
||||
var buffer = allocUnsafe(length);
|
||||
set_memory(changetype<usize>(buffer) + HEADER_SIZE, 0, <usize>length);
|
||||
return buffer;
|
||||
}
|
||||
@ -23,7 +23,7 @@ export class ArrayBuffer {
|
||||
if (end < 0) end = max(len + end, 0);
|
||||
else end = min(end, len);
|
||||
var newLen = max(end - begin, 0);
|
||||
var buffer = allocate(newLen);
|
||||
var buffer = allocUnsafe(newLen);
|
||||
move_memory(changetype<usize>(buffer) + HEADER_SIZE, changetype<usize>(this) + HEADER_SIZE + begin, newLen);
|
||||
return buffer;
|
||||
}
|
||||
|
Reference in New Issue
Block a user