forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProxyBinding.fm
724 lines (665 loc) · 20 KB
/
ProxyBinding.fm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
<#macro getRequiredArgumentCount args>
<#local count = 0>
<#list args as arg>
<#if arg?keys?seq_contains("optional")>
<#if !arg.optional>
<#local count = count + 1>
</#if>
<#elseif arg.type = "java.lang.Object[]">
<#break>
<#else>
<#local count = count + 1>
</#if>
</#list>
<#nested count>
</#macro>
<#macro listChildModules>
<#if isModule>
<#list allModules?keys as module>
<#if module = packageName+"."+proxyClassName>
<#if allModules[module].childModules??>
<#list allModules[module].childModules as childModule>
<#nested childModule_index==0, childModule>
</#list>
</#if>
</#if>
</#list>
</#if>
</#macro>
<#function hasCreateProxies>
<#if isModule>
<#list allModules?keys as module>
<#if module = packageName+"."+proxyClassName>
<#if allModules[module].createProxies??>
<#return true>
</#if>
</#if>
</#list>
</#if>
<#return false>
</#function>
<#macro listCreateProxies>
<#if isModule>
<#list allModules?keys as module>
<#if module = packageName+"."+proxyClassName>
<#if allModules[module].createProxies??>
<#list allModules[module].createProxies as createProxy>
<#nested createProxy_index==0, createProxy, createProxy_has_next>
</#list>
</#if>
</#if>
</#list>
</#if>
</#macro>
<#macro listMethods>
<#if methods??>
<#list methods?keys as methodName>
<#local method = methods[methodName]>
<#local signature>
<@getMethodSignature method.args, method.returnType, false/>
</#local>
<#nested methodName_index==0, methodName, method, signature, methodName_has_next>
</#list>
</#if>
</#macro>
<#macro listConstants>
<#if constants??>
<#list constants?keys as constantName>
<#local constant = constants[constantName]>
<#nested constantName_index==0, constantName, constant>
</#list>
</#if>
</#macro>
<#macro listProperties>
<#if properties??>
<#list properties?keys as propertyName>
<#local property = properties[propertyName]>
<#nested propertyName_index==0, propertyName, property>
</#list>
</#if>
</#macro>
<#macro listDynamicProperties>
<#if dynamicProperties??>
<#list dynamicProperties?keys as propertyName>
<#local dynamicProperty = dynamicProperties[propertyName]>
<#if dynamicProperty.get>
<#local getSignature>
<@getMethodSignature dynamicProperty.getMethodArgs, dynamicProperty.getReturnType, dynamicProperty.getHasInvocation/>
</#local>
<#else>
<#local getSignature = "">
</#if>
<#if dynamicProperty.set>
<#local setSignature>
<@getMethodSignature dynamicProperty.setMethodArgs, dynamicProperty.setReturnType, dynamicProperty.setHasInvocation/>
</#local>
<#else>
<#local setSignature = "">
</#if>
<#nested propertyName_index==0, propertyName, dynamicProperty, getSignature, setSignature>
</#list>
</#if>
</#macro>
<#-- returns whether or not a method name has @Kroll.getProperty or @Kroll.setProperty -->
<#function isDynamicProperty methodName>
<#if dynamicProperties??>
<#list dynamicProperties?keys as propertyName>
<#local dynamicProperty = dynamicProperties[propertyName]>
<#if dynamicProperty.get>
<#if methodName = dynamicProperty.getMethodName>
<#return true>
</#if>
</#if>
<#if dynamicProperty.set>
<#if methodName = dynamicProperty.setMethodName>
<#return true>
</#if>
</#if>
</#list>
</#if>
<#return false>
</#function>
<#macro listPropertyAccessors>
<#list proxyAttrs.propertyAccessors as accessor>
<#local upperCamel = accessor?substring(0, 1)?upper_case + accessor?substring(1)>
<#nested accessor_index==0, accessor, "get" + upperCamel, "set" + upperCamel, accessor_has_next>
</#list>
</#macro>
<#function hasApiTree>
<#-- accounts for _className -->
<#return apiTree?keys?size > 1>
</#function>
<#macro listApiTree>
<#local index = 0>
<#list apiTree?keys as api>
<#if api != "_className">
<#local className = apiTree[api]._className>
<#nested index==0, api, className, api_has_next>
<#local index = index + 1>
</#if>
</#list>
</#macro>
<#macro superNamespace>
<#compress>
<#local superFullClassName = superPackageName + "." + superProxyClassName>
<#if moduleId != "titanium">
<#if tiProxies?keys?seq_contains(superFullClassName)>
titanium::<@Proxy.namespace tiProxies[superFullClassName].proxyAttrs.fullAPIName/>
<#elseif allProxies?keys?seq_contains(superFullClassName)>
<@Proxy.namespace allProxies[superFullClassName].proxyAttrs.fullAPIName/>
</#if>
</#if>
</#compress>
</#macro>
<#macro openModuleNamespace>
<#list moduleId?split(".") as ns>
namespace ${ns?lower_case} {
</#list>
</#macro>
<#macro closeModuleNamespace>
<#list moduleId?split(".")?reverse as ns>
} // ${ns?lower_case}
</#list>
</#macro>
<#macro openNamespace>
<@openModuleNamespace/>
<#list proxyAttrs.fullAPIName?split(".") as ns>
<#if ns_has_next && ns?lower_case != moduleId?lower_case>
namespace ${ns?lower_case} {
</#if>
</#list>
</#macro>
<#macro closeNamespace>
<#list proxyAttrs.fullAPIName?split(".")?reverse as ns>
<#if ns_index != 0 && ns?lower_case != moduleId?lower_case>
} // namespace ${ns?lower_case}
</#if>
</#list>
<@closeModuleNamespace/>
</#macro>
<#macro namespace apiName>
<#compress>
<#list apiName?split(".") as ns>
<#if ns_has_next>
${ns?lower_case}::
</#if>
</#list>
</#compress>
</#macro>
<#function className name>
<#if name?matches("^[0-9].+")>
<#return "_" + name>
<#else>
<#return name>
</#if>
</#function>
<#assign typeInfo = {
"org.appcelerator.kroll.KrollProxy":{
"jsType":"Object",
"jsConvertType":"Value",
"jsToJavaConverter":"jsValueToJavaObject",
"javaToJsConverter":"javaObjectToJsValue",
"jvalue":"l",
"javaCallMethodType":"Object",
"javaReturnType":"jobject",
"javaValidation":true,
"javaDeleteLocalRef":true,
"typeValidation":true,
"defaultValue": "null"
},
"org.appcelerator.kroll.KrollException":{
"jsType":"Value",
"jsConvertType":"Value",
"jsToJavaConverter":"jsValueToJavaError",
"javaToJsConverter":"javaObjectToJsValue",
"jvalue":"l",
"javaCallMethodType":"Object",
"javaReturnType":"jobject",
"javaValidation":true,
"javaDeleteLocalRef":true,
"typeValidation":false,
"defaultValue": "null"
},
"org.appcelerator.kroll.KrollDict":{
"jsType":"Value",
"jsConvertType":"Value",
"jsToJavaConverter":"jsObjectToJavaKrollDict",
"javaToJsConverter":"javaObjectToJsValue",
"jvalue":"l",
"javaCallMethodType":"Object",
"javaReturnType":"jobject",
"javaValidation":true,
"javaDeleteLocalRef":true,
"typeValidation":false,
"defaultValue": "null"
},
"java.lang.String":{
"jsType":"Value",
"jsToJavaConverter":"jsValueToJavaString",
"javaToJsConverter":"javaStringToJsString",
"jvalue":"l",
"javaCallMethodType":"Object",
"javaReturnType":"jstring",
"javaValidation":true,
"javaDeleteLocalRef":true,
"typeValidation":false,
"defaultValue": "null"
},
"java.lang.String[]":{
"jsType":"Array",
"jsHandleCast":"Array",
"jsToJavaConverter":"jsArrayToJavaStringArray",
"javaToJsConverter":"javaArrayToJsArray",
"jvalue":"l", "signature":"[Ljava/lang/String;",
"javaCallMethodType":"Object",
"javaReturnType":"jobjectArray",
"javaValidation": true,
"javaDeleteLocalRef":true,
"defaultValue": "null"
},
"java.lang.Object":{
"jsType":"Value",
"jsConvertType":"Value",
"jsToJavaConverter":"jsValueToJavaObject",
"javaToJsConverter":"javaObjectToJsValue",
"jvalue":"l",
"javaCallMethodType":"Object",
"javaReturnType":"jobject",
"javaValidation":true,
"javaDeleteLocalRef":true,
"typeValidation":false,
"defaultValue": "null"
},
"java.lang.Object[]":{
"jsType":"Array",
"jsHandleCast":"Array",
"jsToJavaConverter":"jsArrayToJavaArray",
"javaToJsConverter":"javaArrayToJsArray",
"jvalue":"l", "signature":"[Ljava/lang/Object;",
"javaCallMethodType":"Object",
"javaReturnType":"jobjectArray",
"javaValidation": true,
"javaDeleteLocalRef":true,
"defaultValue": "null"
},
"int[]":{
"jsType":"Array",
"jsHandleCast":"Array",
"jsToJavaConverter":"jsArrayToJavaIntArray",
"javaToJsConverter":"javaArrayToJsArray",
"jvalue":"l", "signature":"[I",
"javaCallMethodType":"Object",
"javaReturnType":"jintArray",
"javaValidation":true,
"javaDeleteLocalRef":true,
"defaultValue": "null"
},
"int":{
"jsType":"Number",
"jsToJavaConverter":"jsNumberToJavaInt",
"javaToJsConverter":"javaIntToJsNumber",
"jvalue":"i", "signature":"I",
"javaCallMethodType":"Int",
"javaReturnType":"jint",
"typeValidation":false,
"defaultValue": "-1"
},
"short":{
"jsType":"Number",
"jsToJavaConverter":"jsNumberToJavaShort",
"javaToJsConverter":"javaShortToJsNumber",
"jvalue":"s", "signature":"S",
"javaCallMethodType":"Short",
"javaReturnType":"jshort",
"typeValidation":false,
"defaultValue": "-1"
},
"long[]":{
"jsType":"Array",
"jsHandleCast":"Array",
"jsToJavaConverter":"jsArrayToJavaLongArray",
"javaToJsConverter":"javaArrayToJsArray",
"jvalue":"l", "signature":"[J",
"javaCallMethodType":"Object",
"javaReturnType":"jlongArray",
"javaValidation":true,
"javaDeleteLocalRef":true,
"defaultValue": "null"
},
"float[]":{
"jsType":"Array",
"jsHandleCast":"Array",
"jsToJavaConverter":"jsArrayToJavaFloatArray",
"javaToJsConverter":"javaArrayToJsArray",
"jvalue":"l", "signature":"[F",
"javaCallMethodType":"Object",
"javaReturnType":"jfloatArray",
"javaValidation":true,
"javaDeleteLocalRef":true,
"defaultValue": "null"
},
"short[]":{
"jsType":"Array",
"jsHandleCast":"Array",
"jsToJavaConverter":"jsArrayToJavaShortArray",
"javaToJsConverter":"javaArrayToJsArray",
"jvalue":"l", "signature":"[S",
"javaCallMethodType":"Object",
"javaReturnType":"jshortArray",
"javaValidation":true,
"javaDeleteLocalRef":true,
"defaultValue": "null"
},
"long":{
"jsType":"Number",
"jsToJavaConverter":"jsNumberToJavaLong",
"javaToJsConverter":"javaLongToJsNumber",
"jvalue":"j", "signature":"J",
"javaCallMethodType":"Long",
"javaReturnType":"jlong",
"typeValidation":false,
"defaultValue": "-1"
},
"float":{
"jsType":"Number",
"jsToJavaConverter":"jsNumberToJavaFloat",
"javaToJsConverter":"javaFloatToJsNumber",
"jvalue":"f", "signature":"F",
"javaCallMethodType":"Float",
"javaReturnType":"jfloat",
"typeValidation":false,
"defaultValue": "-1f"
},
"double":{
"jsType":"Number",
"jsToJavaConverter":"jsNumberToJavaDouble",
"javaToJsConverter":"javaDoubleToJsNumber",
"jvalue":"d", "signature":"D",
"javaCallMethodType":"Double",
"javaReturnType":"jdouble",
"typeValidation":false,
"defaultValue": "-1d"
},
"boolean":{
"jsType":"Boolean",
"jsToJavaConverter":"jsBooleanToJavaBoolean",
"javaToJsConverter":"javaBooleanToJsBoolean",
"jvalue":"z", "signature":"Z",
"javaCallMethodType":"Boolean",
"javaReturnType":"jboolean",
"defaultValue": "false"
},
"void":{
"signature":"V",
"javaCallMethodType":"Void",
"javaReturnType":"void"
}
}>
<#function getTypeInfo type>
<#if typeInfo?keys?seq_contains(type)>
<#return typeInfo[type]>
</#if>
<#if type?ends_with("Proxy")>
<#return typeInfo["org.appcelerator.kroll.KrollProxy"]>
</#if>
<#if type?ends_with("Exception")>
<#return typeInfo["org.appcelerator.kroll.KrollException"]>
</#if>
<#-- default type -->
<#return typeInfo["java.lang.Object"]>
</#function>
<#macro listMethodArguments args>
<#list args as arg>
<#nested arg_index, getTypeInfo(arg.type), arg.type, (arg.optional?? && arg.optional)>
</#list>
</#macro>
<#function getTypeSignature type>
<#-- Look up the type's signature. If it does not exist, this
type is a Java object. Object signatures take a special format
which has the full class name in it (ex: Ljava.lang.Object;) -->
<#if typeInfo?keys?seq_contains(type) && typeInfo[type]?keys?seq_contains("signature")>
<#return typeInfo[type].signature>
<#else>
<#local jniType = type?replace(".", "/")>
<#local prefix = "L">
<#if type?ends_with("[]")>
<#local jniType = jniType?substring(0, jniType?length - 2)>
<#local prefix = "[L">
</#if>
<#return prefix + jniType + ";">
</#if>
</#function>
<#macro getArgumentsSignature args>
<#list args as arg>
<#local signature = getTypeSignature(arg.type)>
<#nested signature>
</#list>
</#macro>
<#macro getMethodSignature args returnType hasInvocation>
(<#if hasInvocation>${getTypeSignature("org.appcelerator.kroll.KrollInvocation")}</#if><#t>
<@getArgumentsSignature args ; s>${s}</@getArgumentsSignature>)${getTypeSignature(returnType)}<#t>
</#macro>
<#macro generateJNICall returnType>
</#macro>
<#--------------------------------------------------------------
Verify and convert V8 values into JNI values inside a V8
invocation callback. The converted values are stored into an
jvalue array named "jArguments". If validation or conversion
fails, a JS exception is returned.
---------------------------------------------------------------->
<#macro verifyAndConvertArgument expr index info logOnly isOptional>
<#if !isOptional && info.typeValidation!true>
if (!${expr}->Is${info.jsType}() && !${expr}->IsNull()) {
const char *error = "Invalid value, expected type ${info.jsType}.";
LOGE(TAG, error);
<#if !(logOnly!false)>
titanium::JSException::Error(isolate, error);
return;
</#if>
}
</#if>
<#t>
<#local checkNew = (info?keys?seq_contains("javaDeleteLocalRef") && info.javaToJsConverter == "javaObjectToJsValue")>
<#if checkNew>bool isNew_${index};</#if>
<#t>
<#if isOptional>
if (args.Length() <= ${index}) {
<#local defValue = info.defaultValue>
<#if defValue == "null">
<#local defValue = "NULL">
</#if>
jArguments[${index}].${info.jvalue} = ${defValue};
} else {
</#if>
<#t>
<#local current_arg = "arg_" + index>
<#if info.jsType == "Value">
<#local type = "Local<Value>">
<#local valueExpr = expr>
<#elseif info.jsType == "Number">
<#local type = "Local<Number>">
<#local valueExpr = expr + "->ToNumber(isolate)">
<#local stringExpr = expr + "->ToString(isolate)">
<#elseif info?keys?seq_contains("jsHandleCast")>
<#local type = "Local<" + info.jsType + ">">
<#local valueExpr = expr + ".As<" + info.jsType + ">()">
<#else>
<#local type = "Local<" + info.jsType + ">">
<#local valueExpr = expr + "->To" + info.jsType + "(isolate)">
</#if>
<#t>
<#if info.jsType == "Number">
if ((titanium::V8Util::isNaN(isolate, ${expr}) && !${expr}->IsUndefined()) || ${stringExpr}->Length() == 0) {
const char *error = "Invalid value, expected type ${info.jsType}.";
LOGE(TAG, error);
<#if !(logOnly!false)>
titanium::JSException::Error(isolate, error);
return;
</#if>
}
</#if>
<#t>
if (!${expr}->IsNull()) {
${type} ${current_arg} = ${valueExpr};
jArguments[${index}].${info.jvalue} =
titanium::TypeConverter::${info.jsToJavaConverter}(
<#if info.jsToJavaConverter?matches("^js(Number|Date|String|Boolean)To.+")>
<#else>
isolate,
</#if>
env, ${current_arg}<#if checkNew>, &isNew_${index}</#if>);
} else {
jArguments[${index}].${info.jvalue} = NULL;
}
<#t>
<#if isOptional>
}
</#if>
</#macro>
<#macro convertToVarArgs args start>
uint32_t length = args.Length() - ${start};
if (length < 0) {
length = 0;
}
jobjectArray varArgs = env->NewObjectArray(length, titanium::JNIUtil::objectClass, NULL);
for (uint32_t i = 0; i < length; ++i) {
bool isNew;
jobject arg = titanium::TypeConverter::jsValueToJavaObject(isolate, env, args[i+${start}], &isNew);
env->SetObjectArrayElement(varArgs, i, arg);
if (isNew) {
env->DeleteLocalRef(arg);
}
}
jArguments[${start}].l = varArgs;
</#macro>
<#macro verifyAndConvertArguments args method>
<#-- Verify the correct argument count was provided. -->
<@Proxy.getRequiredArgumentCount args=args ; requiredCount>
<#if requiredCount > 0>
if (args.Length() < ${requiredCount}) {
char errorStringBuffer[100];
sprintf(errorStringBuffer, "${method.apiName}: Invalid number of arguments. Expected ${requiredCount} but got %d", args.Length());
titanium::JSException::Error(isolate, errorStringBuffer);
return;
}
</#if>
</@Proxy.getRequiredArgumentCount>
jvalue jArguments[${args?size}];
<#-- Generate argument validation and conversion code -->
<#local varArgsIndex = -1>
<#list args as arg>
<#if arg.type == "java.lang.Object[]" && arg_index = args?size - 1>
<#local varArgsIndex = arg_index>
</#if>
</#list>
<#if method.hasInvocation>
Local<Object> scopeVars = args[0]->ToObject(isolate);
jstring sourceUrl = titanium::TypeConverter::jsValueToJavaString(isolate, env,
scopeVars->Get(Proxy::sourceUrlSymbol.Get(isolate)));
jArguments[0].l = env->NewObject(titanium::JNIUtil::krollInvocationClass,
titanium::JNIUtil::krollInvocationInitMethod, sourceUrl);
env->DeleteLocalRef(sourceUrl);
</#if>
<@Proxy.listMethodArguments args=args ; index, info, type, isOptional>
<#if type != "org.appcelerator.kroll.KrollInvocation">
<#if index = varArgsIndex>
<@Proxy.convertToVarArgs args=args start=index/>
<#else>
<@Proxy.verifyAndConvertArgument expr="args[" + index + "]" index=index info=info logOnly=false isOptional=isOptional/>
</#if>
</#if>
</@Proxy.listMethodArguments>
</#macro>
<#macro cleanupMethodArguments args hasInvocation>
<#if hasInvocation>
env->DeleteLocalRef(jArguments[0].l);
</#if>
<@Proxy.listMethodArguments args=args; index, info, type>
<#if type != "org.appcelerator.kroll.KrollInvocation">
<#if type == "java.lang.Object[]" && index = args?size - 1>
env->DeleteLocalRef(jArguments[${index}].l);
<#else>
<#if info.javaDeleteLocalRef!false>
<#local checkNew = info.javaToJsConverter == "javaObjectToJsValue">
<#if checkNew>
if (isNew_${index}) {
</#if>
env->DeleteLocalRef(jArguments[${index}].l);
<#if checkNew>
}
</#if>
</#if>
</#if>
</#if>
</@Proxy.listMethodArguments>
</#macro>
<#--------------------------------------------------------------
Generate a JNI method call with the given return type, method ID,
and jobject reference. This macro also expects a jvalue array
already exists in the scope name provided in "argsVar".
Outputs the complete statement that performs the JNI call and
stores the return value in "result". A nested section can
beprovided to handle the result.
---------------------------------------------------------------->
<#macro callJNIMethod methodArgs hasInvocation returnType methodID jobjectVar argsVar hasResult>
<#local info = getTypeInfo(returnType)
callExpr = "Call${info.javaCallMethodType}MethodA"
argExpr = "${jobjectVar}, ${methodID}, ${argsVar}"
resultExpr = "${info.javaReturnType} jResult = (${info.javaReturnType})">
<#if hasResult>
${resultExpr}env->${callExpr}(${argExpr});
<#local jsType = info.jsType>
<#if info?keys?seq_contains("jsConvertType")>
<#local jsType = info.jsConvertType>
</#if>
<#else>
env->${callExpr}(${argExpr});
</#if>
<#-- Delete java proxy reference once done making the call. -->
if (!JavaObject::useGlobalRefs) {
env->DeleteLocalRef(${jobjectVar});
}
<@Proxy.cleanupMethodArguments args=methodArgs hasInvocation=hasInvocation/>
if (env->ExceptionCheck()) {
<#if hasResult>Local<Value> jsException = </#if>titanium::JSException::fromJavaException(isolate);
env->ExceptionClear();
<#if hasResult>
return;
</#if>
}
<#if hasResult && info.javaValidation!false>
if (jResult == NULL) {
args.GetReturnValue().Set(Null(isolate));
return;
}
</#if>
<#if hasResult>
Local<${jsType}> v8Result = titanium::TypeConverter::${info.javaToJsConverter}(isolate, env, jResult);
<#if info.javaDeleteLocalRef!false>
env->DeleteLocalRef(jResult);
</#if>
</#if>
<#nested hasResult "v8Result">
</#macro>
<#macro initJNIEnv>
JNIEnv *env = titanium::JNIScope::getEnv();
if (!env) {
titanium::JSException::GetJNIEnvironmentError(isolate);
return;
}
</#macro>
<#macro initMethodID className name signature logOnly>
<#-- Lazy initialize method ID for the Java proxy. -->
static jmethodID methodID = NULL;
if (!methodID) {
methodID = env->GetMethodID(${className}::javaClass, "${name}", "${signature}");
if (!methodID) {
const char *error = "Couldn't find proxy method '${name}' with signature '${signature}'";
LOGE(TAG, error);
<#if !(logOnly!false)>
titanium::JSException::Error(isolate, error);
return;
</#if>
}
}
</#macro>