Skip to content

Commit

Permalink
Ignore Binding's line when file is passed to eval
Browse files Browse the repository at this point in the history
Before this change eval("__LINE__", binding, "file") would return the
current line of the binding; after this change it will return 1.

Spec at https://github.com/jruby/rubyspec/commit/88f3dff4#L1R24

Signed-off-by: Charles Oliver Nutter <headius@headius.com>
  • Loading branch information
ConradIrwin authored and headius committed Feb 21, 2012
1 parent 68d6fe8 commit c692be7
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/org/jruby/RubyKernel.java
Expand Up @@ -1096,29 +1096,25 @@ private static IRubyObject evalCommon(ThreadContext context, IRubyObject recv, I

boolean bindingGiven = args.length > 1 && !args[1].isNil();
Binding binding = bindingGiven ? evalBinding.convertToBinding(args[1]) : context.currentBinding();

if (args.length > 2) {
// file given, use it and force it into binding
binding.setFile(args[2].convertToString().toString());
} else {
// file not given
if (bindingGiven) {
// binding given, use binding's file
} else {
// no binding given, use (eval)
binding.setFile("(eval)");
}
}
if (args.length > 3) {
// file given, use it and force it into binding
// -1 because parser uses zero offsets and other code compensates
binding.setLine(((int) args[3].convertToInteger().getLongValue()) - 1);
} else {
if (bindingGiven) {
// binding given, use binding's line

if (args.length > 3) {
// line given, use it and force it into binding
// -1 because parser uses zero offsets and other code compensates
binding.setLine(((int) args[3].convertToInteger().getLongValue()) - 1);
} else {
// no binding given, use 0 for both
// filename given, but no line, start from the beginning.
binding.setLine(0);
}
} else if (bindingGiven) {
// binding given, use binding's file and line-number
} else {
// no binding given, use (eval) and start from first line.
binding.setFile("(eval)");
binding.setLine(0);
}

// set method to current frame's, which should be caller's
Expand Down

0 comments on commit c692be7

Please sign in to comment.