guard, info on never null, more general array rt

This commit is contained in:
dcode
2019-03-22 15:43:07 +01:00
parent c2ac1a0375
commit 7c0dc66849
69 changed files with 6066 additions and 4930 deletions

View File

@ -1,4 +1,5 @@
import { ALLOCATE, REGISTER, HEADER, HEADER_SIZE, MAX_BYTELENGTH } from "./runtime";
import { E_INVALIDLENGTH } from "./util/error";
@sealed export class ArrayBuffer {
@ -21,7 +22,7 @@ import { ALLOCATE, REGISTER, HEADER, HEADER_SIZE, MAX_BYTELENGTH } from "./runti
}
constructor(length: i32) {
if (<u32>length > <u32>MAX_BYTELENGTH) throw new RangeError("Invalid array buffer length");
if (<u32>length > <u32>MAX_BYTELENGTH) throw new RangeError(E_INVALIDLENGTH);
var buffer = ALLOCATE(<usize>length);
memory.fill(changetype<usize>(buffer), 0, <usize>length);
return REGISTER<ArrayBuffer>(buffer);