Skip to content
Permalink
Browse files
[Truffle] Fix regexp errors.
  • Loading branch information
chrisseaton committed Dec 12, 2014
1 parent 2df1533 commit 9668c249c749a5af237d230a5e673d14235ed7ae
@@ -73,6 +73,7 @@ public class CoreLibrary {
@CompilerDirectives.CompilationFinal private RubyClass rangeClass;
@CompilerDirectives.CompilationFinal private RubyClass rangeErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass regexpClass;
@CompilerDirectives.CompilationFinal private RubyClass regexpErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass rubyTruffleErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass runtimeErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass standardErrorClass;
@@ -215,6 +216,7 @@ public void initialize() {
rangeClass = new RubyClass(context, objectClass, objectClass, "Range");
rangeErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "RangeError");
regexpClass = new RubyRegexp.RubyRegexpClass(context, objectClass);
regexpErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "RegexpError");
rubyTruffleErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "RubyTruffleError");
runtimeErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "RuntimeError");
signalModule = new RubyModule(context, objectClass, "Signal");
@@ -586,6 +588,11 @@ public RubyException internalError(String message, Node currentNode) {
return new RubyException(context.getCoreLibrary().getRubyTruffleErrorClass(), context.makeString("internal implementation error - " + message), RubyCallStack.getBacktrace(currentNode));
}

public RubyException regexpError(String message, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(regexpErrorClass, context.makeString(message), RubyCallStack.getBacktrace(currentNode));
}

public RubyContext getContext() {
return context;
}
@@ -18,6 +18,7 @@
import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.joni.*;
import org.joni.exception.SyntaxException;
import org.joni.exception.ValueException;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
@@ -390,6 +391,8 @@ public static Regex compile(RubyNode currentNode, RubyContext context, byte[] by
return new Regex(bytes, 0, bytes.length, options, encoding, Syntax.RUBY);
} catch (ValueException e) {
throw new org.jruby.truffle.runtime.control.RaiseException(context.getCoreLibrary().runtimeError("error compiling regex", currentNode));
} catch (SyntaxException e) {
throw new org.jruby.truffle.runtime.control.RaiseException(context.getCoreLibrary().regexpError(e.getMessage(), currentNode));
}
}

@@ -1,2 +1 @@
fails:Regexps with interpolation throws RegexpError for malformed interpolation
fails:Regexps with interpolation allows escape sequences in interpolated regexps

0 comments on commit 9668c24

Please sign in to comment.