| Index: plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/JsEvaluateContextImpl.java
|
| diff --git a/plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/JsEvaluateContextImpl.java b/plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/JsEvaluateContextImpl.java
|
| index 19a9c5841f3ee344a87e76a80ef599f1b1a2cd8c..68f71fcaceb68604cb14208ea0bd4701d8820e3e 100644
|
| --- a/plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/JsEvaluateContextImpl.java
|
| +++ b/plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/JsEvaluateContextImpl.java
|
| @@ -10,7 +10,6 @@ import java.util.Map;
|
|
|
| import org.chromium.sdk.JsEvaluateContext;
|
| import org.chromium.sdk.JsValue;
|
| -import org.chromium.sdk.JsVariable;
|
| import org.chromium.sdk.RelayOk;
|
| import org.chromium.sdk.SyncCallback;
|
| import org.chromium.sdk.internal.JsEvaluateContextBase;
|
| @@ -25,25 +24,84 @@ import org.chromium.sdk.internal.v8native.protocol.output.EvaluateMessage;
|
| import org.chromium.sdk.internal.v8native.value.JsValueBase;
|
| import org.chromium.sdk.internal.v8native.value.JsVariableBase;
|
| import org.chromium.sdk.internal.v8native.value.ValueMirror;
|
| -import org.chromium.sdk.util.RelaySyncCallback;
|
| import org.json.simple.JSONValue;
|
|
|
| /**
|
| * Generic implementation of {@link JsEvaluateContext}. The abstract class leaves unspecified
|
| * stack frame identifier (possibly null) and reference to {@link InternalContext}.
|
| */
|
| -abstract class JsEvaluateContextImpl extends JsEvaluateContextBase {
|
| +public abstract class JsEvaluateContextImpl extends JsEvaluateContextBase {
|
| public RelayOk evaluateAsyncImpl(final String expression,
|
| Map<String, ? extends JsValue> additionalContext,
|
| final EvaluateCallback callback, SyncCallback syncCallback)
|
| throws ContextDismissedCheckedException {
|
| + List<Map.Entry<String, EvaluateMessage.Value>> internalAdditionalContext =
|
| + convertAdditionalContextList(additionalContext, getInternalContext());
|
| +
|
| + CallbackInternal callbackInternal;
|
| + if (callback == null) {
|
| + callbackInternal = null;
|
| + } else {
|
| + callbackInternal = new CallbackInternal() {
|
| + @Override
|
| + public void success(final JsValueBase value) {
|
| + ResultOrException result = new ResultOrException() {
|
| + @Override public JsValue getResult() {
|
| + return value;
|
| + }
|
| + @Override public JsValue getException() {
|
| + return null;
|
| + }
|
| + @Override public <R> R accept(Visitor<R> visitor) {
|
| + return visitor.visitResult(value);
|
| + }
|
| + };
|
| + callback.success(result);
|
| + }
|
| +
|
| + @Override
|
| + public void exception(final JsValueBase exception) {
|
| + ResultOrException result = new ResultOrException() {
|
| + @Override public JsValue getResult() {
|
| + return null;
|
| + }
|
| + @Override public JsValue getException() {
|
| + return exception;
|
| + }
|
| + @Override public <R> R accept(Visitor<R> visitor) {
|
| + return visitor.visitException(exception);
|
| + }
|
| + };
|
| + callback.success(result);
|
| + }
|
| +
|
| + @Override public void failure(Exception cause) {
|
| + callback.failure(cause);
|
| + }
|
| + };
|
| + }
|
| +
|
| + return evaluateAsyncInternal(expression, internalAdditionalContext,
|
| + callbackInternal, syncCallback);
|
| + }
|
| +
|
| + /**
|
| + * Internal callback for evaluate operation. It returns internal types.
|
| + */
|
| + public interface CallbackInternal {
|
| + void success(JsValueBase value);
|
| + void exception(JsValueBase exception);
|
| + void failure(Exception cause);
|
| + }
|
| +
|
| + public RelayOk evaluateAsyncInternal(final String expression,
|
| + List<Map.Entry<String, EvaluateMessage.Value>> internalAdditionalContext,
|
| + final CallbackInternal callback, SyncCallback syncCallback)
|
| + throws ContextDismissedCheckedException {
|
|
|
| Integer frameIdentifier = getFrameIdentifier();
|
| Boolean isGlobal = frameIdentifier == null ? Boolean.TRUE : null;
|
|
|
| - List<Map.Entry<String, EvaluateMessage.Value>> internalAdditionalContext =
|
| - convertAdditionalContextList(additionalContext, getInternalContext());
|
| -
|
| DebuggerMessage message = DebuggerMessageFactory.evaluate(expression, frameIdentifier,
|
| isGlobal, Boolean.TRUE, internalAdditionalContext);
|
|
|
| @@ -60,20 +118,9 @@ abstract class JsEvaluateContextImpl extends JsEvaluateContextBase {
|
| }
|
| InternalContext internalContext = getInternalContext();
|
| ValueMirror mirror = internalContext.getValueLoader().addDataToMap(body);
|
| - final JsValue value =
|
| + JsValueBase value =
|
| JsVariableBase.createValue(internalContext.getValueLoader(), mirror);
|
| - ResultOrException result = new ResultOrException() {
|
| - @Override public JsValue getResult() {
|
| - return value;
|
| - }
|
| - @Override public JsValue getException() {
|
| - return null;
|
| - }
|
| - @Override public <R> R accept(Visitor<R> visitor) {
|
| - return visitor.visitResult(value);
|
| - }
|
| - };
|
| - callback.success(result);
|
| + callback.success(value);
|
| }
|
| @Override
|
| public void failure(String message, ErrorDetails errorDetails) {
|
| @@ -84,19 +131,8 @@ abstract class JsEvaluateContextImpl extends JsEvaluateContextBase {
|
| // We incorrectly create string value out of this message and return
|
| // it as an exception.
|
| // TODO: Return actual exception value when protocol supports it.
|
| - final JsValue pseudoException = getValueFactory().createString(message);
|
| - ResultOrException result = new ResultOrException() {
|
| - @Override public JsValue getResult() {
|
| - return null;
|
| - }
|
| - @Override public JsValue getException() {
|
| - return pseudoException;
|
| - }
|
| - @Override public <R> R accept(Visitor<R> visitor) {
|
| - return visitor.visitException(pseudoException);
|
| - }
|
| - };
|
| - callback.success(result);
|
| + JsValueBase pseudoException = getValueFactory().createString(message);
|
| + callback.exception(pseudoException);
|
| }
|
| };
|
|
|
| @@ -111,19 +147,17 @@ abstract class JsEvaluateContextImpl extends JsEvaluateContextBase {
|
| try {
|
| return evaluateAsyncImpl(expression, additionalContext, callback, syncCallback);
|
| } catch (ContextDismissedCheckedException e) {
|
| - maybeRethrowContextException(e);
|
| - // or
|
| - callback.failure(e);
|
| - return RelaySyncCallback.finish(syncCallback);
|
| + return maybeRethrowContextException(e, syncCallback);
|
| }
|
| }
|
|
|
| - @Override public PrimitiveValueFactory getValueFactory() {
|
| - return PRIMITIVE_VALUE_FACTORY;
|
| + @Override public PrimitiveValueFactoryImpl getValueFactory() {
|
| + return PrimitiveValueFactoryImpl.INSTANCE;
|
| }
|
|
|
| - private void maybeRethrowContextException(ContextDismissedCheckedException ex) {
|
| - getInternalContext().getDebugSession().maybeRethrowContextException(ex);
|
| + private RelayOk maybeRethrowContextException(ContextDismissedCheckedException ex,
|
| + SyncCallback syncCallback) {
|
| + return getInternalContext().getDebugSession().maybeRethrowContextException(ex, syncCallback);
|
| }
|
|
|
|
|
| @@ -161,15 +195,17 @@ abstract class JsEvaluateContextImpl extends JsEvaluateContextBase {
|
|
|
| protected abstract InternalContext getInternalContext();
|
|
|
| - private static final PrimitiveValueFactory PRIMITIVE_VALUE_FACTORY =
|
| - new PrimitiveValueFactory() {
|
| + public static class PrimitiveValueFactoryImpl implements PrimitiveValueFactory {
|
| + private static final PrimitiveValueFactoryImpl INSTANCE =
|
| + new PrimitiveValueFactoryImpl();
|
| +
|
| @Override public JsValue getUndefined() {
|
| return new JsValueBase.Impl(JsValue.Type.TYPE_UNDEFINED, null);
|
| }
|
| @Override public JsValue getNull() {
|
| return new JsValueBase.Impl(JsValue.Type.TYPE_NULL, null);
|
| }
|
| - @Override public JsValue createString(String value) {
|
| + @Override public JsValueBase createString(String value) {
|
| return new JsValueBase.Impl(JsValue.Type.TYPE_STRING, value);
|
| }
|
| @Override public JsValue createNumber(double value) {
|
| @@ -184,5 +220,5 @@ abstract class JsEvaluateContextImpl extends JsEvaluateContextBase {
|
| @Override public JsValue createBoolean(boolean value) {
|
| return new JsValueBase.Impl(JsValue.Type.TYPE_BOOLEAN, JSONValue.toJSONString(value));
|
| }
|
| - };
|
| + }
|
| }
|
|
|