Merge jdk8u45-b01

Fri, 12 Dec 2014 14:58:31 -0800

author
asaha
date
Fri, 12 Dec 2014 14:58:31 -0800
changeset 1285
21ec16eb7e63
parent 1284
b54270ace5e5
parent 1171
25ee71a761f5
child 1286
95ab924f3a47

Merge

.hgtags file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethod.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java file | annotate | diff | comparison | revisions
     1.1 --- a/.hgtags	Mon Dec 01 11:40:00 2014 -0800
     1.2 +++ b/.hgtags	Fri Dec 12 14:58:31 2014 -0800
     1.3 @@ -350,4 +350,6 @@
     1.4  7e34104c55cafa0b579be3a480dda383c616a378 jdk8u40-b14
     1.5  fc37699ddc0ed41d4ab5da821211a6d2648c8883 jdk8u40-b15
     1.6  e079f3f6d536510b1ab3589b1038d893d78302ac jdk8u40-b16
     1.7 +88e22262fdb26e3154a1034c2413415e97b9a86a jdk8u40-b17
     1.8 +653739706172ae94e999731a3a9f10f8ce11ffca jdk8u40-b18
     1.9  05a3614ed5276e5db2a73cce918be04b1a2922fb jdk8u45-b00
     2.1 --- a/src/jdk/nashorn/internal/codegen/AssignSymbols.java	Mon Dec 01 11:40:00 2014 -0800
     2.2 +++ b/src/jdk/nashorn/internal/codegen/AssignSymbols.java	Fri Dec 12 14:58:31 2014 -0800
     2.3 @@ -189,7 +189,7 @@
     2.4       * @param body the body of the FunctionNode we are entering
     2.5       */
     2.6      private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
     2.7 -        // This visitor will assign symbol to all declared variables, except "var" declarations in for loop initializers.
     2.8 +        // This visitor will assign symbol to all declared variables.
     2.9          body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
    2.10              @Override
    2.11              protected boolean enterDefault(final Node node) {
    2.12 @@ -200,16 +200,17 @@
    2.13  
    2.14              @Override
    2.15              public Node leaveVarNode(final VarNode varNode) {
    2.16 -                if (varNode.isStatement()) {
    2.17 -                    final IdentNode ident  = varNode.getName();
    2.18 -                    final Block block = varNode.isBlockScoped() ? getLexicalContext().getCurrentBlock() : body;
    2.19 -                    final Symbol symbol = defineSymbol(block, ident.getName(), ident, varNode.getSymbolFlags());
    2.20 -                    if (varNode.isFunctionDeclaration()) {
    2.21 -                        symbol.setIsFunctionDeclaration();
    2.22 -                    }
    2.23 -                    return varNode.setName(ident.setSymbol(symbol));
    2.24 +                final IdentNode ident  = varNode.getName();
    2.25 +                final boolean blockScoped = varNode.isBlockScoped();
    2.26 +                if (blockScoped && lc.inUnprotectedSwitchContext()) {
    2.27 +                    throwUnprotectedSwitchError(varNode);
    2.28                  }
    2.29 -                return varNode;
    2.30 +                final Block block = blockScoped ? lc.getCurrentBlock() : body;
    2.31 +                final Symbol symbol = defineSymbol(block, ident.getName(), ident, varNode.getSymbolFlags());
    2.32 +                if (varNode.isFunctionDeclaration()) {
    2.33 +                    symbol.setIsFunctionDeclaration();
    2.34 +                }
    2.35 +                return varNode.setName(ident.setSymbol(symbol));
    2.36              }
    2.37          });
    2.38      }
    2.39 @@ -356,6 +357,10 @@
    2.40                          throwParserException(ECMAErrors.getMessage("syntax.error.redeclare.variable", name), origin);
    2.41                      } else {
    2.42                          symbol.setHasBeenDeclared();
    2.43 +                        // Set scope flag on top-level block scoped symbols
    2.44 +                        if (function.isProgram() && function.getBody() == block) {
    2.45 +                            symbol.setIsScope();
    2.46 +                        }
    2.47                      }
    2.48                  } else if ((flags & IS_INTERNAL) != 0) {
    2.49                      // Always create a new definition.
    2.50 @@ -540,7 +545,7 @@
    2.51          final int flags;
    2.52          if (varNode.isAnonymousFunctionDeclaration()) {
    2.53              flags = IS_INTERNAL;
    2.54 -        } else if (lc.getCurrentFunction().isProgram()) {
    2.55 +        } else if (!varNode.isBlockScoped() && lc.getCurrentFunction().isProgram()) {
    2.56              flags = IS_SCOPE;
    2.57          } else {
    2.58              flags = 0;
    2.59 @@ -1044,6 +1049,15 @@
    2.60          return !(units == null || units.isEmpty());
    2.61      }
    2.62  
    2.63 +    private void throwUnprotectedSwitchError(final VarNode varNode) {
    2.64 +        // Block scoped declarations in switch statements without explicit blocks should be declared
    2.65 +        // in a common block that contains all the case clauses. We cannot support this without a
    2.66 +        // fundamental rewrite of how switch statements are handled (case nodes contain blocks and are
    2.67 +        // directly contained by switch node). As a temporary solution we throw a reference error here.
    2.68 +        final String msg = ECMAErrors.getMessage("syntax.error.unprotected.switch.declaration", varNode.isLet() ? "let" : "const");
    2.69 +        throwParserException(msg, varNode);
    2.70 +    }
    2.71 +
    2.72      private void throwParserException(final String message, final Node origin) {
    2.73          if (origin == null) {
    2.74              throw new ParserException(message);
     3.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Mon Dec 01 11:40:00 2014 -0800
     3.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Fri Dec 12 14:58:31 2014 -0800
     3.3 @@ -3264,6 +3264,13 @@
     3.4              emitContinueLabel(continueLabel, liveLocalsOnContinue);
     3.5          }
     3.6  
     3.7 +        if (loopNode.hasPerIterationScope() && lc.getParentBlock().needsScope()) {
     3.8 +            // ES6 for loops with LET init need a new scope for each iteration. We just create a shallow copy here.
     3.9 +            method.loadCompilerConstant(SCOPE);
    3.10 +            method.invoke(virtualCallNoLookup(ScriptObject.class, "copy", ScriptObject.class));
    3.11 +            method.storeCompilerConstant(SCOPE);
    3.12 +        }
    3.13 +
    3.14          if(method.isReachable()) {
    3.15              if(modify != null) {
    3.16                  lineNumber(loopNode);
     4.1 --- a/src/jdk/nashorn/internal/codegen/Lower.java	Mon Dec 01 11:40:00 2014 -0800
     4.2 +++ b/src/jdk/nashorn/internal/codegen/Lower.java	Fri Dec 12 14:58:31 2014 -0800
     4.3 @@ -525,7 +525,7 @@
     4.4  
     4.5          if (isAlwaysTrue(test)) {
     4.6              //turn it into a for node without a test.
     4.7 -            final ForNode forNode = (ForNode)new ForNode(whileNode.getLineNumber(), whileNode.getToken(), whileNode.getFinish(), body, ForNode.IS_FOR).accept(this);
     4.8 +            final ForNode forNode = (ForNode)new ForNode(whileNode.getLineNumber(), whileNode.getToken(), whileNode.getFinish(), body, 0).accept(this);
     4.9              lc.replace(whileNode, forNode);
    4.10              return forNode;
    4.11          }
     5.1 --- a/src/jdk/nashorn/internal/codegen/MapCreator.java	Mon Dec 01 11:40:00 2014 -0800
     5.2 +++ b/src/jdk/nashorn/internal/codegen/MapCreator.java	Fri Dec 12 14:58:31 2014 -0800
     5.3 @@ -152,6 +152,10 @@
     5.4              flags |= Property.NOT_WRITABLE;
     5.5          }
     5.6  
     5.7 +        if (symbol.isBlockScoped()) {
     5.8 +            flags |= Property.IS_LEXICAL_BINDING;
     5.9 +        }
    5.10 +
    5.11          // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    5.12          if (symbol.isBlockScoped() && symbol.isScope()) {
    5.13              flags |= Property.NEEDS_DECLARATION;
     6.1 --- a/src/jdk/nashorn/internal/ir/ForNode.java	Mon Dec 01 11:40:00 2014 -0800
     6.2 +++ b/src/jdk/nashorn/internal/ir/ForNode.java	Fri Dec 12 14:58:31 2014 -0800
     6.3 @@ -45,14 +45,14 @@
     6.4      /** Iterator symbol. */
     6.5      private Symbol iterator;
     6.6  
     6.7 -    /** Is this a normal for loop? */
     6.8 -    public static final int IS_FOR      = 1 << 0;
     6.9 -
    6.10      /** Is this a normal for in loop? */
    6.11 -    public static final int IS_FOR_IN   = 1 << 1;
    6.12 +    public static final int IS_FOR_IN           = 1 << 0;
    6.13  
    6.14      /** Is this a normal for each in loop? */
    6.15 -    public static final int IS_FOR_EACH = 1 << 2;
    6.16 +    public static final int IS_FOR_EACH         = 1 << 1;
    6.17 +
    6.18 +    /** Does this loop need a per-iteration scope because its init contain a LET declaration? */
    6.19 +    public static final int PER_ITERATION_SCOPE = 1 << 2;
    6.20  
    6.21      private final int flags;
    6.22  
    6.23 @@ -273,4 +273,18 @@
    6.24      JoinPredecessor setLocalVariableConversionChanged(final LexicalContext lc, final LocalVariableConversion conversion) {
    6.25          return Node.replaceInLexicalContext(lc, this, new ForNode(this, init, test, body, modify, flags, controlFlowEscapes, conversion));
    6.26      }
    6.27 +
    6.28 +    @Override
    6.29 +    public boolean hasPerIterationScope() {
    6.30 +        return (flags & PER_ITERATION_SCOPE) != 0;
    6.31 +    }
    6.32 +
    6.33 +    /**
    6.34 +     * Set the per-iteration-scope flag on this node.
    6.35 +     * @param lc lexical context
    6.36 +     * @return the node with flag set
    6.37 +     */
    6.38 +    public ForNode setPerIterationScope(final LexicalContext lc) {
    6.39 +        return setFlags(lc, flags | PER_ITERATION_SCOPE);
    6.40 +    }
    6.41  }
     7.1 --- a/src/jdk/nashorn/internal/ir/LexicalContext.java	Mon Dec 01 11:40:00 2014 -0800
     7.2 +++ b/src/jdk/nashorn/internal/ir/LexicalContext.java	Fri Dec 12 14:58:31 2014 -0800
     7.3 @@ -597,6 +597,20 @@
     7.4          throw new AssertionError(target + " was expected in lexical context " + LexicalContext.this + " but wasn't");
     7.5      }
     7.6  
     7.7 +    /**
     7.8 +     * Checks whether the current context is inside a switch statement without explicit blocks (curly braces).
     7.9 +     * @return true if in unprotected switch statement
    7.10 +     */
    7.11 +    public boolean inUnprotectedSwitchContext() {
    7.12 +        for (int i = sp; i > 0; i--) {
    7.13 +            final LexicalContextNode next = stack[i];
    7.14 +            if (next instanceof Block) {
    7.15 +                return stack[i - 1] instanceof SwitchNode;
    7.16 +            }
    7.17 +        }
    7.18 +        return false;
    7.19 +    }
    7.20 +
    7.21      @Override
    7.22      public String toString() {
    7.23          final StringBuffer sb = new StringBuffer();
     8.1 --- a/src/jdk/nashorn/internal/ir/LoopNode.java	Mon Dec 01 11:40:00 2014 -0800
     8.2 +++ b/src/jdk/nashorn/internal/ir/LoopNode.java	Fri Dec 12 14:58:31 2014 -0800
     8.3 @@ -176,4 +176,10 @@
     8.4       * @return new loop node if changed otherwise the same
     8.5       */
     8.6      public abstract LoopNode setControlFlowEscapes(final LexicalContext lc, final boolean controlFlowEscapes);
     8.7 +
     8.8 +    /**
     8.9 +     * Does this loop have a LET declaration and hence require a per-iteration scope?
    8.10 +     * @return true if a per-iteration scope is required.
    8.11 +     */
    8.12 +    public abstract boolean hasPerIterationScope();
    8.13  }
     9.1 --- a/src/jdk/nashorn/internal/ir/VarNode.java	Mon Dec 01 11:40:00 2014 -0800
     9.2 +++ b/src/jdk/nashorn/internal/ir/VarNode.java	Fri Dec 12 14:58:31 2014 -0800
     9.3 @@ -45,19 +45,16 @@
     9.4      /** Is this a var statement (as opposed to a "var" in a for loop statement) */
     9.5      private final int flags;
     9.6  
     9.7 -    /** Flag that determines if this function node is a statement */
     9.8 -    public static final int IS_STATEMENT                 = 1 << 0;
     9.9 -
    9.10      /** Flag for ES6 LET declaration */
    9.11 -    public static final int IS_LET                       = 1 << 1;
    9.12 +    public static final int IS_LET                       = 1 << 0;
    9.13  
    9.14      /** Flag for ES6 CONST declaration */
    9.15 -    public static final int IS_CONST                     = 1 << 2;
    9.16 +    public static final int IS_CONST                     = 1 << 1;
    9.17  
    9.18      /** Flag that determines if this is the last function declaration in a function
    9.19       *  This is used to micro optimize the placement of return value assignments for
    9.20       *  a program node */
    9.21 -    public static final int IS_LAST_FUNCTION_DECLARATION = 1 << 3;
    9.22 +    public static final int IS_LAST_FUNCTION_DECLARATION = 1 << 2;
    9.23  
    9.24      /**
    9.25       * Constructor
    9.26 @@ -69,7 +66,7 @@
    9.27       * @param init       init node or null if just a declaration
    9.28       */
    9.29      public VarNode(final int lineNumber, final long token, final int finish, final IdentNode name, final Expression init) {
    9.30 -        this(lineNumber, token, finish, name, init, IS_STATEMENT);
    9.31 +        this(lineNumber, token, finish, name, init, 0);
    9.32      }
    9.33  
    9.34      private VarNode(final VarNode varNode, final IdentNode name, final Expression init, final int flags) {
    9.35 @@ -260,14 +257,6 @@
    9.36      }
    9.37  
    9.38      /**
    9.39 -     * Returns true if this is a var statement (as opposed to a var initializer in a for loop).
    9.40 -     * @return true if this is a var statement (as opposed to a var initializer in a for loop).
    9.41 -     */
    9.42 -    public boolean isStatement() {
    9.43 -        return (flags & IS_STATEMENT) != 0;
    9.44 -    }
    9.45 -
    9.46 -    /**
    9.47       * Returns true if this is a function declaration.
    9.48       * @return true if this is a function declaration.
    9.49       */
    10.1 --- a/src/jdk/nashorn/internal/ir/WhileNode.java	Mon Dec 01 11:40:00 2014 -0800
    10.2 +++ b/src/jdk/nashorn/internal/ir/WhileNode.java	Fri Dec 12 14:58:31 2014 -0800
    10.3 @@ -148,4 +148,9 @@
    10.4          }
    10.5          return test == null;
    10.6      }
    10.7 +
    10.8 +    @Override
    10.9 +    public boolean hasPerIterationScope() {
   10.10 +        return false;
   10.11 +    }
   10.12  }
    11.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Mon Dec 01 11:40:00 2014 -0800
    11.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Fri Dec 12 14:58:31 2014 -0800
    11.3 @@ -34,6 +34,7 @@
    11.4  import java.io.PrintWriter;
    11.5  import java.lang.invoke.MethodHandle;
    11.6  import java.lang.invoke.MethodHandles;
    11.7 +import java.lang.invoke.MethodType;
    11.8  import java.lang.invoke.SwitchPoint;
    11.9  import java.lang.reflect.Field;
   11.10  import java.util.ArrayList;
   11.11 @@ -44,6 +45,7 @@
   11.12  import java.util.concurrent.ConcurrentHashMap;
   11.13  import javax.script.ScriptContext;
   11.14  import javax.script.ScriptEngine;
   11.15 +import jdk.internal.dynalink.CallSiteDescriptor;
   11.16  import jdk.internal.dynalink.linker.GuardedInvocation;
   11.17  import jdk.internal.dynalink.linker.LinkRequest;
   11.18  import jdk.nashorn.api.scripting.ClassFilter;
   11.19 @@ -54,6 +56,8 @@
   11.20  import jdk.nashorn.internal.objects.annotations.ScriptClass;
   11.21  import jdk.nashorn.internal.runtime.ConsString;
   11.22  import jdk.nashorn.internal.runtime.Context;
   11.23 +import jdk.nashorn.internal.runtime.ECMAErrors;
   11.24 +import jdk.nashorn.internal.runtime.GlobalConstants;
   11.25  import jdk.nashorn.internal.runtime.GlobalFunctions;
   11.26  import jdk.nashorn.internal.runtime.JSType;
   11.27  import jdk.nashorn.internal.runtime.NativeJavaPackage;
   11.28 @@ -69,6 +73,7 @@
   11.29  import jdk.nashorn.internal.runtime.arrays.ArrayData;
   11.30  import jdk.nashorn.internal.runtime.linker.Bootstrap;
   11.31  import jdk.nashorn.internal.runtime.linker.InvokeByName;
   11.32 +import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
   11.33  import jdk.nashorn.internal.runtime.regexp.RegExpResult;
   11.34  import jdk.nashorn.internal.scripts.JO;
   11.35  
   11.36 @@ -410,13 +415,14 @@
   11.37      // Used to store the last RegExp result to support deprecated RegExp constructor properties
   11.38      private RegExpResult lastRegExpResult;
   11.39  
   11.40 -    private static final MethodHandle EVAL              = findOwnMH_S("eval",                Object.class, Object.class, Object.class);
   11.41 -    private static final MethodHandle NO_SUCH_PROPERTY  = findOwnMH_S(NO_SUCH_PROPERTY_NAME, Object.class, Object.class, Object.class);
   11.42 -    private static final MethodHandle PRINT             = findOwnMH_S("print",               Object.class, Object.class, Object[].class);
   11.43 -    private static final MethodHandle PRINTLN           = findOwnMH_S("println",             Object.class, Object.class, Object[].class);
   11.44 -    private static final MethodHandle LOAD              = findOwnMH_S("load",                Object.class, Object.class, Object.class);
   11.45 -    private static final MethodHandle LOADWITHNEWGLOBAL = findOwnMH_S("loadWithNewGlobal",   Object.class, Object.class, Object[].class);
   11.46 -    private static final MethodHandle EXIT              = findOwnMH_S("exit",                Object.class, Object.class, Object.class);
   11.47 +    private static final MethodHandle EVAL                 = findOwnMH_S("eval",                Object.class, Object.class, Object.class);
   11.48 +    private static final MethodHandle NO_SUCH_PROPERTY     = findOwnMH_S(NO_SUCH_PROPERTY_NAME, Object.class, Object.class, Object.class);
   11.49 +    private static final MethodHandle PRINT                = findOwnMH_S("print",               Object.class, Object.class, Object[].class);
   11.50 +    private static final MethodHandle PRINTLN              = findOwnMH_S("println",             Object.class, Object.class, Object[].class);
   11.51 +    private static final MethodHandle LOAD                 = findOwnMH_S("load",                Object.class, Object.class, Object.class);
   11.52 +    private static final MethodHandle LOAD_WITH_NEW_GLOBAL = findOwnMH_S("loadWithNewGlobal",   Object.class, Object.class, Object[].class);
   11.53 +    private static final MethodHandle EXIT                 = findOwnMH_S("exit",                Object.class, Object.class, Object.class);
   11.54 +    private static final MethodHandle LEXICAL_SCOPE_FILTER = findOwnMH_S("lexicalScopeFilter", Object.class, Object.class);
   11.55  
   11.56      // initialized by nasgen
   11.57      private static PropertyMap $nasgenmap$;
   11.58 @@ -429,6 +435,12 @@
   11.59      // current ScriptEngine associated - can be null.
   11.60      private ScriptEngine engine;
   11.61  
   11.62 +    // ES6 global lexical scope.
   11.63 +    private final LexicalScope lexicalScope;
   11.64 +
   11.65 +    // Switchpoint for non-constant global callsites in the presence of ES6 lexical scope.
   11.66 +    private SwitchPoint lexicalScopeSwitchPoint;
   11.67 +
   11.68      /**
   11.69       * Set the current script context
   11.70       * @param scontext script context
   11.71 @@ -466,6 +478,7 @@
   11.72          super(checkAndGetMap(context));
   11.73          this.context = context;
   11.74          this.setIsScope();
   11.75 +        this.lexicalScope = context.getEnv()._es6 ? new LexicalScope(this) : null;
   11.76      }
   11.77  
   11.78      /**
   11.79 @@ -1694,6 +1707,133 @@
   11.80          splitState = state;
   11.81      }
   11.82  
   11.83 +    /**
   11.84 +     * Return the ES6 global scope for lexically declared bindings.
   11.85 +     * @return the ES6 lexical global scope.
   11.86 +     */
   11.87 +    public final ScriptObject getLexicalScope() {
   11.88 +        assert context.getEnv()._es6;
   11.89 +        return lexicalScope;
   11.90 +    }
   11.91 +
   11.92 +    @Override
   11.93 +    public void addBoundProperties(final ScriptObject source, final jdk.nashorn.internal.runtime.Property[] properties) {
   11.94 +        PropertyMap ownMap = getMap();
   11.95 +        LexicalScope lexicalScope = null;
   11.96 +        PropertyMap lexicalMap = null;
   11.97 +        boolean hasLexicalDefinitions = false;
   11.98 +
   11.99 +        if (context.getEnv()._es6) {
  11.100 +            lexicalScope = (LexicalScope) getLexicalScope();
  11.101 +            lexicalMap = lexicalScope.getMap();
  11.102 +
  11.103 +            for (final jdk.nashorn.internal.runtime.Property property : properties) {
  11.104 +                if (property.isLexicalBinding()) {
  11.105 +                    hasLexicalDefinitions = true;
  11.106 +                }
  11.107 +                // ES6 15.1.8 steps 6. and 7.
  11.108 +                final jdk.nashorn.internal.runtime.Property globalProperty = ownMap.findProperty(property.getKey());
  11.109 +                if (globalProperty != null && !globalProperty.isConfigurable() && property.isLexicalBinding()) {
  11.110 +                    throw ECMAErrors.syntaxError("redeclare.variable", property.getKey());
  11.111 +                }
  11.112 +                final jdk.nashorn.internal.runtime.Property lexicalProperty = lexicalMap.findProperty(property.getKey());
  11.113 +                if (lexicalProperty != null && !property.isConfigurable()) {
  11.114 +                    throw ECMAErrors.syntaxError("redeclare.variable", property.getKey());
  11.115 +                }
  11.116 +            }
  11.117 +        }
  11.118 +
  11.119 +        for (final jdk.nashorn.internal.runtime.Property property : properties) {
  11.120 +            if (property.isLexicalBinding()) {
  11.121 +                assert lexicalScope != null;
  11.122 +                lexicalMap = lexicalScope.addBoundProperty(lexicalMap, source, property);
  11.123 +
  11.124 +                if (ownMap.findProperty(property.getKey()) != null) {
  11.125 +                    // If property exists in the global object invalidate any global constant call sites.
  11.126 +                    invalidateGlobalConstant(property.getKey());
  11.127 +                }
  11.128 +            } else {
  11.129 +                ownMap = addBoundProperty(ownMap, source, property);
  11.130 +            }
  11.131 +        }
  11.132 +
  11.133 +        setMap(ownMap);
  11.134 +
  11.135 +        if (hasLexicalDefinitions) {
  11.136 +            lexicalScope.setMap(lexicalMap);
  11.137 +            invalidateLexicalSwitchPoint();
  11.138 +        }
  11.139 +    }
  11.140 +
  11.141 +    @Override
  11.142 +    public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
  11.143 +        final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
  11.144 +        final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
  11.145 +
  11.146 +        if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
  11.147 +            if (lexicalScope.hasOwnProperty(name)) {
  11.148 +                return lexicalScope.findGetMethod(desc, request, operator);
  11.149 +            }
  11.150 +        }
  11.151 +
  11.152 +        final GuardedInvocation invocation =  super.findGetMethod(desc, request, operator);
  11.153 +
  11.154 +        // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
  11.155 +        // because those are invalidated per-key in the addBoundProperties method above.
  11.156 +        // We therefor check if the invocation does already have a switchpoint and the property is non-inherited,
  11.157 +        // assuming this only applies to global constants. If other non-inherited properties will
  11.158 +        // start using switchpoints some time in the future we'll have to revisit this.
  11.159 +        if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
  11.160 +            return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
  11.161 +        }
  11.162 +
  11.163 +        return invocation;
  11.164 +    }
  11.165 +
  11.166 +    @Override
  11.167 +    public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
  11.168 +        final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
  11.169 +
  11.170 +        if (lexicalScope != null && isScope) {
  11.171 +            final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
  11.172 +            if (lexicalScope.hasOwnProperty(name)) {
  11.173 +                return lexicalScope.findSetMethod(desc, request);
  11.174 +            }
  11.175 +        }
  11.176 +
  11.177 +        final GuardedInvocation invocation = super.findSetMethod(desc, request);
  11.178 +
  11.179 +        if (isScope && context.getEnv()._es6) {
  11.180 +            return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
  11.181 +        }
  11.182 +
  11.183 +        return invocation;
  11.184 +    }
  11.185 +
  11.186 +    private synchronized SwitchPoint getLexicalScopeSwitchPoint() {
  11.187 +        SwitchPoint switchPoint = lexicalScopeSwitchPoint;
  11.188 +        if (switchPoint == null || switchPoint.hasBeenInvalidated()) {
  11.189 +            switchPoint = lexicalScopeSwitchPoint = new SwitchPoint();
  11.190 +        }
  11.191 +        return switchPoint;
  11.192 +    }
  11.193 +
  11.194 +    private synchronized void invalidateLexicalSwitchPoint() {
  11.195 +        if (lexicalScopeSwitchPoint != null) {
  11.196 +            context.getLogger(GlobalConstants.class).info("Invalidating non-constant globals on lexical scope update");
  11.197 +            SwitchPoint.invalidateAll(new SwitchPoint[]{ lexicalScopeSwitchPoint });
  11.198 +        }
  11.199 +    }
  11.200 +
  11.201 +
  11.202 +    @SuppressWarnings("unused")
  11.203 +    private static Object lexicalScopeFilter(final Object self) {
  11.204 +        if (self instanceof Global) {
  11.205 +            return ((Global) self).getLexicalScope();
  11.206 +        }
  11.207 +        return self;
  11.208 +    }
  11.209 +
  11.210      private <T extends ScriptObject> T initConstructorAndSwitchPoint(final String name, final Class<T> clazz) {
  11.211          final T func = initConstructor(name, clazz);
  11.212          tagBuiltinProperties(name, func);
  11.213 @@ -1739,7 +1879,7 @@
  11.214          this.unescape           = ScriptFunctionImpl.makeFunction("unescape",   GlobalFunctions.UNESCAPE);
  11.215          this.print              = ScriptFunctionImpl.makeFunction("print",      env._print_no_newline ? PRINT : PRINTLN);
  11.216          this.load               = ScriptFunctionImpl.makeFunction("load",       LOAD);
  11.217 -        this.loadWithNewGlobal  = ScriptFunctionImpl.makeFunction("loadWithNewGlobal", LOADWITHNEWGLOBAL);
  11.218 +        this.loadWithNewGlobal  = ScriptFunctionImpl.makeFunction("loadWithNewGlobal", LOAD_WITH_NEW_GLOBAL);
  11.219          this.exit               = ScriptFunctionImpl.makeFunction("exit",       EXIT);
  11.220          this.quit               = ScriptFunctionImpl.makeFunction("quit",       EXIT);
  11.221  
  11.222 @@ -2205,4 +2345,36 @@
  11.223      protected boolean isGlobal() {
  11.224          return true;
  11.225      }
  11.226 +
  11.227 +    /**
  11.228 +     * A class representing the ES6 global lexical scope.
  11.229 +     */
  11.230 +    private static class LexicalScope extends ScriptObject {
  11.231 +
  11.232 +        LexicalScope(final ScriptObject proto) {
  11.233 +            super(proto, PropertyMap.newMap());
  11.234 +        }
  11.235 +
  11.236 +        @Override
  11.237 +        protected GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
  11.238 +            return filterInvocation(super.findGetMethod(desc, request, operator));
  11.239 +        }
  11.240 +
  11.241 +        @Override
  11.242 +        protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
  11.243 +            return filterInvocation(super.findSetMethod(desc, request));
  11.244 +        }
  11.245 +
  11.246 +        @Override
  11.247 +        protected PropertyMap addBoundProperty(final PropertyMap propMap, final ScriptObject source, final jdk.nashorn.internal.runtime.Property property) {
  11.248 +            // We override this method just to make it callable by Global
  11.249 +            return super.addBoundProperty(propMap, source, property);
  11.250 +        }
  11.251 +
  11.252 +        private static GuardedInvocation filterInvocation(final GuardedInvocation invocation) {
  11.253 +            final MethodType type = invocation.getInvocation().type();
  11.254 +            return invocation.asType(type.changeParameterType(0, Object.class)).filterArguments(0, LEXICAL_SCOPE_FILTER);
  11.255 +        }
  11.256 +    }
  11.257 +
  11.258  }
    12.1 --- a/src/jdk/nashorn/internal/objects/NativeDataView.java	Mon Dec 01 11:40:00 2014 -0800
    12.2 +++ b/src/jdk/nashorn/internal/objects/NativeDataView.java	Fri Dec 12 14:58:31 2014 -0800
    12.3 @@ -105,10 +105,10 @@
    12.4  
    12.5      private NativeDataView(final NativeArrayBuffer arrBuf, final ByteBuffer buf, final int offset, final int length) {
    12.6          super(Global.instance().getDataViewPrototype(), $nasgenmap$);
    12.7 -        this.buffer = arrBuf;
    12.8 +        this.buffer     = arrBuf;
    12.9          this.byteOffset = offset;
   12.10          this.byteLength = length;
   12.11 -        this.buf = buf;
   12.12 +        this.buf        = buf;
   12.13      }
   12.14  
   12.15      /**
   12.16 @@ -135,14 +135,14 @@
   12.17              throw typeError("not.an.arraybuffer.in.dataview");
   12.18          }
   12.19  
   12.20 -        final NativeArrayBuffer arrBuf = (NativeArrayBuffer) args[0];
   12.21 +        final NativeArrayBuffer arrBuf = (NativeArrayBuffer)args[0];
   12.22          switch (args.length) {
   12.23 -            case 1:
   12.24 -                return new NativeDataView(arrBuf);
   12.25 -            case 2:
   12.26 -                return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
   12.27 -            default:
   12.28 -                return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
   12.29 +        case 1:
   12.30 +            return new NativeDataView(arrBuf);
   12.31 +        case 2:
   12.32 +            return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
   12.33 +        default:
   12.34 +            return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
   12.35          }
   12.36      }
   12.37  
   12.38 @@ -995,7 +995,7 @@
   12.39  
   12.40      private static NativeDataView checkSelf(final Object self) {
   12.41          if (!(self instanceof NativeDataView)) {
   12.42 -            throw typeError("not.an.arraybuffer", ScriptRuntime.safeToString(self));
   12.43 +            throw typeError("not.an.arraybuffer.in.dataview", ScriptRuntime.safeToString(self));
   12.44          }
   12.45          return (NativeDataView)self;
   12.46      }
    13.1 --- a/src/jdk/nashorn/internal/objects/NativeFunction.java	Mon Dec 01 11:40:00 2014 -0800
    13.2 +++ b/src/jdk/nashorn/internal/objects/NativeFunction.java	Fri Dec 12 14:58:31 2014 -0800
    13.3 @@ -48,6 +48,7 @@
    13.4  import jdk.nashorn.internal.runtime.ScriptFunction;
    13.5  import jdk.nashorn.internal.runtime.ScriptObject;
    13.6  import jdk.nashorn.internal.runtime.ScriptRuntime;
    13.7 +import jdk.nashorn.internal.runtime.linker.Bootstrap;
    13.8  
    13.9  /**
   13.10   * ECMA 15.3 Function Objects
   13.11 @@ -204,11 +205,7 @@
   13.12       * @return function with bound arguments
   13.13       */
   13.14      @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
   13.15 -    public static ScriptFunction bind(final Object self, final Object... args) {
   13.16 -        if (!(self instanceof ScriptFunction)) {
   13.17 -            throw typeError("not.a.function", ScriptRuntime.safeToString(self));
   13.18 -        }
   13.19 -
   13.20 +    public static Object bind(final Object self, final Object... args) {
   13.21          final Object thiz = (args.length == 0) ? UNDEFINED : args[0];
   13.22  
   13.23          Object[] arguments;
   13.24 @@ -219,7 +216,7 @@
   13.25              arguments = ScriptRuntime.EMPTY_ARRAY;
   13.26          }
   13.27  
   13.28 -        return ((ScriptFunctionImpl)self).makeBoundFunction(thiz, arguments);
   13.29 +        return Bootstrap.bindCallable(self, thiz, arguments);
   13.30      }
   13.31  
   13.32      /**
    14.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java	Mon Dec 01 11:40:00 2014 -0800
    14.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java	Fri Dec 12 14:58:31 2014 -0800
    14.3 @@ -28,6 +28,7 @@
    14.4  import static jdk.nashorn.internal.lookup.Lookup.MH;
    14.5  import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
    14.6  import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
    14.7 +
    14.8  import java.lang.invoke.MethodHandle;
    14.9  import java.lang.invoke.MethodHandles;
   14.10  import java.lang.invoke.MethodType;
   14.11 @@ -804,7 +805,7 @@
   14.12              // name and object linked with BeansLinker. (Actually, an even stronger assumption is true: return value is
   14.13              // constant for any given method name and object's class.)
   14.14              return MethodHandles.dropArguments(MethodHandles.constant(Object.class,
   14.15 -                    Bootstrap.bindDynamicMethod(methodGetter.invoke(source), source)), 0, Object.class);
   14.16 +                    Bootstrap.bindCallable(methodGetter.invoke(source), source, null)), 0, Object.class);
   14.17          } catch(RuntimeException|Error e) {
   14.18              throw e;
   14.19          } catch(final Throwable t) {
    15.1 --- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Mon Dec 01 11:40:00 2014 -0800
    15.2 +++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Fri Dec 12 14:58:31 2014 -0800
    15.3 @@ -30,7 +30,6 @@
    15.4  
    15.5  import java.lang.invoke.MethodHandle;
    15.6  import java.util.ArrayList;
    15.7 -
    15.8  import jdk.nashorn.internal.runtime.AccessorProperty;
    15.9  import jdk.nashorn.internal.runtime.GlobalFunctions;
   15.10  import jdk.nashorn.internal.runtime.Property;
   15.11 @@ -237,13 +236,13 @@
   15.12  
   15.13      /**
   15.14       * Same as {@link ScriptFunction#makeBoundFunction(Object, Object[])}. The only reason we override it is so that we
   15.15 -     * can expose it to methods in this package.
   15.16 +     * can expose it.
   15.17       * @param self the self to bind to this function. Can be null (in which case, null is bound as this).
   15.18       * @param args additional arguments to bind to this function. Can be null or empty to not bind additional arguments.
   15.19       * @return a function with the specified self and parameters bound.
   15.20       */
   15.21      @Override
   15.22 -    protected ScriptFunction makeBoundFunction(final Object self, final Object[] args) {
   15.23 +    public ScriptFunction makeBoundFunction(final Object self, final Object[] args) {
   15.24          return super.makeBoundFunction(self, args);
   15.25      }
   15.26  
    16.1 --- a/src/jdk/nashorn/internal/parser/Parser.java	Mon Dec 01 11:40:00 2014 -0800
    16.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java	Fri Dec 12 14:58:31 2014 -0800
    16.3 @@ -559,7 +559,7 @@
    16.4          // Set up new block. Captures first token.
    16.5          Block newBlock = newBlock();
    16.6          try {
    16.7 -            statement();
    16.8 +            statement(false, false, true);
    16.9          } finally {
   16.10              newBlock = restoreBlock(newBlock);
   16.11          }
   16.12 @@ -707,20 +707,9 @@
   16.13              FunctionNode.Kind.SCRIPT,
   16.14              functionLine);
   16.15  
   16.16 -        // If ES6 block scope is enabled add a per-script block for top-level LET and CONST declarations.
   16.17 -        final int startLine = start;
   16.18 -        Block outer = useBlockScope() ? newBlock() : null;
   16.19          functionDeclarations = new ArrayList<>();
   16.20 -
   16.21 -        try {
   16.22 -            sourceElements(allowPropertyFunction);
   16.23 -            addFunctionDeclarations(script);
   16.24 -        } finally {
   16.25 -            if (outer != null) {
   16.26 -                outer = restoreBlock(outer);
   16.27 -                appendStatement(new BlockStatement(startLine, outer));
   16.28 -            }
   16.29 -        }
   16.30 +        sourceElements(allowPropertyFunction);
   16.31 +        addFunctionDeclarations(script);
   16.32          functionDeclarations = null;
   16.33  
   16.34          expect(EOF);
   16.35 @@ -783,7 +772,7 @@
   16.36  
   16.37                  try {
   16.38                      // Get the next element.
   16.39 -                    statement(true, allowPropertyFunction);
   16.40 +                    statement(true, allowPropertyFunction, false);
   16.41                      allowPropertyFunction = false;
   16.42  
   16.43                      // check for directive prologues
   16.44 @@ -873,13 +862,15 @@
   16.45       * Parse any of the basic statement types.
   16.46       */
   16.47      private void statement() {
   16.48 -        statement(false, false);
   16.49 +        statement(false, false, false);
   16.50      }
   16.51  
   16.52      /**
   16.53       * @param topLevel does this statement occur at the "top level" of a script or a function?
   16.54 +     * @param allowPropertyFunction allow property "get" and "set" functions?
   16.55 +     * @param singleStatement are we in a single statement context?
   16.56       */
   16.57 -    private void statement(final boolean topLevel, final boolean allowPropertyFunction) {
   16.58 +    private void statement(final boolean topLevel, final boolean allowPropertyFunction, final boolean singleStatement) {
   16.59          if (type == FUNCTION) {
   16.60              // As per spec (ECMA section 12), function declarations as arbitrary statement
   16.61              // is not "portable". Implementation can issue a warning or disallow the same.
   16.62 @@ -943,6 +934,9 @@
   16.63              break;
   16.64          default:
   16.65              if (useBlockScope() && (type == LET || type == CONST)) {
   16.66 +                if (singleStatement) {
   16.67 +                    throw error(AbstractParser.message("expected.stmt", type.getName() + " declaration"), token);
   16.68 +                }
   16.69                  variableStatement(type, true);
   16.70                  break;
   16.71              }
   16.72 @@ -1068,7 +1062,7 @@
   16.73          next();
   16.74  
   16.75          final List<VarNode> vars = new ArrayList<>();
   16.76 -        int varFlags = VarNode.IS_STATEMENT;
   16.77 +        int varFlags = 0;
   16.78          if (varType == LET) {
   16.79              varFlags |= VarNode.IS_LET;
   16.80          } else if (varType == CONST) {
   16.81 @@ -1221,7 +1215,7 @@
   16.82          Block outer = useBlockScope() ? newBlock() : null;
   16.83  
   16.84          // Create FOR node, capturing FOR token.
   16.85 -        ForNode forNode = new ForNode(line, token, Token.descPosition(token), null, ForNode.IS_FOR);
   16.86 +        ForNode forNode = new ForNode(line, token, Token.descPosition(token), null, 0);
   16.87          lc.push(forNode);
   16.88  
   16.89          try {
   16.90 @@ -1241,19 +1235,22 @@
   16.91  
   16.92              switch (type) {
   16.93              case VAR:
   16.94 -                // Var statements captured in for outer block.
   16.95 +                // Var declaration captured in for outer block.
   16.96                  vars = variableStatement(type, false);
   16.97                  break;
   16.98              case SEMICOLON:
   16.99                  break;
  16.100              default:
  16.101                  if (useBlockScope() && (type == LET || type == CONST)) {
  16.102 -                    // LET/CONST captured in container block created above.
  16.103 +                    if (type == LET) {
  16.104 +                        forNode = forNode.setPerIterationScope(lc);
  16.105 +                    }
  16.106 +                    // LET/CONST declaration captured in container block created above.
  16.107                      vars = variableStatement(type, false);
  16.108                      break;
  16.109                  }
  16.110                  if (env._const_as_var && type == CONST) {
  16.111 -                    // Var statements captured in for outer block.
  16.112 +                    // Var declaration captured in for outer block.
  16.113                      vars = variableStatement(TokenType.VAR, false);
  16.114                      break;
  16.115                  }
  16.116 @@ -1334,11 +1331,12 @@
  16.117              appendStatement(forNode);
  16.118          } finally {
  16.119              lc.pop(forNode);
  16.120 -            if (outer != null) {
  16.121 -                outer.setFinish(forNode.getFinish());
  16.122 -                outer = restoreBlock(outer);
  16.123 -                appendStatement(new BlockStatement(startLine, outer));
  16.124 -            }
  16.125 +        }
  16.126 +
  16.127 +        if (outer != null) {
  16.128 +            outer.setFinish(forNode.getFinish());
  16.129 +            outer = restoreBlock(outer);
  16.130 +            appendStatement(new BlockStatement(startLine, outer));
  16.131          }
  16.132      }
  16.133  
  16.134 @@ -2710,11 +2708,7 @@
  16.135          }
  16.136  
  16.137          if (isStatement) {
  16.138 -            int varFlags = VarNode.IS_STATEMENT;
  16.139 -            if (!topLevel && useBlockScope()) {
  16.140 -                // mark ES6 block functions as lexically scoped
  16.141 -                varFlags |= VarNode.IS_LET;
  16.142 -            }
  16.143 +            final int     varFlags = (topLevel || !useBlockScope()) ? 0 : VarNode.IS_LET;
  16.144              final VarNode varNode = new VarNode(functionLine, functionToken, finish, name, functionNode, varFlags);
  16.145              if (topLevel) {
  16.146                  functionDeclarations.add(varNode);
    17.1 --- a/src/jdk/nashorn/internal/runtime/CodeStore.java	Mon Dec 01 11:40:00 2014 -0800
    17.2 +++ b/src/jdk/nashorn/internal/runtime/CodeStore.java	Fri Dec 12 14:58:31 2014 -0800
    17.3 @@ -82,10 +82,9 @@
    17.4       * Returns a new code store instance.
    17.5       *
    17.6       * @param context the current context
    17.7 -     * @return The instance
    17.8 -     * @throws IOException If an error occurs
    17.9 +     * @return The instance, or null if code store could not be created
   17.10       */
   17.11 -    public static CodeStore newCodeStore(final Context context) throws IOException {
   17.12 +    public static CodeStore newCodeStore(final Context context) {
   17.13          final Class<CodeStore> baseClass = CodeStore.class;
   17.14          try {
   17.15              // security check first
   17.16 @@ -103,9 +102,14 @@
   17.17          } catch (final AccessControlException e) {
   17.18              context.getLogger(CodeStore.class).warning("failed to load code store provider ", e);
   17.19          }
   17.20 -        final CodeStore store = new DirectoryCodeStore(context);
   17.21 -        store.initLogger(context);
   17.22 -        return store;
   17.23 +        try {
   17.24 +            final CodeStore store = new DirectoryCodeStore(context);
   17.25 +            store.initLogger(context);
   17.26 +            return store;
   17.27 +        } catch (final IOException e) {
   17.28 +            context.getLogger(CodeStore.class).warning("failed to create cache directory ", e);
   17.29 +            return null;
   17.30 +        }
   17.31      }
   17.32  
   17.33  
    18.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Mon Dec 01 11:40:00 2014 -0800
    18.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Fri Dec 12 14:58:31 2014 -0800
    18.3 @@ -509,11 +509,7 @@
    18.4          }
    18.5  
    18.6          if (env._persistent_cache) {
    18.7 -            try {
    18.8 -                codeStore = newCodeStore(this);
    18.9 -            } catch (final IOException e) {
   18.10 -                throw new RuntimeException("Error initializing code cache", e);
   18.11 -            }
   18.12 +            codeStore = newCodeStore(this);
   18.13          }
   18.14  
   18.15          // print version info if asked.
   18.16 @@ -1200,7 +1196,7 @@
   18.17          FunctionNode functionNode = null;
   18.18          // We only use the code store here if optimistic types are disabled. With optimistic types, initial compilation
   18.19          // just creates a thin wrapper, and actual code is stored per function in RecompilableScriptFunctionData.
   18.20 -        final boolean useCodeStore = env._persistent_cache && !env._parse_only && !env._optimistic_types;
   18.21 +        final boolean useCodeStore = codeStore != null && !env._parse_only && !env._optimistic_types;
   18.22          final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null;
   18.23  
   18.24          if (useCodeStore) {
    19.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java	Mon Dec 01 11:40:00 2014 -0800
    19.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java	Fri Dec 12 14:58:31 2014 -0800
    19.3 @@ -714,6 +714,9 @@
    19.4       * @return a number
    19.5       */
    19.6      public static double toNumber(final Object obj) {
    19.7 +        if (obj instanceof Double) {
    19.8 +            return (Double)obj;
    19.9 +        }
   19.10          if (obj instanceof Number) {
   19.11              return ((Number)obj).doubleValue();
   19.12          }
    20.1 --- a/src/jdk/nashorn/internal/runtime/Property.java	Mon Dec 01 11:40:00 2014 -0800
    20.2 +++ b/src/jdk/nashorn/internal/runtime/Property.java	Fri Dec 12 14:58:31 2014 -0800
    20.3 @@ -84,14 +84,17 @@
    20.4      public static final int IS_NASGEN_PRIMITIVE     = 1 << 6;
    20.5  
    20.6      /** Is this a builtin property, e.g. Function.prototype.apply */
    20.7 -    public static final int IS_BUILTIN = 1 << 7;
    20.8 +    public static final int IS_BUILTIN              = 1 << 7;
    20.9  
   20.10      /** Is this property bound to a receiver? This means get/set operations will be delegated to
   20.11       *  a statically defined object instead of the object passed as callsite parameter. */
   20.12 -    public static final int IS_BOUND                = 1 << 7;
   20.13 +    public static final int IS_BOUND                = 1 << 8;
   20.14  
   20.15      /** Is this a lexically scoped LET or CONST variable that is dead until it is declared. */
   20.16 -    public static final int NEEDS_DECLARATION       = 1 << 8;
   20.17 +    public static final int NEEDS_DECLARATION       = 1 << 9;
   20.18 +
   20.19 +    /** Is this property an ES6 lexical binding? */
   20.20 +    public static final int IS_LEXICAL_BINDING      = 1 << 10;
   20.21  
   20.22      /** Property key. */
   20.23      private final String key;
   20.24 @@ -714,4 +717,12 @@
   20.25      public boolean isFunctionDeclaration() {
   20.26          return (flags & IS_FUNCTION_DECLARATION) == IS_FUNCTION_DECLARATION;
   20.27      }
   20.28 +
   20.29 +    /**
   20.30 +     * Is this a property defined by ES6 let or const?
   20.31 +     * @return true if this property represents a lexical binding.
   20.32 +     */
   20.33 +    public boolean isLexicalBinding() {
   20.34 +        return (flags & IS_LEXICAL_BINDING) == IS_LEXICAL_BINDING;
   20.35 +    }
   20.36  }
    21.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Mon Dec 01 11:40:00 2014 -0800
    21.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Fri Dec 12 14:58:31 2014 -0800
    21.3 @@ -46,6 +46,8 @@
    21.4  import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.isValid;
    21.5  import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndex;
    21.6  import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
    21.7 +import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.isScopeFlag;
    21.8 +import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.isStrictFlag;
    21.9  import static jdk.nashorn.internal.runtime.linker.NashornGuards.explicitInstanceOfCheck;
   21.10  
   21.11  import java.lang.invoke.MethodHandle;
   21.12 @@ -98,7 +100,7 @@
   21.13   * </ul>
   21.14   */
   21.15  
   21.16 -public abstract class ScriptObject implements PropertyAccess {
   21.17 +public abstract class ScriptObject implements PropertyAccess, Cloneable {
   21.18      /** __proto__ special property name inside object literals. ES6 draft. */
   21.19      public static final String PROTO_PROPERTY_NAME   = "__proto__";
   21.20  
   21.21 @@ -304,29 +306,44 @@
   21.22          PropertyMap newMap = this.getMap();
   21.23  
   21.24          for (final Property property : properties) {
   21.25 -            final String key = property.getKey();
   21.26 -            final Property oldProp = newMap.findProperty(key);
   21.27 -            if (oldProp == null) {
   21.28 -                if (property instanceof UserAccessorProperty) {
   21.29 -                    // Note: we copy accessor functions to this object which is semantically different from binding.
   21.30 -                    final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source));
   21.31 -                    newMap = newMap.addPropertyNoHistory(prop);
   21.32 -                } else {
   21.33 -                    newMap = newMap.addPropertyBind((AccessorProperty)property, source);
   21.34 -                }
   21.35 +            newMap = addBoundProperty(newMap, source, property);
   21.36 +        }
   21.37 +
   21.38 +        this.setMap(newMap);
   21.39 +    }
   21.40 +
   21.41 +    /**
   21.42 +     * Add a bound property from {@code source}, using the interim property map {@code propMap}, and return the
   21.43 +     * new interim property map.
   21.44 +     *
   21.45 +     * @param propMap the property map
   21.46 +     * @param source the source object
   21.47 +     * @param property the property to be added
   21.48 +     * @return the new property map
   21.49 +     */
   21.50 +    protected PropertyMap addBoundProperty(final PropertyMap propMap, final ScriptObject source, final Property property) {
   21.51 +        PropertyMap newMap = propMap;
   21.52 +        final String key = property.getKey();
   21.53 +        final Property oldProp = newMap.findProperty(key);
   21.54 +        if (oldProp == null) {
   21.55 +            if (property instanceof UserAccessorProperty) {
   21.56 +                // Note: we copy accessor functions to this object which is semantically different from binding.
   21.57 +                final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source));
   21.58 +                newMap = newMap.addPropertyNoHistory(prop);
   21.59              } else {
   21.60 -                // See ECMA section 10.5 Declaration Binding Instantiation
   21.61 -                // step 5 processing each function declaration.
   21.62 -                if (property.isFunctionDeclaration() && !oldProp.isConfigurable()) {
   21.63 -                     if (oldProp instanceof UserAccessorProperty ||
   21.64 -                         !(oldProp.isWritable() && oldProp.isEnumerable())) {
   21.65 -                         throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
   21.66 -                     }
   21.67 +                newMap = newMap.addPropertyBind((AccessorProperty)property, source);
   21.68 +            }
   21.69 +        } else {
   21.70 +            // See ECMA section 10.5 Declaration Binding Instantiation
   21.71 +            // step 5 processing each function declaration.
   21.72 +            if (property.isFunctionDeclaration() && !oldProp.isConfigurable()) {
   21.73 +                if (oldProp instanceof UserAccessorProperty ||
   21.74 +                        !(oldProp.isWritable() && oldProp.isEnumerable())) {
   21.75 +                    throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
   21.76                  }
   21.77              }
   21.78          }
   21.79 -
   21.80 -        this.setMap(newMap);
   21.81 +        return newMap;
   21.82      }
   21.83  
   21.84      /**
   21.85 @@ -510,7 +527,11 @@
   21.86          }
   21.87      }
   21.88  
   21.89 -    private void invalidateGlobalConstant(final String key) {
   21.90 +    /**
   21.91 +     * Invalidate any existing global constant method handles that may exist for {@code key}.
   21.92 +     * @param key the property name
   21.93 +     */
   21.94 +    protected void invalidateGlobalConstant(final String key) {
   21.95          final GlobalConstants globalConstants = getGlobalConstants();
   21.96          if (globalConstants != null) {
   21.97              globalConstants.delete(key);
   21.98 @@ -2183,6 +2204,9 @@
   21.99  
  21.100          if (find != null) {
  21.101              if (!find.getProperty().isWritable() && !NashornCallSiteDescriptor.isDeclaration(desc)) {
  21.102 +                if (NashornCallSiteDescriptor.isScope(desc) && find.getProperty().isLexicalBinding()) {
  21.103 +                    throw typeError("assign.constant", name); // Overwriting ES6 const should throw also in non-strict mode.
  21.104 +                }
  21.105                  // Existing, non-writable property
  21.106                  return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
  21.107              }
  21.108 @@ -3084,7 +3108,7 @@
  21.109      private boolean doesNotHaveEnsureLength(final long longIndex, final long oldLength, final int callSiteFlags) {
  21.110          if (longIndex >= oldLength) {
  21.111              if (!isExtensible()) {
  21.112 -                if (NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)) {
  21.113 +                if (isStrictFlag(callSiteFlags)) {
  21.114                      throw typeError("object.non.extensible", JSType.toString(longIndex), ScriptRuntime.safeToString(this));
  21.115                  }
  21.116                  return true;
  21.117 @@ -3108,7 +3132,7 @@
  21.118          final long oldLength = getArray().length();
  21.119          final long longIndex = ArrayIndex.toLongIndex(index);
  21.120          if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) {
  21.121 -            final boolean strict = NashornCallSiteDescriptor.isStrictFlag(callSiteFlags);
  21.122 +            final boolean strict = isStrictFlag(callSiteFlags);
  21.123              setArray(getArray().set(index, value, strict));
  21.124              doesNotHaveEnsureDelete(longIndex, oldLength, strict);
  21.125          }
  21.126 @@ -3118,7 +3142,7 @@
  21.127          final long oldLength = getArray().length();
  21.128          final long longIndex = ArrayIndex.toLongIndex(index);
  21.129          if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) {
  21.130 -            final boolean strict = NashornCallSiteDescriptor.isStrictFlag(callSiteFlags);
  21.131 +            final boolean strict = isStrictFlag(callSiteFlags);
  21.132              setArray(getArray().set(index, value, strict));
  21.133              doesNotHaveEnsureDelete(longIndex, oldLength, strict);
  21.134          }
  21.135 @@ -3128,7 +3152,7 @@
  21.136          final long oldLength = getArray().length();
  21.137          final long longIndex = ArrayIndex.toLongIndex(index);
  21.138          if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) {
  21.139 -            final boolean strict = NashornCallSiteDescriptor.isStrictFlag(callSiteFlags);
  21.140 +            final boolean strict = isStrictFlag(callSiteFlags);
  21.141              setArray(getArray().set(index, value, strict));
  21.142              doesNotHaveEnsureDelete(longIndex, oldLength, strict);
  21.143          }
  21.144 @@ -3138,7 +3162,7 @@
  21.145          final long oldLength = getArray().length();
  21.146          final long longIndex = ArrayIndex.toLongIndex(index);
  21.147          if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) {
  21.148 -            final boolean strict = NashornCallSiteDescriptor.isStrictFlag(callSiteFlags);
  21.149 +            final boolean strict = isStrictFlag(callSiteFlags);
  21.150              setArray(getArray().set(index, value, strict));
  21.151              doesNotHaveEnsureDelete(longIndex, oldLength, strict);
  21.152          }
  21.153 @@ -3159,7 +3183,7 @@
  21.154          invalidateGlobalConstant(key);
  21.155  
  21.156          if (f != null && f.isInherited() && !(f.getProperty() instanceof UserAccessorProperty)) {
  21.157 -            final boolean isScope = NashornCallSiteDescriptor.isScopeFlag(callSiteFlags);
  21.158 +            final boolean isScope = isScopeFlag(callSiteFlags);
  21.159              // If the start object of the find is not this object it means the property was found inside a
  21.160              // 'with' statement expression (see WithObject.findProperty()). In this case we forward the 'set'
  21.161              // to the 'with' object.
  21.162 @@ -3180,16 +3204,19 @@
  21.163  
  21.164          if (f != null) {
  21.165              if (!f.getProperty().isWritable()) {
  21.166 -                if (NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)) {
  21.167 +                if (isScopeFlag(callSiteFlags) && f.getProperty().isLexicalBinding()) {
  21.168 +                    throw typeError("assign.constant", key); // Overwriting ES6 const should throw also in non-strict mode.
  21.169 +                }
  21.170 +                if (isStrictFlag(callSiteFlags)) {
  21.171                      throw typeError("property.not.writable", key, ScriptRuntime.safeToString(this));
  21.172                  }
  21.173                  return;
  21.174              }
  21.175  
  21.176 -            f.setValue(value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags));
  21.177 +            f.setValue(value, isStrictFlag(callSiteFlags));
  21.178  
  21.179          } else if (!isExtensible()) {
  21.180 -            if (NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)) {
  21.181 +            if (isStrictFlag(callSiteFlags)) {
  21.182                  throw typeError("object.non.extensible", key, ScriptRuntime.safeToString(this));
  21.183              }
  21.184          } else {
  21.185 @@ -3216,7 +3243,7 @@
  21.186          if (isValidArrayIndex(index)) {
  21.187              final ArrayData data = getArray();
  21.188              if (data.has(index)) {
  21.189 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.190 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.191              } else {
  21.192                  doesNotHave(index, value, callSiteFlags);
  21.193              }
  21.194 @@ -3236,7 +3263,7 @@
  21.195          if (isValidArrayIndex(index)) {
  21.196              final ArrayData data = getArray();
  21.197              if (data.has(index)) {
  21.198 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.199 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.200              } else {
  21.201                  doesNotHave(index, value, callSiteFlags);
  21.202              }
  21.203 @@ -3256,7 +3283,7 @@
  21.204          if (isValidArrayIndex(index)) {
  21.205              final ArrayData data = getArray();
  21.206              if (data.has(index)) {
  21.207 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.208 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.209              } else {
  21.210                  doesNotHave(index, value, callSiteFlags);
  21.211              }
  21.212 @@ -3276,7 +3303,7 @@
  21.213          if (isValidArrayIndex(index)) {
  21.214              final ArrayData data = getArray();
  21.215              if (data.has(index)) {
  21.216 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.217 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.218              } else {
  21.219                  doesNotHave(index, value, callSiteFlags);
  21.220              }
  21.221 @@ -3295,7 +3322,7 @@
  21.222          if (isValidArrayIndex(index)) {
  21.223              final ArrayData data = getArray();
  21.224              if (data.has(index)) {
  21.225 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.226 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.227              } else {
  21.228                  doesNotHave(index, value, callSiteFlags);
  21.229              }
  21.230 @@ -3314,7 +3341,7 @@
  21.231          if (isValidArrayIndex(index)) {
  21.232              final ArrayData data = getArray();
  21.233              if (data.has(index)) {
  21.234 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.235 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.236              } else {
  21.237                  doesNotHave(index, value, callSiteFlags);
  21.238              }
  21.239 @@ -3333,7 +3360,7 @@
  21.240          if (isValidArrayIndex(index)) {
  21.241              final ArrayData data = getArray();
  21.242              if (data.has(index)) {
  21.243 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.244 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.245              } else {
  21.246                  doesNotHave(index, value, callSiteFlags);
  21.247              }
  21.248 @@ -3352,7 +3379,7 @@
  21.249          if (isValidArrayIndex(index)) {
  21.250              final ArrayData data = getArray();
  21.251              if (data.has(index)) {
  21.252 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.253 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.254              } else {
  21.255                  doesNotHave(index, value, callSiteFlags);
  21.256              }
  21.257 @@ -3371,7 +3398,7 @@
  21.258          if (isValidArrayIndex(index)) {
  21.259              final ArrayData data = getArray();
  21.260              if (data.has(index)) {
  21.261 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.262 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.263              } else {
  21.264                  doesNotHave(index, value, callSiteFlags);
  21.265              }
  21.266 @@ -3390,7 +3417,7 @@
  21.267          if (isValidArrayIndex(index)) {
  21.268              final ArrayData data = getArray();
  21.269              if (data.has(index)) {
  21.270 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.271 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.272              } else {
  21.273                  doesNotHave(index, value, callSiteFlags);
  21.274              }
  21.275 @@ -3409,7 +3436,7 @@
  21.276          if (isValidArrayIndex(index)) {
  21.277              final ArrayData data = getArray();
  21.278              if (data.has(index)) {
  21.279 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.280 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.281              } else {
  21.282                  doesNotHave(index, value, callSiteFlags);
  21.283              }
  21.284 @@ -3428,7 +3455,7 @@
  21.285          if (isValidArrayIndex(index)) {
  21.286              final ArrayData data = getArray();
  21.287              if (data.has(index)) {
  21.288 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.289 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.290              } else {
  21.291                  doesNotHave(index, value, callSiteFlags);
  21.292              }
  21.293 @@ -3446,7 +3473,7 @@
  21.294          if (isValidArrayIndex(index)) {
  21.295              if (getArray().has(index)) {
  21.296                  final ArrayData data = getArray();
  21.297 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.298 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.299              } else {
  21.300                  doesNotHave(index, value, callSiteFlags);
  21.301              }
  21.302 @@ -3464,7 +3491,7 @@
  21.303          if (isValidArrayIndex(index)) {
  21.304              final ArrayData data = getArray();
  21.305              if (data.has(index)) {
  21.306 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.307 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.308              } else {
  21.309                  doesNotHave(index, value, callSiteFlags);
  21.310              }
  21.311 @@ -3483,7 +3510,7 @@
  21.312          if (isValidArrayIndex(index)) {
  21.313              final ArrayData data = getArray();
  21.314              if (data.has(index)) {
  21.315 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.316 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.317              } else {
  21.318                  doesNotHave(index, value, callSiteFlags);
  21.319              }
  21.320 @@ -3502,7 +3529,7 @@
  21.321          if (isValidArrayIndex(index)) {
  21.322              final ArrayData data = getArray();
  21.323              if (data.has(index)) {
  21.324 -                setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)));
  21.325 +                setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
  21.326              } else {
  21.327                  doesNotHave(index, value, callSiteFlags);
  21.328              }
  21.329 @@ -3667,6 +3694,29 @@
  21.330      }
  21.331  
  21.332      /**
  21.333 +     * Return a shallow copy of this ScriptObject.
  21.334 +     * @return a shallow copy.
  21.335 +     */
  21.336 +    public final ScriptObject copy() {
  21.337 +        try {
  21.338 +            return clone();
  21.339 +        } catch (final CloneNotSupportedException e) {
  21.340 +            throw new RuntimeException(e);
  21.341 +        }
  21.342 +    }
  21.343 +
  21.344 +    @Override
  21.345 +    protected ScriptObject clone() throws CloneNotSupportedException {
  21.346 +        final ScriptObject clone = (ScriptObject) super.clone();
  21.347 +        if (objectSpill != null) {
  21.348 +            clone.objectSpill = objectSpill.clone();
  21.349 +            clone.primitiveSpill = primitiveSpill.clone();
  21.350 +        }
  21.351 +        clone.arrayData = arrayData.copy();
  21.352 +        return clone;
  21.353 +    }
  21.354 +
  21.355 +    /**
  21.356       * Make a new UserAccessorProperty property. getter and setter functions are stored in
  21.357       * this ScriptObject and slot values are used in property object.
  21.358       *
    22.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java	Mon Dec 01 11:40:00 2014 -0800
    22.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java	Fri Dec 12 14:58:31 2014 -0800
    22.3 @@ -61,9 +61,9 @@
    22.4      /**
    22.5       * Length of the array data. Not necessarily length of the wrapped array.
    22.6       * This is private to ensure that no one in a subclass is able to touch the length
    22.7 -     * without going through {@link setLength}. This is used to implement
    22.8 +     * without going through {@link #setLength}. This is used to implement
    22.9       * {@link LengthNotWritableFilter}s, ensuring that there are no ways past
   22.10 -     * a {@link setLength} function replaced by a nop
   22.11 +     * a {@link #setLength} function replaced by a nop
   22.12       */
   22.13      private long length;
   22.14  
   22.15 @@ -79,11 +79,7 @@
   22.16       */
   22.17      private static class UntouchedArrayData extends ContinuousArrayData {
   22.18          private UntouchedArrayData() {
   22.19 -            this(0);
   22.20 -        }
   22.21 -
   22.22 -        private UntouchedArrayData(final int length) {
   22.23 -            super(length);
   22.24 +            super(0);
   22.25          }
   22.26  
   22.27          private ArrayData toRealArrayData() {
   22.28 @@ -100,7 +96,8 @@
   22.29  
   22.30          @Override
   22.31          public ContinuousArrayData copy() {
   22.32 -            return new UntouchedArrayData((int)length());
   22.33 +            assert length() == 0;
   22.34 +            return this;
   22.35          }
   22.36  
   22.37          @Override
   22.38 @@ -246,7 +243,7 @@
   22.39          public Class<?> getBoxedElementType() {
   22.40              return Integer.class;
   22.41          }
   22.42 -    };
   22.43 +    }
   22.44  
   22.45      /**
   22.46       * Constructor
    23.1 --- a/src/jdk/nashorn/internal/runtime/arrays/IteratorAction.java	Mon Dec 01 11:40:00 2014 -0800
    23.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/IteratorAction.java	Fri Dec 12 14:58:31 2014 -0800
    23.3 @@ -25,11 +25,7 @@
    23.4  
    23.5  package jdk.nashorn.internal.runtime.arrays;
    23.6  
    23.7 -import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
    23.8 -
    23.9 -import jdk.nashorn.api.scripting.JSObject;
   23.10  import jdk.nashorn.internal.runtime.Context;
   23.11 -import jdk.nashorn.internal.runtime.ScriptFunction;
   23.12  import jdk.nashorn.internal.runtime.ScriptRuntime;
   23.13  import jdk.nashorn.internal.runtime.linker.Bootstrap;
   23.14  
   23.15 @@ -98,17 +94,7 @@
   23.16       * @return result of apply
   23.17       */
   23.18      public final T apply() {
   23.19 -        final boolean strict;
   23.20 -        if (callbackfn instanceof ScriptFunction) {
   23.21 -            strict = ((ScriptFunction)callbackfn).isStrict();
   23.22 -        } else if (callbackfn instanceof JSObject &&
   23.23 -            ((JSObject)callbackfn).isFunction()) {
   23.24 -            strict = ((JSObject)callbackfn).isStrictFunction();
   23.25 -        } else if (Bootstrap.isDynamicMethod(callbackfn) || Bootstrap.isFunctionalInterfaceObject(callbackfn)) {
   23.26 -            strict = false;
   23.27 -        } else {
   23.28 -            throw typeError("not.a.function", ScriptRuntime.safeToString(callbackfn));
   23.29 -        }
   23.30 +        final boolean strict = Bootstrap.isStrictCallable(callbackfn);
   23.31  
   23.32          // for non-strict callback, need to translate undefined thisArg to be global object
   23.33          thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;
    24.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Mon Dec 01 11:40:00 2014 -0800
    24.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Fri Dec 12 14:58:31 2014 -0800
    24.3 @@ -26,6 +26,7 @@
    24.4  package jdk.nashorn.internal.runtime.linker;
    24.5  
    24.6  import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
    24.7 +import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
    24.8  
    24.9  import java.lang.invoke.CallSite;
   24.10  import java.lang.invoke.ConstantCallSite;
   24.11 @@ -50,6 +51,8 @@
   24.12  import jdk.nashorn.internal.codegen.RuntimeCallSite;
   24.13  import jdk.nashorn.internal.lookup.MethodHandleFactory;
   24.14  import jdk.nashorn.internal.lookup.MethodHandleFunctionality;
   24.15 +import jdk.nashorn.internal.objects.ScriptFunctionImpl;
   24.16 +import jdk.nashorn.internal.runtime.ECMAException;
   24.17  import jdk.nashorn.internal.runtime.JSType;
   24.18  import jdk.nashorn.internal.runtime.OptimisticReturnFilters;
   24.19  import jdk.nashorn.internal.runtime.ScriptFunction;
   24.20 @@ -94,7 +97,7 @@
   24.21              new NashornLinker(),
   24.22              new NashornPrimitiveLinker(),
   24.23              new NashornStaticClassLinker(),
   24.24 -            new BoundDynamicMethodLinker(),
   24.25 +            new BoundCallableLinker(),
   24.26              new JavaSuperAdapterLinker(),
   24.27              new JSObjectLinker(nashornBeansLinker),
   24.28              new BrowserJSObjectLinker(nashornBeansLinker),
   24.29 @@ -136,19 +139,47 @@
   24.30          }
   24.31  
   24.32          return obj instanceof ScriptFunction ||
   24.33 -            ((obj instanceof JSObject) && ((JSObject)obj).isFunction()) ||
   24.34 -            isDynamicMethod(obj) ||
   24.35 +            isJSObjectFunction(obj) ||
   24.36 +            BeansLinker.isDynamicMethod(obj) ||
   24.37 +            obj instanceof BoundCallable ||
   24.38              isFunctionalInterfaceObject(obj) ||
   24.39              obj instanceof StaticClass;
   24.40      }
   24.41  
   24.42      /**
   24.43 +     * Returns true if the given object is a strict callable
   24.44 +     * @param callable the callable object to be checked for strictness
   24.45 +     * @return true if the obj is a strict callable, false if it is a non-strict callable.
   24.46 +     * @throws ECMAException with {@code TypeError} if the object is not a callable.
   24.47 +     */
   24.48 +    public static boolean isStrictCallable(final Object callable) {
   24.49 +        if (callable instanceof ScriptFunction) {
   24.50 +            return ((ScriptFunction)callable).isStrict();
   24.51 +        } else if (isJSObjectFunction(callable)) {
   24.52 +            return ((JSObject)callable).isStrictFunction();
   24.53 +        } else if (callable instanceof BoundCallable) {
   24.54 +            return isStrictCallable(((BoundCallable)callable).getCallable());
   24.55 +        } else if (BeansLinker.isDynamicMethod(callable) || callable instanceof StaticClass) {
   24.56 +            return false;
   24.57 +        }
   24.58 +        throw notFunction(callable);
   24.59 +    }
   24.60 +
   24.61 +    private static ECMAException notFunction(final Object obj) {
   24.62 +        return typeError("not.a.function", ScriptRuntime.safeToString(obj));
   24.63 +    }
   24.64 +
   24.65 +    private static boolean isJSObjectFunction(final Object obj) {
   24.66 +        return obj instanceof JSObject && ((JSObject)obj).isFunction();
   24.67 +    }
   24.68 +
   24.69 +    /**
   24.70       * Returns if the given object is a dynalink Dynamic method
   24.71       * @param obj object to be checked
   24.72       * @return true if the obj is a dynamic method
   24.73       */
   24.74      public static boolean isDynamicMethod(final Object obj) {
   24.75 -        return obj instanceof BoundDynamicMethod || BeansLinker.isDynamicMethod(obj);
   24.76 +        return BeansLinker.isDynamicMethod(obj instanceof BoundCallable ? ((BoundCallable)obj).getCallable() : obj);
   24.77      }
   24.78  
   24.79      /**
   24.80 @@ -370,14 +401,22 @@
   24.81      }
   24.82  
   24.83      /**
   24.84 -     * Binds a bean dynamic method (returned by invoking {@code dyn:getMethod} on an object linked with
   24.85 -     * {@code BeansLinker} to a receiver.
   24.86 -     * @param dynamicMethod the dynamic method to bind
   24.87 +     * Binds any object Nashorn can use as a [[Callable]] to a receiver and optionally arguments.
   24.88 +     * @param callable the callable to bind
   24.89       * @param boundThis the bound "this" value.
   24.90 -     * @return a bound dynamic method.
   24.91 +     * @param boundArgs the bound arguments. Can be either null or empty array to signify no arguments are bound.
   24.92 +     * @return a bound callable.
   24.93 +     * @throws ECMAException with {@code TypeError} if the object is not a callable.
   24.94       */
   24.95 -    public static Object bindDynamicMethod(final Object dynamicMethod, final Object boundThis) {
   24.96 -        return new BoundDynamicMethod(dynamicMethod, boundThis);
   24.97 +    public static Object bindCallable(final Object callable, final Object boundThis, final Object[] boundArgs) {
   24.98 +        if (callable instanceof ScriptFunctionImpl) {
   24.99 +            return ((ScriptFunctionImpl)callable).makeBoundFunction(boundThis, boundArgs);
  24.100 +        } else if (callable instanceof BoundCallable) {
  24.101 +            return ((BoundCallable)callable).bind(boundArgs);
  24.102 +        } else if (isCallable(callable)) {
  24.103 +            return new BoundCallable(callable, boundThis, boundArgs);
  24.104 +        }
  24.105 +        throw notFunction(callable);
  24.106      }
  24.107  
  24.108      /**
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundCallable.java	Fri Dec 12 14:58:31 2014 -0800
    25.3 @@ -0,0 +1,96 @@
    25.4 +/*
    25.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    25.7 + *
    25.8 + * This code is free software; you can redistribute it and/or modify it
    25.9 + * under the terms of the GNU General Public License version 2 only, as
   25.10 + * published by the Free Software Foundation.  Oracle designates this
   25.11 + * particular file as subject to the "Classpath" exception as provided
   25.12 + * by Oracle in the LICENSE file that accompanied this code.
   25.13 + *
   25.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   25.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   25.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   25.17 + * version 2 for more details (a copy is included in the LICENSE file that
   25.18 + * accompanied this code).
   25.19 + *
   25.20 + * You should have received a copy of the GNU General Public License version
   25.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   25.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   25.23 + *
   25.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   25.25 + * or visit www.oracle.com if you need additional information or have any
   25.26 + * questions.
   25.27 + */
   25.28 +
   25.29 +package jdk.nashorn.internal.runtime.linker;
   25.30 +
   25.31 +import java.util.Arrays;
   25.32 +import jdk.nashorn.internal.runtime.ScriptRuntime;
   25.33 +
   25.34 +/**
   25.35 + * Represents a Nashorn callable bound to a receiver and optionally arguments. Note that objects of this class
   25.36 + * are just the tuples of a callable and a bound this and arguments, without any behavior. All the behavior is
   25.37 + * defined in the {@code BoundCallableLinker}.
   25.38 + */
   25.39 +public final class BoundCallable {
   25.40 +    private final Object callable;
   25.41 +    private final Object boundThis;
   25.42 +    private final Object[] boundArgs;
   25.43 +
   25.44 +    BoundCallable(final Object callable, final Object boundThis, final Object[] boundArgs) {
   25.45 +        this.callable = callable;
   25.46 +        this.boundThis = boundThis;
   25.47 +        this.boundArgs = isEmptyArray(boundArgs) ? ScriptRuntime.EMPTY_ARRAY : boundArgs.clone();
   25.48 +    }
   25.49 +
   25.50 +    private BoundCallable(final BoundCallable original, final Object[] extraBoundArgs) {
   25.51 +        this.callable = original.callable;
   25.52 +        this.boundThis = original.boundThis;
   25.53 +        this.boundArgs = original.concatenateBoundArgs(extraBoundArgs);
   25.54 +    }
   25.55 +
   25.56 +    Object getCallable() {
   25.57 +        return callable;
   25.58 +    }
   25.59 +
   25.60 +    Object getBoundThis() {
   25.61 +        return boundThis;
   25.62 +    }
   25.63 +
   25.64 +    Object[] getBoundArgs() {
   25.65 +        return boundArgs;
   25.66 +    }
   25.67 +
   25.68 +    BoundCallable bind(final Object[] extraBoundArgs) {
   25.69 +        if (isEmptyArray(extraBoundArgs)) {
   25.70 +            return this;
   25.71 +        }
   25.72 +        return new BoundCallable(this, extraBoundArgs);
   25.73 +    }
   25.74 +
   25.75 +    private Object[] concatenateBoundArgs(final Object[] extraBoundArgs) {
   25.76 +        if (boundArgs.length == 0) {
   25.77 +            return extraBoundArgs.clone();
   25.78 +        }
   25.79 +        final int origBoundArgsLen = boundArgs.length;
   25.80 +        final int extraBoundArgsLen = extraBoundArgs.length;
   25.81 +        final Object[] newBoundArgs = new Object[origBoundArgsLen + extraBoundArgsLen];
   25.82 +        System.arraycopy(boundArgs, 0, newBoundArgs, 0, origBoundArgsLen);
   25.83 +        System.arraycopy(extraBoundArgs, 0, newBoundArgs, origBoundArgsLen, extraBoundArgsLen);
   25.84 +        return newBoundArgs;
   25.85 +    }
   25.86 +
   25.87 +    private static boolean isEmptyArray(final Object[] a) {
   25.88 +        return a == null || a.length == 0;
   25.89 +    }
   25.90 +
   25.91 +    @Override
   25.92 +    public String toString() {
   25.93 +        final StringBuilder b = new StringBuilder(callable.toString()).append(" on ").append(boundThis);
   25.94 +        if (boundArgs.length != 0) {
   25.95 +            b.append(" with ").append(Arrays.toString(boundArgs));
   25.96 +        }
   25.97 +        return b.toString();
   25.98 +    }
   25.99 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundCallableLinker.java	Fri Dec 12 14:58:31 2014 -0800
    26.3 @@ -0,0 +1,132 @@
    26.4 +/*
    26.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    26.7 + *
    26.8 + * This code is free software; you can redistribute it and/or modify it
    26.9 + * under the terms of the GNU General Public License version 2 only, as
   26.10 + * published by the Free Software Foundation.  Oracle designates this
   26.11 + * particular file as subject to the "Classpath" exception as provided
   26.12 + * by Oracle in the LICENSE file that accompanied this code.
   26.13 + *
   26.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   26.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   26.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   26.17 + * version 2 for more details (a copy is included in the LICENSE file that
   26.18 + * accompanied this code).
   26.19 + *
   26.20 + * You should have received a copy of the GNU General Public License version
   26.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   26.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   26.23 + *
   26.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   26.25 + * or visit www.oracle.com if you need additional information or have any
   26.26 + * questions.
   26.27 + */
   26.28 +
   26.29 +package jdk.nashorn.internal.runtime.linker;
   26.30 +
   26.31 +import java.lang.invoke.MethodHandle;
   26.32 +import java.lang.invoke.MethodHandles;
   26.33 +import java.lang.invoke.MethodType;
   26.34 +import java.util.Arrays;
   26.35 +import jdk.internal.dynalink.CallSiteDescriptor;
   26.36 +import jdk.internal.dynalink.linker.GuardedInvocation;
   26.37 +import jdk.internal.dynalink.linker.LinkRequest;
   26.38 +import jdk.internal.dynalink.linker.LinkerServices;
   26.39 +import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
   26.40 +import jdk.internal.dynalink.support.Guards;
   26.41 +
   26.42 +/**
   26.43 + * Links {@link BoundCallable} objects. Passes through to linker services for linking a callable (for either
   26.44 + * "dyn:call" or "dyn:new"), and modifies the returned invocation to deal with the receiver and argument binding.
   26.45 + */
   26.46 +final class BoundCallableLinker implements TypeBasedGuardingDynamicLinker {
   26.47 +    @Override
   26.48 +    public boolean canLinkType(final Class<?> type) {
   26.49 +        return type == BoundCallable.class;
   26.50 +    }
   26.51 +
   26.52 +    @Override
   26.53 +    public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
   26.54 +        final Object objBoundCallable = linkRequest.getReceiver();
   26.55 +        if(!(objBoundCallable instanceof BoundCallable)) {
   26.56 +            return null;
   26.57 +        }
   26.58 +
   26.59 +        final CallSiteDescriptor descriptor = linkRequest.getCallSiteDescriptor();
   26.60 +        if (descriptor.getNameTokenCount() < 2 || !"dyn".equals(descriptor.getNameToken(CallSiteDescriptor.SCHEME))) {
   26.61 +            return null;
   26.62 +        }
   26.63 +        final String operation = descriptor.getNameToken(CallSiteDescriptor.OPERATOR);
   26.64 +        // We need to distinguish "dyn:new" from "dyn:call" because "dyn:call" sites have parameter list of the form
   26.65 +        // "callee, this, args", while "dyn:call" sites have "callee, args" -- they lack the "this" parameter.
   26.66 +        final boolean isCall;
   26.67 +        if ("new".equals(operation)) {
   26.68 +            isCall = false;
   26.69 +        } else if ("call".equals(operation)) {
   26.70 +            isCall = true;
   26.71 +        } else {
   26.72 +            // Only dyn:call and dyn:new are supported.
   26.73 +            return null;
   26.74 +        }
   26.75 +        final BoundCallable boundCallable = (BoundCallable)objBoundCallable;
   26.76 +        final Object callable = boundCallable.getCallable();
   26.77 +        final Object boundThis = boundCallable.getBoundThis();
   26.78 +
   26.79 +        // We need to ask the linker services for a delegate invocation on the target callable.
   26.80 +
   26.81 +        // Replace arguments (boundCallable[, this], args) => (callable[, boundThis], boundArgs, args) when delegating
   26.82 +        final Object[] args = linkRequest.getArguments();
   26.83 +        final Object[] boundArgs = boundCallable.getBoundArgs();
   26.84 +        final int argsLen = args.length;
   26.85 +        final int boundArgsLen = boundArgs.length;
   26.86 +        final Object[] newArgs = new Object[argsLen + boundArgsLen];
   26.87 +        newArgs[0] = callable;
   26.88 +        final int firstArgIndex;
   26.89 +        if (isCall) {
   26.90 +            newArgs[1] = boundThis;
   26.91 +            firstArgIndex = 2;
   26.92 +        } else {
   26.93 +            firstArgIndex = 1;
   26.94 +        }
   26.95 +        System.arraycopy(boundArgs, 0, newArgs, firstArgIndex, boundArgsLen);
   26.96 +        System.arraycopy(args, firstArgIndex, newArgs, firstArgIndex + boundArgsLen, argsLen - firstArgIndex);
   26.97 +
   26.98 +        // Use R(T0, T1, T2, ...) => R(callable.class, boundThis.class, boundArg0.class, ..., boundArgn.class, T2, ...)
   26.99 +        // call site type when delegating to underlying linker (for dyn:new, there's no this).
  26.100 +        final MethodType type = descriptor.getMethodType();
  26.101 +        // Use R(T0, ...) => R(callable.class, ...)
  26.102 +        MethodType newMethodType = descriptor.getMethodType().changeParameterType(0, callable.getClass());
  26.103 +        if (isCall) {
  26.104 +            // R(callable.class, T1, ...) => R(callable.class, boundThis.class, ...)
  26.105 +            newMethodType = newMethodType.changeParameterType(1, boundThis.getClass());
  26.106 +        }
  26.107 +        // R(callable.class[, boundThis.class], T2, ...) => R(callable.class[, boundThis.class], boundArg0.class, ..., boundArgn.class, T2, ...)
  26.108 +        for(int i = boundArgs.length; i-- > 0;) {
  26.109 +            newMethodType = newMethodType.insertParameterTypes(firstArgIndex, boundArgs[i] == null ? Object.class : boundArgs[i].getClass());
  26.110 +        }
  26.111 +        final CallSiteDescriptor newDescriptor = descriptor.changeMethodType(newMethodType);
  26.112 +
  26.113 +        // Delegate to target's linker
  26.114 +        final GuardedInvocation inv = linkerServices.getGuardedInvocation(linkRequest.replaceArguments(newDescriptor, newArgs));
  26.115 +        if(inv == null) {
  26.116 +            return null;
  26.117 +        }
  26.118 +
  26.119 +        // Bind (callable[, boundThis], boundArgs) to the delegate handle
  26.120 +        final MethodHandle boundHandle = MethodHandles.insertArguments(inv.getInvocation(), 0,
  26.121 +                Arrays.copyOf(newArgs, firstArgIndex + boundArgs.length));
  26.122 +        final Class<?> p0Type = type.parameterType(0);
  26.123 +        final MethodHandle droppingHandle;
  26.124 +        if (isCall) {
  26.125 +            // Ignore incoming boundCallable and this
  26.126 +            droppingHandle = MethodHandles.dropArguments(boundHandle, 0, p0Type, type.parameterType(1));
  26.127 +        } else {
  26.128 +            // Ignore incoming boundCallable
  26.129 +            droppingHandle = MethodHandles.dropArguments(boundHandle, 0, p0Type);
  26.130 +        }
  26.131 +        // Identity guard on boundCallable object
  26.132 +        final MethodHandle newGuard = Guards.getIdentityGuard(boundCallable);
  26.133 +        return inv.replaceMethods(droppingHandle, newGuard.asType(newGuard.type().changeParameterType(0, p0Type)));
  26.134 +    }
  26.135 +}
    27.1 --- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethod.java	Mon Dec 01 11:40:00 2014 -0800
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,57 +0,0 @@
    27.4 -/*
    27.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    27.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    27.7 - *
    27.8 - * This code is free software; you can redistribute it and/or modify it
    27.9 - * under the terms of the GNU General Public License version 2 only, as
   27.10 - * published by the Free Software Foundation.  Oracle designates this
   27.11 - * particular file as subject to the "Classpath" exception as provided
   27.12 - * by Oracle in the LICENSE file that accompanied this code.
   27.13 - *
   27.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   27.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   27.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   27.17 - * version 2 for more details (a copy is included in the LICENSE file that
   27.18 - * accompanied this code).
   27.19 - *
   27.20 - * You should have received a copy of the GNU General Public License version
   27.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   27.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   27.23 - *
   27.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   27.25 - * or visit www.oracle.com if you need additional information or have any
   27.26 - * questions.
   27.27 - */
   27.28 -
   27.29 -package jdk.nashorn.internal.runtime.linker;
   27.30 -
   27.31 -import java.util.Objects;
   27.32 -import jdk.internal.dynalink.beans.BeansLinker;
   27.33 -
   27.34 -/**
   27.35 - * Represents a Dynalink dynamic method bound to a receiver. Note that objects of this class are just the tuples of
   27.36 - * a method and a bound this, without any behavior. All the behavior is defined in the {@code BoundDynamicMethodLinker}.
   27.37 - */
   27.38 -final class BoundDynamicMethod {
   27.39 -    private final Object dynamicMethod;
   27.40 -    private final Object boundThis;
   27.41 -
   27.42 -    BoundDynamicMethod(final Object dynamicMethod, final Object boundThis) {
   27.43 -        assert BeansLinker.isDynamicMethod(dynamicMethod);
   27.44 -        this.dynamicMethod = dynamicMethod;
   27.45 -        this.boundThis = boundThis;
   27.46 -    }
   27.47 -
   27.48 -    Object getDynamicMethod() {
   27.49 -        return dynamicMethod;
   27.50 -    }
   27.51 -
   27.52 -    Object getBoundThis() {
   27.53 -        return boundThis;
   27.54 -    }
   27.55 -
   27.56 -    @Override
   27.57 -    public String toString() {
   27.58 -        return dynamicMethod.toString() + " on " + Objects.toString(boundThis);
   27.59 -    }
   27.60 -}
    28.1 --- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java	Mon Dec 01 11:40:00 2014 -0800
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,91 +0,0 @@
    28.4 -/*
    28.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    28.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    28.7 - *
    28.8 - * This code is free software; you can redistribute it and/or modify it
    28.9 - * under the terms of the GNU General Public License version 2 only, as
   28.10 - * published by the Free Software Foundation.  Oracle designates this
   28.11 - * particular file as subject to the "Classpath" exception as provided
   28.12 - * by Oracle in the LICENSE file that accompanied this code.
   28.13 - *
   28.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   28.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   28.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   28.17 - * version 2 for more details (a copy is included in the LICENSE file that
   28.18 - * accompanied this code).
   28.19 - *
   28.20 - * You should have received a copy of the GNU General Public License version
   28.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   28.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   28.23 - *
   28.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   28.25 - * or visit www.oracle.com if you need additional information or have any
   28.26 - * questions.
   28.27 - */
   28.28 -
   28.29 -package jdk.nashorn.internal.runtime.linker;
   28.30 -
   28.31 -import java.lang.invoke.MethodHandle;
   28.32 -import java.lang.invoke.MethodHandles;
   28.33 -import java.lang.invoke.MethodType;
   28.34 -import jdk.internal.dynalink.CallSiteDescriptor;
   28.35 -import jdk.internal.dynalink.beans.BeansLinker;
   28.36 -import jdk.internal.dynalink.linker.GuardedInvocation;
   28.37 -import jdk.internal.dynalink.linker.LinkRequest;
   28.38 -import jdk.internal.dynalink.linker.LinkerServices;
   28.39 -import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
   28.40 -import jdk.internal.dynalink.support.Guards;
   28.41 -
   28.42 -/**
   28.43 - * Links {@code BoundDynamicMethod} objects. Passes through to Dynalink's BeansLinker for linking a dynamic method
   28.44 - * (they only respond to "dyn:call"), and modifies the returned invocation to deal with the receiver binding.
   28.45 - */
   28.46 -final class BoundDynamicMethodLinker implements TypeBasedGuardingDynamicLinker {
   28.47 -    @Override
   28.48 -    public boolean canLinkType(final Class<?> type) {
   28.49 -        return type == BoundDynamicMethod.class;
   28.50 -    }
   28.51 -
   28.52 -    @Override
   28.53 -    public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
   28.54 -        final Object objBoundDynamicMethod = linkRequest.getReceiver();
   28.55 -        if(!(objBoundDynamicMethod instanceof BoundDynamicMethod)) {
   28.56 -            return null;
   28.57 -        }
   28.58 -
   28.59 -        final BoundDynamicMethod boundDynamicMethod = (BoundDynamicMethod)objBoundDynamicMethod;
   28.60 -        final Object dynamicMethod = boundDynamicMethod.getDynamicMethod();
   28.61 -        final Object boundThis = boundDynamicMethod.getBoundThis();
   28.62 -
   28.63 -        // Replace arguments (boundDynamicMethod, this, ...) => (dynamicMethod, boundThis, ...) when delegating to
   28.64 -        // BeansLinker
   28.65 -        final Object[] args = linkRequest.getArguments();
   28.66 -        args[0] = dynamicMethod;
   28.67 -        args[1] = boundThis;
   28.68 -
   28.69 -        // Use R(T0, T1, ...) => R(dynamicMethod.class, boundThis.class, ...) call site type when delegating to
   28.70 -        // BeansLinker.
   28.71 -        final CallSiteDescriptor descriptor = linkRequest.getCallSiteDescriptor();
   28.72 -        final MethodType type = descriptor.getMethodType();
   28.73 -        final Class<?> dynamicMethodClass = dynamicMethod.getClass();
   28.74 -        final CallSiteDescriptor newDescriptor = descriptor.changeMethodType(
   28.75 -                type.changeParameterType(0, dynamicMethodClass).changeParameterType(1, boundThis.getClass()));
   28.76 -
   28.77 -        // Delegate to BeansLinker
   28.78 -        final GuardedInvocation inv = NashornBeansLinker.getGuardedInvocation(BeansLinker.getLinkerForClass(dynamicMethodClass),
   28.79 -                linkRequest.replaceArguments(newDescriptor, args), linkerServices);
   28.80 -        if(inv == null) {
   28.81 -            return null;
   28.82 -        }
   28.83 -
   28.84 -        // Bind (dynamicMethod, boundThis) to the handle
   28.85 -        final MethodHandle boundHandle = MethodHandles.insertArguments(inv.getInvocation(), 0, dynamicMethod, boundThis);
   28.86 -        final Class<?> p0Type = type.parameterType(0);
   28.87 -        // Ignore incoming (boundDynamicMethod, this)
   28.88 -        final MethodHandle droppingHandle = MethodHandles.dropArguments(boundHandle, 0, p0Type, type.parameterType(1));
   28.89 -        // Identity guard on boundDynamicMethod object
   28.90 -        final MethodHandle newGuard = Guards.getIdentityGuard(boundDynamicMethod);
   28.91 -
   28.92 -        return inv.replaceMethods(droppingHandle, newGuard.asType(newGuard.type().changeParameterType(0, p0Type)));
   28.93 -    }
   28.94 -}
    29.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java	Mon Dec 01 11:40:00 2014 -0800
    29.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java	Fri Dec 12 14:58:31 2014 -0800
    29.3 @@ -165,7 +165,7 @@
    29.4       */
    29.5      @SuppressWarnings("unused")
    29.6      private static Object bindDynamicMethod(final Object dynamicMethod, final Object boundThis) {
    29.7 -        return dynamicMethod == null ? ScriptRuntime.UNDEFINED : Bootstrap.bindDynamicMethod(dynamicMethod, boundThis);
    29.8 +        return dynamicMethod == null ? ScriptRuntime.UNDEFINED : Bootstrap.bindCallable(dynamicMethod, boundThis, null);
    29.9      }
   29.10  
   29.11      /**
    30.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties	Mon Dec 01 11:40:00 2014 -0800
    30.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties	Fri Dec 12 14:58:31 2014 -0800
    30.3 @@ -82,7 +82,7 @@
    30.4  type.error.not.a.file={0} is not a File
    30.5  type.error.not.a.numeric.array={0} is not a numeric array
    30.6  type.error.not.a.bytebuffer={0} is not a java.nio.ByteBuffer
    30.7 -type.error.not.an.arraybuffer.in.dataview=First arg to DataView constructor must be an ArrayBuffer
    30.8 +type.error.not.an.arraybuffer.in.dataview=First argument to DataView constructor must be an ArrayBuffer
    30.9  type.error.no.reflection.with.classfilter=Java reflection not supported when class filter is present
   30.10  
   30.11  # operations not permitted on undefined
   30.12 @@ -116,6 +116,7 @@
   30.13  type.error.cannot.convert.to.interface=object {0} cannot be converted to {1} due to "{2}"
   30.14  type.error.array.reduce.invalid.init=invalid initialValue for Array.prototype.reduce
   30.15  type.error.array.reduceright.invalid.init=invalid initialValue for Array.prototype.reduceRight
   30.16 +type.error.assign.constant=Assignment to constant "{0}"
   30.17  type.error.cannot.get.default.string=Cannot get default string value
   30.18  type.error.cannot.get.default.number=Cannot get default number value
   30.19  type.error.cant.apply.with.to.null=Cannot apply "with" to null
   30.20 @@ -166,6 +167,7 @@
   30.21  syntax.error.strict.cant.delete=cannot delete "{0}" in strict mode
   30.22  syntax.error.redeclare.variable=Variable "{0}" has already been declared
   30.23  syntax.error.assign.constant=Assignment to constant "{0}"
   30.24 +syntax.error.unprotected.switch.declaration=Unsupported {0} declaration in unprotected switch statement
   30.25  
   30.26  io.error.cant.write=cannot write "{0}"
   30.27  config.error.no.dest=no destination directory supplied
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/test/script/basic/JDK-8049407-big-endian.js	Fri Dec 12 14:58:31 2014 -0800
    31.3 @@ -0,0 +1,33 @@
    31.4 +/*
    31.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
    31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    31.7 + *
    31.8 + * This code is free software; you can redistribute it and/or modify it
    31.9 + * under the terms of the GNU General Public License version 2 only, as
   31.10 + * published by the Free Software Foundation.
   31.11 + *
   31.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   31.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   31.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   31.15 + * version 2 for more details (a copy is included in the LICENSE file that
   31.16 + * accompanied this code).
   31.17 + *
   31.18 + * You should have received a copy of the GNU General Public License version
   31.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   31.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   31.21 + *
   31.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   31.23 + * or visit www.oracle.com if you need additional information or have any
   31.24 + * questions.
   31.25 + */
   31.26 +
   31.27 +/**
   31.28 + * Verify DataView behavior with little/big endian
   31.29 + *
   31.30 + * @test
   31.31 + * @run
   31.32 + * @bigendian
   31.33 + */
   31.34 +
   31.35 +var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__;
   31.36 +load(dir + "JDK-8049407-payload.js");
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/test/script/basic/JDK-8049407-big-endian.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    32.3 @@ -0,0 +1,1 @@
    32.4 +false
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/test/script/basic/JDK-8049407-payload.js	Fri Dec 12 14:58:31 2014 -0800
    33.3 @@ -0,0 +1,37 @@
    33.4 +/*
    33.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
    33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    33.7 + *
    33.8 + * This code is free software; you can redistribute it and/or modify it
    33.9 + * under the terms of the GNU General Public License version 2 only, as
   33.10 + * published by the Free Software Foundation.
   33.11 + *
   33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   33.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   33.15 + * version 2 for more details (a copy is included in the LICENSE file that
   33.16 + * accompanied this code).
   33.17 + *
   33.18 + * You should have received a copy of the GNU General Public License version
   33.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   33.21 + *
   33.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   33.23 + * or visit www.oracle.com if you need additional information or have any
   33.24 + * questions.
   33.25 + */
   33.26 +
   33.27 +/**
   33.28 + * Verify DataView behavior with little/big endian
   33.29 + *
   33.30 + * @subtest
   33.31 + * @run
   33.32 + */
   33.33 +
   33.34 +var littleEndian = (function() {
   33.35 +	var buffer = new ArrayBuffer(2);
   33.36 +	new DataView(buffer).setInt16(0, 256, true);
   33.37 +	return new Int16Array(buffer)[0] === 256;
   33.38 +    })();
   33.39 +
   33.40 +print(littleEndian);
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/test/script/basic/JDK-8049407.js	Fri Dec 12 14:58:31 2014 -0800
    34.3 @@ -0,0 +1,33 @@
    34.4 +/*
    34.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
    34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    34.7 + *
    34.8 + * This code is free software; you can redistribute it and/or modify it
    34.9 + * under the terms of the GNU General Public License version 2 only, as
   34.10 + * published by the Free Software Foundation.
   34.11 + *
   34.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   34.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   34.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   34.15 + * version 2 for more details (a copy is included in the LICENSE file that
   34.16 + * accompanied this code).
   34.17 + *
   34.18 + * You should have received a copy of the GNU General Public License version
   34.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   34.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   34.21 + *
   34.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   34.23 + * or visit www.oracle.com if you need additional information or have any
   34.24 + * questions.
   34.25 + */
   34.26 +
   34.27 +/**
   34.28 + * Verify DataView behavior with little/big endian
   34.29 + *
   34.30 + * @test
   34.31 + * @run
   34.32 + * @littleendian
   34.33 + */
   34.34 +
   34.35 +var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__;
   34.36 +load(dir + "JDK-8049407-payload.js");
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/test/script/basic/JDK-8049407.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    35.3 @@ -0,0 +1,1 @@
    35.4 +true
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/test/script/basic/JDK-8051778.js	Fri Dec 12 14:58:31 2014 -0800
    36.3 @@ -0,0 +1,83 @@
    36.4 +/*
    36.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
    36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    36.7 + * 
    36.8 + * This code is free software; you can redistribute it and/or modify it
    36.9 + * under the terms of the GNU General Public License version 2 only, as
   36.10 + * published by the Free Software Foundation.
   36.11 + * 
   36.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   36.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   36.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   36.15 + * version 2 for more details (a copy is included in the LICENSE file that
   36.16 + * accompanied this code).
   36.17 + * 
   36.18 + * You should have received a copy of the GNU General Public License version
   36.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   36.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   36.21 + * 
   36.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   36.23 + * or visit www.oracle.com if you need additional information or have any
   36.24 + * questions.
   36.25 + */
   36.26 +
   36.27 +/**
   36.28 + * JDK-8051778: support bind on all Nashorn callables
   36.29 + *
   36.30 + * @test
   36.31 + * @run
   36.32 + */
   36.33 +
   36.34 +var bind = Function.prototype.bind;
   36.35 +
   36.36 +// Bind a POJO method
   36.37 +var l = new java.util.ArrayList();
   36.38 +var l_add_foo = bind.call(l.add, l, "foo");
   36.39 +l_add_foo();
   36.40 +print("l=" + l);
   36.41 +
   36.42 +// Bind a BoundCallable
   36.43 +var l_add = bind.call(l.add, l);
   36.44 +var l_add_foo2 = bind.call(l_add, null, "foo2");
   36.45 +l_add_foo2();
   36.46 +print("l=" + l);
   36.47 +
   36.48 +// Bind a POJO method retrieved from one instance to a different but 
   36.49 +// compatible instance.
   36.50 +var l2 = new java.util.ArrayList();
   36.51 +var l2_size = bind.call(l.size, l2);
   36.52 +print("l2_size()=" + l2_size());
   36.53 +
   36.54 +// Bind a Java type object (used as a constructor).
   36.55 +var construct_two = bind.call(java.lang.Integer, null, 2);
   36.56 +print("Bound Integer(2) constructor: " + new construct_two())
   36.57 +
   36.58 +// Bind a @FunctionalInterface proxying to an object literal. NOTE: the 
   36.59 +// expected value of this.a is always "original" and never "bound". This
   36.60 +// might seem counterintuitive, but we are not binding the apply()
   36.61 +// function of the object literal that defines the BiFunction behaviour,
   36.62 +// we are binding the SAM proxy object instead, and it is always
   36.63 +// forwarding to the apply() function with "this" set to the object
   36.64 +// literal. Basically, binding "this" for SAM proxies is useless; only
   36.65 +// binding arguments makes sense.
   36.66 +var f1 = new java.util.function.BiFunction() {
   36.67 +    apply: function(x, y) {
   36.68 +        return "BiFunction with literal: " + this.a + ", " + x + ", " + y;
   36.69 +    },
   36.70 +    a: "unbound"
   36.71 +};
   36.72 +print((bind.call(f1, {a: "bound"}))(1, 2))
   36.73 +print((bind.call(f1, {a: "bound"}, 3))(4))
   36.74 +print((bind.call(f1, {a: "bound"}, 5, 6))())
   36.75 +
   36.76 +// Bind a @FunctionalInterface proxying to a function. With the same 
   36.77 +// reasoning as above (binding the proxy vs. binding the JS function), 
   36.78 +// the value of this.a will always be undefined, and never "bound".
   36.79 +var f2 = new java.util.function.BiFunction(
   36.80 +    function(x, y) {
   36.81 +        return "BiFunction with function: " + this.a + ", " + x + ", " + y;
   36.82 +    }
   36.83 +);
   36.84 +print((bind.call(f2, {a: "bound"}))(7, 8))
   36.85 +print((bind.call(f2, {a: "bound"}, 9))(10))
   36.86 +print((bind.call(f2, {a: "bound"}, 11, 12))())
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/test/script/basic/JDK-8051778.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    37.3 @@ -0,0 +1,10 @@
    37.4 +l=[foo]
    37.5 +l=[foo, foo2]
    37.6 +l2_size()=0
    37.7 +Bound Integer(2) constructor: 2
    37.8 +BiFunction with literal: unbound, 1, 2
    37.9 +BiFunction with literal: unbound, 3, 4
   37.10 +BiFunction with literal: unbound, 5, 6
   37.11 +BiFunction with function: undefined, 7, 8
   37.12 +BiFunction with function: undefined, 9, 10
   37.13 +BiFunction with function: undefined, 11, 12
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/test/script/basic/NASHORN-377-big-endian.js	Fri Dec 12 14:58:31 2014 -0800
    38.3 @@ -0,0 +1,33 @@
    38.4 +/*
    38.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    38.7 + *
    38.8 + * This code is free software; you can redistribute it and/or modify it
    38.9 + * under the terms of the GNU General Public License version 2 only, as
   38.10 + * published by the Free Software Foundation.
   38.11 + *
   38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   38.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   38.15 + * version 2 for more details (a copy is included in the LICENSE file that
   38.16 + * accompanied this code).
   38.17 + *
   38.18 + * You should have received a copy of the GNU General Public License version
   38.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   38.21 + *
   38.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   38.23 + * or visit www.oracle.com if you need additional information or have any
   38.24 + * questions.
   38.25 + */
   38.26 +
   38.27 +/*
   38.28 + * NASHORN-377: Typed arrays.
   38.29 + *
   38.30 + * @test
   38.31 + * @run
   38.32 + * @bigendian
   38.33 + */
   38.34 +
   38.35 +var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__;
   38.36 +load(dir + "NASHORN-377-payload.js");
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/test/script/basic/NASHORN-377-big-endian.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    39.3 @@ -0,0 +1,34 @@
    39.4 +8 8 true undefined
    39.5 +[object ArrayBuffer] [object ArrayBuffer] [object Int8Array]
    39.6 +0 8 8 1
    39.7 +0 8 8 1
    39.8 +0 8 8 1
    39.9 +0 8 4 2
   39.10 +0 8 4 2
   39.11 +0 8 2 4
   39.12 +0 8 2 4
   39.13 +0 8 2 4
   39.14 +0 8 1 8
   39.15 +7071727374-807677 7071727374807677
   39.16 +727374-807677 2 6
   39.17 +72737480 2 4
   39.18 +71727374 1 4
   39.19 +717273748076
   39.20 +7071727374807677 1886483059 1954575991
   39.21 +70717273-1020305 1886483059 -16909061
   39.22 +70717273fefdfcfb 1886483059 4278058235
   39.23 +40490fdafefdfcfb 2
   39.24 +400921fb4d12d84a 1
   39.25 +400921fb4d12d84a 1074340347 1293080650
   39.26 +00000000400921fb4d12d84a
   39.27 +400921fb4d12-27b6 400921fb4d12d84a
   39.28 +00-100804d12-27b6 ffff00804d12d84a
   39.29 +0 1 2 3 4 5 6 7
   39.30 +0102030405060708
   39.31 +subarray(2,4)=0304 subarray(-6,-4)=0304
   39.32 +010203040506
   39.33 +03040506 0405
   39.34 +0102030405060708090a0b0c0d0e0f10
   39.35 +slice(4,8)=05060708 slice(-8,-4)=090a0b0c
   39.36 +0102030405060708090a0b0c
   39.37 +060708090a0b
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/test/script/basic/NASHORN-377-payload.js	Fri Dec 12 14:58:31 2014 -0800
    40.3 @@ -0,0 +1,226 @@
    40.4 +/*
    40.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    40.7 + *
    40.8 + * This code is free software; you can redistribute it and/or modify it
    40.9 + * under the terms of the GNU General Public License version 2 only, as
   40.10 + * published by the Free Software Foundation.
   40.11 + *
   40.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   40.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   40.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   40.15 + * version 2 for more details (a copy is included in the LICENSE file that
   40.16 + * accompanied this code).
   40.17 + *
   40.18 + * You should have received a copy of the GNU General Public License version
   40.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   40.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   40.21 + *
   40.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   40.23 + * or visit www.oracle.com if you need additional information or have any
   40.24 + * questions.
   40.25 + */
   40.26 +
   40.27 +/*
   40.28 + * NASHORN-377: Typed arrays. Payload for litte and big endian platforms.
   40.29 + *
   40.30 + * @subtest
   40.31 + * @run
   40.32 + */
   40.33 +
   40.34 +var types = [Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];
   40.35 +
   40.36 +//---------------------------------------------------------------------------
   40.37 +// utility functions
   40.38 +//---------------------------------------------------------------------------
   40.39 +function tohex(d, w) {
   40.40 +  var hex = Number(d).toString(16);
   40.41 +  var pad = (w ? w : 8) - hex.length;
   40.42 +  hex = "00000000".substr(0, pad) + hex;
   40.43 +  return hex;
   40.44 +}
   40.45 +
   40.46 +function arrstr(a, n, w) {
   40.47 +  var s = "";
   40.48 +  if (typeof n == "undefined") n = a.length;
   40.49 +  if (typeof w == "undefined") w = a.constructor.BYTES_PER_ELEMENT * 2;
   40.50 +  for (var i = 0; i < n; i++) {
   40.51 +    s += tohex(a[i], w);
   40.52 +  }
   40.53 +  return s;
   40.54 +}
   40.55 +function bufstr(b) {
   40.56 +  if (b.buffer !== undefined) {
   40.57 +    b = b.buffer;
   40.58 +  }
   40.59 +  return arrstr(new Uint8Array(b));
   40.60 +}
   40.61 +
   40.62 +function assertFail(f) {
   40.63 +  try {
   40.64 +    f();
   40.65 +  } catch (e) {
   40.66 +    //print(e);
   40.67 +    return;
   40.68 +  }
   40.69 +  throw "assertion failed: expected exception";
   40.70 +}
   40.71 +
   40.72 +function assertTrue(f) {
   40.73 +  if (f() !== true) throw "assertion failed: " + f;
   40.74 +}
   40.75 +
   40.76 +function isUndefined(x) {
   40.77 +  return typeof x === "undefined";
   40.78 +}
   40.79 +
   40.80 +function fillArray(a, start) {
   40.81 +  if (typeof start == "undefined") start = 1;
   40.82 +  for (var i = 0; i < a.length; i++) {
   40.83 +    a[i] = i + start;
   40.84 +  }
   40.85 +  return a;
   40.86 +}
   40.87 +
   40.88 +//---------------------------------------------------------------------------
   40.89 +// tests
   40.90 +//---------------------------------------------------------------------------
   40.91 +(function() {
   40.92 +  var b = new ArrayBuffer(8);
   40.93 +  var i8 = new Int8Array(b);
   40.94 +  print(i8.buffer.byteLength, b.byteLength, i8.buffer === b, b.length);
   40.95 +  print(b, i8.buffer, i8);
   40.96 +})();
   40.97 +
   40.98 +(function test_attributes() {
   40.99 +  var b = new ArrayBuffer(8);
  40.100 +  for (var i in types) {
  40.101 +    var x = new types[i](b);
  40.102 +    print(x.byteOffset, x.byteLength, x.length, x.constructor.BYTES_PER_ELEMENT);
  40.103 +    assertTrue(function(){ return x.constructor === types[i] });
  40.104 +  }
  40.105 +})();
  40.106 +
  40.107 +(function() {
  40.108 +  var b = new ArrayBuffer(8);
  40.109 +  var i8 = new Int8Array(b);
  40.110 +  fillArray(i8, 0x70);
  40.111 +
  40.112 +  var i8_2 = new Int8Array(b, 2);
  40.113 +  var i8_2_4 = new Uint8Array(b, 2, 4);
  40.114 +
  40.115 +  i8_2_4[3] = 0x80;
  40.116 +
  40.117 +  print(arrstr(i8, 8, 2)  + " " + bufstr(i8));
  40.118 +  print(arrstr(i8_2, 6)   + " " + i8_2.byteOffset   + " " + i8_2.byteLength);
  40.119 +  print(arrstr(i8_2_4, 4) + " " + i8_2_4.byteOffset + " " + i8_2_4.byteLength);
  40.120 +
  40.121 +  var i8_1_5 = i8.subarray(1, 5);
  40.122 +  i8_2_4.subarray(1, 5);
  40.123 +  print(arrstr(i8_1_5, 4) + " " + i8_1_5.byteOffset + " " + i8_1_5.byteLength);
  40.124 +
  40.125 +  print(bufstr(b.slice(1,7)));
  40.126 +})();
  40.127 +
  40.128 +(function() {
  40.129 +  var b = new ArrayBuffer(8);
  40.130 +  fillArray(new Int8Array(b), 0x70);
  40.131 +  new Int8Array(b)[5] = 0x80;
  40.132 +
  40.133 +  var i32 = new Int32Array(b);
  40.134 +  var u32 = new Uint32Array(b);
  40.135 +  print(arrstr(i32), i32[0], i32[1]);
  40.136 +  i32[1] = 0xfefdfcfb;
  40.137 +  print(arrstr(i32), i32[0], i32[1]);
  40.138 +  print(arrstr(u32), u32[0], u32[1]);
  40.139 +
  40.140 +  var pi = 3.1415926;
  40.141 +  var f32 = new Float32Array(b);
  40.142 +  var f64 = new Float64Array(b);
  40.143 +  f32[0] = pi;
  40.144 +  print(bufstr(b), f32.length);
  40.145 +  f64[0] = pi;
  40.146 +  print(bufstr(b), f64.length);
  40.147 +  print(arrstr(u32), u32[0], u32[1]);
  40.148 +
  40.149 +  var d = new Int32Array(3);
  40.150 +  d.set(i32,1);
  40.151 +  print(bufstr(d));
  40.152 +
  40.153 +  var s = new Int16Array(b);
  40.154 +  var t = new Uint16Array(b);
  40.155 +  print(arrstr(s), arrstr(t));
  40.156 +  s[0] = -1; s[1] = 0x80;
  40.157 +  print(arrstr(s), arrstr(t));
  40.158 +})();
  40.159 +
  40.160 +(function enumerate_properties() {
  40.161 +  var i8 = new Int8Array(new ArrayBuffer(8));
  40.162 +  var s = ""; for (var i in i8) { s += i + " "; } print(s.trim());
  40.163 +})();
  40.164 +
  40.165 +// check that ScriptObject fallback is still working
  40.166 +// DISABLED because correct behavior is unclear
  40.167 +(function() {
  40.168 +  // NB: firefox will never set any out-of-bounds or non-array values although it does get both from prototype.
  40.169 +  var z = new Uint8Array(4);
  40.170 +  z["asdf"] = "asdf"; print(z["asdf"]);
  40.171 +  z[0x100000000] = "asdf"; print(z[0x100000000]);
  40.172 +  z[-1] = "asdf"; print(z[-1]);
  40.173 +
  40.174 +  // v8 and nashorn disagree on out-of-bounds uint32 indices: v8 won't go to the prototype.
  40.175 +  z[0xf0000000] = "asdf"; print(z[0xf0000000]);
  40.176 +  z[0xffffffff] = "asdf"; print(z[0xffffffff]);
  40.177 +  z[0x70000000] = "asdf"; print(z[0x70000000]);
  40.178 +
  40.179 +  // this will work in firefox and nashorn (not in v8).
  40.180 +  Uint8Array.prototype[4] = "asdf"; print(z[4]);
  40.181 +});
  40.182 +
  40.183 +(function test_exceptions() {
  40.184 +  assertFail(function() { new Int32Array(new ArrayBuffer(7)); });
  40.185 +  assertFail(function() { new Int32Array(new ArrayBuffer(8), 0, 4); });
  40.186 +  assertFail(function() { new Int32Array(new ArrayBuffer(8),-1, 2); });
  40.187 +  assertFail(function() { new Int32Array(new ArrayBuffer(8), 0,-1); });
  40.188 +})();
  40.189 +
  40.190 +(function test_subarray() {
  40.191 +  var x = fillArray(new Int8Array(8));
  40.192 +  print(arrstr(x));
  40.193 +  print("subarray(2,4)=" + arrstr(x.subarray(2, 4)), "subarray(-6,-4)=" + arrstr(x.subarray(-6, -4))); // negative index refers from the end of the array
  40.194 +  print(arrstr(x.subarray(-10, -2))); // negative index clamped to 0
  40.195 +  assertTrue(function(){ return arrstr(x.subarray(6, 4)) === ""; }); // negative length clamped to 0
  40.196 +  print(arrstr(x.subarray(1,-1).subarray(1,-1)), arrstr(x.subarray(1,-1).subarray(1,-1).subarray(1,-1))); // subarray of subarray
  40.197 +})();
  40.198 +
  40.199 +(function test_slice() {
  40.200 +  var b = new ArrayBuffer(16);
  40.201 +  fillArray(new Int8Array(b));
  40.202 +  print(bufstr(b));
  40.203 +  print("slice(4,8)=" + bufstr(b.slice(4, 8)), "slice(-8,-4)=" + bufstr(b.slice(-8, -4))); // negative index refers from the end of the array
  40.204 +  print(bufstr(b.slice(-20, -4))); // negative index clamped to 0
  40.205 +  assertTrue(function(){ return bufstr(b.slice(8, 4)) === ""; }); // negative length clamped to 0
  40.206 +  print(arrstr(new Int16Array(b.slice(1,-1).slice(2,-1).slice(1,-2).slice(1,-1)))); // slice of slice
  40.207 +})();
  40.208 +
  40.209 +(function test_clamped() {
  40.210 +  var a = new Uint8ClampedArray(10);
  40.211 +  a[0] = -17;       // clamped to 0
  40.212 +  a[1] = 4711;      // clamped to 255
  40.213 +  a[2] = 17.5;      // clamped to 18
  40.214 +  a[3] = 16.5;      // clamped to 16
  40.215 +  a[4] = 255.9;     // clamped to 255
  40.216 +  a[5] = Infinity;  // clamped to 255
  40.217 +  a[6] = -Infinity; // clamped to 0
  40.218 +  a[7] = NaN;       // 0
  40.219 +  assertTrue(function(){ return a[0] === 0 && a[1] === 255 && a[2] === 18 && a[3] === 16 && a[4] === 255 && a[5] === 255 && a[6] === 0 && a[7] === 0; });
  40.220 +})();
  40.221 +
  40.222 +(function test_out_of_bounds() {
  40.223 +  var a = new Int32Array(10);
  40.224 +  a[10] = 10;
  40.225 +  a[100] = 100;
  40.226 +  a[1000] = 1000;
  40.227 +  assertTrue(function(){ return isUndefined(a[10]) && isUndefined(a[11]) && isUndefined(a[100]) && isUndefined(a[123]) && isUndefined(a[1000]); });
  40.228 +})();
  40.229 +
    41.1 --- a/test/script/basic/NASHORN-377.js	Mon Dec 01 11:40:00 2014 -0800
    41.2 +++ b/test/script/basic/NASHORN-377.js	Fri Dec 12 14:58:31 2014 -0800
    41.3 @@ -26,201 +26,8 @@
    41.4   *
    41.5   * @test
    41.6   * @run
    41.7 + * @littleendian
    41.8   */
    41.9  
   41.10 -var types = [Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];
   41.11 -
   41.12 -//---------------------------------------------------------------------------
   41.13 -// utility functions
   41.14 -//---------------------------------------------------------------------------
   41.15 -function tohex(d, w) {
   41.16 -  var hex = Number(d).toString(16);
   41.17 -  var pad = (w ? w : 8) - hex.length;
   41.18 -  hex = "00000000".substr(0, pad) + hex;
   41.19 -  return hex;
   41.20 -}
   41.21 -
   41.22 -function arrstr(a, n, w) {
   41.23 -  var s = "";
   41.24 -  if (typeof n == "undefined") n = a.length;
   41.25 -  if (typeof w == "undefined") w = a.constructor.BYTES_PER_ELEMENT * 2;
   41.26 -  for (var i = 0; i < n; i++) {
   41.27 -    s += tohex(a[i], w);
   41.28 -  }
   41.29 -  return s;
   41.30 -}
   41.31 -function bufstr(b) {
   41.32 -  if (b.buffer !== undefined) {
   41.33 -    b = b.buffer;
   41.34 -  }
   41.35 -  return arrstr(new Uint8Array(b));
   41.36 -}
   41.37 -
   41.38 -function assertFail(f) {
   41.39 -  try {
   41.40 -    f();
   41.41 -  } catch (e) {
   41.42 -    //print(e);
   41.43 -    return;
   41.44 -  }
   41.45 -  throw "assertion failed: expected exception";
   41.46 -}
   41.47 -
   41.48 -function assertTrue(f) {
   41.49 -  if (f() !== true) throw "assertion failed: " + f;
   41.50 -}
   41.51 -
   41.52 -function isUndefined(x) {
   41.53 -  return typeof x === "undefined";
   41.54 -}
   41.55 -
   41.56 -function fillArray(a, start) {
   41.57 -  if (typeof start == "undefined") start = 1;
   41.58 -  for (var i = 0; i < a.length; i++) {
   41.59 -    a[i] = i + start;
   41.60 -  }
   41.61 -  return a;
   41.62 -}
   41.63 -
   41.64 -//---------------------------------------------------------------------------
   41.65 -// tests
   41.66 -//---------------------------------------------------------------------------
   41.67 -(function() {
   41.68 -  var b = new ArrayBuffer(8);
   41.69 -  var i8 = new Int8Array(b);
   41.70 -  print(i8.buffer.byteLength, b.byteLength, i8.buffer === b, b.length);
   41.71 -  print(b, i8.buffer, i8);
   41.72 -})();
   41.73 -
   41.74 -(function test_attributes() {
   41.75 -  var b = new ArrayBuffer(8);
   41.76 -  for (var i in types) {
   41.77 -    var x = new types[i](b);
   41.78 -    print(x.byteOffset, x.byteLength, x.length, x.constructor.BYTES_PER_ELEMENT);
   41.79 -    assertTrue(function(){ return x.constructor === types[i] });
   41.80 -  }
   41.81 -})();
   41.82 -
   41.83 -(function() {
   41.84 -  var b = new ArrayBuffer(8);
   41.85 -  var i8 = new Int8Array(b);
   41.86 -  fillArray(i8, 0x70);
   41.87 -
   41.88 -  var i8_2 = new Int8Array(b, 2);
   41.89 -  var i8_2_4 = new Uint8Array(b, 2, 4);
   41.90 -
   41.91 -  i8_2_4[3] = 0x80;
   41.92 -
   41.93 -  print(arrstr(i8, 8, 2)  + " " + bufstr(i8));
   41.94 -  print(arrstr(i8_2, 6)   + " " + i8_2.byteOffset   + " " + i8_2.byteLength);
   41.95 -  print(arrstr(i8_2_4, 4) + " " + i8_2_4.byteOffset + " " + i8_2_4.byteLength);
   41.96 -
   41.97 -  var i8_1_5 = i8.subarray(1, 5);
   41.98 -  i8_2_4.subarray(1, 5);
   41.99 -  print(arrstr(i8_1_5, 4) + " " + i8_1_5.byteOffset + " " + i8_1_5.byteLength);
  41.100 -
  41.101 -  print(bufstr(b.slice(1,7)));
  41.102 -})();
  41.103 -
  41.104 -(function() {
  41.105 -  var b = new ArrayBuffer(8);
  41.106 -  fillArray(new Int8Array(b), 0x70);
  41.107 -  new Int8Array(b)[5] = 0x80;
  41.108 -
  41.109 -  var i32 = new Int32Array(b);
  41.110 -  var u32 = new Uint32Array(b);
  41.111 -  print(arrstr(i32), i32[0], i32[1]);
  41.112 -  i32[1] = 0xfefdfcfb;
  41.113 -  print(arrstr(i32), i32[0], i32[1]);
  41.114 -  print(arrstr(u32), u32[0], u32[1]);
  41.115 -
  41.116 -  var pi = 3.1415926;
  41.117 -  var f32 = new Float32Array(b);
  41.118 -  var f64 = new Float64Array(b);
  41.119 -  f32[0] = pi;
  41.120 -  print(bufstr(b), f32.length);
  41.121 -  f64[0] = pi;
  41.122 -  print(bufstr(b), f64.length);
  41.123 -  print(arrstr(u32), u32[0], u32[1]);
  41.124 -
  41.125 -  var d = new Int32Array(3);
  41.126 -  d.set(i32,1);
  41.127 -  print(bufstr(d));
  41.128 -
  41.129 -  var s = new Int16Array(b);
  41.130 -  var t = new Uint16Array(b);
  41.131 -  print(arrstr(s), arrstr(t));
  41.132 -  s[0] = -1; s[1] = 0x80;
  41.133 -  print(arrstr(s), arrstr(t));
  41.134 -})();
  41.135 -
  41.136 -(function enumerate_properties() {
  41.137 -  var i8 = new Int8Array(new ArrayBuffer(8));
  41.138 -  var s = ""; for (var i in i8) { s += i + " "; } print(s.trim());
  41.139 -})();
  41.140 -
  41.141 -// check that ScriptObject fallback is still working
  41.142 -// DISABLED because correct behavior is unclear
  41.143 -(function() {
  41.144 -  // NB: firefox will never set any out-of-bounds or non-array values although it does get both from prototype.
  41.145 -  var z = new Uint8Array(4);
  41.146 -  z["asdf"] = "asdf"; print(z["asdf"]);
  41.147 -  z[0x100000000] = "asdf"; print(z[0x100000000]);
  41.148 -  z[-1] = "asdf"; print(z[-1]);
  41.149 -
  41.150 -  // v8 and nashorn disagree on out-of-bounds uint32 indices: v8 won't go to the prototype.
  41.151 -  z[0xf0000000] = "asdf"; print(z[0xf0000000]);
  41.152 -  z[0xffffffff] = "asdf"; print(z[0xffffffff]);
  41.153 -  z[0x70000000] = "asdf"; print(z[0x70000000]);
  41.154 -
  41.155 -  // this will work in firefox and nashorn (not in v8).
  41.156 -  Uint8Array.prototype[4] = "asdf"; print(z[4]);
  41.157 -});
  41.158 -
  41.159 -(function test_exceptions() {
  41.160 -  assertFail(function() { new Int32Array(new ArrayBuffer(7)); });
  41.161 -  assertFail(function() { new Int32Array(new ArrayBuffer(8), 0, 4); });
  41.162 -  assertFail(function() { new Int32Array(new ArrayBuffer(8),-1, 2); });
  41.163 -  assertFail(function() { new Int32Array(new ArrayBuffer(8), 0,-1); });
  41.164 -})();
  41.165 -
  41.166 -(function test_subarray() {
  41.167 -  var x = fillArray(new Int8Array(8));
  41.168 -  print(arrstr(x));
  41.169 -  print("subarray(2,4)=" + arrstr(x.subarray(2, 4)), "subarray(-6,-4)=" + arrstr(x.subarray(-6, -4))); // negative index refers from the end of the array
  41.170 -  print(arrstr(x.subarray(-10, -2))); // negative index clamped to 0
  41.171 -  assertTrue(function(){ return arrstr(x.subarray(6, 4)) === ""; }); // negative length clamped to 0
  41.172 -  print(arrstr(x.subarray(1,-1).subarray(1,-1)), arrstr(x.subarray(1,-1).subarray(1,-1).subarray(1,-1))); // subarray of subarray
  41.173 -})();
  41.174 -
  41.175 -(function test_slice() {
  41.176 -  var b = new ArrayBuffer(16);
  41.177 -  fillArray(new Int8Array(b));
  41.178 -  print(bufstr(b));
  41.179 -  print("slice(4,8)=" + bufstr(b.slice(4, 8)), "slice(-8,-4)=" + bufstr(b.slice(-8, -4))); // negative index refers from the end of the array
  41.180 -  print(bufstr(b.slice(-20, -4))); // negative index clamped to 0
  41.181 -  assertTrue(function(){ return bufstr(b.slice(8, 4)) === ""; }); // negative length clamped to 0
  41.182 -  print(arrstr(new Int16Array(b.slice(1,-1).slice(2,-1).slice(1,-2).slice(1,-1)))); // slice of slice
  41.183 -})();
  41.184 -
  41.185 -(function test_clamped() {
  41.186 -  var a = new Uint8ClampedArray(10);
  41.187 -  a[0] = -17;       // clamped to 0
  41.188 -  a[1] = 4711;      // clamped to 255
  41.189 -  a[2] = 17.5;      // clamped to 18
  41.190 -  a[3] = 16.5;      // clamped to 16
  41.191 -  a[4] = 255.9;     // clamped to 255
  41.192 -  a[5] = Infinity;  // clamped to 255
  41.193 -  a[6] = -Infinity; // clamped to 0
  41.194 -  a[7] = NaN;       // 0
  41.195 -  assertTrue(function(){ return a[0] === 0 && a[1] === 255 && a[2] === 18 && a[3] === 16 && a[4] === 255 && a[5] === 255 && a[6] === 0 && a[7] === 0; });
  41.196 -})();
  41.197 -
  41.198 -(function test_out_of_bounds() {
  41.199 -  var a = new Int32Array(10);
  41.200 -  a[10] = 10;
  41.201 -  a[100] = 100;
  41.202 -  a[1000] = 1000;
  41.203 -  assertTrue(function(){ return isUndefined(a[10]) && isUndefined(a[11]) && isUndefined(a[100]) && isUndefined(a[123]) && isUndefined(a[1000]); });
  41.204 -})();
  41.205 -
  41.206 +var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__;
  41.207 +load(dir + "NASHORN-377-payload.js");
    42.1 --- a/test/script/basic/compile-octane-normal.js	Mon Dec 01 11:40:00 2014 -0800
    42.2 +++ b/test/script/basic/compile-octane-normal.js	Fri Dec 12 14:58:31 2014 -0800
    42.3 @@ -38,5 +38,5 @@
    42.4   */
    42.5  
    42.6  var fn  = __DIR__ + 'compile-octane.js';
    42.7 -var url = "file://" + fn;
    42.8 -loadWithNewGlobal(new java.net.URL(url));
    42.9 +var url = new java.io.File(fn).toURL();
   42.10 +loadWithNewGlobal(url);
    43.1 --- a/test/script/basic/compile-octane-splitter.js	Mon Dec 01 11:40:00 2014 -0800
    43.2 +++ b/test/script/basic/compile-octane-splitter.js	Fri Dec 12 14:58:31 2014 -0800
    43.3 @@ -40,5 +40,5 @@
    43.4   */
    43.5  
    43.6  var fn  = __DIR__ + 'compile-octane.js';
    43.7 -var url = "file://" + fn;
    43.8 -loadWithNewGlobal(new java.net.URL(url));
    43.9 +var url = new java.io.File(fn).toURL();
   43.10 +loadWithNewGlobal(url);
    44.1 --- a/test/script/basic/compile-octane.js	Mon Dec 01 11:40:00 2014 -0800
    44.2 +++ b/test/script/basic/compile-octane.js	Fri Dec 12 14:58:31 2014 -0800
    44.3 @@ -132,7 +132,7 @@
    44.4          str2 += " processing file: " + file + "...";
    44.5          print_if_verbose(str2);
    44.6          }
    44.7 -        newGlobal.load("file://" + path + file);
    44.8 +        newGlobal.load(new java.io.File(path + file).toURL());
    44.9      }
   44.10      }
   44.11      print("Done.");
    45.1 --- a/test/script/basic/es6/const-empty.js	Mon Dec 01 11:40:00 2014 -0800
    45.2 +++ b/test/script/basic/es6/const-empty.js	Fri Dec 12 14:58:31 2014 -0800
    45.3 @@ -33,5 +33,5 @@
    45.4      eval('"use strict";\n' +
    45.5          'const x;\n');
    45.6  } catch (e) {
    45.7 -    print(e);
    45.8 +    print(String(e).replace(/\\/g, "/"));
    45.9  }
    46.1 --- a/test/script/basic/es6/const-redeclare-extra.js	Mon Dec 01 11:40:00 2014 -0800
    46.2 +++ b/test/script/basic/es6/const-redeclare-extra.js	Fri Dec 12 14:58:31 2014 -0800
    46.3 @@ -35,7 +35,7 @@
    46.4      try {
    46.5          eval(code)
    46.6      } catch (e) {
    46.7 -        print(e)
    46.8 +        print(String(e).replace(/\\/g, "/"))
    46.9      }
   46.10  }
   46.11  
    47.1 --- a/test/script/basic/es6/const-redeclare-extra.js.EXPECTED	Mon Dec 01 11:40:00 2014 -0800
    47.2 +++ b/test/script/basic/es6/const-redeclare-extra.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    47.3 @@ -1,9 +1,9 @@
    47.4  SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:3:8 Variable "x" has already been declared
    47.5      var x = {};
    47.6          ^
    47.7 -SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:2:8 Variable "x" has already been declared
    47.8 -    var x = 2;
    47.9 -        ^
   47.10 -SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:2:13 Variable "x" has already been declared
   47.11 -    function x () {}
   47.12 -             ^
   47.13 +SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:3:10 Variable "x" has already been declared
   47.14 +    const x = {};
   47.15 +          ^
   47.16 +SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:3:10 Variable "x" has already been declared
   47.17 +    const x = 5;
   47.18 +          ^
    48.1 --- a/test/script/basic/es6/const-redeclare.js	Mon Dec 01 11:40:00 2014 -0800
    48.2 +++ b/test/script/basic/es6/const-redeclare.js	Fri Dec 12 14:58:31 2014 -0800
    48.3 @@ -34,5 +34,5 @@
    48.4           'const x = 2;\n' +
    48.5           'const x = 2;\n');
    48.6  } catch (e) {
    48.7 -    print(e);
    48.8 +    print(String(e).replace(/\\/g, "/"));
    48.9  }
    49.1 --- a/test/script/basic/es6/for-let.js	Mon Dec 01 11:40:00 2014 -0800
    49.2 +++ b/test/script/basic/es6/for-let.js	Fri Dec 12 14:58:31 2014 -0800
    49.3 @@ -39,3 +39,40 @@
    49.4  } catch (e) {
    49.5      print(e);
    49.6  }
    49.7 +
    49.8 +let a = [];
    49.9 +
   49.10 +for (let i = 0; i < 10; i++) {
   49.11 +    a.push(function() { print(i); });
   49.12 +}
   49.13 +
   49.14 +a.forEach(function(f) { f(); });
   49.15 +
   49.16 +a = [];
   49.17 +
   49.18 +for (let i = 0; i < 10; i++) {
   49.19 +    if (i == 5) {
   49.20 +        i = "foo";
   49.21 +    }
   49.22 +    a.push(function() { print(i); });
   49.23 +}
   49.24 +
   49.25 +a.forEach(function(f) { f(); });
   49.26 +
   49.27 +try {
   49.28 +    print(i);
   49.29 +} catch (e) {
   49.30 +    print(e);
   49.31 +}
   49.32 +
   49.33 +a = [];
   49.34 +
   49.35 +for (let i = 0; i < 20; i++) {
   49.36 +    if (i % 2 == 1) {
   49.37 +        i += 2;
   49.38 +        continue;
   49.39 +    }
   49.40 +    a.push(function() { print(i); });
   49.41 +}
   49.42 +
   49.43 +a.forEach(function(f) { f(); });
    50.1 --- a/test/script/basic/es6/for-let.js.EXPECTED	Mon Dec 01 11:40:00 2014 -0800
    50.2 +++ b/test/script/basic/es6/for-let.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    50.3 @@ -9,3 +9,25 @@
    50.4  8
    50.5  9
    50.6  ReferenceError: "i" is not defined
    50.7 +0
    50.8 +1
    50.9 +2
   50.10 +3
   50.11 +4
   50.12 +5
   50.13 +6
   50.14 +7
   50.15 +8
   50.16 +9
   50.17 +0
   50.18 +1
   50.19 +2
   50.20 +3
   50.21 +4
   50.22 +foo
   50.23 +ReferenceError: "i" is not defined
   50.24 +0
   50.25 +4
   50.26 +8
   50.27 +12
   50.28 +16
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/test/script/basic/es6/let-const-statement-context.js	Fri Dec 12 14:58:31 2014 -0800
    51.3 @@ -0,0 +1,49 @@
    51.4 +/*
    51.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    51.7 + * 
    51.8 + * This code is free software; you can redistribute it and/or modify it
    51.9 + * under the terms of the GNU General Public License version 2 only, as
   51.10 + * published by the Free Software Foundation.
   51.11 + * 
   51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   51.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   51.15 + * version 2 for more details (a copy is included in the LICENSE file that
   51.16 + * accompanied this code).
   51.17 + * 
   51.18 + * You should have received a copy of the GNU General Public License version
   51.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   51.21 + * 
   51.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   51.23 + * or visit www.oracle.com if you need additional information or have any
   51.24 + * questions.
   51.25 + */
   51.26 +
   51.27 +/**
   51.28 + * JDK-8057980: let & const: remaining issues with lexical scoping
   51.29 + *
   51.30 + * @test
   51.31 + * @run
   51.32 + * @option --language=es6
   51.33 + */
   51.34 +
   51.35 +function tryEval(s) {
   51.36 +    try {
   51.37 +        eval(s);
   51.38 +    } catch (e) {
   51.39 +        print(String(e).replace(/\\/g, "/"));
   51.40 +    }
   51.41 +}
   51.42 +
   51.43 +tryEval('if (true) let x = 1;');
   51.44 +tryEval('if (true) const x = 1;');
   51.45 +tryEval('while (true) let x = 1;');
   51.46 +tryEval('while (true) const x = 1;');
   51.47 +tryEval('for (;;) let x = 1;');
   51.48 +tryEval('for (;;) const x = 1;');
   51.49 +tryEval('do let x = 1; while (true);');
   51.50 +tryEval('do const x = 1; while (true);');
   51.51 +tryEval('with (y) const x = 1;');
   51.52 +tryEval('with (y) let x = 1;');
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/test/script/basic/es6/let-const-statement-context.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    52.3 @@ -0,0 +1,30 @@
    52.4 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:10 Expected statement but found let declaration
    52.5 +if (true) let x = 1;
    52.6 +          ^
    52.7 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:10 Expected statement but found const declaration
    52.8 +if (true) const x = 1;
    52.9 +          ^
   52.10 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:13 Expected statement but found let declaration
   52.11 +while (true) let x = 1;
   52.12 +             ^
   52.13 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:13 Expected statement but found const declaration
   52.14 +while (true) const x = 1;
   52.15 +             ^
   52.16 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:9 Expected statement but found let declaration
   52.17 +for (;;) let x = 1;
   52.18 +         ^
   52.19 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:9 Expected statement but found const declaration
   52.20 +for (;;) const x = 1;
   52.21 +         ^
   52.22 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:3 Expected statement but found let declaration
   52.23 +do let x = 1; while (true);
   52.24 +   ^
   52.25 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:3 Expected statement but found const declaration
   52.26 +do const x = 1; while (true);
   52.27 +   ^
   52.28 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:9 Expected statement but found const declaration
   52.29 +with (y) const x = 1;
   52.30 +         ^
   52.31 +SyntaxError: test/script/basic/es6/let-const-statement-context.js#34:8<eval>:1:9 Expected statement but found let declaration
   52.32 +with (y) let x = 1;
   52.33 +         ^
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/test/script/basic/es6/let-const-switch.js	Fri Dec 12 14:58:31 2014 -0800
    53.3 @@ -0,0 +1,45 @@
    53.4 +/*
    53.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    53.7 + * 
    53.8 + * This code is free software; you can redistribute it and/or modify it
    53.9 + * under the terms of the GNU General Public License version 2 only, as
   53.10 + * published by the Free Software Foundation.
   53.11 + * 
   53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   53.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   53.15 + * version 2 for more details (a copy is included in the LICENSE file that
   53.16 + * accompanied this code).
   53.17 + * 
   53.18 + * You should have received a copy of the GNU General Public License version
   53.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   53.21 + * 
   53.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   53.23 + * or visit www.oracle.com if you need additional information or have any
   53.24 + * questions.
   53.25 + */
   53.26 +
   53.27 +/**
   53.28 + * JDK-8057980: let & const: remaining issues with lexical scoping
   53.29 + *
   53.30 + * @test
   53.31 + * @run
   53.32 + * @option --language=es6
   53.33 + */
   53.34 +
   53.35 +function tryEval(s) {
   53.36 +    try {
   53.37 +        eval(s);
   53.38 +    } catch (e) {
   53.39 +        print(String(e).replace(/\\/g, "/"));
   53.40 +    }
   53.41 +}
   53.42 +
   53.43 +tryEval('var x = 0; switch (x) { case 0: { let   x = 1; print(x); } case 1: { let   x = 2; print(x); }} print(x);');
   53.44 +tryEval('var x = 0; switch (x) { case 0: { const x = 1; print(x); } case 1: { const x = 2; print(x); }} print(x);');
   53.45 +
   53.46 +// TODO: the following should not throw
   53.47 +tryEval('switch (x) { case 0: let x = 1; }');
   53.48 +tryEval('switch (x) { case 0: const x = 1; }');
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/test/script/basic/es6/let-const-switch.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    54.3 @@ -0,0 +1,12 @@
    54.4 +1
    54.5 +2
    54.6 +0
    54.7 +1
    54.8 +2
    54.9 +0
   54.10 +SyntaxError: test/script/basic/es6/let-const-switch.js#34:8<eval>:1:25 Unsupported let declaration in unprotected switch statement
   54.11 +switch (x) { case 0: let x = 1; }
   54.12 +                         ^
   54.13 +SyntaxError: test/script/basic/es6/let-const-switch.js#34:8<eval>:1:27 Unsupported const declaration in unprotected switch statement
   54.14 +switch (x) { case 0: const x = 1; }
   54.15 +                           ^
    55.1 --- a/test/script/basic/es6/let-load.js	Mon Dec 01 11:40:00 2014 -0800
    55.2 +++ b/test/script/basic/es6/let-load.js	Fri Dec 12 14:58:31 2014 -0800
    55.3 @@ -26,7 +26,8 @@
    55.4   *
    55.5   * @test
    55.6   * @run
    55.7 - * @option --language=es6 */
    55.8 + * @option --language=es6
    55.9 + */
   55.10  
   55.11  "use strict";
   55.12  
   55.13 @@ -39,17 +40,8 @@
   55.14  }
   55.15  
   55.16  print("imported var: " + a);
   55.17 -try {
   55.18 -    print("imported let: " + b);
   55.19 -} catch (e) {
   55.20 -    print(e);
   55.21 -}
   55.22 -
   55.23 -try {
   55.24 -    print("imported const: " + c);
   55.25 -} catch (e) {
   55.26 -    print(e);
   55.27 -}
   55.28 +print("imported let: " + b);
   55.29 +print("imported const: " + c);
   55.30  
   55.31  top();
   55.32  
   55.33 @@ -59,4 +51,10 @@
   55.34      print(e);
   55.35  }
   55.36  
   55.37 +try {
   55.38 +    c = "foo";
   55.39 +} catch (e) {
   55.40 +    print(e);
   55.41 +}
   55.42  
   55.43 +
    56.1 --- a/test/script/basic/es6/let-load.js.EXPECTED	Mon Dec 01 11:40:00 2014 -0800
    56.2 +++ b/test/script/basic/es6/let-load.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    56.3 @@ -2,7 +2,8 @@
    56.4  block function
    56.5  print local defs: 20 30
    56.6  imported var: 1
    56.7 -ReferenceError: "b" is not defined
    56.8 -ReferenceError: "c" is not defined
    56.9 +imported let: 2
   56.10 +imported const: 3
   56.11  top level function
   56.12  ReferenceError: "block" is not defined
   56.13 +TypeError: Assignment to constant "c"
    57.1 --- a/test/script/basic/es6/let-redeclare-extra.js	Mon Dec 01 11:40:00 2014 -0800
    57.2 +++ b/test/script/basic/es6/let-redeclare-extra.js	Fri Dec 12 14:58:31 2014 -0800
    57.3 @@ -34,7 +34,7 @@
    57.4      try {
    57.5          eval(code)
    57.6      } catch (e) {
    57.7 -        print(e)
    57.8 +        print(String(e).replace(/\\/g, "/"))
    57.9      }
   57.10  }
   57.11  
    58.1 --- a/test/script/basic/es6/let-redeclare-extra.js.EXPECTED	Mon Dec 01 11:40:00 2014 -0800
    58.2 +++ b/test/script/basic/es6/let-redeclare-extra.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    58.3 @@ -4,12 +4,12 @@
    58.4  SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:3:8 Variable "x" has already been declared
    58.5      var x = 2;
    58.6          ^
    58.7 -SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:2:8 Variable "x" has already been declared
    58.8 -    var x = 2;
    58.9 +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:3:8 Variable "x" has already been declared
   58.10 +    let x = undefined;
   58.11          ^
   58.12  SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:2:10 Variable "x" has already been declared
   58.13      const x = function (){};
   58.14            ^
   58.15 -SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:3:13 Variable "a" has already been declared
   58.16 -    function a () {};
   58.17 -             ^
   58.18 +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:2:8 Variable "a" has already been declared
   58.19 +    let a = 2;
   58.20 +        ^
    59.1 --- a/test/script/basic/es6/let-redeclare.js	Mon Dec 01 11:40:00 2014 -0800
    59.2 +++ b/test/script/basic/es6/let-redeclare.js	Fri Dec 12 14:58:31 2014 -0800
    59.3 @@ -34,5 +34,5 @@
    59.4           'let x = 2;\n' +
    59.5           'let x = 2;\n');
    59.6  } catch (e) {
    59.7 -    print(e);
    59.8 +    print(String(e).replace(/\\/g, "/"));
    59.9  }
    60.1 --- a/test/script/basic/es6/let_const_closure.js.EXPECTED	Mon Dec 01 11:40:00 2014 -0800
    60.2 +++ b/test/script/basic/es6/let_const_closure.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    60.3 @@ -5,9 +5,9 @@
    60.4  test
    60.5  test
    60.6  test
    60.7 -3
    60.8 -3
    60.9 -3
   60.10  0
   60.11  1
   60.12  2
   60.13 +0
   60.14 +1
   60.15 +2
    61.1 --- a/test/script/basic/es6/let_const_reuse.js	Mon Dec 01 11:40:00 2014 -0800
    61.2 +++ b/test/script/basic/es6/let_const_reuse.js	Fri Dec 12 14:58:31 2014 -0800
    61.3 @@ -34,7 +34,7 @@
    61.4       try {
    61.5           eval(code)
    61.6       } catch (e) {
    61.7 -         print(e)
    61.8 +         print(String(e).replace(/\\/g, "/"))
    61.9       }
   61.10  }
   61.11  
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/test/script/basic/es6/lexical-toplevel-def.js	Fri Dec 12 14:58:31 2014 -0800
    62.3 @@ -0,0 +1,34 @@
    62.4 +/*
    62.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    62.7 + * 
    62.8 + * This code is free software; you can redistribute it and/or modify it
    62.9 + * under the terms of the GNU General Public License version 2 only, as
   62.10 + * published by the Free Software Foundation.
   62.11 + * 
   62.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   62.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   62.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   62.15 + * version 2 for more details (a copy is included in the LICENSE file that
   62.16 + * accompanied this code).
   62.17 + * 
   62.18 + * You should have received a copy of the GNU General Public License version
   62.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   62.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   62.21 + * 
   62.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   62.23 + * or visit www.oracle.com if you need additional information or have any
   62.24 + * questions.
   62.25 + */
   62.26 +
   62.27 +/**
   62.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   62.29 + *
   62.30 + * @subtest
   62.31 + */
   62.32 +
   62.33 +var   VAR   = "VAR";
   62.34 +let   LET   = "LET";
   62.35 +const CONST = "CONST";
   62.36 +function FUNC() {}
   62.37 +this.GLOBAL = "GLOBAL";
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/test/script/basic/es6/lexical-toplevel-print.js	Fri Dec 12 14:58:31 2014 -0800
    63.3 @@ -0,0 +1,51 @@
    63.4 +/*
    63.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    63.7 + * 
    63.8 + * This code is free software; you can redistribute it and/or modify it
    63.9 + * under the terms of the GNU General Public License version 2 only, as
   63.10 + * published by the Free Software Foundation.
   63.11 + * 
   63.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   63.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   63.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   63.15 + * version 2 for more details (a copy is included in the LICENSE file that
   63.16 + * accompanied this code).
   63.17 + * 
   63.18 + * You should have received a copy of the GNU General Public License version
   63.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   63.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   63.21 + * 
   63.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   63.23 + * or visit www.oracle.com if you need additional information or have any
   63.24 + * questions.
   63.25 + */
   63.26 +
   63.27 +/**
   63.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   63.29 + *
   63.30 + * @subtest
   63.31 + */
   63.32 +
   63.33 +print(VAR);
   63.34 +print(LET);
   63.35 +print(CONST);
   63.36 +print(FUNC);
   63.37 +print(GLOBAL);
   63.38 +print(this.VAR);
   63.39 +print(this.LET);   // undefined
   63.40 +print(this.CONST); // undefined
   63.41 +print(this.FUNC);
   63.42 +print(this.GLOBAL);
   63.43 +print("VAR" in this);
   63.44 +print("LET" in this);   // false
   63.45 +print("CONST" in this); // false
   63.46 +print("FUNC" in this);
   63.47 +print("GLOBAL" in this);
   63.48 +
   63.49 +try {
   63.50 +    LET   = LET + "LET";
   63.51 +    CONST = CONST + "CONST";
   63.52 +} catch (e) {
   63.53 +    print(String(e).replace(/\\/g, "/"));
   63.54 +}
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-func-on-let.js	Fri Dec 12 14:58:31 2014 -0800
    64.3 @@ -0,0 +1,31 @@
    64.4 +/*
    64.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    64.7 + * 
    64.8 + * This code is free software; you can redistribute it and/or modify it
    64.9 + * under the terms of the GNU General Public License version 2 only, as
   64.10 + * published by the Free Software Foundation.
   64.11 + * 
   64.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   64.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   64.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   64.15 + * version 2 for more details (a copy is included in the LICENSE file that
   64.16 + * accompanied this code).
   64.17 + * 
   64.18 + * You should have received a copy of the GNU General Public License version
   64.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   64.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   64.21 + * 
   64.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   64.23 + * or visit www.oracle.com if you need additional information or have any
   64.24 + * questions.
   64.25 + */
   64.26 +
   64.27 +/**
   64.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   64.29 + *
   64.30 + * @subtest
   64.31 + */
   64.32 +
   64.33 +function LET() {}
   64.34 +var SHOULD_NOT_EXIST = 10;
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-let-on-builtin.js	Fri Dec 12 14:58:31 2014 -0800
    65.3 @@ -0,0 +1,30 @@
    65.4 +/*
    65.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    65.7 + * 
    65.8 + * This code is free software; you can redistribute it and/or modify it
    65.9 + * under the terms of the GNU General Public License version 2 only, as
   65.10 + * published by the Free Software Foundation.
   65.11 + * 
   65.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   65.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   65.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   65.15 + * version 2 for more details (a copy is included in the LICENSE file that
   65.16 + * accompanied this code).
   65.17 + * 
   65.18 + * You should have received a copy of the GNU General Public License version
   65.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   65.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   65.21 + * 
   65.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   65.23 + * or visit www.oracle.com if you need additional information or have any
   65.24 + * questions.
   65.25 + */
   65.26 +
   65.27 +/**
   65.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   65.29 + *
   65.30 + * @subtest
   65.31 + */
   65.32 +
   65.33 +let Object = "LEXICAL BUILTIN";
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-let-on-func.js	Fri Dec 12 14:58:31 2014 -0800
    66.3 @@ -0,0 +1,31 @@
    66.4 +/*
    66.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    66.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    66.7 + * 
    66.8 + * This code is free software; you can redistribute it and/or modify it
    66.9 + * under the terms of the GNU General Public License version 2 only, as
   66.10 + * published by the Free Software Foundation.
   66.11 + * 
   66.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   66.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   66.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   66.15 + * version 2 for more details (a copy is included in the LICENSE file that
   66.16 + * accompanied this code).
   66.17 + * 
   66.18 + * You should have received a copy of the GNU General Public License version
   66.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   66.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   66.21 + * 
   66.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   66.23 + * or visit www.oracle.com if you need additional information or have any
   66.24 + * questions.
   66.25 + */
   66.26 +
   66.27 +/**
   66.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   66.29 + *
   66.30 + * @subtest
   66.31 + */
   66.32 +
   66.33 +let FUNC = 10;
   66.34 +var SHOULD_NOT_EXIST = 10;
    67.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-let-on-global.js	Fri Dec 12 14:58:31 2014 -0800
    67.3 @@ -0,0 +1,30 @@
    67.4 +/*
    67.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    67.7 + * 
    67.8 + * This code is free software; you can redistribute it and/or modify it
    67.9 + * under the terms of the GNU General Public License version 2 only, as
   67.10 + * published by the Free Software Foundation.
   67.11 + * 
   67.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   67.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   67.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   67.15 + * version 2 for more details (a copy is included in the LICENSE file that
   67.16 + * accompanied this code).
   67.17 + * 
   67.18 + * You should have received a copy of the GNU General Public License version
   67.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   67.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   67.21 + * 
   67.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   67.23 + * or visit www.oracle.com if you need additional information or have any
   67.24 + * questions.
   67.25 + */
   67.26 +
   67.27 +/**
   67.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   67.29 + *
   67.30 + * @subtest
   67.31 + */
   67.32 +
   67.33 +let GLOBAL = "LEXICAL GLOBAL";
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-let-on-var.js	Fri Dec 12 14:58:31 2014 -0800
    68.3 @@ -0,0 +1,31 @@
    68.4 +/*
    68.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    68.7 + * 
    68.8 + * This code is free software; you can redistribute it and/or modify it
    68.9 + * under the terms of the GNU General Public License version 2 only, as
   68.10 + * published by the Free Software Foundation.
   68.11 + * 
   68.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   68.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   68.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   68.15 + * version 2 for more details (a copy is included in the LICENSE file that
   68.16 + * accompanied this code).
   68.17 + * 
   68.18 + * You should have received a copy of the GNU General Public License version
   68.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   68.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   68.21 + * 
   68.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   68.23 + * or visit www.oracle.com if you need additional information or have any
   68.24 + * questions.
   68.25 + */
   68.26 +
   68.27 +/**
   68.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   68.29 + *
   68.30 + * @subtest
   68.31 + */
   68.32 +
   68.33 +let VAR = 10;
   68.34 +var SHOULD_NOT_EXIST = 10;
    69.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-var-on-let.js	Fri Dec 12 14:58:31 2014 -0800
    69.3 @@ -0,0 +1,31 @@
    69.4 +/*
    69.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    69.7 + * 
    69.8 + * This code is free software; you can redistribute it and/or modify it
    69.9 + * under the terms of the GNU General Public License version 2 only, as
   69.10 + * published by the Free Software Foundation.
   69.11 + * 
   69.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   69.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   69.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   69.15 + * version 2 for more details (a copy is included in the LICENSE file that
   69.16 + * accompanied this code).
   69.17 + * 
   69.18 + * You should have received a copy of the GNU General Public License version
   69.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   69.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   69.21 + * 
   69.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   69.23 + * or visit www.oracle.com if you need additional information or have any
   69.24 + * questions.
   69.25 + */
   69.26 +
   69.27 +/**
   69.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   69.29 + *
   69.30 + * @subtest
   69.31 + */
   69.32 +
   69.33 +var LET = 10;
   69.34 +var SHOULD_NOT_EXIST = 10;
    70.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare.js	Fri Dec 12 14:58:31 2014 -0800
    70.3 @@ -0,0 +1,78 @@
    70.4 +/*
    70.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    70.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    70.7 + * 
    70.8 + * This code is free software; you can redistribute it and/or modify it
    70.9 + * under the terms of the GNU General Public License version 2 only, as
   70.10 + * published by the Free Software Foundation.
   70.11 + * 
   70.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   70.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   70.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   70.15 + * version 2 for more details (a copy is included in the LICENSE file that
   70.16 + * accompanied this code).
   70.17 + * 
   70.18 + * You should have received a copy of the GNU General Public License version
   70.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   70.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   70.21 + * 
   70.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   70.23 + * or visit www.oracle.com if you need additional information or have any
   70.24 + * questions.
   70.25 + */
   70.26 +
   70.27 +/**
   70.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   70.29 + *
   70.30 + * @test
   70.31 + * @run
   70.32 + * @option -scripting
   70.33 + * @option --language=es6
   70.34 + */
   70.35 +
   70.36 +load(__DIR__ + "lexical-toplevel-def.js");
   70.37 +
   70.38 +var global = this;
   70.39 +
   70.40 +function tryIt (code) {
   70.41 +    try {
   70.42 +        eval(code)
   70.43 +    } catch (e) {
   70.44 +        print(String(e).replace(/\\/g, "/"))
   70.45 +    }
   70.46 +}
   70.47 +
   70.48 +function loadScript(script) {
   70.49 +    print(script);
   70.50 +    try {
   70.51 +        load(__DIR__ + script);
   70.52 +    } catch (e) {
   70.53 +        print(String(e).replace(/\\/g, "/"));
   70.54 +    }
   70.55 +    print(VAR);
   70.56 +    print(LET);
   70.57 +    print(CONST);
   70.58 +    print(FUNC);
   70.59 +    print(GLOBAL);
   70.60 +    print(global.VAR);
   70.61 +    print(global.LET);
   70.62 +    print(global.CONST);
   70.63 +    print(global.FUNC);
   70.64 +    print(global.GLOBAL);
   70.65 +    try {
   70.66 +        print(SHOULD_NOT_EXIST);
   70.67 +    } catch (e) {
   70.68 +        print(String(e).replace(/\\/g, "/"));
   70.69 +    }
   70.70 +    print(global.SHOULD_NOT_EXIST);
   70.71 +    print(Object);
   70.72 +    print(global.Object);
   70.73 +    print();
   70.74 +}
   70.75 +
   70.76 +loadScript("lexical-toplevel-redeclare-var-on-let.js");
   70.77 +loadScript("lexical-toplevel-redeclare-func-on-let.js");
   70.78 +loadScript("lexical-toplevel-redeclare-let-on-var.js");
   70.79 +loadScript("lexical-toplevel-redeclare-let-on-func.js");
   70.80 +loadScript("lexical-toplevel-redeclare-let-on-builtin.js");
   70.81 +loadScript("lexical-toplevel-redeclare-let-on-global.js");
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    71.3 @@ -0,0 +1,100 @@
    71.4 +lexical-toplevel-redeclare-var-on-let.js
    71.5 +SyntaxError: Variable "LET" has already been declared
    71.6 +VAR
    71.7 +LET
    71.8 +CONST
    71.9 +function FUNC() {}
   71.10 +GLOBAL
   71.11 +VAR
   71.12 +undefined
   71.13 +undefined
   71.14 +function FUNC() {}
   71.15 +GLOBAL
   71.16 +ReferenceError: "SHOULD_NOT_EXIST" is not defined
   71.17 +undefined
   71.18 +function Object() { [native code] }
   71.19 +function Object() { [native code] }
   71.20 +
   71.21 +lexical-toplevel-redeclare-func-on-let.js
   71.22 +SyntaxError: Variable "LET" has already been declared
   71.23 +VAR
   71.24 +LET
   71.25 +CONST
   71.26 +function FUNC() {}
   71.27 +GLOBAL
   71.28 +VAR
   71.29 +undefined
   71.30 +undefined
   71.31 +function FUNC() {}
   71.32 +GLOBAL
   71.33 +ReferenceError: "SHOULD_NOT_EXIST" is not defined
   71.34 +undefined
   71.35 +function Object() { [native code] }
   71.36 +function Object() { [native code] }
   71.37 +
   71.38 +lexical-toplevel-redeclare-let-on-var.js
   71.39 +SyntaxError: Variable "VAR" has already been declared
   71.40 +VAR
   71.41 +LET
   71.42 +CONST
   71.43 +function FUNC() {}
   71.44 +GLOBAL
   71.45 +VAR
   71.46 +undefined
   71.47 +undefined
   71.48 +function FUNC() {}
   71.49 +GLOBAL
   71.50 +ReferenceError: "SHOULD_NOT_EXIST" is not defined
   71.51 +undefined
   71.52 +function Object() { [native code] }
   71.53 +function Object() { [native code] }
   71.54 +
   71.55 +lexical-toplevel-redeclare-let-on-func.js
   71.56 +SyntaxError: Variable "FUNC" has already been declared
   71.57 +VAR
   71.58 +LET
   71.59 +CONST
   71.60 +function FUNC() {}
   71.61 +GLOBAL
   71.62 +VAR
   71.63 +undefined
   71.64 +undefined
   71.65 +function FUNC() {}
   71.66 +GLOBAL
   71.67 +ReferenceError: "SHOULD_NOT_EXIST" is not defined
   71.68 +undefined
   71.69 +function Object() { [native code] }
   71.70 +function Object() { [native code] }
   71.71 +
   71.72 +lexical-toplevel-redeclare-let-on-builtin.js
   71.73 +VAR
   71.74 +LET
   71.75 +CONST
   71.76 +function FUNC() {}
   71.77 +GLOBAL
   71.78 +VAR
   71.79 +undefined
   71.80 +undefined
   71.81 +function FUNC() {}
   71.82 +GLOBAL
   71.83 +ReferenceError: "SHOULD_NOT_EXIST" is not defined
   71.84 +undefined
   71.85 +LEXICAL BUILTIN
   71.86 +function Object() { [native code] }
   71.87 +
   71.88 +lexical-toplevel-redeclare-let-on-global.js
   71.89 +VAR
   71.90 +LET
   71.91 +CONST
   71.92 +function FUNC() {}
   71.93 +LEXICAL GLOBAL
   71.94 +VAR
   71.95 +undefined
   71.96 +undefined
   71.97 +function FUNC() {}
   71.98 +GLOBAL
   71.99 +ReferenceError: "SHOULD_NOT_EXIST" is not defined
  71.100 +undefined
  71.101 +LEXICAL BUILTIN
  71.102 +function Object() { [native code] }
  71.103 +
    72.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.2 +++ b/test/script/basic/es6/lexical-toplevel.js	Fri Dec 12 14:58:31 2014 -0800
    72.3 @@ -0,0 +1,35 @@
    72.4 +/*
    72.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    72.7 + * 
    72.8 + * This code is free software; you can redistribute it and/or modify it
    72.9 + * under the terms of the GNU General Public License version 2 only, as
   72.10 + * published by the Free Software Foundation.
   72.11 + * 
   72.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   72.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   72.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   72.15 + * version 2 for more details (a copy is included in the LICENSE file that
   72.16 + * accompanied this code).
   72.17 + * 
   72.18 + * You should have received a copy of the GNU General Public License version
   72.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   72.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   72.21 + * 
   72.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   72.23 + * or visit www.oracle.com if you need additional information or have any
   72.24 + * questions.
   72.25 + */
   72.26 +
   72.27 +/**
   72.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts
   72.29 + *
   72.30 + * @test
   72.31 + * @run
   72.32 + * @option --language=es6
   72.33 + */
   72.34 +
   72.35 +load(__DIR__ + "lexical-toplevel-def.js");
   72.36 +
   72.37 +load(__DIR__ + "lexical-toplevel-print.js");
   72.38 +load(__DIR__ + "lexical-toplevel-print.js");
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/test/script/basic/es6/lexical-toplevel.js.EXPECTED	Fri Dec 12 14:58:31 2014 -0800
    73.3 @@ -0,0 +1,32 @@
    73.4 +VAR
    73.5 +LET
    73.6 +CONST
    73.7 +function FUNC() {}
    73.8 +GLOBAL
    73.9 +VAR
   73.10 +undefined
   73.11 +undefined
   73.12 +function FUNC() {}
   73.13 +GLOBAL
   73.14 +true
   73.15 +false
   73.16 +false
   73.17 +true
   73.18 +true
   73.19 +TypeError: Assignment to constant "CONST"
   73.20 +VAR
   73.21 +LETLET
   73.22 +CONST
   73.23 +function FUNC() {}
   73.24 +GLOBAL
   73.25 +VAR
   73.26 +undefined
   73.27 +undefined
   73.28 +function FUNC() {}
   73.29 +GLOBAL
   73.30 +true
   73.31 +false
   73.32 +false
   73.33 +true
   73.34 +true
   73.35 +TypeError: Assignment to constant "CONST"
    74.1 --- a/test/script/nosecurity/JDK-8050964.js	Mon Dec 01 11:40:00 2014 -0800
    74.2 +++ b/test/script/nosecurity/JDK-8050964.js	Fri Dec 12 14:58:31 2014 -0800
    74.3 @@ -50,6 +50,7 @@
    74.4  var jdepsPath = javahome + "/../bin/jdeps".replaceAll(/\//g, File.separater);
    74.5  
    74.6  // run jdep on nashorn.jar - only summary but print profile info
    74.7 +$ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin
    74.8  `${jdepsPath} -s -P ${nashornJar.absolutePath}`
    74.9  
   74.10  // check for "(compact1)" in output from jdep tool
    75.1 --- a/test/script/nosecurity/JDK-8055034.js	Mon Dec 01 11:40:00 2014 -0800
    75.2 +++ b/test/script/nosecurity/JDK-8055034.js	Fri Dec 12 14:58:31 2014 -0800
    75.3 @@ -49,7 +49,7 @@
    75.4  var jjsCmd = javahome + "/../bin/jjs";
    75.5  jjsCmd += " -J-Djava.ext.dirs=" + nashornJarDir;
    75.6  jjsCmd = jjsCmd.toString().replaceAll(/\//g, File.separater);
    75.7 -
    75.8 +$ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin
    75.9  $EXEC(jjsCmd, "var x = Object.create(null);\nx;\nprint('PASSED');\nexit(0)");
   75.10  
   75.11  // $ERR has all interactions including prompts! Just check for error substring.
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/test/src/jdk/nashorn/internal/runtime/LexicalBindingTest.java	Fri Dec 12 14:58:31 2014 -0800
    76.3 @@ -0,0 +1,212 @@
    76.4 +/*
    76.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    76.7 + *
    76.8 + * This code is free software; you can redistribute it and/or modify it
    76.9 + * under the terms of the GNU General Public License version 2 only, as
   76.10 + * published by the Free Software Foundation.  Oracle designates this
   76.11 + * particular file as subject to the "Classpath" exception as provided
   76.12 + * by Oracle in the LICENSE file that accompanied this code.
   76.13 + *
   76.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   76.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   76.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   76.17 + * version 2 for more details (a copy is included in the LICENSE file that
   76.18 + * accompanied this code).
   76.19 + *
   76.20 + * You should have received a copy of the GNU General Public License version
   76.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   76.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   76.23 + *
   76.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   76.25 + * or visit www.oracle.com if you need additional information or have any
   76.26 + * questions.
   76.27 + */
   76.28 +
   76.29 +package jdk.nashorn.internal.runtime;
   76.30 +
   76.31 +import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
   76.32 +import org.testng.annotations.Test;
   76.33 +
   76.34 +import javax.script.Bindings;
   76.35 +import javax.script.ScriptContext;
   76.36 +import javax.script.ScriptEngine;
   76.37 +import javax.script.ScriptException;
   76.38 +import javax.script.SimpleScriptContext;
   76.39 +
   76.40 +import static org.testng.Assert.assertEquals;
   76.41 +
   76.42 +/**
   76.43 + * Top-level lexical binding tests.
   76.44 + *
   76.45 + * @test
   76.46 + * @run testng jdk.nashorn.internal.runtime.LexicalBindingTest
   76.47 + */
   76.48 +@SuppressWarnings("javadoc")
   76.49 +public class LexicalBindingTest {
   76.50 +
   76.51 +    final static String LANGUAGE_ES6 = "--language=es6";
   76.52 +    final static int NUMBER_OF_CONTEXTS = 20;
   76.53 +    final static int MEGAMORPHIC_LOOP_COUNT = 20;
   76.54 +
   76.55 +    /**
   76.56 +     * Test access to global var-declared variables for shared script classes with multiple globals.
   76.57 +     */
   76.58 +    @Test
   76.59 +    public static void megamorphicVarTest() throws ScriptException, InterruptedException {
   76.60 +        final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
   76.61 +        final ScriptEngine e = factory.getScriptEngine();
   76.62 +        final ScriptContext[] contexts = new ScriptContext[NUMBER_OF_CONTEXTS];
   76.63 +        final String sharedScript = "foo";
   76.64 +
   76.65 +
   76.66 +        for (int i = 0; i < NUMBER_OF_CONTEXTS; i++) {
   76.67 +            final ScriptContext context = contexts[i] = new SimpleScriptContext();
   76.68 +            final Bindings b = e.createBindings();
   76.69 +            context.setBindings(b, ScriptContext.ENGINE_SCOPE);
   76.70 +            assertEquals(e.eval("var foo = '" + i + "';", context), null);
   76.71 +        }
   76.72 +
   76.73 +        for (int i = 0; i < NUMBER_OF_CONTEXTS; i++) {
   76.74 +            final ScriptContext context = contexts[i];
   76.75 +            assertEquals(e.eval(sharedScript, context), String.valueOf(i));
   76.76 +        }
   76.77 +    }
   76.78 +
   76.79 +    /**
   76.80 +     * Test access to global lexically declared variables for shared script classes with multiple globals.
   76.81 +     */
   76.82 +    @Test
   76.83 +    public static void megamorphicMultiGlobalLetTest() throws ScriptException, InterruptedException {
   76.84 +        final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
   76.85 +        final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6);
   76.86 +        final ScriptContext[] contexts = new ScriptContext[NUMBER_OF_CONTEXTS];
   76.87 +        final String sharedScript = "foo";
   76.88 +
   76.89 +
   76.90 +        for (int i = 0; i < NUMBER_OF_CONTEXTS; i++) {
   76.91 +            final ScriptContext context = contexts[i] = new SimpleScriptContext();
   76.92 +            final Bindings b = e.createBindings();
   76.93 +            context.setBindings(b, ScriptContext.ENGINE_SCOPE);
   76.94 +            assertEquals(e.eval("let foo = '" + i + "';", context), null);
   76.95 +        }
   76.96 +
   76.97 +        for (int i = 0; i < NUMBER_OF_CONTEXTS; i++) {
   76.98 +            final ScriptContext context = contexts[i];
   76.99 +            assertEquals(e.eval(sharedScript, context), String.valueOf(i));
  76.100 +        }
  76.101 +    }
  76.102 +
  76.103 +
  76.104 +    /**
  76.105 +     * Test access to global lexically declared variables for shared script classes with single global.
  76.106 +     */
  76.107 +    @Test
  76.108 +    public static void megamorphicSingleGlobalLetTest() throws ScriptException, InterruptedException {
  76.109 +        final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
  76.110 +        final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6);
  76.111 +        final String sharedGetterScript = "foo";
  76.112 +        final String sharedSetterScript = "foo = 1";
  76.113 +
  76.114 +        for (int i = 0; i < MEGAMORPHIC_LOOP_COUNT; i++) {
  76.115 +            assertEquals(e.eval(sharedSetterScript), 1);
  76.116 +            assertEquals(e.eval(sharedGetterScript), 1);
  76.117 +            assertEquals(e.eval("delete foo; a" + i + " = 1; foo = " + i + ";"), i);
  76.118 +            assertEquals(e.eval(sharedGetterScript), i);
  76.119 +        }
  76.120 +
  76.121 +        assertEquals(e.eval("let foo = 'foo';"), null);
  76.122 +        assertEquals(e.eval(sharedGetterScript), "foo");
  76.123 +        assertEquals(e.eval(sharedSetterScript), 1);
  76.124 +        assertEquals(e.eval(sharedGetterScript), 1);
  76.125 +        assertEquals(e.eval("this.foo"), MEGAMORPHIC_LOOP_COUNT - 1);
  76.126 +    }
  76.127 +
  76.128 +    /**
  76.129 +     * Test access to global lexically declared variables for shared script classes with single global.
  76.130 +     */
  76.131 +    @Test
  76.132 +    public static void megamorphicInheritedGlobalLetTest() throws ScriptException, InterruptedException {
  76.133 +        final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
  76.134 +        final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6);
  76.135 +        final String sharedGetterScript = "foo";
  76.136 +        final String sharedSetterScript = "foo = 1";
  76.137 +
  76.138 +        for (int i = 0; i < MEGAMORPHIC_LOOP_COUNT; i++) {
  76.139 +            assertEquals(e.eval(sharedSetterScript), 1);
  76.140 +            assertEquals(e.eval(sharedGetterScript), 1);
  76.141 +            assertEquals(e.eval("delete foo; a" + i + " = 1; Object.prototype.foo = " + i + ";"), i);
  76.142 +            assertEquals(e.eval(sharedGetterScript), i);
  76.143 +        }
  76.144 +
  76.145 +        assertEquals(e.eval("let foo = 'foo';"), null);
  76.146 +        assertEquals(e.eval(sharedGetterScript), "foo");
  76.147 +        assertEquals(e.eval(sharedSetterScript), 1);
  76.148 +        assertEquals(e.eval(sharedGetterScript), 1);
  76.149 +        assertEquals(e.eval("this.foo"), MEGAMORPHIC_LOOP_COUNT - 1);
  76.150 +    }
  76.151 +
  76.152 +    /**
  76.153 +     * Test multi-threaded access to global lexically declared variables for shared script classes with multiple globals.
  76.154 +     */
  76.155 +    @Test
  76.156 +    public static void multiThreadedLetTest() throws ScriptException, InterruptedException {
  76.157 +        final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
  76.158 +        final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6);
  76.159 +        final Bindings b = e.createBindings();
  76.160 +        final ScriptContext origContext = e.getContext();
  76.161 +        final ScriptContext newCtxt = new SimpleScriptContext();
  76.162 +        newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
  76.163 +        final String sharedScript = "foo";
  76.164 +
  76.165 +        assertEquals(e.eval("let foo = 'original context';", origContext), null);
  76.166 +        assertEquals(e.eval("let foo = 'new context';", newCtxt), null);
  76.167 +
  76.168 +        final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
  76.169 +        final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000));
  76.170 +        t1.start();
  76.171 +        t2.start();
  76.172 +        t1.join();
  76.173 +        t2.join();
  76.174 +
  76.175 +        assertEquals(e.eval("foo = 'newer context';", newCtxt), "newer context");
  76.176 +        final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
  76.177 +        final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000));
  76.178 +
  76.179 +        t3.start();
  76.180 +        t4.start();
  76.181 +        t3.join();
  76.182 +        t4.join();
  76.183 +
  76.184 +        assertEquals(e.eval(sharedScript), "original context");
  76.185 +        assertEquals(e.eval(sharedScript, newCtxt), "newer context");
  76.186 +    }
  76.187 +
  76.188 +    private static class ScriptRunner implements Runnable {
  76.189 +
  76.190 +        final ScriptEngine engine;
  76.191 +        final ScriptContext context;
  76.192 +        final String source;
  76.193 +        final Object expected;
  76.194 +        final int iterations;
  76.195 +
  76.196 +        ScriptRunner(final ScriptEngine engine, final ScriptContext context, final String source, final Object expected, final int iterations) {
  76.197 +            this.engine = engine;
  76.198 +            this.context = context;
  76.199 +            this.source = source;
  76.200 +            this.expected = expected;
  76.201 +            this.iterations = iterations;
  76.202 +        }
  76.203 +
  76.204 +        @Override
  76.205 +        public void run() {
  76.206 +            try {
  76.207 +                for (int i = 0; i < iterations; i++) {
  76.208 +                    assertEquals(engine.eval(source, context), expected);
  76.209 +                }
  76.210 +            } catch (final ScriptException se) {
  76.211 +                throw new RuntimeException(se);
  76.212 +            }
  76.213 +        }
  76.214 +    }
  76.215 +}
    77.1 --- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java	Mon Dec 01 11:40:00 2014 -0800
    77.2 +++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java	Fri Dec 12 14:58:31 2014 -0800
    77.3 @@ -46,6 +46,7 @@
    77.4  import java.io.File;
    77.5  import java.io.FileReader;
    77.6  import java.io.IOException;
    77.7 +import java.nio.ByteOrder;
    77.8  import java.nio.file.FileSystem;
    77.9  import java.nio.file.FileSystems;
   77.10  import java.nio.file.FileVisitOption;
   77.11 @@ -264,6 +265,12 @@
   77.12                      isTest = false;
   77.13                      isNotTest = true;
   77.14                      break;
   77.15 +                case "@bigendian":
   77.16 +                    shouldRun = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
   77.17 +                    break;
   77.18 +                case "@littleendian":
   77.19 +                    shouldRun = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
   77.20 +                    break;
   77.21                  case "@runif": {
   77.22                      final String prop = scanner.next();
   77.23                      if (System.getProperty(prop) != null) {

mercurial