Skip to content

Commit

Permalink
[GR-15886] Improve fallback part of InspectorRuntime.callFunctionOn.
Browse files Browse the repository at this point in the history
PullRequest: graal/3617
  • Loading branch information
dbalek committed May 22, 2019
2 parents 6a01cae + 628038c commit ac702cd
Showing 1 changed file with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ public Void executeCommand() throws CommandProcessException {
throw new CommandProcessException("Named range out of bounds.");
}
arr.put(indexRange.end() - indexRange.start());
} else if (LanguageChecks.isJS(value.getOriginalLanguage())) {
arr.put(props.size() + 1); // +1 for __proto__
} else {
arr.put(props.size());
}
Expand All @@ -530,7 +532,11 @@ public Void executeCommand() throws CommandProcessException {
} else {
arr.put(value.getArray().size());
}
arr.put(0);
if (LanguageChecks.isJS(value.getOriginalLanguage())) {
arr.put(1); // +1 for __proto__
} else {
arr.put(0);
}
result = new JSONObject();
result.put("value", arr);
} else if (functionNoWS.equals(FUNCTION_GET_COLLECTION_NUM_PROPS)) {
Expand All @@ -546,6 +552,8 @@ public Void executeCommand() throws CommandProcessException {
throw new CommandProcessException("Named range out of bounds.");
}
arr.put(indexRange.end() - indexRange.start());
} else if (LanguageChecks.isJS(value.getOriginalLanguage())) {
arr.put(props.size() + 1); // +1 for __proto__
} else {
arr.put(props.size());
}
Expand Down Expand Up @@ -628,8 +636,30 @@ public Void executeCommand() throws CommandProcessException {
}
}
}
String code = "(" + functionTrimmed + ")(" + ((value != null) ? value.getName() : "") + ")";
DebugValue eval = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(code);
StringBuilder code = new StringBuilder();
code.append("(").append(functionTrimmed).append(").apply(").append(value != null ? value.getName() : "null");
if (arguments != null) {
code.append(",[");
for (int i = 0; i < arguments.length(); i++) {
JSONObject arg = arguments.getJSONObject(i);
if (i > 0) {
code.append(",");
}
Object id = arg.opt("objectId");
if (id instanceof String) {
RemoteObject remoteArg = context.getRemoteObjectsHandler().getRemote((String) id);
if (remoteArg == null) {
throw new CommandProcessException("Cannot resolve argument by its objectId: " + id);
}
code.append(remoteArg.getDebugValue().getName());
} else {
code.append(arg.get("value"));
}
}
code.append("]");
}
code.append(")");
DebugValue eval = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(code.toString());
result = asResult(eval);
}
json.put("result", result);
Expand Down

0 comments on commit ac702cd

Please sign in to comment.