@@ -120,17 +120,22 @@ impl Js {
120
120
match * arg {
121
121
shared:: Type :: Number => {
122
122
dst. push_str ( "number" ) ;
123
- self . expose_assert_num ( ) ;
124
- arg_conversions. push_str ( & format ! ( "_assertNum({});\n " , name) ) ;
123
+ if self . debug {
124
+ self . expose_assert_num ( ) ;
125
+ arg_conversions. push_str ( & format ! ( "_assertNum({});\n " , name) ) ;
126
+ }
125
127
pass ( & name)
126
128
}
127
129
shared:: Type :: Boolean => {
128
130
dst. push_str ( "boolean" ) ;
129
- self . expose_assert_bool ( ) ;
130
- arg_conversions. push_str ( & format ! ( "\
131
- const bool{i} = _assertBoolean({name});
132
- " , name = name, i = i) ) ;
133
- pass ( & format ! ( "bool{i}" , i = i) )
131
+ if self . debug {
132
+ self . expose_assert_bool ( ) ;
133
+ arg_conversions. push_str ( & format ! ( "\
134
+ _assertBoolean({name});
135
+ " , name = name) ) ;
136
+ } else {
137
+ }
138
+ pass ( & format ! ( "arg{i} ? 1 : 0" , i = i) )
134
139
}
135
140
shared:: Type :: BorrowedStr |
136
141
shared:: Type :: String => {
@@ -151,19 +156,26 @@ impl Js {
151
156
shared:: Type :: ByRef ( ref s) |
152
157
shared:: Type :: ByMutRef ( ref s) => {
153
158
dst. push_str ( s) ;
154
- self . expose_assert_class ( ) ;
155
- arg_conversions. push_str ( & format ! ( "\
156
- const ptr{i} = _assertClass({arg}, {struct_});
157
- " , i = i, arg = name, struct_ = s) ) ;
158
- pass ( & format ! ( "ptr{}" , i) ) ;
159
+ if self . debug {
160
+ self . expose_assert_class ( ) ;
161
+ arg_conversions. push_str ( & format ! ( "\
162
+ _assertClass({arg}, {struct_});
163
+ " , arg = name, struct_ = s) ) ;
164
+ }
165
+ pass ( & format ! ( "{}.__wasmPtr" , name) ) ;
159
166
}
160
167
shared:: Type :: ByValue ( ref s) => {
161
168
dst. push_str ( s) ;
162
- self . expose_assert_class ( ) ;
169
+ if self . debug {
170
+ self . expose_assert_class ( ) ;
171
+ arg_conversions. push_str ( & format ! ( "\
172
+ _assertClass({arg}, {struct_});
173
+ " , arg = name, struct_ = s) ) ;
174
+ }
163
175
arg_conversions. push_str ( & format ! ( "\
164
- const ptr{i} = _assertClass( {arg}, {struct_}) ;
176
+ const ptr{i} = {arg}.__wasmPtr ;
165
177
{arg}.__wasmPtr = 0;
166
- " , i = i, arg = name, struct_ = s ) ) ;
178
+ " , i = i, arg = name) ) ;
167
179
pass ( & format ! ( "ptr{}" , i) ) ;
168
180
}
169
181
shared:: Type :: JsObject => {
@@ -313,37 +325,33 @@ impl Js {
313
325
}
314
326
ts_dst. push_str ( "): " ) ;
315
327
dst. push_str ( "): " ) ;
316
- let mut convert = None ;
317
- match import. ret {
328
+ let invoc = format ! ( "_imports.{}({})" , import . name , invocation ) ;
329
+ let invoc = match import. ret {
318
330
Some ( shared:: Type :: Number ) => {
319
331
ts_dst. push_str ( "number" ) ;
320
332
dst. push_str ( "number" ) ;
333
+ invoc
321
334
}
322
335
Some ( shared:: Type :: Boolean ) => {
323
336
ts_dst. push_str ( "boolean" ) ;
324
337
dst. push_str ( "number" ) ;
325
- convert = Some ( "_assertBoolean" ) ;
326
- self . expose_assert_bool ( ) ;
338
+ format ! ( "{} ? 1 : 0" , invoc)
327
339
}
328
340
Some ( shared:: Type :: JsObject ) => {
329
341
ts_dst. push_str ( "any" ) ;
330
342
dst. push_str ( "number" ) ;
331
343
self . expose_add_heap_object ( ) ;
332
- convert = Some ( "addHeapObject" ) ;
344
+ format ! ( "addHeapObject({})" , invoc )
333
345
}
334
346
None => {
335
347
ts_dst. push_str ( "void" ) ;
336
348
dst. push_str ( "void" ) ;
349
+ invoc
337
350
}
338
351
_ => unimplemented ! ( ) ,
339
- }
352
+ } ;
340
353
ts_dst. push_str ( "\n " ) ;
341
354
dst. push_str ( " {\n " ) ;
342
- let invoc = format ! ( "_imports.{}({})" , import. name, invocation) ;
343
- let invoc = match convert {
344
- Some ( s) => format ! ( "{}({})" , s, invoc) ,
345
- None => invoc,
346
- } ;
347
355
dst. push_str ( & format ! ( "return {};\n }}" , invoc) ) ;
348
356
349
357
( dst, ts_dst)
@@ -819,14 +827,9 @@ impl Js {
819
827
return
820
828
}
821
829
self . globals . push_str ( "\
822
- function _assertBoolean(n: boolean): number {
830
+ function _assertBoolean(n: boolean) {
823
831
if (typeof(n) !== 'boolean')
824
832
throw new Error('expected a boolean argument');
825
- if (n) {
826
- return 1;
827
- } else {
828
- return 0;
829
- }
830
833
}
831
834
" ) ;
832
835
}
0 commit comments