Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor
  • Loading branch information
MaxGraey committed Apr 15, 2021
commit 6be028fac670f06a09fd693aee20157b6eb1f51c
10 changes: 6 additions & 4 deletions lib/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ function postInstantiate(extendedExports, instance) {
const __unpin = exports.__unpin || F_NOEXPORTRUNTIME;
const __collect = exports.__collect || F_NOEXPORTRUNTIME;
const __rtti_base = exports.__rtti_base;
const rttiBase = __rtti_base ? function () { return __rtti_base; } : F_NOEXPORTRUNTIME;
const getRttiCount = __rtti_base
? function (arr) { return arr[__rtti_base >>> 2]; }
: F_NOEXPORTRUNTIME;

extendedExports.__new = __new;
extendedExports.__pin = __pin;
Expand All @@ -99,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[rttiBase() >>> 2];
const count = getRttiCount(U32);
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
return U32[(__rtti_base + 4 >>> 2) + id * 2];
}
Expand All @@ -114,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[rttiBase() >>> 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 @@ -285,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[rttiBase() >>> 2]) {
if (id <= getRttiCount(U32)) {
do {
if (id == baseId) return true;
id = getBase(id);
Expand Down