# HG changeset patch # User hannesw # Date 1427402365 -3600 # Node ID edd4d654c9be8fb0bee8479c1e2ac4435518d3ba # Parent dff9f4cfafd99702a1ade3c694b483a374db59ec 8075366: Slow scope access to global let/const does not work Reviewed-by: sundar, attila, lagergren diff -r dff9f4cfafd9 -r edd4d654c9be src/jdk/nashorn/internal/objects/Global.java --- a/src/jdk/nashorn/internal/objects/Global.java Wed Mar 25 17:43:55 2015 +0100 +++ b/src/jdk/nashorn/internal/objects/Global.java Thu Mar 26 21:39:25 2015 +0100 @@ -60,6 +60,7 @@ import jdk.nashorn.internal.objects.annotations.Setter; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.ECMAErrors; +import jdk.nashorn.internal.runtime.FindProperty; import jdk.nashorn.internal.runtime.GlobalConstants; import jdk.nashorn.internal.runtime.GlobalFunctions; import jdk.nashorn.internal.runtime.JSType; @@ -2205,6 +2206,17 @@ } @Override + protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { + if (lexicalScope != null && start != this && start.isScope()) { + final FindProperty find = lexicalScope.findProperty(key, false); + if (find != null) { + return find; + } + } + return super.findProperty(key, deep, start); + } + + @Override public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) { final boolean isScope = NashornCallSiteDescriptor.isScope(desc); diff -r dff9f4cfafd9 -r edd4d654c9be src/jdk/nashorn/internal/runtime/ScriptObject.java --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Mar 25 17:43:55 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Mar 26 21:39:25 2015 +0100 @@ -812,7 +812,7 @@ * * @return FindPropertyData or null if not found. */ - FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { + protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { final PropertyMap selfMap = getMap(); final Property property = selfMap.findProperty(key); diff -r dff9f4cfafd9 -r edd4d654c9be src/jdk/nashorn/internal/runtime/WithObject.java --- a/src/jdk/nashorn/internal/runtime/WithObject.java Wed Mar 25 17:43:55 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Thu Mar 26 21:39:25 2015 +0100 @@ -198,7 +198,7 @@ * @return FindPropertyData or null if not found. */ @Override - FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { + protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { // We call findProperty on 'expression' with 'expression' itself as start parameter. // This way in ScriptObject.setObject we can tell the property is from a 'with' expression // (as opposed from another non-scope object in the proto chain such as Object.prototype). diff -r dff9f4cfafd9 -r edd4d654c9be test/script/basic/es6/let-eval.js --- a/test/script/basic/es6/let-eval.js Wed Mar 25 17:43:55 2015 +0100 +++ b/test/script/basic/es6/let-eval.js Thu Mar 26 21:39:25 2015 +0100 @@ -96,3 +96,9 @@ f(); print(typeof a, typeof b, typeof c, typeof x, typeof z); + +let v = 1; +eval("print('v: ' + v); v = 2; print ('v: ' + v);"); +print("this.v: " + this.v); +print("v: " + v); + diff -r dff9f4cfafd9 -r edd4d654c9be test/script/basic/es6/let-eval.js.EXPECTED --- a/test/script/basic/es6/let-eval.js.EXPECTED Wed Mar 25 17:43:55 2015 +0100 +++ b/test/script/basic/es6/let-eval.js.EXPECTED Thu Mar 26 21:39:25 2015 +0100 @@ -14,3 +14,7 @@ 2 1 0 2 1 0 undefined undefined undefined undefined undefined undefined +v: 1 +v: 2 +this.v: undefined +v: 2