|
9 | 9 | */
|
10 | 10 | package org.jruby.truffle.nodes.rubinius;
|
11 | 11 |
|
| 12 | +import com.oracle.truffle.api.CompilerDirectives; |
12 | 13 | import org.joni.Matcher;
|
13 | 14 | import org.jruby.truffle.runtime.RubyContext;
|
| 15 | +import org.jruby.truffle.runtime.control.RaiseException; |
14 | 16 | import org.jruby.truffle.runtime.core.*;
|
15 | 17 |
|
16 | 18 | import com.oracle.truffle.api.dsl.Specialization;
|
17 | 19 | import com.oracle.truffle.api.source.SourceSection;
|
| 20 | +import org.jruby.util.StringSupport; |
18 | 21 |
|
19 | 22 | /**
|
20 | 23 | * Rubinius primitives associated with the Ruby {@code Regexp} class.
|
@@ -59,6 +62,17 @@ public RegexpSearchRegionPrimitiveNode(RegexpSearchRegionPrimitiveNode prev) {
|
59 | 62 | public Object searchRegion(RubyRegexp regexp, RubyString string, int start, int end, boolean forward) {
|
60 | 63 | notDesignedForCompilation();
|
61 | 64 |
|
| 65 | + if (regexp.getRegex() == null) { |
| 66 | + CompilerDirectives.transferToInterpreter(); |
| 67 | + throw new RaiseException(getContext().getCoreLibrary().typeError("uninitialized Regexp", this)); |
| 68 | + } |
| 69 | + |
| 70 | + if (string.scanForCodeRange() == StringSupport.CR_BROKEN) { |
| 71 | + CompilerDirectives.transferToInterpreter(); |
| 72 | + throw new RaiseException(getContext().getCoreLibrary().argumentError( |
| 73 | + String.format("invalid byte sequence in %s", string.getByteList().getEncoding()), this)); |
| 74 | + } |
| 75 | + |
62 | 76 | final Matcher matcher = regexp.getRegex().matcher(string.getBytes().bytes());
|
63 | 77 |
|
64 | 78 | return regexp.matchCommon(string, false, false, matcher, start, end);
|
|
0 commit comments