Permalink
Browse files

Merge branch 'andreastt/minor_cleanup'

  • Loading branch information...
2 parents a7e3f91 + 6ca069b commit 387458744765d74cbca6624c15576eb9fff6b8c8 Andreas Tolf Tolfsen committed Apr 2, 2012
@@ -17,16 +17,16 @@
package com.opera.core.systems.model;
/**
- * Holds the result of a script execution, namely for an object, scope protocol assigns an object id
- * for each object retrieved through the protocol, this id can also be used later on to release the
- * object.
+ * Holds the result of a script execution, namely for an object. The Scope protocol assigns an
+ * object ID for each object retrieved through the protocol, this ID can be used later to release
+ * the object.
*
* @author Deniz Turkoglu <dturkoglu@opera.com>
*/
public class ScriptResult {
- protected int objectId;
- protected String className;
+ private final int objectId;
+ private final String className;
public ScriptResult(int objectId, String className) {
this.objectId = objectId;
@@ -37,16 +37,8 @@ public int getObjectId() {
return objectId;
}
- public void setObjectId(int objectId) {
- this.objectId = objectId;
- }
-
public String getClassName() {
return className;
}
- public void setClassName(String className) {
- this.className = className;
- }
-
}
@@ -31,6 +31,8 @@
import java.util.Collection;
import java.util.List;
+import static com.opera.core.systems.scope.internal.OperaIntervals.SCRIPT_RETRY_INTERVAL;
+
public abstract class AbstractEcmascriptService extends AbstractService
implements IEcmaScriptDebugger {
@@ -74,13 +76,17 @@ public AbstractEcmascriptService(ScopeServices services, String version) {
currentFramePath = "_top";
}
+ public void setDriver(OperaDriver driver) {
+ this.driver = driver;
+ }
+
/**
* Reset the timeout and retries. It will use the {@link OperaIntervals#SCRIPT_RETRY_INTERVAL} as
* the default value of the sleep interval {@link #sleepDuration}.
*/
protected void resetCounters() {
retries = 0;
- sleepDuration = OperaIntervals.SCRIPT_RETRY_INTERVAL.getValue();
+ sleepDuration = SCRIPT_RETRY_INTERVAL.getValue();
}
/**
@@ -96,6 +102,7 @@ protected String buildEvalString(List<WebElement> elements, String script, Objec
if (params != null && params.length > 0) {
StringBuilder builder = new StringBuilder();
+
for (Object object : params) {
if (builder.toString().length() > 0) {
builder.append(",");
@@ -104,10 +111,12 @@ protected String buildEvalString(List<WebElement> elements, String script, Objec
if (object instanceof Collection<?>) {
builder.append("[");
Collection<?> collection = (Collection<?>) object;
+
for (Object argument : collection) {
processArgument(argument, builder, elements);
builder.append(",");
}
+
int lastCharIndex = builder.length() - 1;
if (builder.charAt(lastCharIndex) != '[') {
builder.deleteCharAt(lastCharIndex);
@@ -120,15 +129,15 @@ protected String buildEvalString(List<WebElement> elements, String script, Objec
}
String arguments = builder.toString();
- toSend = "(function(){" + script + "})(" + arguments + ")";
+ toSend = String.format("(function(){%s})(%s)", script, arguments);
} else {
toSend = script;
}
return toSend;
}
- protected void processArgument(Object object, StringBuilder builder, List<WebElement> elements) {
+ private void processArgument(Object object, StringBuilder builder, List<WebElement> elements) {
if (object instanceof WebElement) {
elements.add((WebElement) object);
builder.append(String.valueOf(object));
@@ -162,7 +171,6 @@ protected void recover() {
updateRuntime();
}
-
protected Object parseNumber(String value) {
Number number;
@@ -174,7 +182,8 @@ protected Object parseNumber(String value) {
return number.doubleValue();
}
} catch (ParseException e) {
- throw new WebDriverException("The result from the script can not be parsed");
+ throw new WebDriverException("A number result from the script can not be parsed: " +
+ e.getMessage());
}
}
@@ -195,8 +204,4 @@ public void cleanUpRuntimes() {
cleanUpRuntimes(windowId);
}
- public void setDriver(OperaDriver driver) {
- this.driver = driver;
- }
-
}
@@ -45,8 +45,6 @@
WINDOW_EVENT_TIMEOUT(5000),
OPERA_IDLE_TIMEOUT(5000),
POLL_INTERVAL(10),
- SCRIPT_RETRY(5),
- SCRIPT_RETRY_INTERVAL(50),
HANDSHAKE_TIMEOUT(30000),
/**
@@ -81,6 +79,12 @@
*/
SCRIPT_TIMEOUT(10000),
+ /**
+ * The interval at which an ECMAScript should be attempted reevaluated in the case of it for some
+ * reason failing. A script reevaluation will time out on {@link #SCRIPT_TIMEOUT}.
+ */
+ SCRIPT_RETRY_INTERVAL(50),
+
/**
* After starting the launcher we need to wait for the launcher to connect to our listener. If
* the launcher does not connect within this timeout, we assume something has gone wrong.
@@ -256,13 +256,13 @@ protected Response eval(String using, int runtimeId, Variable... variables) {
Response response = executeCommand(ESDebuggerCommand.EVAL, builder,
OperaIntervals.SCRIPT_TIMEOUT.getValue());
- if (response == null && retries < OperaIntervals.SCRIPT_RETRY.getValue()) {
+ if (response == null && retries < OperaIntervals.SCRIPT_RETRY_INTERVAL.getValue()) {
retries++;
sleepDuration += sleepDuration;
sleep(sleepDuration);
recover();
return eval(using, variables);
- } else if (retries >= OperaIntervals.SCRIPT_RETRY.getValue()) {
+ } else if (retries >= OperaIntervals.SCRIPT_RETRY_INTERVAL.getValue()) {
resetCounters();
throw new WebDriverException("No response on executing JS command");
}
@@ -333,9 +333,8 @@ protected Object parseEvalReply(EvalResult result) {
// Would be great give the JS error here, but it appears that by the
// time we callFunctionOnObject the error object has gone...
throw new WebDriverException("Ecmascript exception");
- }
- // FIXME what is the best approach here?
- else if (status.equals("cancelled-by-scheduler")) {
+ } else if (status.equals("cancelled-by-scheduler")) {
+ // TODO: what is the best approach here?
return null;
} else if (status.equals("aborted")) {
Oops, something went wrong.

0 comments on commit 3874587

Please sign in to comment.