private IRubyObject prepareRaiseException(Ruby runtime, IRubyObject[] args, Block block) { if (args.length == 0) { IRubyObject lastException = errorInfo; if (lastException.isNil()) { return new RaiseException(runtime, runtime.getRuntimeError(), "", false).getException(); } return lastException; } IRubyObject exception; ThreadContext context = getRuntime().getCurrentContext(); if (args.length == 1) { if (args[0] instanceof RubyString) { return runtime.getRuntimeError().newInstance(context, args, block); } if (!args[0].respondsTo("exception")) { return runtime.newTypeError("exception class/object expected").getException(); } exception = args[0].callMethod(context, "exception"); } else { if (!args[0].respondsTo("exception")) { return runtime.newTypeError("exception class/object expected").getException(); } exception = args[0].callMethod(context, "exception", args[1]); } if (!runtime.getException().isInstance(exception)) { return runtime.newTypeError("exception object expected").getException(); } if (args.length == 3) { ((RubyException) exception).set_backtrace(args[2]); } return exception; }
protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) { Ruby runtime = recv.getRuntime(); DateTime dt = new DateTime(DateTimeZone.UTC); byte[] fromAsBytes = null; fromAsBytes = from.convertToString().getBytes(); if (fromAsBytes.length != 8) { throw runtime.newTypeError("marshaled time format differ"); } int p = 0; int s = 0; for (int i = 0; i < 4; i++) { p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i); } for (int i = 4; i < 8; i++) { s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4)); } boolean utc = false; if ((p & (1 << 31)) == 0) { dt = dt.withMillis(p * 1000L); time.setUSec((s & 0xFFFFF) % 1000); } else { p &= ~(1 << 31); utc = ((p >>> 30 & 0x1) == 0x1); dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900); dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1); dt = dt.withDayOfMonth(((p >>> 5) & 0x1F)); dt = dt.withHourOfDay((p & 0x1F)); dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F)); dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F)); // marsaling dumps usec, not msec dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000); time.setUSec((s & 0xFFFFF) % 1000); } time.setDateTime(dt); if (!utc) time.localtime(); from.getInstanceVariables().copyInstanceVariablesInto(time); return time; }