Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ function postInstantiate(baseModule, instance) {
}
checkMem();

/** Raises an exception if a pointer is the NULL pointer. */
function checkNull(ptr) {
if (!ptr) throw Error("null pointer deref");
}

/** Allocates a new string in the module's memory and returns its pointer. */
function newString(str) {
var dataLength = str.length;
Expand All @@ -96,6 +101,7 @@ function postInstantiate(baseModule, instance) {
/** Gets a string from the module's memory by its pointer. */
function getString(ptr) {
checkMem();
checkNull(ptr);
return getStringImpl(U32, U16, ptr);
}

Expand Down Expand Up @@ -145,6 +151,7 @@ function postInstantiate(baseModule, instance) {
var elementSize = ctor.BYTES_PER_ELEMENT;
if (!elementSize) throw Error("not a typed array");
checkMem();
checkNull(ptr);
var buf = U32[ ptr >>> 2];
var byteOffset = U32[(ptr + 4) >>> 2];
var byteLength = U32[(ptr + 8) >>> 2];
Expand Down