@@ -540,7 +540,7 @@ protected RubyBinding getCallerBinding(VirtualFrame frame) {
540540 public Object eval (VirtualFrame frame , RubyString source , UndefinedPlaceholder binding , UndefinedPlaceholder filename , UndefinedPlaceholder lineNumber ) {
541541 notDesignedForCompilation ();
542542
543- return eval (source , getCallerBinding (frame ), filename , lineNumber );
543+ return getContext (). eval (source . getBytes () , getCallerBinding (frame ), true , this );
544544 }
545545
546546 @ Specialization
@@ -555,36 +555,49 @@ public Object eval(VirtualFrame frame, RubyString source, RubyNilClass noBinding
555555 public Object eval (RubyString source , RubyBinding binding , UndefinedPlaceholder filename , UndefinedPlaceholder lineNumber ) {
556556 notDesignedForCompilation ();
557557
558- return getContext ().eval (source .getBytes (), binding , this );
558+ return getContext ().eval (source .getBytes (), binding , false , this );
559559 }
560560
561561 @ Specialization
562562 public Object eval (RubyString source , RubyBinding binding , RubyString filename , UndefinedPlaceholder lineNumber ) {
563563 notDesignedForCompilation ();
564564
565565 // TODO (nirvdrum Dec. 29, 2014) Do something with the supplied filename.
566- return getContext ().eval (source .getBytes (), binding , this );
566+ return getContext ().eval (source .getBytes (), binding , false , this );
567567 }
568568
569569 @ Specialization
570570 public Object eval (RubyString source , RubyBinding binding , RubyString filename , int lineNumber ) {
571571 notDesignedForCompilation ();
572572
573573 // TODO (nirvdrum Dec. 29, 2014) Do something with the supplied filename and lineNumber.
574- return getContext ().eval (source .getBytes (), binding , this );
574+ return getContext ().eval (source .getBytes (), binding , false , this );
575575 }
576576
577577 @ Specialization (guards = "!isRubyString(arguments[0])" )
578578 public Object eval (VirtualFrame frame , RubyBasicObject object , UndefinedPlaceholder binding , UndefinedPlaceholder filename , UndefinedPlaceholder lineNumber ) {
579579 notDesignedForCompilation ();
580580
581- return eval (frame , object , getCallerBinding (frame ), filename , lineNumber );
581+ return evalCoerced (frame , object , getCallerBinding (frame ), true , filename , lineNumber );
582582 }
583583
584584 @ Specialization (guards = "!isRubyString(arguments[0])" )
585585 public Object eval (VirtualFrame frame , RubyBasicObject object , RubyBinding binding , UndefinedPlaceholder filename , UndefinedPlaceholder lineNumber ) {
586586 notDesignedForCompilation ();
587587
588+ return evalCoerced (frame , object , binding , false , filename , lineNumber );
589+ }
590+
591+ @ Specialization (guards = "!isRubyBinding(arguments[1])" )
592+ public Object eval (RubyBasicObject source , RubyBasicObject badBinding , UndefinedPlaceholder filename , UndefinedPlaceholder lineNumber ) {
593+ throw new RaiseException (
594+ getContext ().getCoreLibrary ().typeError (
595+ String .format ("wrong argument type %s (expected binding)" ,
596+ badBinding .getLogicalClass ().getName ()),
597+ this ));
598+ }
599+
600+ private Object evalCoerced (VirtualFrame frame , RubyBasicObject object , RubyBinding binding , boolean ownScopeForAssignments , UndefinedPlaceholder filename , UndefinedPlaceholder lineNumber ) {
588601 Object coerced ;
589602
590603 try {
@@ -601,7 +614,7 @@ public Object eval(VirtualFrame frame, RubyBasicObject object, RubyBinding bindi
601614 }
602615
603616 if (coerced instanceof RubyString ) {
604- return getContext ().eval (((RubyString ) coerced ).getBytes (), binding , this );
617+ return getContext ().eval (((RubyString ) coerced ).getBytes (), binding , ownScopeForAssignments , this );
605618 } else {
606619 throw new RaiseException (
607620 getContext ().getCoreLibrary ().typeError (
@@ -612,15 +625,6 @@ public Object eval(VirtualFrame frame, RubyBasicObject object, RubyBinding bindi
612625 this ));
613626 }
614627 }
615-
616- @ Specialization (guards = "!isRubyBinding(arguments[1])" )
617- public Object eval (RubyBasicObject source , RubyBasicObject badBinding , UndefinedPlaceholder filename , UndefinedPlaceholder lineNumber ) {
618- throw new RaiseException (
619- getContext ().getCoreLibrary ().typeError (
620- String .format ("wrong argument type %s (expected binding)" ,
621- badBinding .getLogicalClass ().getName ()),
622- this ));
623- }
624628 }
625629
626630 @ CoreMethod (names = "exec" , isModuleFunction = true , required = 1 , argumentsAsArray = true )
0 commit comments