private V8CommandProcessor.V8HandlerCallback createScriptUpdateCallback(
final UpdateCallback callback, final boolean previewOnly) {
return new V8CommandCallbackBase() {
@Override
public void success(SuccessCommandResponse successResponse) {
ChangeLiveBody body;
try {
body = successResponse.body().asChangeLiveBody();
} catch (JsonProtocolParseException e) {
throw new RuntimeException(e);
}
LiveEditResult resultDescription = body.getResultDescription();
boolean resumed = false;
if (!previewOnly) {
ScriptLoadCallback scriptCallback = new ScriptLoadCallback() {
@Override
public void failure(String message) {
LOGGER.log(Level.SEVERE,
"Failed to reload script after LiveEdit script update; " + message);
}
@Override
public void success() {
DebugEventListener listener = debugSession.getDebugEventListener();
if (listener != null) {
listener.scriptContentChanged(ScriptImpl.this);
}
}
};
V8Helper.reloadScriptAsync(debugSession, Collections.singletonList(getId()),
scriptCallback, null);
if (body.stepin_recommended() == Boolean.TRUE) {
DebugContext debugContext = debugSession.getContextBuilder().getCurrentDebugContext();
if (debugContext == null) {
// We may have already issued 'continue' since the moment that change live command
// was sent so the context was dropped. Ignore this case.
} else {
debugContext.continueVm(DebugContext.StepAction.IN, 0, null);
resumed = true;
}
} else {
if (resultDescription != null && resultDescription.stack_modified()) {
debugSession.recreateCurrentContext();
}
}
}
if (callback != null) {
callback.success(resumed, body.getChangeLog(),
UpdateResultParser.wrapChangeDescription(resultDescription));
}
}
@Override