1
- import { Blob } from "./blob " ;
1
+ import { IDLBlob } from "./IDLBlob " ;
2
2
import {
3
3
ClassObject ,
4
4
FunctionArguments ,
@@ -85,7 +85,7 @@ function generateCallMethodName(name: string) {
85
85
return name ;
86
86
}
87
87
88
- function generateOptionalInitBody ( blob : Blob , declare : FunctionDeclaration , argument : FunctionArguments , argsIndex : number , previousArguments : string [ ] , options : GenFunctionBodyOptions ) {
88
+ function generateOptionalInitBody ( blob : IDLBlob , declare : FunctionDeclaration , argument : FunctionArguments , argsIndex : number , previousArguments : string [ ] , options : GenFunctionBodyOptions ) {
89
89
let call = '' ;
90
90
let returnValueAssignment = '' ;
91
91
if ( declare . returnType [ 0 ] != FunctionArgumentType . void ) {
@@ -110,7 +110,7 @@ if (argc <= ${argsIndex + 1}) {
110
110
}` ;
111
111
}
112
112
113
- function generateFunctionCallBody ( blob : Blob , declaration : FunctionDeclaration , options : GenFunctionBodyOptions = { isConstructor : false , isInstanceMethod : false } ) {
113
+ function generateFunctionCallBody ( blob : IDLBlob , declaration : FunctionDeclaration , options : GenFunctionBodyOptions = { isConstructor : false , isInstanceMethod : false } ) {
114
114
let minimalRequiredArgc = 0 ;
115
115
declaration . args . forEach ( m => {
116
116
if ( m . required ) minimalRequiredArgc ++ ;
@@ -157,14 +157,14 @@ ${optionalArgumentsInit.join('\n')}
157
157
` ;
158
158
}
159
159
160
- function generateGlobalFunctionSource ( blob : Blob , object : FunctionObject ) {
160
+ function generateGlobalFunctionSource ( blob : IDLBlob , object : FunctionObject ) {
161
161
let body = generateFunctionBody ( blob , object . declare ) ;
162
162
return `static JSValue ${ object . declare . name } (JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
163
163
${ body }
164
164
}` ;
165
165
}
166
166
167
- function generateReturnValueInit ( blob : Blob , type : ParameterType [ ] , options : GenFunctionBodyOptions = { isConstructor : false , isInstanceMethod : false } ) {
167
+ function generateReturnValueInit ( blob : IDLBlob , type : ParameterType [ ] , options : GenFunctionBodyOptions = { isConstructor : false , isInstanceMethod : false } ) {
168
168
if ( type [ 0 ] == FunctionArgumentType . void ) return '' ;
169
169
170
170
if ( options . isConstructor ) {
@@ -180,7 +180,7 @@ function generateReturnValueInit(blob: Blob, type: ParameterType[], options: Gen
180
180
return `Converter<${ generateTypeConverter ( type ) } >::ImplType return_value;` ;
181
181
}
182
182
183
- function generateReturnValueResult ( blob : Blob , type : ParameterType [ ] , options : GenFunctionBodyOptions = { isConstructor : false , isInstanceMethod : false } ) : string {
183
+ function generateReturnValueResult ( blob : IDLBlob , type : ParameterType [ ] , options : GenFunctionBodyOptions = { isConstructor : false , isInstanceMethod : false } ) : string {
184
184
if ( type [ 0 ] == FunctionArgumentType . void ) return 'JS_NULL' ;
185
185
if ( options . isConstructor ) {
186
186
return `return_value->ToQuickJS()` ;
@@ -199,7 +199,7 @@ function generateReturnValueResult(blob: Blob, type: ParameterType[], options: G
199
199
200
200
type GenFunctionBodyOptions = { isConstructor ?: boolean , isInstanceMethod ?: boolean } ;
201
201
202
- function generateFunctionBody ( blob : Blob , declare : FunctionDeclaration , options : GenFunctionBodyOptions = { isConstructor : false , isInstanceMethod : false } ) {
202
+ function generateFunctionBody ( blob : IDLBlob , declare : FunctionDeclaration , options : GenFunctionBodyOptions = { isConstructor : false , isInstanceMethod : false } ) {
203
203
let paramCheck = generateMethodArgumentsCheck ( declare ) ;
204
204
let callBody = generateFunctionCallBody ( blob , declare , options ) ;
205
205
let returnValueInit = generateReturnValueInit ( blob , declare . returnType , options ) ;
@@ -222,22 +222,22 @@ ${addIndent(callBody, 4)}
222
222
` ;
223
223
}
224
224
225
- function generateClassConstructorCallback ( blob : Blob , declare : FunctionDeclaration ) {
225
+ function generateClassConstructorCallback ( blob : IDLBlob , declare : FunctionDeclaration ) {
226
226
return `JSValue QJS${ getClassName ( blob ) } ::ConstructorCallback(JSContext* ctx, JSValue func_obj, JSValue this_val, int argc, JSValue* argv, int flags) {
227
227
${ generateFunctionBody ( blob , declare , { isConstructor : true } ) }
228
228
}
229
229
` ;
230
230
}
231
231
232
- function generatePropertyGetterCallback ( blob : Blob , prop : PropsDeclaration ) {
232
+ function generatePropertyGetterCallback ( blob : IDLBlob , prop : PropsDeclaration ) {
233
233
return `static JSValue ${ prop . name } AttributeGetCallback(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
234
234
auto* ${ blob . filename } = toScriptWrappable<${ getClassName ( blob ) } >(this_val);
235
235
assert(${ blob . filename } != nullptr);
236
236
return Converter<${ generateTypeConverter ( prop . type ) } >::ToValue(ctx, ${ blob . filename } ->${ prop . name } ());
237
237
}` ;
238
238
}
239
239
240
- function generatePropertySetterCallback ( blob : Blob , prop : PropsDeclaration ) {
240
+ function generatePropertySetterCallback ( blob : IDLBlob , prop : PropsDeclaration ) {
241
241
return `static JSValue ${ prop . name } AttributeSetCallback(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
242
242
auto* ${ blob . filename } = toScriptWrappable<${ getClassName ( blob ) } >(this_val);
243
243
ExceptionState exception_state;
@@ -249,15 +249,15 @@ function generatePropertySetterCallback(blob: Blob, prop: PropsDeclaration) {
249
249
}` ;
250
250
}
251
251
252
- function generateMethodCallback ( blob : Blob , methods : FunctionDeclaration [ ] ) : string [ ] {
252
+ function generateMethodCallback ( blob : IDLBlob , methods : FunctionDeclaration [ ] ) : string [ ] {
253
253
return methods . map ( method => {
254
254
return `static JSValue ${ method . name } (JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
255
255
${ generateFunctionBody ( blob , method , { isInstanceMethod : true } ) }
256
256
}` ;
257
257
} ) ;
258
258
}
259
259
260
- function generateClassSource ( blob : Blob , object : ClassObject ) {
260
+ function generateClassSource ( blob : IDLBlob , object : ClassObject ) {
261
261
let constructorCallback = '' ;
262
262
if ( object . construct ) {
263
263
constructorCallback = generateClassConstructorCallback ( blob , object . construct ) ;
@@ -281,7 +281,7 @@ function generateClassSource(blob: Blob, object: ClassObject) {
281
281
] . join ( '\n' ) ;
282
282
}
283
283
284
- function generateInstallGlobalFunctions ( blob : Blob , installList : string [ ] ) {
284
+ function generateInstallGlobalFunctions ( blob : IDLBlob , installList : string [ ] ) {
285
285
return `void QJS${ getClassName ( blob ) } ::InstallGlobalFunctions(ExecutingContext* context) {
286
286
std::initializer_list<MemberInstaller::FunctionConfig> functionConfig {
287
287
${ installList . join ( ',\n' ) }
@@ -291,7 +291,7 @@ function generateInstallGlobalFunctions(blob: Blob, installList: string[]) {
291
291
}` ;
292
292
}
293
293
294
- function generateConstructorInstaller ( blob : Blob ) {
294
+ function generateConstructorInstaller ( blob : IDLBlob ) {
295
295
return `void QJS${ getClassName ( blob ) } ::InstallConstructor(ExecutingContext* context) {
296
296
const WrapperTypeInfo* wrapperTypeInfo = GetWrapperTypeInfo();
297
297
JSValue constructor = context->contextData()->constructorForType(wrapperTypeInfo);
@@ -303,7 +303,7 @@ function generateConstructorInstaller(blob: Blob) {
303
303
}` ;
304
304
}
305
305
306
- function generatePrototypeMethodsInstaller ( blob : Blob , installList : string [ ] ) {
306
+ function generatePrototypeMethodsInstaller ( blob : IDLBlob , installList : string [ ] ) {
307
307
return `void QJS${ getClassName ( blob ) } ::InstallPrototypeMethods(ExecutingContext* context) {
308
308
const WrapperTypeInfo* wrapperTypeInfo = GetWrapperTypeInfo();
309
309
JSValue prototype = context->contextData()->prototypeForType(wrapperTypeInfo);
@@ -317,7 +317,7 @@ function generatePrototypeMethodsInstaller(blob: Blob, installList: string[]) {
317
317
` ;
318
318
}
319
319
320
- function generatePrototypePropsInstaller ( blob : Blob , installList : string [ ] ) {
320
+ function generatePrototypePropsInstaller ( blob : IDLBlob , installList : string [ ] ) {
321
321
return `void QJS${ getClassName ( blob ) } ::InstallPrototypeProperties(ExecutingContext* context) {
322
322
const WrapperTypeInfo* wrapperTypeInfo = GetWrapperTypeInfo();
323
323
JSValue prototype = context->contextData()->prototypeForType(wrapperTypeInfo);
@@ -331,7 +331,7 @@ function generatePrototypePropsInstaller(blob: Blob, installList: string[]) {
331
331
` ;
332
332
}
333
333
334
- export function generateCppSource ( blob : Blob ) {
334
+ export function generateCppSource ( blob : IDLBlob ) {
335
335
let functionInstallList : string [ ] = [ ] ;
336
336
let classMethodsInstallList : string [ ] = [ ] ;
337
337
let classPropsInstallList : string [ ] = [ ] ;
0 commit comments