コード例 #1
0
ファイル: ToStrNode.java プロジェクト: r6p/jruby
  @Specialization(guards = "!isRubyString(object)")
  public RubyBasicObject coerceObject(VirtualFrame frame, Object object) {
    final Object coerced;

    try {
      coerced = toStrNode.call(frame, object, "to_str", null);
    } catch (RaiseException e) {
      if (((RubyBasicObject) e.getRubyException()).getLogicalClass()
          == getContext().getCoreLibrary().getNoMethodErrorClass()) {
        CompilerDirectives.transferToInterpreter();
        throw new RaiseException(
            getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "String", this));
      } else {
        throw e;
      }
    }

    if (RubyGuards.isRubyString(coerced)) {
      return (RubyBasicObject) coerced;
    } else {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(
          getContext()
              .getCoreLibrary()
              .typeErrorBadCoercion(object, "String", "to_str", coerced, this));
    }
  }
コード例 #2
0
ファイル: TryNode.java プロジェクト: godfat/jruby
  @ExplodeLoop
  private Object handleException(VirtualFrame frame, RaiseException exception) {
    CompilerAsserts.neverPartOfCompilation();

    notDesignedForCompilation();
    getContext()
        .getCoreLibrary()
        .getGlobalVariablesObject()
        .getOperations()
        .setInstanceVariable(
            getContext().getCoreLibrary().getGlobalVariablesObject(),
            "$!",
            exception.getRubyException());

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

    throw exception;
  }
コード例 #3
0
  @Override
  public Object isDefined(VirtualFrame frame) {
    final RubyConstant constant;
    try {
      constant = lookupConstantNode.executeLookupConstant(frame);
    } catch (RaiseException e) {
      if (Layouts.BASIC_OBJECT.getLogicalClass(((DynamicObject) e.getRubyException()))
          == getContext().getCoreLibrary().getNameErrorClass()) {
        // private constant
        return nil();
      }
      throw e;
    }

    if (constant == null) {
      return nil();
    } else {
      return Layouts.STRING.createString(
          getContext().getCoreLibrary().getStringFactory(),
          RubyString.encodeBytelist("constant", UTF8Encoding.INSTANCE),
          StringSupport.CR_7BIT,
          null);
    }
  }