@@ -138,13 +138,13 @@ function getTypeName(type: ParameterType) {
138
138
function generatePropParser ( prop : PropsDeclaration , externalInitialize : string [ ] , info : DAPInfoCollector ) : string | null {
139
139
function wrapOptional ( code : string ) {
140
140
function generateUnInitializeValue ( ) : string {
141
- if ( prop . type [ 0 ] === FunctionArgumentType . dom_string ) {
141
+ if ( prop . type . value === FunctionArgumentType . dom_string ) {
142
142
callCode = `args->${ prop . name } = NULL;` ;
143
- } else if ( prop . type [ 0 ] === FunctionArgumentType . double ) {
143
+ } else if ( prop . type . value === FunctionArgumentType . double ) {
144
144
callCode = `args->${ prop . name } = 0.0;` ;
145
- } else if ( prop . type [ 0 ] === FunctionArgumentType . int64 ) {
145
+ } else if ( prop . type . value === FunctionArgumentType . int64 ) {
146
146
callCode = `args->${ prop . name } = 0;`
147
- } else if ( prop . type [ 0 ] === FunctionArgumentType . boolean ) {
147
+ } else if ( prop . type . value === FunctionArgumentType . boolean ) {
148
148
callCode = `args->${ prop . name } = 0;`
149
149
} else {
150
150
callCode = `args->${ prop . name } = NULL;` ;
@@ -161,16 +161,8 @@ function generatePropParser(prop: PropsDeclaration, externalInitialize: string[]
161
161
162
162
const typeKind = getTypeKind ( prop . type ) ;
163
163
let callCode = '' ;
164
- if ( prop . type [ 0 ] === FunctionArgumentType . dom_string ) {
165
- callCode = `args->${ prop . name } = get_property_string_copy(ctx, arguments, "${ prop . name } ");` ;
166
- } else if ( prop . type [ 0 ] === FunctionArgumentType . double ) {
167
- callCode = `args->${ prop . name } = get_property_float64(ctx, arguments, "${ prop . name } ");` ;
168
- } else if ( prop . type [ 0 ] === FunctionArgumentType . int64 ) {
169
- callCode = `args->${ prop . name } = get_property_int64(ctx, arguments, "${ prop . name } ");`
170
- } else if ( prop . type [ 0 ] === FunctionArgumentType . boolean ) {
171
- callCode = `args->${ prop . name } = get_property_boolean(ctx, arguments, "${ prop . name } ");`
172
- } else {
173
- let targetTypes = Array . from ( info . others ) . find ( o => o . name === prop . type [ 0 ] ) ;
164
+ if ( typeKind === PropTypeKind . normal || typeKind === PropTypeKind . normalArray ) {
165
+ const isArray = prop . type . isArray ;
174
166
175
167
let value = prop . type . value ;
176
168
if ( isArray ) {
@@ -212,9 +204,9 @@ function generatePropParser(prop: PropsDeclaration, externalInitialize: string[]
212
204
213
205
function generateMemberInit ( prop : PropsDeclaration , externalInitialize : string [ ] , info : DAPInfoCollector ) : string {
214
206
let initCode = '' ;
215
- if ( prop . type [ 0 ] === FunctionArgumentType . boolean ) {
207
+ if ( prop . type . value === FunctionArgumentType . boolean ) {
216
208
initCode = `body->${ prop . name } = 0;` ;
217
- } else if ( prop . type [ 0 ] === FunctionArgumentType . int64 || prop . type [ 0 ] === FunctionArgumentType . double ) {
209
+ } else if ( prop . type . value === FunctionArgumentType . int64 || prop . type . value === FunctionArgumentType . double ) {
218
210
initCode = `body->${ prop . name } = 0;` ;
219
211
} else {
220
212
initCode = `body->${ prop . name } = NULL;` ;
@@ -225,10 +217,9 @@ function generateMemberInit(prop: PropsDeclaration, externalInitialize: string[]
225
217
return initCode ;
226
218
}
227
219
228
- function generateMemberStringifyCode ( prop : PropsDeclaration , bodyName : string , externalInitialize : string [ ] , info : DAPInfoCollector ) : string {
229
- function wrapIf ( code : string ) {
230
- if ( prop . type [ 0 ] === FunctionArgumentType . dom_string || typeof prop . type [ 0 ] === 'string' ) {
231
- return `if (${ bodyName } ->${ prop . name } != NULL) {
220
+ function wrapIf ( code : string , expression : string , type : ParameterType ) {
221
+ if ( type . value === FunctionArgumentType . dom_string || typeof type . value === 'string' ) {
222
+ return `if (${ expression } != NULL) {
232
223
${ code }
233
224
}` ;
234
225
} else if ( type . value === FunctionArgumentType . double || type . value === FunctionArgumentType . int64 ) {
@@ -242,13 +233,13 @@ function generateMemberStringifyCode(prop: PropsDeclaration, bodyName: string, e
242
233
function generateMemberStringifyCode ( prop : PropsDeclaration , bodyName : string , externalInitialize : string [ ] , info : DAPInfoCollector ) : string {
243
234
244
235
function generateQuickJSInitFromType ( type : ParameterType ) {
245
- if ( type === FunctionArgumentType . double ) {
236
+ if ( type . value === FunctionArgumentType . double ) {
246
237
return `JS_NewFloat64` ;
247
- } else if ( type === FunctionArgumentType . dom_string ) {
238
+ } else if ( type . value === FunctionArgumentType . dom_string ) {
248
239
return `JS_NewString` ;
249
- } else if ( type === FunctionArgumentType . int64 ) {
240
+ } else if ( type . value === FunctionArgumentType . int64 ) {
250
241
return `JS_NewInt64` ;
251
- } else if ( type === FunctionArgumentType . boolean ) {
242
+ } else if ( type . value === FunctionArgumentType . boolean ) {
252
243
return `JS_NewBool` ;
253
244
} else {
254
245
let targetTypes = Array . from ( info . others ) . find ( o => o . name === type . value ) ;
@@ -262,33 +253,42 @@ function generateMemberStringifyCode(prop: PropsDeclaration, bodyName: string, e
262
253
263
254
function genCallCode ( type : ParameterType , prop : PropsDeclaration ) {
264
255
let callCode = '' ;
265
- if ( type === FunctionArgumentType . int64 ) {
256
+ if ( type . value === FunctionArgumentType . int64 ) {
266
257
callCode = `JS_SetPropertyStr(ctx, object, "${ prop . name } ", ${ generateQuickJSInitFromType ( type ) } (ctx, ${ bodyName } ->${ prop . name } ));` ;
267
- } else if ( type === FunctionArgumentType . boolean ) {
258
+ } else if ( type . value === FunctionArgumentType . boolean ) {
268
259
callCode = `JS_SetPropertyStr(ctx, object, "${ prop . name } ", ${ generateQuickJSInitFromType ( type ) } (ctx, ${ bodyName } ->${ prop . name } ));` ;
269
- } else if ( type === FunctionArgumentType . dom_string ) {
260
+ } else if ( type . value === FunctionArgumentType . dom_string ) {
270
261
callCode = `JS_SetPropertyStr(ctx, object, "${ prop . name } ", ${ generateQuickJSInitFromType ( type ) } (ctx, ${ bodyName } ->${ prop . name } ));` ;
271
- } else if ( type === FunctionArgumentType . double ) {
262
+ } else if ( type . value === FunctionArgumentType . double ) {
272
263
callCode = `JS_SetPropertyStr(ctx, object, "${ prop . name } ", ${ generateQuickJSInitFromType ( type ) } (ctx, ${ bodyName } ->${ prop . name } ));` ;
273
264
} else {
274
- if ( type === FunctionArgumentType . array ) {
265
+ if ( type . isArray ) {
266
+ let isReference = typeof ( prop . type . value as ParameterType ) . value === 'string' ;
267
+ let arrCallCode = `JS_SetPropertyUint32(ctx, arr, i, ${ generateQuickJSInitFromType ( prop . type . value as ParameterType ) } (ctx, ${ isReference ? '&' : '' } ${ bodyName } ->${ prop . name } [i]));` ;
268
+ const typeKind = getTypeKind ( type ) ;
269
+ if ( prop . optional && typeKind === PropTypeKind . normalArray ) {
270
+ arrCallCode = `if (${ bodyName } ->${ prop . name } != NULL) {
271
+ ${ arrCallCode }
272
+ }` ;
273
+ }
274
+
275
275
callCode = `JSValue arr = JS_NewArray(ctx);
276
276
for(int i = 0; i < ${ bodyName } ->${ prop . name } Len; i ++) {
277
277
${ arrCallCode }
278
278
}
279
279
JS_SetPropertyStr(ctx, object, "${ prop . name } ", arr);`
280
280
} else {
281
- let targetTypes = Array . from ( info . others ) . find ( o => o . name === type ) ;
281
+ let targetTypes = Array . from ( info . others ) . find ( o => o . name === type . value ) ;
282
282
if ( targetTypes ) {
283
283
generateTypeStringify ( targetTypes , prop . name , info , externalInitialize ) ;
284
- callCode = `JS_SetPropertyStr(ctx, object, "${ prop . name } ", stringify_property_${ type } (ctx, ${ bodyName } ->${ prop . name } ));`
284
+ callCode = `JS_SetPropertyStr(ctx, object, "${ prop . name } ", stringify_property_${ type . value } (ctx, ${ bodyName } ->${ prop . name } ));`
285
285
}
286
286
}
287
287
}
288
288
return callCode ;
289
289
}
290
290
291
- let callCode = genCallCode ( prop . type [ 0 ] , prop ) ;
291
+ let callCode = genCallCode ( prop . type , prop ) ;
292
292
293
293
return addIndent ( prop . optional ? wrapIf ( callCode , `${ bodyName } ->${ prop . name } ` , prop . type ) : callCode , 2 ) ;
294
294
}
0 commit comments