Skip to content

Commit

Permalink
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -257,6 +257,11 @@ public DynamicObject errnoError(int errno, String extraMessage, Node currentNode

// IndexError

@TruffleBoundary
public DynamicObject indexErrorOutOfString(int index, Node currentNode) {
return indexError(StringUtils.format("index %d out of string", index), currentNode);
}

@TruffleBoundary
public DynamicObject indexError(String message, Node currentNode) {
return ExceptionOperations.createRubyException(
Original file line number Diff line number Diff line change
@@ -2658,16 +2658,12 @@ public static class StringNodesHelper {

public static int checkIndex(int length, int index, RubyNode node) {
if (index > length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(
node.getContext().getCoreExceptions().indexError(StringUtils.format("index %d out of string", index), node));
throw new RaiseException(node.getContext().getCoreExceptions().indexErrorOutOfString(index, node));
}

if (index < 0) {
if (-index > length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(
node.getContext().getCoreExceptions().indexError(StringUtils.format("index %d out of string", index), node));
throw new RaiseException(node.getContext().getCoreExceptions().indexErrorOutOfString(index, node));
}

index += length;
@@ -2682,16 +2678,12 @@ public static int checkIndexForRef(DynamicObject string, int index, RubyNode nod
final int length = rope(string).byteLength();

if (index >= length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(
node.getContext().getCoreExceptions().indexError(StringUtils.format("index %d out of string", index), node));
throw new RaiseException(node.getContext().getCoreExceptions().indexErrorOutOfString(index, node));
}

if (index < 0) {
if (-index > length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(
node.getContext().getCoreExceptions().indexError(StringUtils.format("index %d out of string", index), node));
throw new RaiseException(node.getContext().getCoreExceptions().indexErrorOutOfString(index, node));
}

index += length;

0 comments on commit 46cfd64

Please sign in to comment.