Skip to content

Commit a383a00

Browse files
committed
one more idea for #1558 that shows promise
1 parent a22579c commit a383a00

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

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

+16-8
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,11 @@ private AttachResult recurseAndAttach(String name, Object o, Set<Object> seen) {
11171117
return AttachResult.dirty(value);
11181118
}
11191119
}
1120-
if (o instanceof JsFunction) {
1120+
if (o instanceof Class) {
1121+
Class clazz = (Class) o;
1122+
Value value = JS.evalForValue("Java.type('" + clazz.getCanonicalName() + "')");
1123+
return AttachResult.dirty(value);
1124+
} else if (o instanceof JsFunction) {
11211125
JsFunction jf = (JsFunction) o;
11221126
try {
11231127
return AttachResult.dirty(attachSource(jf.source));
@@ -1169,7 +1173,11 @@ private Object recurseAndAttachAndDeepClone(String name, Object o, Set<Object> s
11691173
return null;
11701174
}
11711175
}
1172-
if (o instanceof JsFunction) {
1176+
if (o instanceof Class) {
1177+
Class clazz = (Class) o;
1178+
Value value = JS.evalForValue("Java.type('" + clazz.getCanonicalName() + "')");
1179+
return value;
1180+
} else if (o instanceof JsFunction) {
11731181
JsFunction jf = (JsFunction) o;
11741182
try {
11751183
return attachSource(jf.source);
@@ -1212,20 +1220,20 @@ protected Object recurseAndDetachAndDeepClone(Object o) {
12121220

12131221
private Object recurseAndDetachAndDeepClone(String name, Object o, Set<Object> seen) {
12141222
if (o instanceof Value) {
1215-
Value value = (Value) o;
1223+
Value value = Value.asValue(o);
12161224
try {
1217-
if (value.canExecute()) {
1225+
if (value.canExecute()) {
12181226
if (value.isMetaObject()) { // js function
12191227
return new JsFunction(value);
12201228
} else { // java function
12211229
return new JsExecutable(value);
12221230
}
1223-
} else {
1224-
return value;
1231+
} else if (value.isHostObject()) {
1232+
return value.asHostObject();
12251233
}
12261234
} catch (Exception e) {
1227-
logger.warn("[*** detach deep ***] ignoring non-json value in callonce / callSingle: '{}' - {}", e.getMessage());
1228-
return value; // try our luck
1235+
logger.warn("[*** detach deep ***] ignoring non-json value in callonce / callSingle: '{}' - {}", name, e.getMessage());
1236+
return null;
12291237
}
12301238
}
12311239
if (o instanceof List) {

karate-core/src/main/java/com/intuit/karate/graal/JsExecutable.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,18 @@
3333
* @author pthomas3
3434
*/
3535
public class JsExecutable implements ProxyExecutable {
36-
36+
3737
private static final Logger logger = LoggerFactory.getLogger(JsExecutable.class);
3838

39-
private final Value value;
39+
public final Value value;
4040

4141
public JsExecutable(Value value) {
4242
this.value = value;
4343
}
4444

45-
private static final Object LOCK = new Object();
46-
4745
@Override
4846
public Object execute(Value... arguments) {
49-
synchronized (LOCK) {
50-
logger.warn("[*** execute ***] global lock on java function possibly from callonce / callSingle: {}", value);
51-
return value.execute(arguments);
52-
}
47+
return value.execute(arguments);
5348
}
5449

5550
}

0 commit comments

Comments
 (0)