8075366: Slow scope access to global let/const does not work

Thu, 26 Mar 2015 21:39:25 +0100

author
hannesw
date
Thu, 26 Mar 2015 21:39:25 +0100
changeset 1271
edd4d654c9be
parent 1270
dff9f4cfafd9
child 1272
c3dece9375d4

8075366: Slow scope access to global let/const does not work
Reviewed-by: sundar, attila, lagergren

src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/WithObject.java file | annotate | diff | comparison | revisions
test/script/basic/es6/let-eval.js file | annotate | diff | comparison | revisions
test/script/basic/es6/let-eval.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Wed Mar 25 17:43:55 2015 +0100
     1.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Thu Mar 26 21:39:25 2015 +0100
     1.3 @@ -60,6 +60,7 @@
     1.4  import jdk.nashorn.internal.objects.annotations.Setter;
     1.5  import jdk.nashorn.internal.runtime.Context;
     1.6  import jdk.nashorn.internal.runtime.ECMAErrors;
     1.7 +import jdk.nashorn.internal.runtime.FindProperty;
     1.8  import jdk.nashorn.internal.runtime.GlobalConstants;
     1.9  import jdk.nashorn.internal.runtime.GlobalFunctions;
    1.10  import jdk.nashorn.internal.runtime.JSType;
    1.11 @@ -2205,6 +2206,17 @@
    1.12      }
    1.13  
    1.14      @Override
    1.15 +    protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) {
    1.16 +        if (lexicalScope != null && start != this && start.isScope()) {
    1.17 +            final FindProperty find = lexicalScope.findProperty(key, false);
    1.18 +            if (find != null) {
    1.19 +                return find;
    1.20 +            }
    1.21 +        }
    1.22 +        return super.findProperty(key, deep, start);
    1.23 +    }
    1.24 +
    1.25 +    @Override
    1.26      public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    1.27          final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
    1.28  
     2.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Wed Mar 25 17:43:55 2015 +0100
     2.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Mar 26 21:39:25 2015 +0100
     2.3 @@ -812,7 +812,7 @@
     2.4       *
     2.5       * @return FindPropertyData or null if not found.
     2.6       */
     2.7 -    FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) {
     2.8 +    protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) {
     2.9  
    2.10          final PropertyMap selfMap  = getMap();
    2.11          final Property    property = selfMap.findProperty(key);
     3.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java	Wed Mar 25 17:43:55 2015 +0100
     3.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java	Thu Mar 26 21:39:25 2015 +0100
     3.3 @@ -198,7 +198,7 @@
     3.4       * @return FindPropertyData or null if not found.
     3.5       */
     3.6      @Override
     3.7 -    FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) {
     3.8 +    protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) {
     3.9          // We call findProperty on 'expression' with 'expression' itself as start parameter.
    3.10          // This way in ScriptObject.setObject we can tell the property is from a 'with' expression
    3.11          // (as opposed from another non-scope object in the proto chain such as Object.prototype).
     4.1 --- a/test/script/basic/es6/let-eval.js	Wed Mar 25 17:43:55 2015 +0100
     4.2 +++ b/test/script/basic/es6/let-eval.js	Thu Mar 26 21:39:25 2015 +0100
     4.3 @@ -96,3 +96,9 @@
     4.4  f();
     4.5  
     4.6  print(typeof a, typeof b, typeof c, typeof x, typeof z);
     4.7 +
     4.8 +let v = 1;
     4.9 +eval("print('v: ' + v); v = 2; print ('v: ' + v);");
    4.10 +print("this.v: " + this.v);
    4.11 +print("v: " + v);
    4.12 +
     5.1 --- a/test/script/basic/es6/let-eval.js.EXPECTED	Wed Mar 25 17:43:55 2015 +0100
     5.2 +++ b/test/script/basic/es6/let-eval.js.EXPECTED	Thu Mar 26 21:39:25 2015 +0100
     5.3 @@ -14,3 +14,7 @@
     5.4  2 1 0
     5.5  2 1 0 undefined
     5.6  undefined undefined undefined undefined undefined
     5.7 +v: 1
     5.8 +v: 2
     5.9 +this.v: undefined
    5.10 +v: 2

mercurial