Skip to content

Commit a2ad469

Browse files
committedApr 18, 2021
graal asValue / asHostObject trick works well #1558
1 parent bbd5152 commit a2ad469

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed
 

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,12 @@ private Object recurseAndAttach(Object o, Set<Object> seen) {
10911091
return attach(value);
10921092
}
10931093
} catch (Exception e) {
1094-
logger.warn("failed to re-attach graal value: {}", e.getMessage());
1094+
logger.trace("failed to re-attach graal value (will re-try): {}", e.getMessage());
1095+
try {
1096+
return Value.asValue(value.asHostObject());
1097+
} catch (Exception inner) {
1098+
logger.warn("failed to re-attach graal value: {}", inner.getMessage());
1099+
}
10951100
}
10961101
return null;
10971102
} else if (o instanceof JsFunction) {
@@ -1142,7 +1147,12 @@ private Object recurseAndAttachAndDeepClone(Object o, Set<Object> seen) {
11421147
}
11431148
o = JsValue.toJava(value);
11441149
} catch (Exception e) {
1145-
logger.warn("failed to re-attach graal value: {}", e.getMessage());
1150+
logger.trace("failed to re-attach graal value (will re-try): {}", e.getMessage());
1151+
try {
1152+
return Value.asValue(value.asHostObject());
1153+
} catch (Exception inner) {
1154+
logger.warn("failed to re-attach graal value: {}", inner.getMessage());
1155+
}
11461156
return null; // we try to move on after stripping this (js function) from the tree
11471157
}
11481158
}

‎karate-core/src/test/java/com/intuit/karate/core/parallel/karate-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function fn() {
66
var result = karate.callSingle('call-single-from-config.feature', config);
77
config.message = result.response.message;
88
// this will throw the [Multi threaded access requested by thread xxx but is not allowed for language(s) js.] error
9-
// config.Hello = result.Hello;
9+
config.Hello = result.Hello;
1010
var result2 = karate.callSingle('call-single-from-config2.feature', result);
1111
config.message2 = result2.message;
1212
return config;

‎karate-core/src/test/java/com/intuit/karate/core/parallel/parallel.feature

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Scenario: one
1515
* match response == { one: '#string' }
1616
* def result = karate.callSingle('call-single-from-feature.feature')
1717
* match result.response == { message: 'from feature' }
18+
# use java instance from callSingle in config
19+
* match Hello.sayHello('world') == 'hello world'
1820

1921
Scenario: two
2022
* path 'two'

0 commit comments

Comments
 (0)
Please sign in to comment.