File tree Expand file tree Collapse file tree 3 files changed +21
-8
lines changed
core/src/main/java/org/jruby/runtime Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -317,10 +317,15 @@ public BacktraceElement getBacktrace() {
317
317
new Frame (),
318
318
Visibility .PUBLIC );
319
319
320
+ /**
321
+ * Duplicate this binding and setup the proper cloned instance of the eval scope so that any previously
322
+ * captured variables still exist but are not shared with the original binding.
323
+ * @param context the current thread context
324
+ * @return the duplicated binding
325
+ */
320
326
public Binding dup (ThreadContext context ) {
321
327
Binding newBinding = new Binding (this );
322
- DynamicScope scope = getEvalScope (context .runtime );
323
- newBinding .evalScope = scope .dup ();
328
+ newBinding .evalScope = getEvalScope (context .runtime ).dupEvalScope ();
324
329
return newBinding ;
325
330
}
326
331
}
Original file line number Diff line number Diff line change @@ -600,12 +600,13 @@ public DynamicScope cloneScope() {
600
600
}
601
601
}
602
602
603
- public DynamicScope dup () {
604
- DynamicScope newScope = new ManyVarsDynamicScope (staticScope .duplicate (), parent );
605
- IRubyObject [] values = getValues ();
606
- for (int i = 0 ; i < values .length ; i ++) {
607
- newScope .setValueDepthZero (values [i ], i );
608
- }
603
+ /**
604
+ * Binding needs to clone its scope with all the current values.
605
+ * @return a duplicate of this scope with all the current values
606
+ */
607
+ public DynamicScope dupEvalScope () {
608
+ ManyVarsDynamicScope newScope = new ManyVarsDynamicScope (staticScope .duplicate (), parent );
609
+ newScope .setVariableValues (getValues ());
609
610
return newScope ;
610
611
}
611
612
}
Original file line number Diff line number Diff line change @@ -50,6 +50,13 @@ private void allocate() {
50
50
if (variableValues == null ) variableValues = IRubyObject .array (staticScope .getNumberOfVariables ());
51
51
}
52
52
53
+ // WARNING: This is used when dup'ing an eval scope. We know the size and that it will 100% always be
54
+ // a ManyVarsDynamicScope. This should not be used by anything else. If there ever ends up being another
55
+ // use then it should be documented in this warning.
56
+ public void setVariableValues (IRubyObject [] variableValues ) {
57
+ this .variableValues = variableValues ;
58
+ }
59
+
53
60
public IRubyObject [] getValues () {
54
61
return variableValues ;
55
62
}
You can’t perform that action at this time.
0 commit comments