final Object reallyDeliver = toDeliver;
final String fevent = event;
if (child == null) {
// We are called on child's script runtime, so enqueue a task here
enqueueTask(new ScriptTask() {
@Override
public void execute(Context cx, Scriptable scope)
{
if ("disconnect".equals(fevent)) {
// Special handling for a disconnect from the parent
if (process.isConnected()) {
process.setConnected(false);
process.getEmit().call(cx, scope, process, new Object[] { fevent });
}
} else {
process.getEmit().call(cx, scope, process,
new Object[] { fevent, reallyDeliver });
}
}
});
} else {
// We are the child's script runtime. Enqueue task that sends to the parent
// "child" here actually refers to the "child_process" object inside the parent!
assert(child.getRuntime() != this);
child.getRuntime().enqueueTask(new ScriptTask()
{
@Override
public void execute(Context cx, Scriptable scope)
{
// Now we should be running inside the script thread of the other script