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: badd94b6e3e4
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ad232c900de9
Choose a head ref
  • 8 commits
  • 13 files changed
  • 1 contributor

Commits on Jan 12, 2016

  1. Copy the full SHA
    7f47946 View commit details
  2. Copy the full SHA
    8e34785 View commit details
  3. Copy the full SHA
    682b462 View commit details
  4. Copy the full SHA
    5ed3f54 View commit details
  5. Copy the full SHA
    f63e70f View commit details
  6. Copy the full SHA
    8795541 View commit details
  7. Copy the full SHA
    67a5eeb View commit details
  8. Fix misspelling in tags.

    headius committed Jan 12, 2016
    Copy the full SHA
    ad232c9 View commit details
20 changes: 20 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3903,6 +3903,26 @@ public RaiseException newNameError(String message, String name, Throwable origEx
return newNameError(message, name, origException, false);
}

public RaiseException newNameError(String message, IRubyObject recv, IRubyObject name) {
IRubyObject msg = new RubyNameError.RubyNameErrorMessage(this, message, recv, name);
RubyException err = RubyNameError.newRubyNameError(getNameError(), msg, name);

return new RaiseException(err);
}

public RaiseException newNameError(String message, IRubyObject recv, String name) {
RubySymbol nameSym = newSymbol(name);
return newNameError(message, recv, nameSym);
}

public RaiseException newNoMethodError(String message, IRubyObject recv, String name, RubyArray args) {
RubySymbol nameStr = newSymbol(name);
IRubyObject msg = new RubyNameError.RubyNameErrorMessage(this, message, recv, nameStr);
RubyException err = RubyNoMethodError.newNoMethodError(getNoMethodError(), msg, nameStr, args);

return new RaiseException(err);
}

