| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.sdk.internal.wip; | 5 package org.chromium.sdk.internal.wip; |
| 6 | 6 |
| 7 import static org.chromium.sdk.util.BasicUtil.getSafe; | 7 import static org.chromium.sdk.util.BasicUtil.getSafe; |
| 8 | 8 |
| 9 import java.util.ArrayList; | 9 import java.util.ArrayList; |
| 10 import java.util.Collection; | 10 import java.util.Collection; |
| 11 import java.util.Collections; | 11 import java.util.Collections; |
| 12 import java.util.HashMap; | 12 import java.util.HashMap; |
| 13 import java.util.HashSet; | 13 import java.util.HashSet; |
| 14 import java.util.List; | 14 import java.util.List; |
| 15 import java.util.Map; | 15 import java.util.Map; |
| 16 import java.util.Set; | 16 import java.util.Set; |
| 17 import java.util.concurrent.atomic.AtomicReference; | 17 import java.util.concurrent.atomic.AtomicReference; |
| 18 import java.util.logging.Level; | 18 import java.util.logging.Level; |
| 19 import java.util.logging.Logger; | 19 import java.util.logging.Logger; |
| 20 | 20 |
| 21 import org.chromium.sdk.Breakpoint; | 21 import org.chromium.sdk.Breakpoint; |
| 22 import org.chromium.sdk.CallFrame; | 22 import org.chromium.sdk.CallFrame; |
| 23 import org.chromium.sdk.DebugContext; | 23 import org.chromium.sdk.DebugContext; |
| 24 import org.chromium.sdk.DebugContext.StepAction; | 24 import org.chromium.sdk.DebugContext.StepAction; |
| 25 import org.chromium.sdk.ExceptionData; | 25 import org.chromium.sdk.ExceptionData; |
| 26 import org.chromium.sdk.JavascriptVm; | 26 import org.chromium.sdk.JavascriptVm; |
| 27 import org.chromium.sdk.JsArray; | |
| 28 import org.chromium.sdk.JsEvaluateContext; | 27 import org.chromium.sdk.JsEvaluateContext; |
| 29 import org.chromium.sdk.JsFunction; | |
| 30 import org.chromium.sdk.JsObject; | 28 import org.chromium.sdk.JsObject; |
| 31 import org.chromium.sdk.JsScope; | 29 import org.chromium.sdk.JsScope; |
| 32 import org.chromium.sdk.JsValue; | 30 import org.chromium.sdk.JsValue; |
| 33 import org.chromium.sdk.JsVariable; | 31 import org.chromium.sdk.JsVariable; |
| 34 import org.chromium.sdk.RelayOk; | 32 import org.chromium.sdk.RelayOk; |
| 35 import org.chromium.sdk.RemoteValueMapping; | 33 import org.chromium.sdk.RemoteValueMapping; |
| 36 import org.chromium.sdk.RestartFrameExtension; | 34 import org.chromium.sdk.RestartFrameExtension; |
| 37 import org.chromium.sdk.SyncCallback; | 35 import org.chromium.sdk.SyncCallback; |
| 38 import org.chromium.sdk.TextStreamPosition; | 36 import org.chromium.sdk.TextStreamPosition; |
| 39 import org.chromium.sdk.internal.protocolparser.JsonProtocolParseException; | 37 import org.chromium.sdk.internal.protocolparser.JsonProtocolParseException; |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 return callFrame.getScript() != null; | 561 return callFrame.getScript() != null; |
| 564 } | 562 } |
| 565 }; | 563 }; |
| 566 | 564 |
| 567 | 565 |
| 568 static JsScope createScope(ScopeValue scopeData, WipValueLoader valueLoader) { | 566 static JsScope createScope(ScopeValue scopeData, WipValueLoader valueLoader) { |
| 569 JsScope.Type type = WIP_TO_SDK_SCOPE_TYPE.get(scopeData.type()); | 567 JsScope.Type type = WIP_TO_SDK_SCOPE_TYPE.get(scopeData.type()); |
| 570 if (type == null) { | 568 if (type == null) { |
| 571 type = JsScope.Type.UNKNOWN; | 569 type = JsScope.Type.UNKNOWN; |
| 572 } | 570 } |
| 573 if (type == JsScope.Type.WITH) { | 571 if (type == JsScope.Type.WITH || type == JsScope.Type.GLOBAL) { |
| 574 return new WithScopeImpl(scopeData, valueLoader); | 572 return new ObjectScopeImpl(scopeData, type, valueLoader); |
| 575 } else { | 573 } else { |
| 576 return new ScopeImpl(scopeData, type, valueLoader); | 574 return new DeclarativeScopeImpl(scopeData, type, valueLoader); |
| 577 } | 575 } |
| 578 } | 576 } |
| 579 | 577 |
| 580 private static class ScopeImpl implements JsScope { | 578 private static class DeclarativeScopeImpl implements JsScope.Declarative { |
| 581 private final AsyncFutureRef<Getter<ScopeVariables>> propertiesRef = | 579 private final AsyncFutureRef<Getter<ScopeVariables>> propertiesRef = |
| 582 new AsyncFutureRef<Getter<ScopeVariables>>(); | 580 new AsyncFutureRef<Getter<ScopeVariables>>(); |
| 583 private final String objectId; | 581 private final String objectId; |
| 584 private final Type type; | 582 private final Type type; |
| 585 private final WipValueLoader valueLoader; | 583 private final WipValueLoader valueLoader; |
| 586 | 584 |
| 587 public ScopeImpl(ScopeValue scopeData, Type type, WipValueLoader valueLoader
) { | 585 public DeclarativeScopeImpl(ScopeValue scopeData, Type type, WipValueLoader
valueLoader) { |
| 588 this.type = type; | 586 this.type = type; |
| 589 this.objectId = scopeData.object().objectId(); | 587 this.objectId = scopeData.object().objectId(); |
| 590 this.valueLoader = valueLoader; | 588 this.valueLoader = valueLoader; |
| 591 } | 589 } |
| 592 | 590 |
| 593 @Override | 591 @Override public Type getType() { |
| 594 public Type getType() { | |
| 595 return type; | 592 return type; |
| 596 } | 593 } |
| 597 | 594 |
| 598 @Override | 595 @Override public Declarative asDeclarativeScope() { |
| 599 public WithScope asWithScope() { | 596 return this; |
| 597 } |
| 598 |
| 599 @Override public ObjectBased asObjectBased() { |
| 600 return null; | 600 return null; |
| 601 } | 601 } |
| 602 | 602 |
| 603 @Override public <R> R accept(Visitor<R> visitor) { |
| 604 return visitor.visitDeclarative(this); |
| 605 } |
| 606 |
| 603 @Override | 607 @Override |
| 604 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { | 608 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { |
| 605 int currentCacheState = valueLoader.getCacheState(); | 609 int currentCacheState = valueLoader.getCacheState(); |
| 606 if (propertiesRef.isInitialized()) { | 610 if (propertiesRef.isInitialized()) { |
| 607 ScopeVariables result = propertiesRef.getSync().get(); | 611 ScopeVariables result = propertiesRef.getSync().get(); |
| 608 if (result.cacheState == currentCacheState) { | 612 if (result.cacheState == currentCacheState) { |
| 609 return result.variables; | 613 return result.variables; |
| 610 } | 614 } |
| 611 startLoadOperation(true, currentCacheState); | 615 startLoadOperation(true, currentCacheState); |
| 612 } else { | 616 } else { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 public Getter<ScopeVariables> forException(Exception exception) { | 667 public Getter<ScopeVariables> forException(Exception exception) { |
| 664 return WipValueLoader.Getter.newFailure(exception); | 668 return WipValueLoader.Getter.newFailure(exception); |
| 665 } | 669 } |
| 666 }; | 670 }; |
| 667 // This is blocking. | 671 // This is blocking. |
| 668 valueLoader.loadPropertiesInFuture(objectId, processor, reload, currentCac
heState, | 672 valueLoader.loadPropertiesInFuture(objectId, processor, reload, currentCac
heState, |
| 669 propertiesRef); | 673 propertiesRef); |
| 670 } | 674 } |
| 671 } | 675 } |
| 672 | 676 |
| 673 private static class WithScopeImpl implements JsScope.WithScope { | 677 private static class ObjectScopeImpl implements JsScope.ObjectBased { |
| 674 private final JsValue jsValue; | 678 private final JsValue jsValue; |
| 679 private final JsScope.Type type; |
| 675 | 680 |
| 676 WithScopeImpl(ScopeValue scopeData, WipValueLoader valueLoader) { | 681 ObjectScopeImpl(ScopeValue scopeData, JsScope.Type type, WipValueLoader valu
eLoader) { |
| 677 jsValue = valueLoader.getValueBuilder().wrap(scopeData.object()); | 682 this.jsValue = valueLoader.getValueBuilder().wrap(scopeData.object()); |
| 683 this.type = type; |
| 684 } |
| 685 |
| 686 @Override public Type getType() { |
| 687 return type; |
| 688 } |
| 689 |
| 690 @Override public Declarative asDeclarativeScope() { |
| 691 return null; |
| 692 } |
| 693 |
| 694 @Override public ObjectBased asObjectBased() { |
| 695 return this; |
| 696 } |
| 697 |
| 698 @Override public <R> R accept(Visitor<R> visitor) { |
| 699 return visitor.visitObject(this); |
| 678 } | 700 } |
| 679 | 701 |
| 680 @Override | 702 @Override |
| 681 public Type getType() { | 703 public JsObject getScopeObject() throws MethodIsBlockingException { |
| 682 return Type.WITH; | 704 JsObject jsObject = jsValue.asObject(); |
| 683 } | 705 if (jsObject == null) { |
| 684 | 706 throw new RuntimeException("Received scope object value is not an object
"); |
| 685 @Override | |
| 686 public WithScope asWithScope() { | |
| 687 return this; | |
| 688 } | |
| 689 | |
| 690 @Override | |
| 691 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { | |
| 692 JsObject asObject = jsValue.asObject(); | |
| 693 if (asObject == null) { | |
| 694 return Collections.emptyList(); | |
| 695 } | 707 } |
| 696 return new ArrayList<JsVariable>(asObject.getProperties()); | 708 return jsObject; |
| 697 } | |
| 698 | |
| 699 @Override | |
| 700 public JsValue getWithArgument() { | |
| 701 return jsValue; | |
| 702 } | 709 } |
| 703 } | 710 } |
| 704 | 711 |
| 705 static final class GlobalEvaluateContext extends WipEvaluateContextBase<Evalua
teData> { | 712 static final class GlobalEvaluateContext extends WipEvaluateContextBase<Evalua
teData> { |
| 706 | 713 |
| 707 GlobalEvaluateContext(WipValueLoader valueLoader) { | 714 GlobalEvaluateContext(WipValueLoader valueLoader) { |
| 708 super(valueLoader); | 715 super(valueLoader); |
| 709 } | 716 } |
| 710 | 717 |
| 711 @Override protected WipParamsWithResponse<EvaluateData> createRequestParams(
String expression, | 718 @Override protected WipParamsWithResponse<EvaluateData> createRequestParams(
String expression, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 default: | 778 default: |
| 772 throw new RuntimeException(); | 779 throw new RuntimeException(); |
| 773 } | 780 } |
| 774 } | 781 } |
| 775 | 782 |
| 776 private static final ResumeParams RESUME_PARAMS = new ResumeParams(); | 783 private static final ResumeParams RESUME_PARAMS = new ResumeParams(); |
| 777 private static final StepIntoParams STEP_INTO_PARAMS = new StepIntoParams(); | 784 private static final StepIntoParams STEP_INTO_PARAMS = new StepIntoParams(); |
| 778 private static final StepOutParams STEP_OUT_PARAMS = new StepOutParams(); | 785 private static final StepOutParams STEP_OUT_PARAMS = new StepOutParams(); |
| 779 private static final StepOverParams STEP_OVER_PARAMS = new StepOverParams(); | 786 private static final StepOverParams STEP_OVER_PARAMS = new StepOverParams(); |
| 780 } | 787 } |
| OLD | NEW |