コード例 #1
0
ファイル: TryNode.java プロジェクト: godfat/jruby
 public TryNode(
     RubyContext context,
     SourceSection sourceSection,
     ExceptionTranslatingNode tryPart,
     RescueNode[] rescueParts,
     RubyNode elsePart) {
   super(context, sourceSection);
   this.tryPart = tryPart;
   this.rescueParts = rescueParts;
   this.elsePart = elsePart;
   clearExceptionVariableNode =
       new WriteInstanceVariableNode(
           context,
           sourceSection,
           "$!",
           new ObjectLiteralNode(
               context, sourceSection, context.getCoreLibrary().getGlobalVariablesObject()),
           new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject()),
           true);
 }
コード例 #2
0
ファイル: SequenceNode.java プロジェクト: godfat/jruby
  public static RubyNode sequence(
      RubyContext context, SourceSection sourceSection, List<RubyNode> sequence) {
    final List<RubyNode> flattened = flatten(sequence, true);

    if (flattened.isEmpty()) {
      return new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject());
    } else if (flattened.size() == 1) {
      return flattened.get(0);
    } else {
      return new SequenceNode(
          context, sourceSection, flattened.toArray(new RubyNode[flattened.size()]));
    }
  }
コード例 #3
0
ファイル: TryNode.java プロジェクト: jwinter/jruby
  private Object handleException(VirtualFrame frame, RuntimeException exception) {
    CompilerAsserts.neverPartOfCompilation();

    final RubyContext context = getContext();

    final RubyBasicObject rubyException =
        ExceptionTranslator.translateException(context, exception);

    context.getCoreLibrary().getGlobalVariablesObject().setInstanceVariable("$!", rubyException);

    for (RescueNode rescue : rescueParts) {
      if (rescue.canHandle(frame, rubyException)) {
        return rescue.execute(frame);
      }
    }

    throw exception;
  }