@@ -88,7 +88,10 @@ function postInstantiate(extendedExports, instance) {
8888 const __pin = exports . __pin || F_NOEXPORTRUNTIME ;
8989 const __unpin = exports . __unpin || F_NOEXPORTRUNTIME ;
9090 const __collect = exports . __collect || F_NOEXPORTRUNTIME ;
91- const __rtti_base = exports . __rtti_base || ~ 0 ; // oob if not present
91+ const __rtti_base = exports . __rtti_base ;
92+ const getRttiCount = __rtti_base
93+ ? function ( arr ) { return arr [ __rtti_base >>> 2 ] ; }
94+ : F_NOEXPORTRUNTIME ;
9295
9396 extendedExports . __new = __new ;
9497 extendedExports . __pin = __pin ;
@@ -98,7 +101,7 @@ function postInstantiate(extendedExports, instance) {
98101 /** Gets the runtime type info for the given id. */
99102 function getInfo ( id ) {
100103 const U32 = new Uint32Array ( memory . buffer ) ;
101- const count = U32 [ __rtti_base >>> 2 ] ;
104+ const count = getRttiCount ( U32 ) ;
102105 if ( ( id >>>= 0 ) >= count ) throw Error ( `invalid id: ${ id } ` ) ;
103106 return U32 [ ( __rtti_base + 4 >>> 2 ) + id * 2 ] ;
104107 }
@@ -113,7 +116,7 @@ function postInstantiate(extendedExports, instance) {
113116 /** Gets the runtime base id for the given id. */
114117 function getBase ( id ) {
115118 const U32 = new Uint32Array ( memory . buffer ) ;
116- const count = U32 [ __rtti_base >>> 2 ] ;
119+ const count = getRttiCount ( U32 ) ;
117120 if ( ( id >>>= 0 ) >= count ) throw Error ( `invalid id: ${ id } ` ) ;
118121 return U32 [ ( __rtti_base + 4 >>> 2 ) + id * 2 + 1 ] ;
119122 }
@@ -284,7 +287,7 @@ function postInstantiate(extendedExports, instance) {
284287 function __instanceof ( ptr , baseId ) {
285288 const U32 = new Uint32Array ( memory . buffer ) ;
286289 let id = U32 [ ptr + ID_OFFSET >>> 2 ] ;
287- if ( id <= U32 [ __rtti_base >>> 2 ] ) {
290+ if ( id <= getRttiCount ( U32 ) ) {
288291 do {
289292 if ( id == baseId ) return true ;
290293 id = getBase ( id ) ;
0 commit comments