| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3178,9 +3178,11 @@ public IRubyObject sort_bang19(ThreadContext context, Block block) { | |||
| 3178 | 3178 | } | |
| 3179 | 3179 | ||
| 3180 | 3180 | private IRubyObject sortInternal(final ThreadContext context, boolean honorOverride) { | |
| 3181 | + Ruby runtime = context.runtime; | ||
| 3182 | + | ||
| 3181 | 3183 | // One check per specialized fast-path to make the check invariant. | |
| 3182 | - final boolean fixnumBypass = !honorOverride || context.runtime.newFixnum(0).isBuiltin("<=>"); | ||
| 3183 | - final boolean stringBypass = !honorOverride || context.runtime.newString("").isBuiltin("<=>"); | ||
| 3184 | + final boolean fixnumBypass = !honorOverride || runtime.getFixnum().isMethodBuiltin("<=>"); | ||
| 3185 | + final boolean stringBypass = !honorOverride || runtime.getString().isMethodBuiltin("<=>"); | ||
| 3184 | 3186 | ||
| 3185 | 3187 | try { | |
| 3186 | 3188 | Qsort.sort(values, begin, begin + realLength, new Comparator() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1501,9 +1501,7 @@ public ClassIndex getNativeClassIndex() { | |||
| 1501 | 1501 | * @return true if so | |
| 1502 | 1502 | */ | |
| 1503 | 1503 | public boolean isBuiltin(String methodName) { | |
| 1504 | - DynamicMethod method = getMetaClass().searchMethodInner(methodName); | ||
| 1505 | - | ||
| 1506 | - return method != null && method.isBuiltin(); | ||
| 1504 | + return getMetaClass().isMethodBuiltin(methodName); | ||
| 1507 | 1505 | } | |
| 1508 | 1506 | ||
| 1509 | 1507 | @JRubyMethod(name = "singleton_method_added", module = true, visibility = PRIVATE) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,9 +38,6 @@ | |||
| 38 | 38 | import jnr.constants.platform.OpenFlags; | |
| 39 | 39 | import jnr.posix.POSIX; | |
| 40 | 40 | import org.jcodings.Encoding; | |
| 41 | - import org.jruby.util.io.ModeFlags; | ||
| 42 | - import org.jruby.util.io.OpenFile; | ||
| 43 | - import org.jruby.util.io.ChannelDescriptor; | ||
| 44 | 41 | import java.io.File; | |
| 45 | 42 | import java.io.FileDescriptor; | |
| 46 | 43 | import java.io.FileNotFoundException; | |
@@ -77,22 +74,25 @@ | |||
| 77 | 74 | import org.jruby.util.ByteList; | |
| 78 | 75 | import org.jruby.util.FileResource; | |
| 79 | 76 | import org.jruby.util.JRubyFile; | |
| 77 | + import org.jruby.util.ResourceException; | ||
| 80 | 78 | import org.jruby.util.TypeConverter; | |
| 81 | - import org.jruby.util.io.DirectoryAsFileException; | ||
| 82 | - import org.jruby.util.io.PermissionDeniedException; | ||
| 83 | - import org.jruby.util.io.Stream; | ||
| 84 | - import org.jruby.util.io.ChannelStream; | ||
| 85 | - import org.jruby.util.io.IOOptions; | ||
| 79 | + import org.jruby.util.encoding.Transcoder; | ||
| 86 | 80 | import org.jruby.util.io.BadDescriptorException; | |
| 81 | + import org.jruby.util.io.ChannelDescriptor; | ||
| 82 | + import org.jruby.util.io.ChannelStream; | ||
| 83 | + import org.jruby.util.io.DirectoryAsFileException; | ||
| 84 | + import org.jruby.util.io.EncodingUtils; | ||
| 87 | 85 | import org.jruby.util.io.FileExistsException; | |
| 86 | + import org.jruby.util.io.IOEncodable; | ||
| 87 | + import org.jruby.util.io.IOOptions; | ||
| 88 | 88 | import org.jruby.util.io.InvalidValueException; | |
| 89 | + import org.jruby.util.io.ModeFlags; | ||
| 90 | + import org.jruby.util.io.OpenFile; | ||
| 89 | 91 | import org.jruby.util.io.PipeException; | |
| 92 | + import org.jruby.util.io.Stream; | ||
| 90 | 93 | import org.jruby.exceptions.RaiseException; | |
| 91 | 94 | import org.jruby.runtime.Helpers; | |
| 92 | 95 | import org.jruby.runtime.encoding.EncodingService; | |
| 93 | - import org.jruby.util.encoding.Transcoder; | ||
| 94 | - import org.jruby.util.io.EncodingUtils; | ||
| 95 | - import org.jruby.util.io.IOEncodable; | ||
| 96 | 96 | ||
| 97 | 97 | /** | |
| 98 | 98 | * Ruby File class equivalent in java. | |
@@ -1317,23 +1317,16 @@ private ChannelDescriptor sysopen(String path, ModeFlags modes, int perm) { | |||
| 1317 | 1317 | // TODO: check if too many open files, GC and try again | |
| 1318 | 1318 | ||
| 1319 | 1319 | return descriptor; | |
| 1320 | - } catch (PermissionDeniedException pde) { | ||
| 1321 | - // PDException can be thrown only when creating the file and | ||
| 1322 | - // permission is denied. See JavaDoc of PermissionDeniedException. | ||
| 1323 | - throw getRuntime().newErrnoEACCESError(path); | ||
| 1324 | - } catch (FileNotFoundException fnfe) { | ||
| 1325 | - // FNFException can be thrown in both cases, when the file | ||
| 1326 | - // is not found, or when permission is denied. | ||
| 1327 | - if (Ruby.isSecurityRestricted() || new File(path).exists()) { | ||
| 1328 | - throw getRuntime().newErrnoEACCESError(path); | ||
| 1329 | - } | ||
| 1330 | - throw getRuntime().newErrnoENOENTError(path); | ||
| 1331 | - } catch (DirectoryAsFileException dafe) { | ||
| 1332 | - throw getRuntime().newErrnoEISDirError(); | ||
| 1333 | - } catch (FileExistsException fee) { | ||
| 1334 | - throw getRuntime().newErrnoEEXISTError(path); | ||
| 1335 | - } catch (IOException ioe) { | ||
| 1336 | - throw getRuntime().newIOErrorFromException(ioe); | ||
| 1320 | + } catch (ResourceException resourceException) { | ||
| 1321 | + throw resourceException.newRaiseException(getRuntime()); | ||
| 1322 | + } catch (FileNotFoundException ignored) { | ||
| 1323 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1324 | + } catch (DirectoryAsFileException ignored) { | ||
| 1325 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1326 | + } catch (FileExistsException ignored) { | ||
| 1327 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1328 | + } catch (IOException ignored) { | ||
| 1329 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1337 | 1330 | } | |
| 1338 | 1331 | } | |
| 1339 | 1332 | ||
@@ -1343,34 +1336,18 @@ private Stream fopen(String path, ModeFlags flags) { | |||
| 1343 | 1336 | getRuntime(), | |
| 1344 | 1337 | path, | |
| 1345 | 1338 | flags); | |
| 1339 | + } catch (InvalidValueException ex) { | ||
| 1340 | + throw getRuntime().newErrnoEINVALError(); | ||
| 1341 | + } catch (PipeException ex) { | ||
| 1342 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1346 | 1343 | } catch (BadDescriptorException e) { | |
| 1347 | - throw getRuntime().newErrnoEBADFError(); | ||
| 1348 | - } catch (PermissionDeniedException pde) { | ||
| 1349 | - // PDException can be thrown only when creating the file and | ||
| 1350 | - // permission is denied. See JavaDoc of PermissionDeniedException. | ||
| 1351 | - throw getRuntime().newErrnoEACCESError(path); | ||
| 1344 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1352 | 1345 | } catch (FileNotFoundException ex) { | |
| 1353 | - // FNFException can be thrown in both cases, when the file | ||
| 1354 | - // is not found, or when permission is denied. | ||
| 1355 | - // FIXME: yes, this is indeed gross. | ||
| 1356 | - String message = ex.getMessage(); | ||
| 1357 | - | ||
| 1358 | - if (message.contains(/*P*/"ermission denied") || | ||
| 1359 | - message.contains(/*A*/"ccess is denied")) { | ||
| 1360 | - throw getRuntime().newErrnoEACCESError(path); | ||
| 1361 | - } | ||
| 1362 | - | ||
| 1363 | - throw getRuntime().newErrnoENOENTError(path); | ||
| 1364 | - } catch (DirectoryAsFileException ex) { | ||
| 1365 | - throw getRuntime().newErrnoEISDirError(); | ||
| 1346 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1366 | 1347 | } catch (FileExistsException ex) { | |
| 1367 | - throw getRuntime().newErrnoEEXISTError(path); | ||
| 1348 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1368 | 1349 | } catch (IOException ex) { | |
| 1369 | - throw getRuntime().newIOErrorFromException(ex); | ||
| 1370 | - } catch (InvalidValueException ex) { | ||
| 1371 | - throw getRuntime().newErrnoEINVALError(); | ||
| 1372 | - } catch (PipeException ex) { | ||
| 1373 | - throw getRuntime().newErrnoEPIPEError(); | ||
| 1350 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1374 | 1351 | } catch (SecurityException ex) { | |
| 1375 | 1352 | throw getRuntime().newErrnoEACCESError(path); | |
| 1376 | 1353 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,8 +36,11 @@ | |||
| 36 | 36 | package org.jruby; | |
| 37 | 37 | ||
| 38 | 38 | import org.jruby.runtime.Helpers; | |
| 39 | + import org.jruby.util.ResourceException; | ||
| 39 | 40 | import org.jruby.util.StringSupport; | |
| 41 | + import org.jruby.util.io.DirectoryAsFileException; | ||
| 40 | 42 | import org.jruby.util.io.EncodingUtils; | |
| 43 | + import org.jruby.util.io.FileExistsException; | ||
| 41 | 44 | import org.jruby.util.io.ModeFlags; | |
| 42 | 45 | import org.jruby.util.io.SelectBlob; | |
| 43 | 46 | import jnr.constants.platform.Fcntl; | |
@@ -88,8 +91,6 @@ | |||
| 88 | 91 | import org.jruby.util.io.ChannelStream; | |
| 89 | 92 | import org.jruby.util.io.InvalidValueException; | |
| 90 | 93 | import org.jruby.util.io.PipeException; | |
| 91 | - import org.jruby.util.io.FileExistsException; | ||
| 92 | - import org.jruby.util.io.DirectoryAsFileException; | ||
| 93 | 94 | import org.jruby.util.io.STDIO; | |
| 94 | 95 | import org.jruby.util.io.OpenFile; | |
| 95 | 96 | import org.jruby.util.io.ChannelDescriptor; | |
@@ -342,11 +343,7 @@ protected void reopenPath(Ruby runtime, IRubyObject[] args) { | |||
| 342 | 343 | openFile.setPath(path); | |
| 343 | 344 | ||
| 344 | 345 | if (openFile.getMainStream() == null) { | |
| 345 | - try { | ||
| 346 | - openFile.setMainStream(ChannelStream.fopen(runtime, path, modes.getModeFlags())); | ||
| 347 | - } catch (FileExistsException fee) { | ||
| 348 | - throw runtime.newErrnoEEXISTError(path); | ||
| 349 | - } | ||
| 346 | + openFile.setMainStream(ChannelStream.fopen(runtime, path, modes.getModeFlags())); | ||
| 350 | 347 | ||
| 351 | 348 | if (openFile.getPipeStream() != null) { | |
| 352 | 349 | openFile.getPipeStream().fclose(); | |
@@ -360,14 +357,16 @@ protected void reopenPath(Ruby runtime, IRubyObject[] args) { | |||
| 360 | 357 | // TODO: pipe handler to be reopened with path and "w" mode | |
| 361 | 358 | } | |
| 362 | 359 | } | |
| 360 | + } catch (InvalidValueException e) { | ||
| 361 | + throw runtime.newErrnoEINVALError(); | ||
| 363 | 362 | } catch (PipeException pe) { | |
| 364 | - throw runtime.newErrnoEPIPEError(); | ||
| 363 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 365 | 364 | } catch (IOException ex) { | |
| 366 | - throw runtime.newIOErrorFromException(ex); | ||
| 365 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 367 | 366 | } catch (BadDescriptorException ex) { | |
| 368 | - throw runtime.newErrnoEBADFError(); | ||
| 369 | - } catch (InvalidValueException e) { | ||
| 370 | - throw runtime.newErrnoEINVALError(); | ||
| 367 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 368 | + } catch (FileExistsException fee) { | ||
| 369 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 371 | 370 | } | |
| 372 | 371 | } | |
| 373 | 372 | ||
@@ -1179,16 +1178,19 @@ private static IRubyObject sysopenCommon(IRubyObject recv, IRubyObject[] args, B | |||
| 1179 | 1178 | runtime.getJRubyClassLoader()); | |
| 1180 | 1179 | // always a new fileno, so ok to use internal only | |
| 1181 | 1180 | fileno = descriptor.getFileno(); | |
| 1181 | + } catch (ResourceException resourceException) { | ||
| 1182 | + throw resourceException.newRaiseException(runtime); | ||
| 1183 | + } catch (FileNotFoundException ignored) { | ||
| 1184 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1185 | + } catch (DirectoryAsFileException ignored) { | ||
| 1186 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1187 | + } catch (FileExistsException ignored) { | ||
| 1188 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1189 | + } catch (IOException ignored) { | ||
| 1190 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1182 | 1191 | } | |
| 1183 | - catch (FileNotFoundException fnfe) { | ||
| 1184 | - throw runtime.newErrnoENOENTError(path); | ||
| 1185 | - } catch (DirectoryAsFileException dafe) { | ||
| 1186 | - throw runtime.newErrnoEISDirError(path); | ||
| 1187 | - } catch (FileExistsException fee) { | ||
| 1188 | - throw runtime.newErrnoEEXISTError(path); | ||
| 1189 | - } catch (IOException ioe) { | ||
| 1190 | - throw runtime.newIOErrorFromException(ioe); | ||
| 1191 | - } | ||
| 1192 | + | ||
| 1193 | + | ||
| 1192 | 1194 | return runtime.newFixnum(fileno); | |
| 1193 | 1195 | } | |
| 1194 | 1196 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3869,6 +3869,19 @@ private static void visitMethods(NodeVisitor visitor, RubyModule mod) { | |||
| 3869 | 3869 | } | |
| 3870 | 3870 | } | |
| 3871 | 3871 | ||
| 3872 | + /** | ||
| 3873 | + * Return true if the given method is defined on this class and is a builtin | ||
| 3874 | + * (defined in Java at boot). | ||
| 3875 | + * | ||
| 3876 | + * @param methodName | ||
| 3877 | + * @return | ||
| 3878 | + */ | ||
| 3879 | + public boolean isMethodBuiltin(String methodName) { | ||
| 3880 | + DynamicMethod method = searchMethodInner(methodName); | ||
| 3881 | + | ||
| 3882 | + return method != null && method.isBuiltin(); | ||
| 3883 | + } | ||
| 3884 | + | ||
| 3872 | 3885 | @Deprecated | |
| 3873 | 3886 | public void checkMethodBound(ThreadContext context, IRubyObject[] args, Visibility visibility) { | |
| 3874 | 3887 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,7 @@ | |||
| 50 | 50 | import org.jruby.RubyObject; | |
| 51 | 51 | import org.jruby.RubyRational; | |
| 52 | 52 | import org.jruby.RubyString; | |
| 53 | - | ||
| 53 | + import org.jruby.RubySymbol; | ||
| 54 | 54 | import org.jruby.anno.JRubyClass; | |
| 55 | 55 | import org.jruby.anno.JRubyConstant; | |
| 56 | 56 | import org.jruby.anno.JRubyMethod; | |
@@ -360,25 +360,16 @@ public static IRubyObject mode(ThreadContext context, IRubyObject recv, IRubyObj | |||
| 360 | 360 | return newExceptionMode; | |
| 361 | 361 | } | |
| 362 | 362 | ||
| 363 | - long _ROUND_MODE = ((RubyFixnum)clazz.getConstant("ROUND_MODE")).getLongValue(); | ||
| 364 | - if (longMode == _ROUND_MODE) { | ||
| 365 | - if (value.isNil()) return c.searchInternalModuleVariable("vpRoundingMode"); | ||
| 366 | - if (!(value instanceof RubyFixnum)) { | ||
| 367 | - throw context.runtime.newTypeError("wrong argument type " + mode.getMetaClass() + " (expected Fixnum)"); | ||
| 368 | - } | ||
| 369 | - | ||
| 370 | - RubyFixnum roundingMode = (RubyFixnum)value; | ||
| 371 | - if (roundingMode == clazz.getConstant("ROUND_UP") || | ||
| 372 | - roundingMode == clazz.getConstant("ROUND_DOWN") || | ||
| 373 | - roundingMode == clazz.getConstant("ROUND_FLOOR") || | ||
| 374 | - roundingMode == clazz.getConstant("ROUND_CEILING") || | ||
| 375 | - roundingMode == clazz.getConstant("ROUND_HALF_UP") || | ||
| 376 | - roundingMode == clazz.getConstant("ROUND_HALF_DOWN") || | ||
| 377 | - roundingMode == clazz.getConstant("ROUND_HALF_EVEN")) { | ||
| 378 | - c.setInternalModuleVariable("vpRoundingMode", roundingMode); | ||
| 379 | - } else { | ||
| 380 | - throw context.runtime.newTypeError("invalid rounding mode"); | ||
| 363 | + long ROUND_MODE = ((RubyFixnum)clazz.getConstant("ROUND_MODE")).getLongValue(); | ||
| 364 | + if (longMode == ROUND_MODE) { | ||
| 365 | + if (value.isNil()) { | ||
| 366 | + return c.searchInternalModuleVariable("vpRoundingMode"); | ||
| 381 | 367 | } | |
| 368 | + | ||
| 369 | + RoundingMode javaRoundingMode = javaRoundingModeFromRubyRoundingMode(context.runtime, value); | ||
| 370 | + RubyFixnum roundingMode = context.runtime.newFixnum(javaRoundingMode.ordinal()); | ||
| 371 | + c.setInternalModuleVariable("vpRoundingMode", roundingMode); | ||
| 372 | + | ||
| 382 | 373 | return c.searchInternalModuleVariable("vpRoundingMode"); | |
| 383 | 374 | } | |
| 384 | 375 | throw context.runtime.newTypeError("first argument for BigDecimal#mode invalid"); | |
@@ -1113,20 +1104,20 @@ public IRubyObject exponent() { | |||
| 1113 | 1104 | public IRubyObject finite_p() { | |
| 1114 | 1105 | return getRuntime().newBoolean(!isNaN() && !isInfinity()); | |
| 1115 | 1106 | } | |
| 1116 | - | ||
| 1107 | + | ||
| 1117 | 1108 | private void floorNaNInfinityCheck(Ruby runtime) { | |
| 1118 | 1109 | if (isNaN() || isInfinity()) { | |
| 1119 | 1110 | throw runtime.newFloatDomainError("Computation results to '" + to_s(NULL_ARRAY).asJavaString() + "'"); | |
| 1120 | 1111 | } | |
| 1121 | 1112 | } | |
| 1122 | 1113 | ||
| 1123 | - private IRubyObject floorInternal(ThreadContext context, int n) { | ||
| 1114 | + private RubyBigDecimal floorInternal(ThreadContext context, int n) { | ||
| 1124 | 1115 | return value.scale() > n ? new RubyBigDecimal(context.runtime, value.setScale(n, RoundingMode.FLOOR)) : this; | |
| 1125 | 1116 | } | |
| 1126 | 1117 | ||
| 1127 | 1118 | @JRubyMethod public IRubyObject floor(ThreadContext context) { | |
| 1128 | 1119 | floorNaNInfinityCheck(context.runtime); | |
| 1129 | - return floorInternal(context, 0); | ||
| 1120 | + return floorInternal(context, 0).to_int(); | ||
| 1130 | 1121 | } | |
| 1131 | 1122 | ||
| 1132 | 1123 | @JRubyMethod public IRubyObject floor(ThreadContext context, IRubyObject arg) { | |
@@ -1180,23 +1171,49 @@ public IRubyObject precs(ThreadContext context) { | |||
| 1180 | 1171 | ||
| 1181 | 1172 | @JRubyMethod | |
| 1182 | 1173 | public IRubyObject round(ThreadContext context) { | |
| 1183 | - return new RubyBigDecimal(context.runtime, value.setScale(0, getRoundingMode(context.runtime))); | ||
| 1174 | + return new RubyBigDecimal(context.runtime, value.setScale(0, getRoundingMode(context.runtime))).to_int(); | ||
| 1184 | 1175 | } | |
| 1185 | 1176 | ||
| 1186 | 1177 | @JRubyMethod | |
| 1187 | 1178 | public IRubyObject round(ThreadContext context, IRubyObject scale) { | |
| 1188 | - return new RubyBigDecimal(context.runtime, value.setScale(num2int(scale), getRoundingMode(context.runtime))); | ||
| 1179 | + return new RubyBigDecimal(context.runtime, value.setScale(num2int(scale), getRoundingMode(context.runtime))).to_int(); | ||
| 1189 | 1180 | } | |
| 1190 | 1181 | ||
| 1191 | 1182 | @JRubyMethod | |
| 1192 | 1183 | public IRubyObject round(ThreadContext context, IRubyObject scale, IRubyObject mode) { | |
| 1193 | 1184 | return new RubyBigDecimal(context.runtime, | |
| 1194 | - value.setScale(num2int(scale), javaRoundingModeFromRubyRoundingMode(mode))); | ||
| 1185 | + value.setScale(num2int(scale), javaRoundingModeFromRubyRoundingMode(context.runtime, mode))); | ||
| 1195 | 1186 | } | |
| 1196 | 1187 | ||
| 1197 | 1188 | //this relies on the Ruby rounding enumerations == Java ones, which they (currently) all are | |
| 1198 | - private RoundingMode javaRoundingModeFromRubyRoundingMode(IRubyObject arg) { | ||
| 1199 | - return RoundingMode.valueOf(num2int(arg)); | ||
| 1189 | + private static RoundingMode javaRoundingModeFromRubyRoundingMode(Ruby runtime, IRubyObject arg) { | ||
| 1190 | + if (arg instanceof RubySymbol) { | ||
| 1191 | + RubySymbol roundingModeSymbol = (RubySymbol) arg; | ||
| 1192 | + String roundingModeString = roundingModeSymbol.asJavaString(); | ||
| 1193 | + if (roundingModeString.equals("up")) { | ||
| 1194 | + return RoundingMode.UP; | ||
| 1195 | + } else if (roundingModeString.equals("down") || roundingModeString.equals("truncate")) { | ||
| 1196 | + return RoundingMode.DOWN; | ||
| 1197 | + } else if (roundingModeString.equals("half_up") || roundingModeString.equals("default")) { | ||
| 1198 | + return RoundingMode.HALF_UP; | ||
| 1199 | + } else if (roundingModeString.equals("half_down")) { | ||
| 1200 | + return RoundingMode.HALF_DOWN; | ||
| 1201 | + } else if (roundingModeString.equals("half_even") || roundingModeString.equals("banker")) { | ||
| 1202 | + return RoundingMode.HALF_EVEN; | ||
| 1203 | + } else if (roundingModeString.equals("ceiling") || roundingModeString.equals("ceil")) { | ||
| 1204 | + return RoundingMode.CEILING; | ||
| 1205 | + } else if (roundingModeString.equals("floor")) { | ||
| 1206 | + return RoundingMode.FLOOR; | ||
| 1207 | + } else { | ||
| 1208 | + throw runtime.newArgumentError("invalid rounding mode"); | ||
| 1209 | + } | ||
| 1210 | + } else { | ||
| 1211 | + try { | ||
| 1212 | + return RoundingMode.valueOf(num2int(arg)); | ||
| 1213 | + } catch (IllegalArgumentException iae) { | ||
| 1214 | + throw runtime.newArgumentError("invalid rounding mode"); | ||
| 1215 | + } | ||
| 1216 | + } | ||
| 1200 | 1217 | } | |
| 1201 | 1218 | ||
| 1202 | 1219 | @JRubyMethod | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -181,11 +181,14 @@ public IRubyObject initialize_copy(IRubyObject original) { | |||
| 181 | 181 | ||
| 182 | 182 | private static Class<?> getJavaClass(ThreadContext context, RubyModule module) { | |
| 183 | 183 | try { | |
| 184 | - IRubyObject jClass = Helpers.invoke(context, module, "java_class"); | ||
| 184 | + IRubyObject jClass = Helpers.invoke(context, module, "java_class"); | ||
| 185 | 185 | ||
| 186 | - | ||
| 187 | - return !(jClass instanceof JavaClass) ? null : ((JavaClass) jClass).javaClass(); | ||
| 188 | - } catch (Exception e) { return null; } | ||
| 186 | + return !(jClass instanceof JavaClass) ? null : ((JavaClass) jClass).javaClass(); | ||
| 187 | + } catch (Exception e) { | ||
| 188 | + // clear $! since our "java_class" invoke above may have failed and set it | ||
| 189 | + context.setErrorInfo(context.nil); | ||
| 190 | + return null; | ||
| 191 | + } | ||
| 189 | 192 | } | |
| 190 | 193 | ||
| 191 | 194 | /** | |
| Back | FazBrowse Home | New Git URL |
0 commit comments