@@ -1025,14 +1025,27 @@ public void init() { // not in constructor because it has to be on Runnable.run(
1025
1025
AttachResult ar = recurseAndAttach (k , v , seen );
1026
1026
JS .put (k , ar .value );
1027
1027
});
1028
- // re-hydrate any functions from caller or background
1029
1028
vars .forEach ((k , v ) -> {
1029
+ // re-hydrate any functions from caller or background
1030
1030
AttachResult ar = recurseAndAttach (k , v .getValue (), seen );
1031
1031
// note that we don't update the vars !
1032
1032
// if we do, any "bad" out-of-context values will crash the constructor of Variable
1033
1033
// it is possible the vars are detached / re-used later, so we kind of defer the inevitable
1034
1034
JS .put (k , ar .value );
1035
1035
});
1036
+ if (runtime .caller .arg != null && runtime .caller .arg .isMap ()) {
1037
+ // add the call arg as separate "over ride" variables
1038
+ Map <String , Object > arg = runtime .caller .arg .getValue ();
1039
+ arg .forEach ((k , v ) -> {
1040
+ AttachResult ar = recurseAndAttach (k , v , seen );
1041
+ try {
1042
+ vars .put (k , new Variable (ar .value ));
1043
+ } catch (Exception e ) {
1044
+ logger .warn ("[*** init call-arg ***] ignoring non-json value: '{}' - {}" , k , e .getMessage ());
1045
+ }
1046
+ JS .put (k , ar .value );
1047
+ });
1048
+ }
1036
1049
JS .put (KARATE , bridge );
1037
1050
JS .put (READ , readFunction );
1038
1051
HttpClient client = runtime .featureRuntime .suite .clientFactory .create (this );
@@ -1096,7 +1109,7 @@ private AttachResult recurseAndAttach(String name, Object o, Set<Object> seen) {
1096
1109
}
1097
1110
} catch (Exception e ) {
1098
1111
logger .warn ("[*** attach ***] ignoring non-json value: '{}' - {}" , name , e .getMessage ());
1099
- // here we sweep things under the carpet and hope that graal does not notice !
1112
+ // here we try our luck and hope that graal does not notice !
1100
1113
return AttachResult .dirty (value );
1101
1114
}
1102
1115
} else if (o instanceof JsFunction ) {
@@ -1196,19 +1209,14 @@ private Object recurseAndDetachAndDeepClone(String name, Object o, Set<Object> s
1196
1209
if (o instanceof Value ) {
1197
1210
Value value = (Value ) o ;
1198
1211
try {
1199
- if (value .canExecute ()) {
1200
- if (value .isMetaObject ()) { // js function
1201
- return new JsFunction (value );
1202
- } else { // java function
1203
- return new JsExecutable (value );
1204
- }
1212
+ if (value .canExecute () && value .isMetaObject ()) { // js function
1213
+ return new JsFunction (value );
1205
1214
} else {
1206
- // everything else including java-type references that do not need special attach handling
1207
- o = JsValue .toJava (value );
1215
+ return value ;
1208
1216
}
1209
1217
} catch (Exception e ) {
1210
1218
logger .warn ("[*** detach deep ***] ignoring non-json value in callonce / callSingle: '{}' - {}" , e .getMessage ());
1211
- return null ;
1219
+ return value ; // try our luck
1212
1220
}
1213
1221
}
1214
1222
if (o instanceof List ) {
@@ -1301,31 +1309,35 @@ public void setHiddenVariable(String key, Object value) {
1301
1309
1302
1310
public void setVariable (String key , Object value ) {
1303
1311
Variable v ;
1312
+ Object o ;
1304
1313
if (value instanceof Variable ) {
1305
1314
v = (Variable ) value ;
1315
+ o = v .getValue ();
1306
1316
} else {
1307
- v = new Variable (value );
1317
+ o = value ;
1318
+ try {
1319
+ v = new Variable (value );
1320
+ } catch (Exception e ) {
1321
+ v = null ;
1322
+ logger .warn ("[*** set variable ***] ignoring non-json value: {} - {}" , key , e .getMessage ());
1323
+ }
1324
+ }
1325
+ if (v != null ) {
1326
+ vars .put (key , v );
1308
1327
}
1309
- vars .put (key , v );
1310
1328
if (JS != null ) {
1311
- JS .put (key , v . getValue () );
1329
+ JS .put (key , o );
1312
1330
}
1313
1331
if (children != null ) {
1314
- children .forEach (c -> c .setVariable (key , value ));
1332
+ children .forEach (c -> c .setVariable (key , o ));
1315
1333
}
1316
1334
}
1317
1335
1318
1336
public void setVariables (Map <String , Object > map ) {
1319
1337
if (map == null ) {
1320
1338
return ;
1321
1339
}
1322
- map .forEach ((k , v ) -> {
1323
- try {
1324
- setVariable (k , v );
1325
- } catch (Exception e ) {
1326
- logger .warn ("[*** set variables ***] ignoring non-json value: {} - {}" , k , e .getMessage ());
1327
- }
1328
- });
1340
+ map .forEach ((k , v ) -> setVariable (k , v ));
1329
1341
}
1330
1342
1331
1343
private static Map <String , Variable > copy (Map <String , Variable > source , boolean deep ) {
0 commit comments