| 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 return null; | 473 return null; |
| 474 } | 474 } |
| 475 }; | 475 }; |
| 476 } | 476 } |
| 477 | 477 |
| 478 static JsScope createScope(ScopeValue scopeData, WipValueLoader valueLoader) { | 478 static JsScope createScope(ScopeValue scopeData, WipValueLoader valueLoader) { |
| 479 JsScope.Type type = WIP_TO_SDK_SCOPE_TYPE.get(scopeData.type()); | 479 JsScope.Type type = WIP_TO_SDK_SCOPE_TYPE.get(scopeData.type()); |
| 480 if (type == null) { | 480 if (type == null) { |
| 481 type = JsScope.Type.UNKNOWN; | 481 type = JsScope.Type.UNKNOWN; |
| 482 } | 482 } |
| 483 if (type == JsScope.Type.WITH) { | 483 if (type == JsScope.Type.WITH || type == JsScope.Type.GLOBAL) { |
| 484 return new WithScopeImpl(scopeData, valueLoader); | 484 return new ObjectScopeImpl(scopeData, type, valueLoader); |
| 485 } else { | 485 } else { |
| 486 return new ScopeImpl(scopeData, type, valueLoader); | 486 return new DeclarativeScopeImpl(scopeData, type, valueLoader); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | 489 |
| 490 private static class ScopeImpl implements JsScope { | 490 private static class DeclarativeScopeImpl implements JsScope.Declarative { |
| 491 private final AsyncFutureRef<Getter<ScopeVariables>> propertiesRef = | 491 private final AsyncFutureRef<Getter<ScopeVariables>> propertiesRef = |
| 492 new AsyncFutureRef<Getter<ScopeVariables>>(); | 492 new AsyncFutureRef<Getter<ScopeVariables>>(); |
| 493 private final String objectId; | 493 private final String objectId; |
| 494 private final Type type; | 494 private final Type type; |
| 495 private final WipValueLoader valueLoader; | 495 private final WipValueLoader valueLoader; |
| 496 | 496 |
| 497 public ScopeImpl(ScopeValue scopeData, Type type, WipValueLoader valueLoader
) { | 497 public DeclarativeScopeImpl(ScopeValue scopeData, Type type, WipValueLoader
valueLoader) { |
| 498 this.type = type; | 498 this.type = type; |
| 499 this.objectId = scopeData.object().objectId(); | 499 this.objectId = scopeData.object().objectId(); |
| 500 this.valueLoader = valueLoader; | 500 this.valueLoader = valueLoader; |
| 501 } | 501 } |
| 502 | 502 |
| 503 @Override | 503 @Override public Type getType() { |
| 504 public Type getType() { | |
| 505 return type; | 504 return type; |
| 506 } | 505 } |
| 507 | 506 |
| 508 @Override | 507 @Override public Declarative asDeclarativeScope() { |
| 509 public WithScope asWithScope() { | 508 return this; |
| 509 } |
| 510 |
| 511 @Override public ObjectBased asObjectBased() { |
| 510 return null; | 512 return null; |
| 511 } | 513 } |
| 512 | 514 |
| 515 @Override public <R> R accept(Visitor<R> visitor) { |
| 516 return visitor.visitDeclarative(this); |
| 517 } |
| 518 |
| 513 @Override | 519 @Override |
| 514 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { | 520 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { |
| 515 int currentCacheState = valueLoader.getCacheState(); | 521 int currentCacheState = valueLoader.getCacheState(); |
| 516 if (propertiesRef.isInitialized()) { | 522 if (propertiesRef.isInitialized()) { |
| 517 ScopeVariables result = propertiesRef.getSync().get(); | 523 ScopeVariables result = propertiesRef.getSync().get(); |
| 518 if (result.cacheState == currentCacheState) { | 524 if (result.cacheState == currentCacheState) { |
| 519 return result.variables; | 525 return result.variables; |
| 520 } | 526 } |
| 521 startLoadOperation(true, currentCacheState); | 527 startLoadOperation(true, currentCacheState); |
| 522 } else { | 528 } else { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 public Getter<ScopeVariables> forException(Exception exception) { | 581 public Getter<ScopeVariables> forException(Exception exception) { |
| 576 return WipValueLoader.Getter.newFailure(exception); | 582 return WipValueLoader.Getter.newFailure(exception); |
| 577 } | 583 } |
| 578 }; | 584 }; |
| 579 // This is blocking. | 585 // This is blocking. |
| 580 valueLoader.loadPropertiesInFuture(objectId, processor, reload, currentCac
heState, | 586 valueLoader.loadPropertiesInFuture(objectId, processor, reload, currentCac
heState, |
| 581 propertiesRef); | 587 propertiesRef); |
| 582 } | 588 } |
| 583 } | 589 } |
| 584 | 590 |
| 585 private static class WithScopeImpl implements JsScope.WithScope { | 591 private static class ObjectScopeImpl implements JsScope.ObjectBased { |
| 586 private final JsValue jsValue; | 592 private final JsValue jsValue; |
| 593 private final JsScope.Type type; |
| 587 | 594 |
| 588 WithScopeImpl(ScopeValue scopeData, WipValueLoader valueLoader) { | 595 ObjectScopeImpl(ScopeValue scopeData, JsScope.Type type, WipValueLoader valu
eLoader) { |
| 589 jsValue = valueLoader.getValueBuilder().wrap(scopeData.object(), null); | 596 jsValue = valueLoader.getValueBuilder().wrap(scopeData.object(), null); |
| 597 this.type = type; |
| 598 } |
| 599 |
| 600 @Override public Type getType() { |
| 601 return type; |
| 602 } |
| 603 |
| 604 @Override public Declarative asDeclarativeScope() { |
| 605 return null; |
| 606 } |
| 607 |
| 608 @Override public ObjectBased asObjectBased() { |
| 609 return this; |
| 610 } |
| 611 |
| 612 @Override public <R> R accept(Visitor<R> visitor) { |
| 613 return visitor.visitObject(this); |
| 590 } | 614 } |
| 591 | 615 |
| 592 @Override | 616 @Override |
| 593 public Type getType() { | 617 public JsObject getScopeObject() throws MethodIsBlockingException { |
| 594 return Type.WITH; | 618 JsObject jsObject = jsValue.asObject(); |
| 595 } | 619 if (jsObject == null) { |
| 596 | 620 throw new RuntimeException("Received scope object value is not an object
"); |
| 597 @Override | |
| 598 public WithScope asWithScope() { | |
| 599 return this; | |
| 600 } | |
| 601 | |
| 602 @Override | |
| 603 public List<? extends JsVariable> getVariables() throws MethodIsBlockingExce
ption { | |
| 604 JsObject asObject = jsValue.asObject(); | |
| 605 if (asObject == null) { | |
| 606 return Collections.emptyList(); | |
| 607 } | 621 } |
| 608 return new ArrayList<JsVariable>(asObject.getProperties()); | 622 return jsObject; |
| 609 } | |
| 610 | |
| 611 @Override | |
| 612 public JsValue getWithArgument() { | |
| 613 return jsValue; | |
| 614 } | 623 } |
| 615 } | 624 } |
| 616 | 625 |
| 617 static final class GlobalEvaluateContext extends WipEvaluateContextBase<Evalua
teData> { | 626 static final class GlobalEvaluateContext extends WipEvaluateContextBase<Evalua
teData> { |
| 618 | 627 |
| 619 GlobalEvaluateContext(WipValueLoader valueLoader) { | 628 GlobalEvaluateContext(WipValueLoader valueLoader) { |
| 620 super(valueLoader); | 629 super(valueLoader); |
| 621 } | 630 } |
| 622 | 631 |
| 623 @Override protected WipParamsWithResponse<EvaluateData> createRequestParams(
String expression, | 632 @Override protected WipParamsWithResponse<EvaluateData> createRequestParams(
String expression, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 default: | 692 default: |
| 684 throw new RuntimeException(); | 693 throw new RuntimeException(); |
| 685 } | 694 } |
| 686 } | 695 } |
| 687 | 696 |
| 688 private static final ResumeParams RESUME_PARAMS = new ResumeParams(); | 697 private static final ResumeParams RESUME_PARAMS = new ResumeParams(); |
| 689 private static final StepIntoParams STEP_INTO_PARAMS = new StepIntoParams(); | 698 private static final StepIntoParams STEP_INTO_PARAMS = new StepIntoParams(); |
| 690 private static final StepOutParams STEP_OUT_PARAMS = new StepOutParams(); | 699 private static final StepOutParams STEP_OUT_PARAMS = new StepOutParams(); |
| 691 private static final StepOverParams STEP_OVER_PARAMS = new StepOverParams(); | 700 private static final StepOverParams STEP_OVER_PARAMS = new StepOverParams(); |
| 692 } | 701 } |
| OLD | NEW |