Skip to content

Commit ac702cd

Browse files
committed
[GR-15886] Improve fallback part of InspectorRuntime.callFunctionOn.
PullRequest: graal/3617
2 parents 6a01cae + 628038c commit ac702cd

File tree

1 file changed

+33
-3
lines changed
  • tools/src/com.oracle.truffle.tools.chromeinspector/src/com/oracle/truffle/tools/chromeinspector

1 file changed

+33
-3
lines changed

tools/src/com.oracle.truffle.tools.chromeinspector/src/com/oracle/truffle/tools/chromeinspector/InspectorRuntime.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ public Void executeCommand() throws CommandProcessException {
511511
throw new CommandProcessException("Named range out of bounds.");
512512
}
513513
arr.put(indexRange.end() - indexRange.start());
514+
} else if (LanguageChecks.isJS(value.getOriginalLanguage())) {
515+
arr.put(props.size() + 1); // +1 for __proto__
514516
} else {
515517
arr.put(props.size());
516518
}
@@ -530,7 +532,11 @@ public Void executeCommand() throws CommandProcessException {
530532
} else {
531533
arr.put(value.getArray().size());
532534
}
533-
arr.put(0);
535+
if (LanguageChecks.isJS(value.getOriginalLanguage())) {
536+
arr.put(1); // +1 for __proto__
537+
} else {
538+
arr.put(0);
539+
}
534540
result = new JSONObject();
535541
result.put("value", arr);
536542
} else if (functionNoWS.equals(FUNCTION_GET_COLLECTION_NUM_PROPS)) {
@@ -546,6 +552,8 @@ public Void executeCommand() throws CommandProcessException {
546552
throw new CommandProcessException("Named range out of bounds.");
547553
}
548554
arr.put(indexRange.end() - indexRange.start());
555+
} else if (LanguageChecks.isJS(value.getOriginalLanguage())) {
556+
arr.put(props.size() + 1); // +1 for __proto__
549557
} else {
550558
arr.put(props.size());
551559
}
@@ -628,8 +636,30 @@ public Void executeCommand() throws CommandProcessException {
628636
}
629637
}
630638
}
631-
String code = "(" + functionTrimmed + ")(" + ((value != null) ? value.getName() : "") + ")";
632-
DebugValue eval = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(code);
639+
StringBuilder code = new StringBuilder();
640+
code.append("(").append(functionTrimmed).append(").apply(").append(value != null ? value.getName() : "null");
641+
if (arguments != null) {
642+
code.append(",[");
643+
for (int i = 0; i < arguments.length(); i++) {
644+
JSONObject arg = arguments.getJSONObject(i);
645+
if (i > 0) {
646+
code.append(",");
647+
}
648+
Object id = arg.opt("objectId");
649+
if (id instanceof String) {
650+
RemoteObject remoteArg = context.getRemoteObjectsHandler().getRemote((String) id);
651+
if (remoteArg == null) {
652+
throw new CommandProcessException("Cannot resolve argument by its objectId: " + id);
653+
}
654+
code.append(remoteArg.getDebugValue().getName());
655+
} else {
656+
code.append(arg.get("value"));
657+
}
658+
}
659+
code.append("]");
660+
}
661+
code.append(")");
662+
DebugValue eval = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(code.toString());
633663
result = asResult(eval);
634664
}
635665
json.put("result", result);

0 commit comments

Comments
 (0)