public RaiseException newNameError(String message, String name, Throwable origException, boolean printWhenVerbose) {
if (origException != null) {
if (printWhenVerbose && isVerbose()) {
20 changes: 13 additions & 7 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -1589,7 +1589,7 @@ public static IRubyObject method_missing19(ThreadContext context, IRubyObject re
throw context.runtime.newArgumentError("no id given");
}

return RubyKernel.methodMissingDirect(context, recv, (RubySymbol)args[0], lastVis, lastCallType, args, block);
return RubyKernel.methodMissingDirect(context, recv, (RubySymbol)args[0], lastVis, lastCallType, args);
}

@JRubyMethod(name = "__send__", omit = true)
@@ -2685,7 +2685,7 @@ public IRubyObject op_not_match(ThreadContext context, IRubyObject arg) {
* fred.instance_variable_defined?("@c") #=> false
*/
public IRubyObject instance_variable_defined_p(ThreadContext context, IRubyObject name) {
if (variableTableContains(validateInstanceVariable(name.asJavaString()))) {
if (variableTableContains(validateInstanceVariable(name, name.asJavaString()))) {
return context.runtime.getTrue();
}
return context.runtime.getFalse();
@@ -2713,7 +2713,7 @@ public IRubyObject instance_variable_defined_p(ThreadContext context, IRubyObjec
*/
public IRubyObject instance_variable_get(ThreadContext context, IRubyObject name) {
Object value;
if ((value = variableTableFetch(validateInstanceVariable(name.asJavaString()))) != null) {
if ((value = variableTableFetch(validateInstanceVariable(name, name.asJavaString()))) != null) {
return (IRubyObject)value;
}
return context.runtime.getNil();
@@ -2741,7 +2741,7 @@ public IRubyObject instance_variable_get(ThreadContext context, IRubyObject name
*/
public IRubyObject instance_variable_set(IRubyObject name, IRubyObject value) {
// no need to check for ensureInstanceVariablesSettable() here, that'll happen downstream in setVariable
return (IRubyObject)variableTableStore(validateInstanceVariable(name.asJavaString()), value);
return (IRubyObject)variableTableStore(validateInstanceVariable(name, name.asJavaString()), value);
}

/** rb_obj_remove_instance_variable
@@ -2769,10 +2769,10 @@ public IRubyObject instance_variable_set(IRubyObject name, IRubyObject value) {
public IRubyObject remove_instance_variable(ThreadContext context, IRubyObject name, Block block) {
ensureInstanceVariablesSettable();
IRubyObject value;
if ((value = (IRubyObject)variableTableRemove(validateInstanceVariable(name.asJavaString()))) != null) {
if ((value = (IRubyObject)variableTableRemove(validateInstanceVariable(name, name.asJavaString()))) != null) {
return value;
}
throw context.runtime.newNameError("instance variable " + name.asJavaString() + " not defined", name.asJavaString());
throw context.runtime.newNameError("instance variable " + name.asJavaString() + " not defined", this, name);
}

/** rb_obj_instance_variables
@@ -2865,7 +2865,13 @@ protected static int nonFixnumHashCode(IRubyObject hashValue) {
protected String validateInstanceVariable(String name) {
if (IdUtil.isValidInstanceVariableName(name)) return name;

throw getRuntime().newNameError("`" + name + "' is not allowable as an instance variable name", name);
throw getRuntime().newNameError("`" + name + "' is not allowable as an instance variable name", this, name);
}

protected String validateInstanceVariable(IRubyObject nameObj, String name) {
if (IdUtil.isValidInstanceVariableName(name)) return name;

throw getRuntime().newNameError("`" + name + "' is not allowable as an instance variable name", this, nameObj);
}

/**
73 changes: 35 additions & 38 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ public MethodMissingMethod(RubyModule implementationClass, Visibility visibility

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return RubyKernel.methodMissing(context, self, name, visibility, callType, args, block);
return RubyKernel.methodMissing(context, self, name, visibility, callType, args);
}

}
@@ -168,7 +168,7 @@ public static IRubyObject autoload(final IRubyObject recv, IRubyObject symbol, I
String nonInternedName = symbol.asJavaString();

final RubyString fileString = StringSupport.checkEmbeddedNulls(runtime,
RubyFile.get_path(runtime.getCurrentContext(), file));
RubyFile.get_path(runtime.getCurrentContext(), file));

if (!IdUtil.isValidConstantName(nonInternedName)) {
throw runtime.newNameError("autoload must be constant name", nonInternedName);
@@ -216,54 +216,45 @@ public static IRubyObject method_missing(ThreadContext context, IRubyObject recv
throw context.runtime.newArgumentError("no id given");
}

return methodMissingDirect(context, recv, (RubySymbol)args[0], lastVis, lastCallType, args, block);
return methodMissingDirect(context, recv, (RubySymbol) args[0], lastVis, lastCallType, args);
}

protected static IRubyObject methodMissingDirect(ThreadContext context, IRubyObject recv, RubySymbol symbol, Visibility lastVis, CallType lastCallType, IRubyObject[] args, Block block) {
protected static IRubyObject methodMissingDirect(ThreadContext context, IRubyObject recv, RubySymbol symbol, Visibility lastVis, CallType lastCallType, IRubyObject[] args) {
return methodMissing(context, recv, symbol.toString(), lastVis, lastCallType, args, true);
}

public static IRubyObject methodMissing(ThreadContext context, IRubyObject recv, String name, Visibility lastVis, CallType lastCallType, IRubyObject[] args) {
return methodMissing(context, recv, name, lastVis, lastCallType, args, false);
}

public static IRubyObject methodMissing(ThreadContext context, IRubyObject recv, String name, Visibility lastVis, CallType lastCallType, IRubyObject[] args, boolean dropFirst) {
Ruby runtime = context.runtime;

// create a lightweight thunk
IRubyObject msg = new RubyNameError.RubyNameErrorMessage(runtime,
recv,
symbol,
lastVis,
lastCallType);
final IRubyObject[]exArgs;
final RubyClass exc;
if (lastCallType != CallType.VARIABLE) {
exc = runtime.getNoMethodError();
exArgs = new IRubyObject[]{msg, symbol, RubyArray.newArrayNoCopy(runtime, args, 1)};
throw runtime.newNoMethodError(getMethodMissingFormat(lastVis, lastCallType), recv, name, RubyArray.newArrayNoCopy(runtime, args, dropFirst ? 1 : 0));
} else {
exc = runtime.getNameError();
exArgs = new IRubyObject[]{msg, symbol};
throw runtime.newNameError(getMethodMissingFormat(lastVis, lastCallType), recv, name);
}

throw new RaiseException((RubyException)exc.newInstance(context, exArgs, Block.NULL_BLOCK));
}

public static IRubyObject methodMissing(ThreadContext context, IRubyObject recv, String name, Visibility lastVis, CallType lastCallType, IRubyObject[] args, Block block) {
Ruby runtime = context.runtime;
RubySymbol symbol = runtime.newSymbol(name);

// create a lightweight thunk
IRubyObject msg = new RubyNameError.RubyNameErrorMessage(runtime,
recv,
symbol,
lastVis,
lastCallType);
final IRubyObject[]exArgs;
final RubyClass exc;
if (lastCallType != CallType.VARIABLE) {
exc = runtime.getNoMethodError();
exArgs = new IRubyObject[]{msg, symbol, RubyArray.newArrayNoCopy(runtime, args)};
} else {
exc = runtime.getNameError();
exArgs = new IRubyObject[]{msg, symbol};
private static String getMethodMissingFormat(Visibility visibility, CallType callType) {

String format = null;

if (visibility == PRIVATE) {
format = "private method `%s' called for %s";
} else if (visibility == PROTECTED) {
format = "protected method `%s' called for %s";
} else if (callType == CallType.VARIABLE) {
format = "undefined local variable or method `%s' for %s";
} else if (callType == CallType.SUPER) {
format = "super: no superclass method `%s'";
}

throw new RaiseException((RubyException)exc.newInstance(context, exArgs, Block.NULL_BLOCK));
}
if (format == null) format = "undefined method `%s' for %s";

return format;
}

private static IRubyObject[] popenArgs(Ruby runtime, String pipedArg, IRubyObject[] args) {
IRubyObject command = runtime.newString(pipedArg.substring(1));
@@ -2064,4 +2055,10 @@ public static RubyArray instance_variables19(ThreadContext context, IRubyObject
return ((RubyBasicObject)self).instance_variables19(context);
}
/* end delegated bindings */

@Deprecated
public static IRubyObject methodMissing(ThreadContext context, IRubyObject recv, String name, Visibility lastVis, CallType lastCallType, IRubyObject[] args, Block block) {
return methodMissing(context, recv, name, lastVis, lastCallType, args);
}

}
39 changes: 33 additions & 6 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -2929,7 +2929,7 @@ private RubyModule proceedWithPrepend(RubyModule insertBelow, RubyModule moduleT

@JRubyMethod(name = "class_variable_defined?", required = 1)
public IRubyObject class_variable_defined_p(ThreadContext context, IRubyObject var) {
String internedName = validateClassVariable(var.asJavaString().intern());
String internedName = validateClassVariable(var, var.asJavaString().intern());
RubyModule module = this;
do {
if (module.hasClassVariable(internedName)) {
@@ -2944,7 +2944,7 @@ public IRubyObject class_variable_defined_p(ThreadContext context, IRubyObject v
*
*/
public IRubyObject class_variable_get(IRubyObject var) {
return getClassVar(validateClassVariable(var.asJavaString()).intern());
return getClassVar(var, validateClassVariable(var, var.asJavaString()).intern());
}

@JRubyMethod(name = "class_variable_get")
@@ -2956,7 +2956,7 @@ public IRubyObject class_variable_get19(IRubyObject var) {
*
*/
public IRubyObject class_variable_set(IRubyObject var, IRubyObject value) {
return setClassVar(validateClassVariable(var.asJavaString()).intern(), value);
return setClassVar(validateClassVariable(var, var.asJavaString()).intern(), value);
}

@JRubyMethod(name = "class_variable_set")
@@ -3173,7 +3173,7 @@ public IRubyObject const_missing(ThreadContext context, IRubyObject rubyName, Bl
longName = shortName;
}

throw runtime.newNameErrorObject("uninitialized constant " + longName, runtime.newSymbol(shortName));
throw runtime.newNameError("uninitialized constant " + longName, this, rubyName);
}

public RubyArray constants(ThreadContext context) {
@@ -3362,6 +3362,26 @@ public IRubyObject fastSetClassVar(final String internedName, final IRubyObject
* @return The variable's value, or throws NameError if not found
*/
public IRubyObject getClassVar(String name) {
IRubyObject value = getClassVarQuiet(name);

if (value == null) {
throw getRuntime().newNameError("uninitialized class variable %s in %s", this, name);
}

return value;
}

public IRubyObject getClassVar(IRubyObject nameObject, String name) {
IRubyObject value = getClassVarQuiet(name);

if (value == null) {
throw getRuntime().newNameError("uninitialized class variable %s in %s", this, nameObject);
}

return value;
}

public IRubyObject getClassVarQuiet(String name) {
assert IdUtil.isClassVariable(name);
Object value;
RubyModule module = this;
@@ -3370,7 +3390,7 @@ public IRubyObject getClassVar(String name) {
if ((value = module.fetchClassVariable(name)) != null) return (IRubyObject)value;
} while ((module = module.getSuperClass()) != null);

throw getRuntime().newNameError("uninitialized class variable " + name + " in " + getName(), name);
return null;
}

@Deprecated
@@ -3919,7 +3939,14 @@ protected final String validateClassVariable(String name) {
if (IdUtil.isValidClassVariableName(name)) {
return name;
}
throw getRuntime().newNameError("`" + name + "' is not allowed as a class variable name", name);
throw getRuntime().newNameError("`" + name + "' is not allowed as a class variable name", this, name);
}

protected final String validateClassVariable(IRubyObject nameObj, String name) {
if (IdUtil.isValidClassVariableName(name)) {
return name;
}
throw getRuntime().newNameError("`" + name + "' is not allowed as a class variable name", this, nameObj);
}

protected final void ensureClassVariablesSettable() {
Loading