|
200 | 200 | import java.util.concurrent.TimeUnit; |
201 | 201 | import java.util.concurrent.atomic.AtomicInteger; |
202 | 202 | import java.util.concurrent.atomic.AtomicLong; |
| 203 | +import java.util.function.Consumer; |
203 | 204 | import java.util.regex.Pattern; |
204 | 205 |
|
205 | 206 | import static java.lang.invoke.MethodHandles.explicitCastArguments; |
@@ -1563,80 +1564,70 @@ public IRubyObject[] getNilPrefilledArray() { |
1563 | 1564 | } |
1564 | 1565 |
|
1565 | 1566 | private void initExceptions() { |
1566 | | - standardError = RubyStandardError.createStandardErrorClass(this, exceptionClass); |
1567 | | - runtimeError = defineClassIfAllowed("RuntimeError", standardError); |
1568 | | - ioError = defineClassIfAllowed("IOError", standardError); |
1569 | | - scriptError = defineClassIfAllowed("ScriptError", exceptionClass); |
1570 | | - rangeError = defineClassIfAllowed("RangeError", standardError); |
| 1567 | + ifAllowed("StandardError", (ruby) -> standardError = RubyStandardError.define(ruby, exceptionClass)); |
| 1568 | + ifAllowed("RubyError", (ruby) -> runtimeError = RubyRuntimeError.define(ruby, standardError)); |
| 1569 | + ifAllowed("IOError", (ruby) -> ioError = RubyIOError.define(ruby, standardError)); |
| 1570 | + ifAllowed("ScriptError", (ruby) -> scriptError = RubyScriptError.define(ruby, exceptionClass)); |
| 1571 | + ifAllowed("RangeError", (ruby) -> rangeError = RubyRangeError.define(ruby, standardError)); |
| 1572 | + ifAllowed("SignalException", (ruby) -> signalException = RubySignalException.define(ruby, exceptionClass)); |
| 1573 | + ifAllowed("NameError", (ruby) -> { |
| 1574 | + nameError = RubyNameError.define(ruby, standardError); |
| 1575 | + nameErrorMessage = RubyNameError.defineMessage(ruby, nameError); |
| 1576 | + }); |
| 1577 | + ifAllowed("NoMethodError", (ruby) -> noMethodError = RubyNoMethodError.define(ruby, nameError)); |
| 1578 | + ifAllowed("SystemExit", (ruby) -> systemExit = RubySystemExit.define(ruby, exceptionClass)); |
| 1579 | + ifAllowed("LocalJumpError", (ruby) -> localJumpError = RubyLocalJumpError.define(ruby, standardError)); |
| 1580 | + ifAllowed("SystemCallError", (ruby) -> systemCallError = RubySystemCallError.define(ruby, standardError)); |
| 1581 | + |
| 1582 | + ifAllowed("Fatal", (ruby) -> fatal = RubyFatal.define(ruby, exceptionClass)); |
| 1583 | + ifAllowed("Interrupt", (ruby) -> interrupt = RubyInterrupt.define(ruby, signalException)); |
| 1584 | + ifAllowed("TypeError", (ruby) -> typeError = RubyTypeError.define(ruby, standardError)); |
| 1585 | + ifAllowed("ArgumentError", (ruby) -> argumentError = RubyArgumentError.define(ruby, standardError)); |
| 1586 | + ifAllowed("UncaughtThrowError", (ruby) -> uncaughtThrowError = RubyUncaughtThrowError.define(ruby, argumentError)); |
| 1587 | + ifAllowed("IndexError", (ruby) -> indexError = RubyIndexError.define(ruby, standardError)); |
| 1588 | + ifAllowed("StopIteration", (ruby) -> stopIteration = RubyStopIteration.define(ruby, indexError)); |
| 1589 | + ifAllowed("SyntaxError", (ruby) -> syntaxError = RubySyntaxError.define(ruby, scriptError)); |
| 1590 | + ifAllowed("LoadError", (ruby) -> loadError = RubyLoadError.define(ruby, scriptError)); |
| 1591 | + ifAllowed("NotImplementedError", (ruby) -> notImplementedError = RubyNotImplementedError.define(ruby, scriptError)); |
| 1592 | + ifAllowed("SecurityError", (ruby) -> securityError = RubySecurityError.define(ruby, exceptionClass)); |
| 1593 | + ifAllowed("NoMemoryError", (ruby) -> noMemoryError = RubyNoMemoryError.define(ruby, exceptionClass)); |
| 1594 | + ifAllowed("RegexpError", (ruby) -> regexpError = RubyRegexpError.define(ruby, standardError)); |
| 1595 | + // Proposal to RubyCommons for interrupting Regexps |
| 1596 | + ifAllowed("InterruptedRegexpError", (ruby) -> interruptedRegexpError = RubyInterruptedRegexpError.define(ruby, regexpError)); |
| 1597 | + ifAllowed("EOFError", (ruby) -> eofError = RubyEOFError.define(ruby, ioError)); |
| 1598 | + ifAllowed("ThreadError", (ruby) -> threadError = RubyThreadError.define(ruby, standardError)); |
| 1599 | + ifAllowed("ConcurrencyError", (ruby) -> concurrencyError = RubyConcurrencyError.define(ruby, threadError)); |
| 1600 | + ifAllowed("SystemStackError", (ruby) -> systemStackError = RubySystemStackError.define(ruby, exceptionClass)); |
| 1601 | + ifAllowed("ZeroDivisionError", (ruby) -> zeroDivisionError = RubyZeroDivisionError.define(ruby, standardError)); |
| 1602 | + ifAllowed("FloatDomainError", (ruby) -> RubyFloatDomainError.define(ruby, rangeError)); |
| 1603 | + ifAllowed("EncodingError", (ruby) -> { |
| 1604 | + encodingError = RubyEncodingError.define(ruby, standardError); |
| 1605 | + encodingCompatibilityError = RubyEncodingError.RubyCompatibilityError.define(ruby, encodingError, encodingClass); |
| 1606 | + invalidByteSequenceError = RubyEncodingError.RubyInvalidByteSequenceError.define(ruby, encodingError, encodingClass); |
| 1607 | + undefinedConversionError = RubyEncodingError.RubyUndefinedConversionError.define(ruby, encodingError, encodingClass); |
| 1608 | + converterNotFoundError = RubyEncodingError.RubyConverterNotFoundError.define(ruby, encodingError, encodingClass); |
| 1609 | + }); |
| 1610 | + ifAllowed("Fiber", (ruby) -> fiberError = RubyFiberError.define(ruby, standardError)); |
| 1611 | + ifAllowed("ConcurrencyError", (ruby) -> concurrencyError = RubyConcurrencyError.define(ruby, threadError)); |
| 1612 | + ifAllowed("KeyError", (ruby) -> keyError = RubyKeyError.define(ruby, indexError)); |
| 1613 | + ifAllowed("DomainError", (ruby) -> mathDomainError = RubyDomainError.define(ruby, argumentError, mathModule)); |
1571 | 1614 |
|
1572 | | - if (profile.allowClass("SignalException")) { |
1573 | | - signalException = RubySignalException.createSignalExceptionClass(this, exceptionClass); |
1574 | | - } |
1575 | | - if (profile.allowClass("NameError")) { |
1576 | | - nameError = RubyNameError.createNameErrorClass(this, standardError); |
1577 | | - nameErrorMessage = RubyNameError.createNameErrorMessageClass(this, nameError); |
1578 | | - } |
1579 | | - if (profile.allowClass("NoMethodError")) { |
1580 | | - noMethodError = RubyNoMethodError.createNoMethodErrorClass(this, nameError); |
1581 | | - } |
1582 | | - if (profile.allowClass("SystemExit")) { |
1583 | | - systemExit = RubySystemExit.createSystemExitClass(this, exceptionClass); |
1584 | | - } |
1585 | | - if (profile.allowClass("LocalJumpError")) { |
1586 | | - localJumpError = RubyLocalJumpError.createLocalJumpErrorClass(this, standardError); |
| 1615 | + initErrno(); |
| 1616 | + |
| 1617 | + initNativeException(); |
| 1618 | + } |
| 1619 | + |
| 1620 | + private void ifAllowed(String name, Consumer<Ruby> callback) { |
| 1621 | + if (profile.allowClass(name)) { |
| 1622 | + callback.accept(this); |
1587 | 1623 | } |
| 1624 | + } |
| 1625 | + |
| 1626 | + @SuppressWarnings("deprecation") |
| 1627 | + private void initNativeException() { |
1588 | 1628 | if (profile.allowClass("NativeException")) { |
1589 | 1629 | nativeException = NativeException.createClass(this, runtimeError); |
1590 | 1630 | } |
1591 | | - if (profile.allowClass("SystemCallError")) { |
1592 | | - systemCallError = RubySystemCallError.createSystemCallErrorClass(this, standardError); |
1593 | | - } |
1594 | | - |
1595 | | - fatal = defineClassIfAllowed("Fatal", exceptionClass); |
1596 | | - if (profile.allowClass("Interrupt")) { |
1597 | | - interrupt = RubyInterrupt.createInterruptClass(this, signalException); |
1598 | | - } |
1599 | | - typeError = defineClassIfAllowed("TypeError", standardError); |
1600 | | - argumentError = defineClassIfAllowed("ArgumentError", standardError); |
1601 | | - if (profile.allowClass("UncaughtThrowError")) { |
1602 | | - uncaughtThrowError = RubyUncaughtThrowError.createUncaughtThrowErrorClass(this, argumentError); |
1603 | | - } |
1604 | | - indexError = defineClassIfAllowed("IndexError", standardError); |
1605 | | - if (profile.allowClass("StopIteration")) { |
1606 | | - stopIteration = RubyStopIteration.createStopIterationClass(this, indexError); |
1607 | | - } |
1608 | | - syntaxError = defineClassIfAllowed("SyntaxError", scriptError); |
1609 | | - loadError = defineClassIfAllowed("LoadError", scriptError); |
1610 | | - notImplementedError = defineClassIfAllowed("NotImplementedError", scriptError); |
1611 | | - securityError = defineClassIfAllowed("SecurityError", exceptionClass); |
1612 | | - noMemoryError = defineClassIfAllowed("NoMemoryError", exceptionClass); |
1613 | | - regexpError = defineClassIfAllowed("RegexpError", standardError); |
1614 | | - interruptedRegexpError = defineClassIfAllowed("InterruptedRegexpError", regexpError); // Proposal to RubyCommons for interrupting Regexps |
1615 | | - eofError = defineClassIfAllowed("EOFError", ioError); |
1616 | | - threadError = defineClassIfAllowed("ThreadError", standardError); |
1617 | | - concurrencyError = defineClassIfAllowed("ConcurrencyError", threadError); |
1618 | | - systemStackError = defineClassIfAllowed("SystemStackError", exceptionClass); |
1619 | | - zeroDivisionError = defineClassIfAllowed("ZeroDivisionError", standardError); |
1620 | | - floatDomainError = defineClassIfAllowed("FloatDomainError", rangeError); |
1621 | | - |
1622 | | - if (profile.allowClass("EncodingError")) { |
1623 | | - encodingError = defineClass("EncodingError", standardError, standardError.getAllocator()); |
1624 | | - encodingCompatibilityError = defineClassUnder("CompatibilityError", encodingError, encodingError.getAllocator(), encodingClass); |
1625 | | - invalidByteSequenceError = defineClassUnder("InvalidByteSequenceError", encodingError, encodingError.getAllocator(), encodingClass); |
1626 | | - invalidByteSequenceError.defineAnnotatedMethods(RubyConverter.EncodingErrorMethods.class); |
1627 | | - invalidByteSequenceError.defineAnnotatedMethods(RubyConverter.InvalidByteSequenceErrorMethods.class); |
1628 | | - undefinedConversionError = defineClassUnder("UndefinedConversionError", encodingError, encodingError.getAllocator(), encodingClass); |
1629 | | - undefinedConversionError.defineAnnotatedMethods(RubyConverter.EncodingErrorMethods.class); |
1630 | | - undefinedConversionError.defineAnnotatedMethods(RubyConverter.UndefinedConversionErrorMethods.class); |
1631 | | - converterNotFoundError = defineClassUnder("ConverterNotFoundError", encodingError, encodingError.getAllocator(), encodingClass); |
1632 | | - fiberError = defineClass("FiberError", standardError, standardError.getAllocator()); |
1633 | | - } |
1634 | | - concurrencyError = defineClassIfAllowed("ConcurrencyError", threadError); |
1635 | | - keyError = defineClassIfAllowed("KeyError", indexError); |
1636 | | - |
1637 | | - mathDomainError = defineClassUnder("DomainError", argumentError, argumentError.getAllocator(), mathModule); |
1638 | | - |
1639 | | - initErrno(); |
1640 | 1631 | } |
1641 | 1632 |
|
1642 | 1633 | private void initLibraries() { |
|
0 commit comments