Skip to content

Commit

Permalink
one more idea for #1558 that shows promise
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jun 25, 2021
1 parent a22579c commit a383a00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,11 @@ private AttachResult recurseAndAttach(String name, Object o, Set<Object> seen) {
return AttachResult.dirty(value);
}
}
if (o instanceof JsFunction) {
if (o instanceof Class) {
Class clazz = (Class) o;
Value value = JS.evalForValue("Java.type('" + clazz.getCanonicalName() + "')");
return AttachResult.dirty(value);
} else if (o instanceof JsFunction) {
JsFunction jf = (JsFunction) o;
try {
return AttachResult.dirty(attachSource(jf.source));
Expand Down Expand Up @@ -1169,7 +1173,11 @@ private Object recurseAndAttachAndDeepClone(String name, Object o, Set<Object> s
return null;
}
}
if (o instanceof JsFunction) {
if (o instanceof Class) {
Class clazz = (Class) o;
Value value = JS.evalForValue("Java.type('" + clazz.getCanonicalName() + "')");
return value;
} else if (o instanceof JsFunction) {
JsFunction jf = (JsFunction) o;
try {
return attachSource(jf.source);
Expand Down Expand Up @@ -1212,20 +1220,20 @@ protected Object recurseAndDetachAndDeepClone(Object o) {

private Object recurseAndDetachAndDeepClone(String name, Object o, Set<Object> seen) {
if (o instanceof Value) {
Value value = (Value) o;
Value value = Value.asValue(o);
try {
if (value.canExecute()) {
if (value.canExecute()) {
if (value.isMetaObject()) { // js function
return new JsFunction(value);
} else { // java function
return new JsExecutable(value);
}
} else {
return value;
} else if (value.isHostObject()) {
return value.asHostObject();
}
} catch (Exception e) {
logger.warn("[*** detach deep ***] ignoring non-json value in callonce / callSingle: '{}' - {}", e.getMessage());
return value; // try our luck
logger.warn("[*** detach deep ***] ignoring non-json value in callonce / callSingle: '{}' - {}", name, e.getMessage());
return null;
}
}
if (o instanceof List) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,18 @@
* @author pthomas3
*/
public class JsExecutable implements ProxyExecutable {

private static final Logger logger = LoggerFactory.getLogger(JsExecutable.class);

private final Value value;
public final Value value;

public JsExecutable(Value value) {
this.value = value;
}

private static final Object LOCK = new Object();

@Override
public Object execute(Value... arguments) {
synchronized (LOCK) {
logger.warn("[*** execute ***] global lock on java function possibly from callonce / callSingle: {}", value);
return value.execute(arguments);
}
return value.execute(arguments);
}

}

0 comments on commit a383a00

Please sign in to comment.