@JRubyMethod(compat = RUBY1_9) public IRubyObject primitive_errinfo(ThreadContext context) { Ruby runtime = context.runtime; RubyCoderResult lastResult = transcoder.getLastResult(); // if we have not done anything, produce an empty errinfo if (lastResult == null) { return runtime.newArray( new IRubyObject[] { runtime.newSymbol("source_buffer_empty"), context.nil, context.nil, context.nil, context.nil }); } RubyArray errinfo = RubyArray.newArray(context.runtime); if (!lastResult.isError()) { return runtime.newArray( new IRubyObject[] { runtime.newSymbol(lastResult.stringResult), context.nil, context.nil, context.nil, context.nil }); } else { errinfo.append(runtime.newSymbol(lastResult.stringResult)); // FIXME: gross errinfo.append(RubyString.newString(runtime, lastResult.inEncoding.getName())); errinfo.append(RubyString.newString(runtime, lastResult.outEncoding.getName())); if (lastResult.isError() && lastResult.errorBytes != null) { // FIXME: do this elsewhere and cache it ByteList errorBytes = new ByteList(lastResult.errorBytes, lastResult.inEncoding, true); errinfo.append(RubyString.newString(runtime, errorBytes)); } else { errinfo.append(RubyString.newEmptyString(runtime)); } if (lastResult.readagainBytes != null) { // FIXME: do this elsewhere and cache it ByteList readagainBytes = new ByteList(lastResult.readagainBytes, lastResult.inEncoding, true); errinfo.append(RubyString.newString(runtime, readagainBytes)); } else { errinfo.append(RubyString.newEmptyString(runtime)); } } return errinfo; }
public static IRubyObject newLocationArray(Ruby runtime, RubyStackTraceElement[] elements) { RubyArray ary = runtime.newArray(elements.length); for (RubyStackTraceElement element : elements) { ary.append(new RubyThread.Location(runtime, runtime.getLocation(), element)); } return ary; }