@@ -81,16 +81,16 @@ function postInstantiate(extendedExports, instance) {
81
81
const exports = instance . exports ;
82
82
const memory = exports . memory ;
83
83
const table = exports . table ;
84
- const new_ = exports [ "__new" ] ;
85
- const retain = exports [ "__retain" ] ;
86
- const rttiBase = exports [ "__rtti_base" ] || ~ 0 ; // oob if not present
84
+ const __new = exports [ "__new" ] ;
85
+ const __retain = exports [ "__retain" ] ;
86
+ const __rtti_base = exports [ "__rtti_base" ] || ~ 0 ; // oob if not present
87
87
88
88
/** Gets the runtime type info for the given id. */
89
89
function getInfo ( id ) {
90
90
const U32 = new Uint32Array ( memory . buffer ) ;
91
- const count = U32 [ rttiBase >>> 2 ] ;
91
+ const count = U32 [ __rtti_base >>> 2 ] ;
92
92
if ( ( id >>>= 0 ) >= count ) throw Error ( `invalid id: ${ id } ` ) ;
93
- return U32 [ ( rttiBase + 4 >>> 2 ) + id * 2 ] ;
93
+ return U32 [ ( __rtti_base + 4 >>> 2 ) + id * 2 ] ;
94
94
}
95
95
96
96
/** Gets and validate runtime type info for the given id for array like objects */
@@ -103,9 +103,9 @@ function postInstantiate(extendedExports, instance) {
103
103
/** Gets the runtime base id for the given id. */
104
104
function getBase ( id ) {
105
105
const U32 = new Uint32Array ( memory . buffer ) ;
106
- const count = U32 [ rttiBase >>> 2 ] ;
106
+ const count = U32 [ __rtti_base >>> 2 ] ;
107
107
if ( ( id >>>= 0 ) >= count ) throw Error ( `invalid id: ${ id } ` ) ;
108
- return U32 [ ( rttiBase + 4 >>> 2 ) + id * 2 + 1 ] ;
108
+ return U32 [ ( __rtti_base + 4 >>> 2 ) + id * 2 + 1 ] ;
109
109
}
110
110
111
111
/** Gets the runtime alignment of a collection's values. */
@@ -120,8 +120,9 @@ function postInstantiate(extendedExports, instance) {
120
120
121
121
/** Allocates a new string in the module's memory and returns its retained pointer. */
122
122
function __newString ( str ) {
123
+ if ( str == null ) return 0 ;
123
124
const length = str . length ;
124
- const ptr = new_ ( length << 1 , STRING_ID ) ;
125
+ const ptr = __new ( length << 1 , STRING_ID ) ;
125
126
const U16 = new Uint16Array ( memory . buffer ) ;
126
127
for ( var i = 0 , p = ptr >>> 1 ; i < length ; ++ i ) U16 [ p + i ] = str . charCodeAt ( i ) ;
127
128
return ptr ;
@@ -131,6 +132,7 @@ function postInstantiate(extendedExports, instance) {
131
132
132
133
/** Reads a string from the module's memory by its pointer. */
133
134
function __getString ( ptr ) {
135
+ if ( ! ptr ) return null ;
134
136
const buffer = memory . buffer ;
135
137
const id = new Uint32Array ( buffer ) [ ptr + ID_OFFSET >>> 2 ] ;
136
138
if ( id !== STRING_ID ) throw Error ( `not a string: ${ ptr } ` ) ;
@@ -163,22 +165,22 @@ function postInstantiate(extendedExports, instance) {
163
165
const info = getArrayInfo ( id ) ;
164
166
const align = getValueAlign ( info ) ;
165
167
const length = values . length ;
166
- const buf = new_ ( length << align , info & STATICARRAY ? id : ARRAYBUFFER_ID ) ;
168
+ const buf = __new ( length << align , info & STATICARRAY ? id : ARRAYBUFFER_ID ) ;
167
169
let result ;
168
170
if ( info & STATICARRAY ) {
169
171
result = buf ;
170
172
} else {
171
- const arr = new_ ( info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE , id ) ;
173
+ const arr = __new ( info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE , id ) ;
172
174
const U32 = new Uint32Array ( memory . buffer ) ;
173
- U32 [ arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2 ] = retain ( buf ) ;
175
+ U32 [ arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2 ] = __retain ( buf ) ;
174
176
U32 [ arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2 ] = buf ;
175
177
U32 [ arr + ARRAYBUFFERVIEW_DATALENGTH_OFFSET >>> 2 ] = length << align ;
176
178
if ( info & ARRAY ) U32 [ arr + ARRAY_LENGTH_OFFSET >>> 2 ] = length ;
177
179
result = arr ;
178
180
}
179
181
const view = getView ( align , info & VAL_SIGNED , info & VAL_FLOAT ) ;
180
182
if ( info & VAL_MANAGED ) {
181
- for ( let i = 0 ; i < length ; ++ i ) view [ ( buf >>> align ) + i ] = retain ( values [ i ] ) ;
183
+ for ( let i = 0 ; i < length ; ++ i ) view [ ( buf >>> align ) + i ] = __retain ( values [ i ] ) ;
182
184
} else {
183
185
view . set ( values , buf >>> align ) ;
184
186
}
@@ -267,7 +269,7 @@ function postInstantiate(extendedExports, instance) {
267
269
function __instanceof ( ptr , baseId ) {
268
270
const U32 = new Uint32Array ( memory . buffer ) ;
269
271
let id = U32 [ ptr + ID_OFFSET >>> 2 ] ;
270
- if ( id <= U32 [ rttiBase >>> 2 ] ) {
272
+ if ( id <= U32 [ __rtti_base >>> 2 ] ) {
271
273
do {
272
274
if ( id == baseId ) return true ;
273
275
id = getBase ( id ) ;
@@ -331,7 +333,6 @@ export async function instantiateStreaming(source, imports = {}) {
331
333
332
334
/** Demangles an AssemblyScript module's exports to a friendly object structure. */
333
335
export function demangle ( exports , extendedExports = { } ) {
334
- extendedExports = Object . create ( extendedExports ) ;
335
336
const setArgumentsLength = exports [ "__argumentsLength" ]
336
337
? length => { exports [ "__argumentsLength" ] . value = length ; }
337
338
: exports [ "__setArgumentsLength" ] || exports [ "__setargc" ] || ( ( ) => { /* nop */ } ) ;
0 commit comments