Skip to content

Commit 4b56abb

Browse files
committed
small changes while cleaning up #1558
1 parent 64d88b4 commit 4b56abb

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,15 @@ public void init() { // not in constructor because it has to be on Runnable.run(
10221022
runtime.magicVariables.forEach((k, v) -> {
10231023
// even hidden variables may need pre-processing
10241024
// for e.g. the __arg may contain functions that originated in a different js context
1025-
recurseAndAttach(k, v, seen);
1026-
setHiddenVariable(k, v);
1025+
Object o = recurseAndAttach(k, v, seen);
1026+
if (o == null) {
1027+
o = v;
1028+
}
1029+
JS.put(k, o);
10271030
});
10281031
attachVariables(seen); // re-hydrate any functions from caller or background
1029-
setHiddenVariable(KARATE, bridge);
1030-
setHiddenVariable(READ, readFunction);
1032+
JS.put(KARATE, bridge);
1033+
JS.put(READ, readFunction);
10311034
HttpClient client = runtime.featureRuntime.suite.clientFactory.create(this);
10321035
// edge case: can be set by dynamic scenario outline background
10331036
// or be left as-is because a callonce triggered init()
@@ -1072,12 +1075,6 @@ protected Map<String, Variable> detachVariables() {
10721075
return detached;
10731076
}
10741077

1075-
// only called by "call" routine
1076-
protected void recurseAndAttach(String name, Object o) {
1077-
Set<Object> seen = Collections.newSetFromMap(new IdentityHashMap());
1078-
recurseAndAttach(name, o, seen);
1079-
}
1080-
10811078
private Object recurseAndAttach(String name, Object o, Set<Object> seen) {
10821079
if (o instanceof Value) {
10831080
try {
@@ -1943,7 +1940,8 @@ public Variable call(Variable called, Variable arg, boolean sharedScope) {
19431940
case FEATURE:
19441941
// will be always a map or a list of maps (loop call result)
19451942
Object callResult = callFeature(called.getValue(), arg, -1, sharedScope);
1946-
recurseAndAttach("", callResult);
1943+
Set<Object> seen = Collections.newSetFromMap(new IdentityHashMap());
1944+
recurseAndAttach("", callResult, seen);
19471945
return new Variable(callResult);
19481946
default:
19491947
throw new RuntimeException("not a callable feature or js function: " + called);

0 commit comments

Comments
 (0)