Skip to content

Commit

Permalink
Optional invocation of ForeignInvokeNode should not throw TypeError w…
Browse files Browse the repository at this point in the history
…hen there is no valid function.
  • Loading branch information
iamstolis committed Jun 14, 2024
1 parent e63189d commit 682097c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ private boolean isNullish(Object targetValue) {
return isNullish.profile(isNullOrUndefinedNode.executeBoolean(targetValue));
}

public JSTargetableNode getExpressionNode() {
return expressionNode;
}

@Override
public JavaScriptNode getTarget() {
return expressionNode.getTarget();
Expand Down Expand Up @@ -279,14 +283,14 @@ protected JavaScriptNode copyUninitialized(Set<Class<? extends Tag>> materialize
}

@SuppressWarnings("serial")
private static final class ShortCircuitException extends ControlFlowException {
public static final class ShortCircuitException extends ControlFlowException {

private static final ShortCircuitException INSTANCE = new ShortCircuitException();

private ShortCircuitException() {
}

static ShortCircuitException instance() {
public static ShortCircuitException instance() {
return INSTANCE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import com.oracle.truffle.js.nodes.access.JSConstantNode.JSConstantUndefinedNode;
import com.oracle.truffle.js.nodes.access.JSProxyCallNode;
import com.oracle.truffle.js.nodes.access.JSTargetableNode;
import com.oracle.truffle.js.nodes.access.OptionalChainNode.ShortCircuitException;
import com.oracle.truffle.js.nodes.access.OptionalChainNode.ShortCircuitTargetableNode;
import com.oracle.truffle.js.nodes.access.PropertyGetNode;
import com.oracle.truffle.js.nodes.access.PropertyNode;
Expand Down Expand Up @@ -1596,6 +1597,11 @@ private Object fallback(Object receiver, Object[] arguments, Object[] callArgume
}
}
errorBranch.enter();
// There is no valid function to invoke. Do not throw if the invocation
// is optional, short-circuit instead.
if (getParent() instanceof InvokeNode invokeNode && invokeNode.getFunctionTargetDelegate() instanceof ShortCircuitTargetableNode) {
throw ShortCircuitException.instance();
}
throw Errors.createTypeErrorInteropException(receiver, ex != null ? ex : UnknownIdentifierException.create(Strings.toJavaString(functionName)), "invokeMember", functionName, this);
}

Expand Down

0 comments on commit 682097c

Please sign in to comment.