Skip to content

Commit

Permalink
Fix: Use F_NOEXPORTRUNTIME if __rtti_base is missing (AssemblyScript#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGraey authored Apr 15, 2021
1 parent 30f5d13 commit 7e20ad2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ function postInstantiate(extendedExports, instance) {
const __pin = exports.__pin || F_NOEXPORTRUNTIME;
const __unpin = exports.__unpin || F_NOEXPORTRUNTIME;
const __collect = exports.__collect || F_NOEXPORTRUNTIME;
const __rtti_base = exports.__rtti_base || ~0; // oob if not present
const __rtti_base = exports.__rtti_base;
const getRttiCount = __rtti_base
? function (arr) { return arr[__rtti_base >>> 2]; }
: F_NOEXPORTRUNTIME;

extendedExports.__new = __new;
extendedExports.__pin = __pin;
Expand All @@ -98,7 +101,7 @@ function postInstantiate(extendedExports, instance) {
/** Gets the runtime type info for the given id. */
function getInfo(id) {
const U32 = new Uint32Array(memory.buffer);
const count = U32[__rtti_base >>> 2];
const count = getRttiCount(U32);
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
return U32[(__rtti_base + 4 >>> 2) + id * 2];
}
Expand All @@ -113,7 +116,7 @@ function postInstantiate(extendedExports, instance) {
/** Gets the runtime base id for the given id. */
function getBase(id) {
const U32 = new Uint32Array(memory.buffer);
const count = U32[__rtti_base >>> 2];
const count = getRttiCount(U32);
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
return U32[(__rtti_base + 4 >>> 2) + id * 2 + 1];
}
Expand Down Expand Up @@ -284,7 +287,7 @@ function postInstantiate(extendedExports, instance) {
function __instanceof(ptr, baseId) {
const U32 = new Uint32Array(memory.buffer);
let id = U32[ptr + ID_OFFSET >>> 2];
if (id <= U32[__rtti_base >>> 2]) {
if (id <= getRttiCount(U32)) {
do {
if (id == baseId) return true;
id = getBase(id);
Expand Down

0 comments on commit 7e20ad2

Please sign in to comment.