src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptRuntime.java
Print this page
@@ -371,13 +371,18 @@
*
* @param scope Scope to merge.
* @return prototype object after merge
*/
public static ScriptObject mergeScope(final ScriptObject scope) {
- final ScriptObject global = scope.getProto();
- global.addBoundProperties(scope);
- return global;
+ final ScriptObject proto = scope.getProto();
+ // Variable declarations go into the first parent scope that is not a with-statement
+ ScriptObject parentScope = proto;
+ while (parentScope instanceof WithObject) {
+ parentScope = parentScope.getProto();
+ }
+ parentScope.addBoundProperties(scope);
+ return proto;
}
/**
* Call a function given self and args. If the number of the arguments is known in advance, you can likely achieve
* better performance by {@link Bootstrap#createDynamicInvoker(String, Class, Class...) creating a dynamic invoker}