| 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; |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 return callFrame.getScript() != null; | 563 return callFrame.getScript() != null; |
| 564 } | 564 } |
| 565 }; | 565 }; |
| 566 | 566 |
| 567 | 567 |
| 568 static JsScope createScope(ScopeValue scopeData, WipValueLoader valueLoader) { | 568 static JsScope createScope(ScopeValue scopeData, WipValueLoader valueLoader) { |
| 569 JsScope.Type type = WIP_TO_SDK_SCOPE_TYPE.get(scopeData.type()); | 569 JsScope.Type type = WIP_TO_SDK_SCOPE_TYPE.get(scopeData.type()); |
| 570 if (type == null) { | 570 if (type == null) { |
| 571 type = JsScope.Type.UNKNOWN; | 571 type = JsScope.Type.UNKNOWN; |
| 572 } | 572 } |
| 573 if (type == JsScope.Type.WITH) { | 573 if (type == JsScope.Type.WITH || type == JsScope.Type.GLOBAL) { |
| 574 return new WithScopeImpl(scopeData, valueLoader); | 574 return new ObjectScopeImpl(scopeData, type, valueLoader); |
| 575 } else { | 575 } else { |
| 576 return new ScopeImpl(scopeData, type, valueLoader); | 576 return new DeclarativeScopeImpl(scopeData, type, valueLoader); |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 | 579 |
| 580 private static class ScopeImpl implements JsScope { | 580 private static class DeclarativeScopeImpl implements JsScope.Declarative { |
| 581 private final AsyncFutureRef<Getter<ScopeVariables>> propertiesRef = | 581 private final AsyncFutureRef<Getter<ScopeVariables>> propertiesRef = |
| 582 new AsyncFutureRef<Getter<ScopeVariables>>(); | 582 new AsyncFutureRef<Getter<ScopeVariables>>(); |
| 583 private final String objectId; | 583 private final String objectId; |
| 584 private final Type type; | 584 private final Type type; |
| 585 private final WipValueLoader valueLoader; | 585 private final WipValueLoader valueLoader; |
| 586 | 586 |
| 587 public ScopeImpl(ScopeValue scopeData, Type type, WipValueLoader valueLoader
) { | 587 public DeclarativeScopeImpl(ScopeValue scopeData, Type type, WipValueLoader
valueLoader) { |
| 588 this.type = type; | 588 this.type = type; |
| 589 this.objectId = scopeData.object().objectId(); | 589 this.objectId = scopeData.object().objectId(); |
| 590 this.valueLoader = valueLoader; | 590 this.valueLoader = valueLoader; |
| 591 } | 591 } |
| 592 | 592 |
| 593 @Override | 593 @Override public Type getType() { |
| 594 public Type getType() { | |
| 595 return type; | 594 return type; |
| 596 } | 595 } |
| 597 | 596 |
| 598 @Override | 597 @Override public Declarative asDeclarativeScope() { |
| 599 public WithScope asWithScope() { | 598 return this; |
| 599 } |
| 600 |
| 601 @Override public ObjectBased asObjectBased() { |
| 600 return null; | 602 return null; |
| 601 } | 603 } |
| 602 | 604 |
| 605 @Override public <R> R accept(Visitor<R> visitor) { |
| 606 return visitor.visitDeclarative(this); |
| 607 } |
| 608 |
| 603 @Override | 609 @Override |
| 604 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { | 610 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { |
| 605 int currentCacheState = valueLoader.getCacheState(); | 611 int currentCacheState = valueLoader.getCacheState(); |
| 606 if (propertiesRef.isInitialized()) { | 612 if (propertiesRef.isInitialized()) { |
| 607 ScopeVariables result = propertiesRef.getSync().get(); | 613 ScopeVariables result = propertiesRef.getSync().get(); |
| 608 if (result.cacheState == currentCacheState) { | 614 if (result.cacheState == currentCacheState) { |
| 609 return result.variables; | 615 return result.variables; |
| 610 } | 616 } |
| 611 startLoadOperation(true, currentCacheState); | 617 startLoadOperation(true, currentCacheState); |
| 612 } else { | 618 } else { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 public Getter<ScopeVariables> forException(Exception exception) { | 671 public Getter<ScopeVariables> forException(Exception exception) { |
| 666 return WipValueLoader.Getter.newFailure(exception); | 672 return WipValueLoader.Getter.newFailure(exception); |
| 667 } | 673 } |
| 668 }; | 674 }; |
| 669 // This is blocking. | 675 // This is blocking. |
| 670 valueLoader.loadPropertiesInFuture(objectId, processor, reload, currentCac
heState, | 676 valueLoader.loadPropertiesInFuture(objectId, processor, reload, currentCac
heState, |
| 671 propertiesRef); | 677 propertiesRef); |
| 672 } | 678 } |
| 673 } | 679 } |
| 674 | 680 |
| 675 private static class WithScopeImpl implements JsScope.WithScope { | 681 private static class ObjectScopeImpl implements JsScope.ObjectBased { |
| 676 private final JsValue jsValue; | 682 private final JsValue jsValue; |
| 683 private final JsScope.Type type; |
| 677 | 684 |
| 678 WithScopeImpl(ScopeValue scopeData, WipValueLoader valueLoader) { | 685 ObjectScopeImpl(ScopeValue scopeData, JsScope.Type type, WipValueLoader valu
eLoader) { |
| 679 jsValue = valueLoader.getValueBuilder().wrap(scopeData.object(), null); | 686 jsValue = valueLoader.getValueBuilder().wrap(scopeData.object(), null); |
| 687 this.type = type; |
| 688 } |
| 689 |
| 690 @Override public Type getType() { |
| 691 return type; |
| 692 } |
| 693 |
| 694 @Override public Declarative asDeclarativeScope() { |
| 695 return null; |
| 696 } |
| 697 |
| 698 @Override public ObjectBased asObjectBased() { |
| 699 return this; |
| 700 } |
| 701 |
| 702 @Override public <R> R accept(Visitor<R> visitor) { |
| 703 return visitor.visitObject(this); |
| 680 } | 704 } |
| 681 | 705 |
| 682 @Override | 706 @Override |
| 683 public Type getType() { | 707 public JsObject getScopeObject() throws MethodIsBlockingException { |
| 684 return Type.WITH; | 708 JsObject jsObject = jsValue.asObject(); |
| 685 } | 709 if (jsObject == null) { |
| 686 | 710 throw new RuntimeException("Received scope object value is not an object
"); |
| 687 @Override | |
| 688 public WithScope asWithScope() { | |
| 689 return this; | |
| 690 } | |
| 691 | |
| 692 @Override | |
| 693 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { | |
| 694 JsObject asObject = jsValue.asObject(); | |
| 695 if (asObject == null) { | |
| 696 return Collections.emptyList(); | |
| 697 } | 711 } |
| 698 return new ArrayList<JsVariable>(asObject.getProperties()); | 712 return jsObject; |
| 699 } | |
| 700 | |
| 701 @Override | |
| 702 public JsValue getWithArgument() { | |
| 703 return jsValue; | |
| 704 } | 713 } |
| 705 } | 714 } |
| 706 | 715 |
| 707 static final class GlobalEvaluateContext extends WipEvaluateContextBase<Evalua
teData> { | 716 static final class GlobalEvaluateContext extends WipEvaluateContextBase<Evalua
teData> { |
| 708 | 717 |
| 709 GlobalEvaluateContext(WipValueLoader valueLoader) { | 718 GlobalEvaluateContext(WipValueLoader valueLoader) { |
| 710 super(valueLoader); | 719 super(valueLoader); |
| 711 } | 720 } |
| 712 | 721 |
| 713 @Override protected WipParamsWithResponse<EvaluateData> createRequestParams(
String expression, | 722 @Override protected WipParamsWithResponse<EvaluateData> createRequestParams(
String expression, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 default: | 782 default: |
| 774 throw new RuntimeException(); | 783 throw new RuntimeException(); |
| 775 } | 784 } |
| 776 } | 785 } |
| 777 | 786 |
| 778 private static final ResumeParams RESUME_PARAMS = new ResumeParams(); | 787 private static final ResumeParams RESUME_PARAMS = new ResumeParams(); |
| 779 private static final StepIntoParams STEP_INTO_PARAMS = new StepIntoParams(); | 788 private static final StepIntoParams STEP_INTO_PARAMS = new StepIntoParams(); |
| 780 private static final StepOutParams STEP_OUT_PARAMS = new StepOutParams(); | 789 private static final StepOutParams STEP_OUT_PARAMS = new StepOutParams(); |
| 781 private static final StepOverParams STEP_OVER_PARAMS = new StepOverParams(); | 790 private static final StepOverParams STEP_OVER_PARAMS = new StepOverParams(); |
| 782 } | 791 } |
| OLD | NEW |