Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c30264c6dfdd
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ab853cd09b3d
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jun 4, 2015

  1. Copy the full SHA
    95fa59c View commit details
  2. 10
    Copy the full SHA
    ab853cd View commit details
1 change: 0 additions & 1 deletion spec/truffle/tags/core/regexp/initialize_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Regexp#initialize raises a SecurityError on a Regexp literal
fails:Regexp#initialize raises a TypeError on an initialized non-literal Regexp
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
@@ -53,12 +54,21 @@ public RegexpInitializePrimitiveNode(RubyContext context, SourceSection sourceSe
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRegexpLiteral(regexp)")
public RubyRegexp initializeRegexpLiteral(RubyRegexp regexp, RubyString pattern, int options) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().securityError("can't modify literal regexp", this));
}

@Specialization(guards = "!isRegexpLiteral(regexp)")
public RubyRegexp initialize(RubyRegexp regexp, RubyString pattern, int options) {
regexp.initialize(this, StringNodes.getByteList(pattern), options);
return regexp;
}

public static boolean isRegexpLiteral(RubyRegexp regexp) {
return regexp.getOptions().isLiteral();
}
}

@RubiniusPrimitive(name = "regexp_options")
@@ -75,6 +85,7 @@ public int options(RubyRegexp regexp) {

@Specialization(guards = "!isInitialized(regexp)")
public int optionsNotInitialized(RubyRegexp regexp) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeError("uninitialized Regexp", this));
}

Original file line number Diff line number Diff line change
@@ -105,6 +105,7 @@ public class CoreLibrary {
private final RubyClass regexpErrorClass;
private final RubyClass rubyTruffleErrorClass;
private final RubyClass runtimeErrorClass;
private final RubyClass securityErrorClass;
private final RubyClass standardErrorClass;
private final RubyClass stringClass;
private final RubyClass stringDataClass;
@@ -276,7 +277,7 @@ public CoreLibrary(RubyContext context) {
syntaxErrorClass = defineClass(scriptErrorClass, "SyntaxError");

// SecurityError
defineClass(exceptionClass, "SecurityError");
securityErrorClass = defineClass(exceptionClass, "SecurityError");

// SignalException
RubyClass signalExceptionClass = defineClass(exceptionClass, "SignalException");
@@ -1161,6 +1162,11 @@ public RubyException threadError(String message, Node currentNode) {
return new RubyException(threadErrorClass, StringNodes.createString(context.getCoreLibrary().getStringClass(), message), RubyCallStack.getBacktrace(currentNode));
}

public RubyException securityError(String message, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(securityErrorClass, StringNodes.createString(context.getCoreLibrary().getStringClass(), message), RubyCallStack.getBacktrace(currentNode));
}

public RubyException systemCallError(String message, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(systemCallErrorClass, StringNodes.createString(context.getCoreLibrary().getStringClass(), message), RubyCallStack.getBacktrace(currentNode));