Wed, 26 Nov 2014 13:57:43 -0800
Merge
1.1 --- a/src/jdk/nashorn/internal/codegen/AssignSymbols.java Wed Nov 26 08:00:20 2014 -0800 1.2 +++ b/src/jdk/nashorn/internal/codegen/AssignSymbols.java Wed Nov 26 13:57:43 2014 -0800 1.3 @@ -356,6 +356,10 @@ 1.4 throwParserException(ECMAErrors.getMessage("syntax.error.redeclare.variable", name), origin); 1.5 } else { 1.6 symbol.setHasBeenDeclared(); 1.7 + // Set scope flag on top-level block scoped symbols 1.8 + if (function.isProgram() && function.getBody() == block) { 1.9 + symbol.setIsScope(); 1.10 + } 1.11 } 1.12 } else if ((flags & IS_INTERNAL) != 0) { 1.13 // Always create a new definition. 1.14 @@ -540,7 +544,7 @@ 1.15 final int flags; 1.16 if (varNode.isAnonymousFunctionDeclaration()) { 1.17 flags = IS_INTERNAL; 1.18 - } else if (lc.getCurrentFunction().isProgram()) { 1.19 + } else if (!varNode.isBlockScoped() && lc.getCurrentFunction().isProgram()) { 1.20 flags = IS_SCOPE; 1.21 } else { 1.22 flags = 0;
2.1 --- a/src/jdk/nashorn/internal/codegen/MapCreator.java Wed Nov 26 08:00:20 2014 -0800 2.2 +++ b/src/jdk/nashorn/internal/codegen/MapCreator.java Wed Nov 26 13:57:43 2014 -0800 2.3 @@ -152,6 +152,10 @@ 2.4 flags |= Property.NOT_WRITABLE; 2.5 } 2.6 2.7 + if (symbol.isBlockScoped()) { 2.8 + flags |= Property.IS_LEXICAL_BINDING; 2.9 + } 2.10 + 2.11 // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError. 2.12 if (symbol.isBlockScoped() && symbol.isScope()) { 2.13 flags |= Property.NEEDS_DECLARATION;
3.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed Nov 26 08:00:20 2014 -0800 3.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Wed Nov 26 13:57:43 2014 -0800 3.3 @@ -34,6 +34,7 @@ 3.4 import java.io.PrintWriter; 3.5 import java.lang.invoke.MethodHandle; 3.6 import java.lang.invoke.MethodHandles; 3.7 +import java.lang.invoke.MethodType; 3.8 import java.lang.invoke.SwitchPoint; 3.9 import java.lang.reflect.Field; 3.10 import java.util.ArrayList; 3.11 @@ -44,6 +45,7 @@ 3.12 import java.util.concurrent.ConcurrentHashMap; 3.13 import javax.script.ScriptContext; 3.14 import javax.script.ScriptEngine; 3.15 +import jdk.internal.dynalink.CallSiteDescriptor; 3.16 import jdk.internal.dynalink.linker.GuardedInvocation; 3.17 import jdk.internal.dynalink.linker.LinkRequest; 3.18 import jdk.nashorn.api.scripting.ClassFilter; 3.19 @@ -54,6 +56,8 @@ 3.20 import jdk.nashorn.internal.objects.annotations.ScriptClass; 3.21 import jdk.nashorn.internal.runtime.ConsString; 3.22 import jdk.nashorn.internal.runtime.Context; 3.23 +import jdk.nashorn.internal.runtime.ECMAErrors; 3.24 +import jdk.nashorn.internal.runtime.GlobalConstants; 3.25 import jdk.nashorn.internal.runtime.GlobalFunctions; 3.26 import jdk.nashorn.internal.runtime.JSType; 3.27 import jdk.nashorn.internal.runtime.NativeJavaPackage; 3.28 @@ -69,6 +73,7 @@ 3.29 import jdk.nashorn.internal.runtime.arrays.ArrayData; 3.30 import jdk.nashorn.internal.runtime.linker.Bootstrap; 3.31 import jdk.nashorn.internal.runtime.linker.InvokeByName; 3.32 +import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 3.33 import jdk.nashorn.internal.runtime.regexp.RegExpResult; 3.34 import jdk.nashorn.internal.scripts.JO; 3.35 3.36 @@ -410,13 +415,14 @@ 3.37 // Used to store the last RegExp result to support deprecated RegExp constructor properties 3.38 private RegExpResult lastRegExpResult; 3.39 3.40 - private static final MethodHandle EVAL = findOwnMH_S("eval", Object.class, Object.class, Object.class); 3.41 - private static final MethodHandle NO_SUCH_PROPERTY = findOwnMH_S(NO_SUCH_PROPERTY_NAME, Object.class, Object.class, Object.class); 3.42 - private static final MethodHandle PRINT = findOwnMH_S("print", Object.class, Object.class, Object[].class); 3.43 - private static final MethodHandle PRINTLN = findOwnMH_S("println", Object.class, Object.class, Object[].class); 3.44 - private static final MethodHandle LOAD = findOwnMH_S("load", Object.class, Object.class, Object.class); 3.45 - private static final MethodHandle LOADWITHNEWGLOBAL = findOwnMH_S("loadWithNewGlobal", Object.class, Object.class, Object[].class); 3.46 - private static final MethodHandle EXIT = findOwnMH_S("exit", Object.class, Object.class, Object.class); 3.47 + private static final MethodHandle EVAL = findOwnMH_S("eval", Object.class, Object.class, Object.class); 3.48 + private static final MethodHandle NO_SUCH_PROPERTY = findOwnMH_S(NO_SUCH_PROPERTY_NAME, Object.class, Object.class, Object.class); 3.49 + private static final MethodHandle PRINT = findOwnMH_S("print", Object.class, Object.class, Object[].class); 3.50 + private static final MethodHandle PRINTLN = findOwnMH_S("println", Object.class, Object.class, Object[].class); 3.51 + private static final MethodHandle LOAD = findOwnMH_S("load", Object.class, Object.class, Object.class); 3.52 + private static final MethodHandle LOAD_WITH_NEW_GLOBAL = findOwnMH_S("loadWithNewGlobal", Object.class, Object.class, Object[].class); 3.53 + private static final MethodHandle EXIT = findOwnMH_S("exit", Object.class, Object.class, Object.class); 3.54 + private static final MethodHandle LEXICAL_SCOPE_FILTER = findOwnMH_S("lexicalScopeFilter", Object.class, Object.class); 3.55 3.56 // initialized by nasgen 3.57 private static PropertyMap $nasgenmap$; 3.58 @@ -429,6 +435,12 @@ 3.59 // current ScriptEngine associated - can be null. 3.60 private ScriptEngine engine; 3.61 3.62 + // ES6 global lexical scope. 3.63 + private final LexicalScope lexicalScope; 3.64 + 3.65 + // Switchpoint for non-constant global callsites in the presence of ES6 lexical scope. 3.66 + private SwitchPoint lexicalScopeSwitchPoint; 3.67 + 3.68 /** 3.69 * Set the current script context 3.70 * @param scontext script context 3.71 @@ -466,6 +478,7 @@ 3.72 super(checkAndGetMap(context)); 3.73 this.context = context; 3.74 this.setIsScope(); 3.75 + this.lexicalScope = context.getEnv()._es6 ? new LexicalScope(this) : null; 3.76 } 3.77 3.78 /** 3.79 @@ -1694,6 +1707,133 @@ 3.80 splitState = state; 3.81 } 3.82 3.83 + /** 3.84 + * Return the ES6 global scope for lexically declared bindings. 3.85 + * @return the ES6 lexical global scope. 3.86 + */ 3.87 + public final ScriptObject getLexicalScope() { 3.88 + assert context.getEnv()._es6; 3.89 + return lexicalScope; 3.90 + } 3.91 + 3.92 + @Override 3.93 + public void addBoundProperties(final ScriptObject source, final jdk.nashorn.internal.runtime.Property[] properties) { 3.94 + PropertyMap ownMap = getMap(); 3.95 + LexicalScope lexicalScope = null; 3.96 + PropertyMap lexicalMap = null; 3.97 + boolean hasLexicalDefinitions = false; 3.98 + 3.99 + if (context.getEnv()._es6) { 3.100 + lexicalScope = (LexicalScope) getLexicalScope(); 3.101 + lexicalMap = lexicalScope.getMap(); 3.102 + 3.103 + for (final jdk.nashorn.internal.runtime.Property property : properties) { 3.104 + if (property.isLexicalBinding()) { 3.105 + hasLexicalDefinitions = true; 3.106 + } 3.107 + // ES6 15.1.8 steps 6. and 7. 3.108 + final jdk.nashorn.internal.runtime.Property globalProperty = ownMap.findProperty(property.getKey()); 3.109 + if (globalProperty != null && !globalProperty.isConfigurable() && property.isLexicalBinding()) { 3.110 + throw ECMAErrors.syntaxError("redeclare.variable", property.getKey()); 3.111 + } 3.112 + final jdk.nashorn.internal.runtime.Property lexicalProperty = lexicalMap.findProperty(property.getKey()); 3.113 + if (lexicalProperty != null && !property.isConfigurable()) { 3.114 + throw ECMAErrors.syntaxError("redeclare.variable", property.getKey()); 3.115 + } 3.116 + } 3.117 + } 3.118 + 3.119 + for (final jdk.nashorn.internal.runtime.Property property : properties) { 3.120 + if (property.isLexicalBinding()) { 3.121 + assert lexicalScope != null; 3.122 + lexicalMap = lexicalScope.addBoundProperty(lexicalMap, source, property); 3.123 + 3.124 + if (ownMap.findProperty(property.getKey()) != null) { 3.125 + // If property exists in the global object invalidate any global constant call sites. 3.126 + invalidateGlobalConstant(property.getKey()); 3.127 + } 3.128 + } else { 3.129 + ownMap = addBoundProperty(ownMap, source, property); 3.130 + } 3.131 + } 3.132 + 3.133 + setMap(ownMap); 3.134 + 3.135 + if (hasLexicalDefinitions) { 3.136 + lexicalScope.setMap(lexicalMap); 3.137 + invalidateLexicalSwitchPoint(); 3.138 + } 3.139 + } 3.140 + 3.141 + @Override 3.142 + public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) { 3.143 + final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 3.144 + final boolean isScope = NashornCallSiteDescriptor.isScope(desc); 3.145 + 3.146 + if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) { 3.147 + if (lexicalScope.hasOwnProperty(name)) { 3.148 + return lexicalScope.findGetMethod(desc, request, operator); 3.149 + } 3.150 + } 3.151 + 3.152 + final GuardedInvocation invocation = super.findGetMethod(desc, request, operator); 3.153 + 3.154 + // We want to avoid adding our generic lexical scope switchpoint to global constant invocations, 3.155 + // because those are invalidated per-key in the addBoundProperties method above. 3.156 + // We therefor check if the invocation does already have a switchpoint and the property is non-inherited, 3.157 + // assuming this only applies to global constants. If other non-inherited properties will 3.158 + // start using switchpoints some time in the future we'll have to revisit this. 3.159 + if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) { 3.160 + return invocation.addSwitchPoint(getLexicalScopeSwitchPoint()); 3.161 + } 3.162 + 3.163 + return invocation; 3.164 + } 3.165 + 3.166 + @Override 3.167 + public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) { 3.168 + final boolean isScope = NashornCallSiteDescriptor.isScope(desc); 3.169 + 3.170 + if (lexicalScope != null && isScope) { 3.171 + final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 3.172 + if (lexicalScope.hasOwnProperty(name)) { 3.173 + return lexicalScope.findSetMethod(desc, request); 3.174 + } 3.175 + } 3.176 + 3.177 + final GuardedInvocation invocation = super.findSetMethod(desc, request); 3.178 + 3.179 + if (isScope && context.getEnv()._es6) { 3.180 + return invocation.addSwitchPoint(getLexicalScopeSwitchPoint()); 3.181 + } 3.182 + 3.183 + return invocation; 3.184 + } 3.185 + 3.186 + private synchronized SwitchPoint getLexicalScopeSwitchPoint() { 3.187 + SwitchPoint switchPoint = lexicalScopeSwitchPoint; 3.188 + if (switchPoint == null || switchPoint.hasBeenInvalidated()) { 3.189 + switchPoint = lexicalScopeSwitchPoint = new SwitchPoint(); 3.190 + } 3.191 + return switchPoint; 3.192 + } 3.193 + 3.194 + private synchronized void invalidateLexicalSwitchPoint() { 3.195 + if (lexicalScopeSwitchPoint != null) { 3.196 + context.getLogger(GlobalConstants.class).info("Invalidating non-constant globals on lexical scope update"); 3.197 + SwitchPoint.invalidateAll(new SwitchPoint[]{ lexicalScopeSwitchPoint }); 3.198 + } 3.199 + } 3.200 + 3.201 + 3.202 + @SuppressWarnings("unused") 3.203 + private static Object lexicalScopeFilter(final Object self) { 3.204 + if (self instanceof Global) { 3.205 + return ((Global) self).getLexicalScope(); 3.206 + } 3.207 + return self; 3.208 + } 3.209 + 3.210 private <T extends ScriptObject> T initConstructorAndSwitchPoint(final String name, final Class<T> clazz) { 3.211 final T func = initConstructor(name, clazz); 3.212 tagBuiltinProperties(name, func); 3.213 @@ -1739,7 +1879,7 @@ 3.214 this.unescape = ScriptFunctionImpl.makeFunction("unescape", GlobalFunctions.UNESCAPE); 3.215 this.print = ScriptFunctionImpl.makeFunction("print", env._print_no_newline ? PRINT : PRINTLN); 3.216 this.load = ScriptFunctionImpl.makeFunction("load", LOAD); 3.217 - this.loadWithNewGlobal = ScriptFunctionImpl.makeFunction("loadWithNewGlobal", LOADWITHNEWGLOBAL); 3.218 + this.loadWithNewGlobal = ScriptFunctionImpl.makeFunction("loadWithNewGlobal", LOAD_WITH_NEW_GLOBAL); 3.219 this.exit = ScriptFunctionImpl.makeFunction("exit", EXIT); 3.220 this.quit = ScriptFunctionImpl.makeFunction("quit", EXIT); 3.221 3.222 @@ -2205,4 +2345,36 @@ 3.223 protected boolean isGlobal() { 3.224 return true; 3.225 } 3.226 + 3.227 + /** 3.228 + * A class representing the ES6 global lexical scope. 3.229 + */ 3.230 + private static class LexicalScope extends ScriptObject { 3.231 + 3.232 + LexicalScope(final ScriptObject proto) { 3.233 + super(proto, PropertyMap.newMap()); 3.234 + } 3.235 + 3.236 + @Override 3.237 + protected GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) { 3.238 + return filterInvocation(super.findGetMethod(desc, request, operator)); 3.239 + } 3.240 + 3.241 + @Override 3.242 + protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) { 3.243 + return filterInvocation(super.findSetMethod(desc, request)); 3.244 + } 3.245 + 3.246 + @Override 3.247 + protected PropertyMap addBoundProperty(final PropertyMap propMap, final ScriptObject source, final jdk.nashorn.internal.runtime.Property property) { 3.248 + // We override this method just to make it callable by Global 3.249 + return super.addBoundProperty(propMap, source, property); 3.250 + } 3.251 + 3.252 + private static GuardedInvocation filterInvocation(final GuardedInvocation invocation) { 3.253 + final MethodType type = invocation.getInvocation().type(); 3.254 + return invocation.asType(type.changeParameterType(0, Object.class)).filterArguments(0, LEXICAL_SCOPE_FILTER); 3.255 + } 3.256 + } 3.257 + 3.258 }
4.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Wed Nov 26 08:00:20 2014 -0800 4.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Wed Nov 26 13:57:43 2014 -0800 4.3 @@ -707,20 +707,9 @@ 4.4 FunctionNode.Kind.SCRIPT, 4.5 functionLine); 4.6 4.7 - // If ES6 block scope is enabled add a per-script block for top-level LET and CONST declarations. 4.8 - final int startLine = start; 4.9 - Block outer = useBlockScope() ? newBlock() : null; 4.10 functionDeclarations = new ArrayList<>(); 4.11 - 4.12 - try { 4.13 - sourceElements(allowPropertyFunction); 4.14 - addFunctionDeclarations(script); 4.15 - } finally { 4.16 - if (outer != null) { 4.17 - outer = restoreBlock(outer); 4.18 - appendStatement(new BlockStatement(startLine, outer)); 4.19 - } 4.20 - } 4.21 + sourceElements(allowPropertyFunction); 4.22 + addFunctionDeclarations(script); 4.23 functionDeclarations = null; 4.24 4.25 expect(EOF);
5.1 --- a/src/jdk/nashorn/internal/runtime/CodeStore.java Wed Nov 26 08:00:20 2014 -0800 5.2 +++ b/src/jdk/nashorn/internal/runtime/CodeStore.java Wed Nov 26 13:57:43 2014 -0800 5.3 @@ -82,10 +82,9 @@ 5.4 * Returns a new code store instance. 5.5 * 5.6 * @param context the current context 5.7 - * @return The instance 5.8 - * @throws IOException If an error occurs 5.9 + * @return The instance, or null if code store could not be created 5.10 */ 5.11 - public static CodeStore newCodeStore(final Context context) throws IOException { 5.12 + public static CodeStore newCodeStore(final Context context) { 5.13 final Class<CodeStore> baseClass = CodeStore.class; 5.14 try { 5.15 // security check first 5.16 @@ -103,9 +102,14 @@ 5.17 } catch (final AccessControlException e) { 5.18 context.getLogger(CodeStore.class).warning("failed to load code store provider ", e); 5.19 } 5.20 - final CodeStore store = new DirectoryCodeStore(context); 5.21 - store.initLogger(context); 5.22 - return store; 5.23 + try { 5.24 + final CodeStore store = new DirectoryCodeStore(context); 5.25 + store.initLogger(context); 5.26 + return store; 5.27 + } catch (final IOException e) { 5.28 + context.getLogger(CodeStore.class).warning("failed to create cache directory ", e); 5.29 + return null; 5.30 + } 5.31 } 5.32 5.33
6.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Wed Nov 26 08:00:20 2014 -0800 6.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Wed Nov 26 13:57:43 2014 -0800 6.3 @@ -509,11 +509,7 @@ 6.4 } 6.5 6.6 if (env._persistent_cache) { 6.7 - try { 6.8 - codeStore = newCodeStore(this); 6.9 - } catch (final IOException e) { 6.10 - throw new RuntimeException("Error initializing code cache", e); 6.11 - } 6.12 + codeStore = newCodeStore(this); 6.13 } 6.14 6.15 // print version info if asked. 6.16 @@ -1200,7 +1196,7 @@ 6.17 FunctionNode functionNode = null; 6.18 // We only use the code store here if optimistic types are disabled. With optimistic types, initial compilation 6.19 // just creates a thin wrapper, and actual code is stored per function in RecompilableScriptFunctionData. 6.20 - final boolean useCodeStore = env._persistent_cache && !env._parse_only && !env._optimistic_types; 6.21 + final boolean useCodeStore = codeStore != null && !env._parse_only && !env._optimistic_types; 6.22 final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null; 6.23 6.24 if (useCodeStore) {
7.1 --- a/src/jdk/nashorn/internal/runtime/Property.java Wed Nov 26 08:00:20 2014 -0800 7.2 +++ b/src/jdk/nashorn/internal/runtime/Property.java Wed Nov 26 13:57:43 2014 -0800 7.3 @@ -84,14 +84,17 @@ 7.4 public static final int IS_NASGEN_PRIMITIVE = 1 << 6; 7.5 7.6 /** Is this a builtin property, e.g. Function.prototype.apply */ 7.7 - public static final int IS_BUILTIN = 1 << 7; 7.8 + public static final int IS_BUILTIN = 1 << 7; 7.9 7.10 /** Is this property bound to a receiver? This means get/set operations will be delegated to 7.11 * a statically defined object instead of the object passed as callsite parameter. */ 7.12 - public static final int IS_BOUND = 1 << 7; 7.13 + public static final int IS_BOUND = 1 << 8; 7.14 7.15 /** Is this a lexically scoped LET or CONST variable that is dead until it is declared. */ 7.16 - public static final int NEEDS_DECLARATION = 1 << 8; 7.17 + public static final int NEEDS_DECLARATION = 1 << 9; 7.18 + 7.19 + /** Is this property an ES6 lexical binding? */ 7.20 + public static final int IS_LEXICAL_BINDING = 1 << 10; 7.21 7.22 /** Property key. */ 7.23 private final String key; 7.24 @@ -714,4 +717,12 @@ 7.25 public boolean isFunctionDeclaration() { 7.26 return (flags & IS_FUNCTION_DECLARATION) == IS_FUNCTION_DECLARATION; 7.27 } 7.28 + 7.29 + /** 7.30 + * Is this a property defined by ES6 let or const? 7.31 + * @return true if this property represents a lexical binding. 7.32 + */ 7.33 + public boolean isLexicalBinding() { 7.34 + return (flags & IS_LEXICAL_BINDING) == IS_LEXICAL_BINDING; 7.35 + } 7.36 }
8.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Nov 26 08:00:20 2014 -0800 8.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Nov 26 13:57:43 2014 -0800 8.3 @@ -304,29 +304,44 @@ 8.4 PropertyMap newMap = this.getMap(); 8.5 8.6 for (final Property property : properties) { 8.7 - final String key = property.getKey(); 8.8 - final Property oldProp = newMap.findProperty(key); 8.9 - if (oldProp == null) { 8.10 - if (property instanceof UserAccessorProperty) { 8.11 - // Note: we copy accessor functions to this object which is semantically different from binding. 8.12 - final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source)); 8.13 - newMap = newMap.addPropertyNoHistory(prop); 8.14 - } else { 8.15 - newMap = newMap.addPropertyBind((AccessorProperty)property, source); 8.16 - } 8.17 + newMap = addBoundProperty(newMap, source, property); 8.18 + } 8.19 + 8.20 + this.setMap(newMap); 8.21 + } 8.22 + 8.23 + /** 8.24 + * Add a bound property from {@code source}, using the interim property map {@code propMap}, and return the 8.25 + * new interim property map. 8.26 + * 8.27 + * @param propMap the property map 8.28 + * @param source the source object 8.29 + * @param property the property to be added 8.30 + * @return the new property map 8.31 + */ 8.32 + protected PropertyMap addBoundProperty(final PropertyMap propMap, final ScriptObject source, final Property property) { 8.33 + PropertyMap newMap = propMap; 8.34 + final String key = property.getKey(); 8.35 + final Property oldProp = newMap.findProperty(key); 8.36 + if (oldProp == null) { 8.37 + if (property instanceof UserAccessorProperty) { 8.38 + // Note: we copy accessor functions to this object which is semantically different from binding. 8.39 + final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source)); 8.40 + newMap = newMap.addPropertyNoHistory(prop); 8.41 } else { 8.42 - // See ECMA section 10.5 Declaration Binding Instantiation 8.43 - // step 5 processing each function declaration. 8.44 - if (property.isFunctionDeclaration() && !oldProp.isConfigurable()) { 8.45 - if (oldProp instanceof UserAccessorProperty || 8.46 - !(oldProp.isWritable() && oldProp.isEnumerable())) { 8.47 - throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this)); 8.48 - } 8.49 + newMap = newMap.addPropertyBind((AccessorProperty)property, source); 8.50 + } 8.51 + } else { 8.52 + // See ECMA section 10.5 Declaration Binding Instantiation 8.53 + // step 5 processing each function declaration. 8.54 + if (property.isFunctionDeclaration() && !oldProp.isConfigurable()) { 8.55 + if (oldProp instanceof UserAccessorProperty || 8.56 + !(oldProp.isWritable() && oldProp.isEnumerable())) { 8.57 + throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this)); 8.58 } 8.59 } 8.60 } 8.61 - 8.62 - this.setMap(newMap); 8.63 + return newMap; 8.64 } 8.65 8.66 /** 8.67 @@ -510,7 +525,11 @@ 8.68 } 8.69 } 8.70 8.71 - private void invalidateGlobalConstant(final String key) { 8.72 + /** 8.73 + * Invalidate any existing global constant method handles that may exist for {@code key}. 8.74 + * @param key the property name 8.75 + */ 8.76 + protected void invalidateGlobalConstant(final String key) { 8.77 final GlobalConstants globalConstants = getGlobalConstants(); 8.78 if (globalConstants != null) { 8.79 globalConstants.delete(key);
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/script/basic/JDK-8049407-big-endian.js Wed Nov 26 13:57:43 2014 -0800 9.3 @@ -0,0 +1,33 @@ 9.4 +/* 9.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +/** 9.28 + * Verify DataView behavior with little/big endian 9.29 + * 9.30 + * @test 9.31 + * @run 9.32 + * @bigendian 9.33 + */ 9.34 + 9.35 +var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__; 9.36 +load(dir + "JDK-8049407-payload.js");
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/script/basic/JDK-8049407-big-endian.js.EXPECTED Wed Nov 26 13:57:43 2014 -0800 10.3 @@ -0,0 +1,1 @@ 10.4 +false
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/script/basic/JDK-8049407-payload.js Wed Nov 26 13:57:43 2014 -0800 11.3 @@ -0,0 +1,37 @@ 11.4 +/* 11.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. 11.11 + * 11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.15 + * version 2 for more details (a copy is included in the LICENSE file that 11.16 + * accompanied this code). 11.17 + * 11.18 + * You should have received a copy of the GNU General Public License version 11.19 + * 2 along with this work; if not, write to the Free Software Foundation, 11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.21 + * 11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.23 + * or visit www.oracle.com if you need additional information or have any 11.24 + * questions. 11.25 + */ 11.26 + 11.27 +/** 11.28 + * Verify DataView behavior with little/big endian 11.29 + * 11.30 + * @subtest 11.31 + * @run 11.32 + */ 11.33 + 11.34 +var littleEndian = (function() { 11.35 + var buffer = new ArrayBuffer(2); 11.36 + new DataView(buffer).setInt16(0, 256, true); 11.37 + return new Int16Array(buffer)[0] === 256; 11.38 + })(); 11.39 + 11.40 +print(littleEndian);
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/script/basic/JDK-8049407.js Wed Nov 26 13:57:43 2014 -0800 12.3 @@ -0,0 +1,33 @@ 12.4 +/* 12.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +/** 12.28 + * Verify DataView behavior with little/big endian 12.29 + * 12.30 + * @test 12.31 + * @run 12.32 + * @littleendian 12.33 + */ 12.34 + 12.35 +var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__; 12.36 +load(dir + "JDK-8049407-payload.js");
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/script/basic/JDK-8049407.js.EXPECTED Wed Nov 26 13:57:43 2014 -0800 13.3 @@ -0,0 +1,1 @@ 13.4 +true
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/script/basic/NASHORN-377-big-endian.js Wed Nov 26 13:57:43 2014 -0800 14.3 @@ -0,0 +1,33 @@ 14.4 +/* 14.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/* 14.28 + * NASHORN-377: Typed arrays. 14.29 + * 14.30 + * @test 14.31 + * @run 14.32 + * @bigendian 14.33 + */ 14.34 + 14.35 +var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__; 14.36 +load(dir + "NASHORN-377-payload.js");
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/script/basic/NASHORN-377-big-endian.js.EXPECTED Wed Nov 26 13:57:43 2014 -0800 15.3 @@ -0,0 +1,34 @@ 15.4 +8 8 true undefined 15.5 +[object ArrayBuffer] [object ArrayBuffer] [object Int8Array] 15.6 +0 8 8 1 15.7 +0 8 8 1 15.8 +0 8 8 1 15.9 +0 8 4 2 15.10 +0 8 4 2 15.11 +0 8 2 4 15.12 +0 8 2 4 15.13 +0 8 2 4 15.14 +0 8 1 8 15.15 +7071727374-807677 7071727374807677 15.16 +727374-807677 2 6 15.17 +72737480 2 4 15.18 +71727374 1 4 15.19 +717273748076 15.20 +7071727374807677 1886483059 1954575991 15.21 +70717273-1020305 1886483059 -16909061 15.22 +70717273fefdfcfb 1886483059 4278058235 15.23 +40490fdafefdfcfb 2 15.24 +400921fb4d12d84a 1 15.25 +400921fb4d12d84a 1074340347 1293080650 15.26 +00000000400921fb4d12d84a 15.27 +400921fb4d12-27b6 400921fb4d12d84a 15.28 +00-100804d12-27b6 ffff00804d12d84a 15.29 +0 1 2 3 4 5 6 7 15.30 +0102030405060708 15.31 +subarray(2,4)=0304 subarray(-6,-4)=0304 15.32 +010203040506 15.33 +03040506 0405 15.34 +0102030405060708090a0b0c0d0e0f10 15.35 +slice(4,8)=05060708 slice(-8,-4)=090a0b0c 15.36 +0102030405060708090a0b0c 15.37 +060708090a0b
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/script/basic/NASHORN-377-payload.js Wed Nov 26 13:57:43 2014 -0800 16.3 @@ -0,0 +1,226 @@ 16.4 +/* 16.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +/* 16.28 + * NASHORN-377: Typed arrays. Payload for litte and big endian platforms. 16.29 + * 16.30 + * @subtest 16.31 + * @run 16.32 + */ 16.33 + 16.34 +var types = [Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array]; 16.35 + 16.36 +//--------------------------------------------------------------------------- 16.37 +// utility functions 16.38 +//--------------------------------------------------------------------------- 16.39 +function tohex(d, w) { 16.40 + var hex = Number(d).toString(16); 16.41 + var pad = (w ? w : 8) - hex.length; 16.42 + hex = "00000000".substr(0, pad) + hex; 16.43 + return hex; 16.44 +} 16.45 + 16.46 +function arrstr(a, n, w) { 16.47 + var s = ""; 16.48 + if (typeof n == "undefined") n = a.length; 16.49 + if (typeof w == "undefined") w = a.constructor.BYTES_PER_ELEMENT * 2; 16.50 + for (var i = 0; i < n; i++) { 16.51 + s += tohex(a[i], w); 16.52 + } 16.53 + return s; 16.54 +} 16.55 +function bufstr(b) { 16.56 + if (b.buffer !== undefined) { 16.57 + b = b.buffer; 16.58 + } 16.59 + return arrstr(new Uint8Array(b)); 16.60 +} 16.61 + 16.62 +function assertFail(f) { 16.63 + try { 16.64 + f(); 16.65 + } catch (e) { 16.66 + //print(e); 16.67 + return; 16.68 + } 16.69 + throw "assertion failed: expected exception"; 16.70 +} 16.71 + 16.72 +function assertTrue(f) { 16.73 + if (f() !== true) throw "assertion failed: " + f; 16.74 +} 16.75 + 16.76 +function isUndefined(x) { 16.77 + return typeof x === "undefined"; 16.78 +} 16.79 + 16.80 +function fillArray(a, start) { 16.81 + if (typeof start == "undefined") start = 1; 16.82 + for (var i = 0; i < a.length; i++) { 16.83 + a[i] = i + start; 16.84 + } 16.85 + return a; 16.86 +} 16.87 + 16.88 +//--------------------------------------------------------------------------- 16.89 +// tests 16.90 +//--------------------------------------------------------------------------- 16.91 +(function() { 16.92 + var b = new ArrayBuffer(8); 16.93 + var i8 = new Int8Array(b); 16.94 + print(i8.buffer.byteLength, b.byteLength, i8.buffer === b, b.length); 16.95 + print(b, i8.buffer, i8); 16.96 +})(); 16.97 + 16.98 +(function test_attributes() { 16.99 + var b = new ArrayBuffer(8); 16.100 + for (var i in types) { 16.101 + var x = new types[i](b); 16.102 + print(x.byteOffset, x.byteLength, x.length, x.constructor.BYTES_PER_ELEMENT); 16.103 + assertTrue(function(){ return x.constructor === types[i] }); 16.104 + } 16.105 +})(); 16.106 + 16.107 +(function() { 16.108 + var b = new ArrayBuffer(8); 16.109 + var i8 = new Int8Array(b); 16.110 + fillArray(i8, 0x70); 16.111 + 16.112 + var i8_2 = new Int8Array(b, 2); 16.113 + var i8_2_4 = new Uint8Array(b, 2, 4); 16.114 + 16.115 + i8_2_4[3] = 0x80; 16.116 + 16.117 + print(arrstr(i8, 8, 2) + " " + bufstr(i8)); 16.118 + print(arrstr(i8_2, 6) + " " + i8_2.byteOffset + " " + i8_2.byteLength); 16.119 + print(arrstr(i8_2_4, 4) + " " + i8_2_4.byteOffset + " " + i8_2_4.byteLength); 16.120 + 16.121 + var i8_1_5 = i8.subarray(1, 5); 16.122 + i8_2_4.subarray(1, 5); 16.123 + print(arrstr(i8_1_5, 4) + " " + i8_1_5.byteOffset + " " + i8_1_5.byteLength); 16.124 + 16.125 + print(bufstr(b.slice(1,7))); 16.126 +})(); 16.127 + 16.128 +(function() { 16.129 + var b = new ArrayBuffer(8); 16.130 + fillArray(new Int8Array(b), 0x70); 16.131 + new Int8Array(b)[5] = 0x80; 16.132 + 16.133 + var i32 = new Int32Array(b); 16.134 + var u32 = new Uint32Array(b); 16.135 + print(arrstr(i32), i32[0], i32[1]); 16.136 + i32[1] = 0xfefdfcfb; 16.137 + print(arrstr(i32), i32[0], i32[1]); 16.138 + print(arrstr(u32), u32[0], u32[1]); 16.139 + 16.140 + var pi = 3.1415926; 16.141 + var f32 = new Float32Array(b); 16.142 + var f64 = new Float64Array(b); 16.143 + f32[0] = pi; 16.144 + print(bufstr(b), f32.length); 16.145 + f64[0] = pi; 16.146 + print(bufstr(b), f64.length); 16.147 + print(arrstr(u32), u32[0], u32[1]); 16.148 + 16.149 + var d = new Int32Array(3); 16.150 + d.set(i32,1); 16.151 + print(bufstr(d)); 16.152 + 16.153 + var s = new Int16Array(b); 16.154 + var t = new Uint16Array(b); 16.155 + print(arrstr(s), arrstr(t)); 16.156 + s[0] = -1; s[1] = 0x80; 16.157 + print(arrstr(s), arrstr(t)); 16.158 +})(); 16.159 + 16.160 +(function enumerate_properties() { 16.161 + var i8 = new Int8Array(new ArrayBuffer(8)); 16.162 + var s = ""; for (var i in i8) { s += i + " "; } print(s.trim()); 16.163 +})(); 16.164 + 16.165 +// check that ScriptObject fallback is still working 16.166 +// DISABLED because correct behavior is unclear 16.167 +(function() { 16.168 + // NB: firefox will never set any out-of-bounds or non-array values although it does get both from prototype. 16.169 + var z = new Uint8Array(4); 16.170 + z["asdf"] = "asdf"; print(z["asdf"]); 16.171 + z[0x100000000] = "asdf"; print(z[0x100000000]); 16.172 + z[-1] = "asdf"; print(z[-1]); 16.173 + 16.174 + // v8 and nashorn disagree on out-of-bounds uint32 indices: v8 won't go to the prototype. 16.175 + z[0xf0000000] = "asdf"; print(z[0xf0000000]); 16.176 + z[0xffffffff] = "asdf"; print(z[0xffffffff]); 16.177 + z[0x70000000] = "asdf"; print(z[0x70000000]); 16.178 + 16.179 + // this will work in firefox and nashorn (not in v8). 16.180 + Uint8Array.prototype[4] = "asdf"; print(z[4]); 16.181 +}); 16.182 + 16.183 +(function test_exceptions() { 16.184 + assertFail(function() { new Int32Array(new ArrayBuffer(7)); }); 16.185 + assertFail(function() { new Int32Array(new ArrayBuffer(8), 0, 4); }); 16.186 + assertFail(function() { new Int32Array(new ArrayBuffer(8),-1, 2); }); 16.187 + assertFail(function() { new Int32Array(new ArrayBuffer(8), 0,-1); }); 16.188 +})(); 16.189 + 16.190 +(function test_subarray() { 16.191 + var x = fillArray(new Int8Array(8)); 16.192 + print(arrstr(x)); 16.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 16.194 + print(arrstr(x.subarray(-10, -2))); // negative index clamped to 0 16.195 + assertTrue(function(){ return arrstr(x.subarray(6, 4)) === ""; }); // negative length clamped to 0 16.196 + print(arrstr(x.subarray(1,-1).subarray(1,-1)), arrstr(x.subarray(1,-1).subarray(1,-1).subarray(1,-1))); // subarray of subarray 16.197 +})(); 16.198 + 16.199 +(function test_slice() { 16.200 + var b = new ArrayBuffer(16); 16.201 + fillArray(new Int8Array(b)); 16.202 + print(bufstr(b)); 16.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 16.204 + print(bufstr(b.slice(-20, -4))); // negative index clamped to 0 16.205 + assertTrue(function(){ return bufstr(b.slice(8, 4)) === ""; }); // negative length clamped to 0 16.206 + print(arrstr(new Int16Array(b.slice(1,-1).slice(2,-1).slice(1,-2).slice(1,-1)))); // slice of slice 16.207 +})(); 16.208 + 16.209 +(function test_clamped() { 16.210 + var a = new Uint8ClampedArray(10); 16.211 + a[0] = -17; // clamped to 0 16.212 + a[1] = 4711; // clamped to 255 16.213 + a[2] = 17.5; // clamped to 18 16.214 + a[3] = 16.5; // clamped to 16 16.215 + a[4] = 255.9; // clamped to 255 16.216 + a[5] = Infinity; // clamped to 255 16.217 + a[6] = -Infinity; // clamped to 0 16.218 + a[7] = NaN; // 0 16.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; }); 16.220 +})(); 16.221 + 16.222 +(function test_out_of_bounds() { 16.223 + var a = new Int32Array(10); 16.224 + a[10] = 10; 16.225 + a[100] = 100; 16.226 + a[1000] = 1000; 16.227 + assertTrue(function(){ return isUndefined(a[10]) && isUndefined(a[11]) && isUndefined(a[100]) && isUndefined(a[123]) && isUndefined(a[1000]); }); 16.228 +})(); 16.229 +
17.1 --- a/test/script/basic/NASHORN-377.js Wed Nov 26 08:00:20 2014 -0800 17.2 +++ b/test/script/basic/NASHORN-377.js Wed Nov 26 13:57:43 2014 -0800 17.3 @@ -26,201 +26,8 @@ 17.4 * 17.5 * @test 17.6 * @run 17.7 + * @littleendian 17.8 */ 17.9 17.10 -var types = [Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array]; 17.11 - 17.12 -//--------------------------------------------------------------------------- 17.13 -// utility functions 17.14 -//--------------------------------------------------------------------------- 17.15 -function tohex(d, w) { 17.16 - var hex = Number(d).toString(16); 17.17 - var pad = (w ? w : 8) - hex.length; 17.18 - hex = "00000000".substr(0, pad) + hex; 17.19 - return hex; 17.20 -} 17.21 - 17.22 -function arrstr(a, n, w) { 17.23 - var s = ""; 17.24 - if (typeof n == "undefined") n = a.length; 17.25 - if (typeof w == "undefined") w = a.constructor.BYTES_PER_ELEMENT * 2; 17.26 - for (var i = 0; i < n; i++) { 17.27 - s += tohex(a[i], w); 17.28 - } 17.29 - return s; 17.30 -} 17.31 -function bufstr(b) { 17.32 - if (b.buffer !== undefined) { 17.33 - b = b.buffer; 17.34 - } 17.35 - return arrstr(new Uint8Array(b)); 17.36 -} 17.37 - 17.38 -function assertFail(f) { 17.39 - try { 17.40 - f(); 17.41 - } catch (e) { 17.42 - //print(e); 17.43 - return; 17.44 - } 17.45 - throw "assertion failed: expected exception"; 17.46 -} 17.47 - 17.48 -function assertTrue(f) { 17.49 - if (f() !== true) throw "assertion failed: " + f; 17.50 -} 17.51 - 17.52 -function isUndefined(x) { 17.53 - return typeof x === "undefined"; 17.54 -} 17.55 - 17.56 -function fillArray(a, start) { 17.57 - if (typeof start == "undefined") start = 1; 17.58 - for (var i = 0; i < a.length; i++) { 17.59 - a[i] = i + start; 17.60 - } 17.61 - return a; 17.62 -} 17.63 - 17.64 -//--------------------------------------------------------------------------- 17.65 -// tests 17.66 -//--------------------------------------------------------------------------- 17.67 -(function() { 17.68 - var b = new ArrayBuffer(8); 17.69 - var i8 = new Int8Array(b); 17.70 - print(i8.buffer.byteLength, b.byteLength, i8.buffer === b, b.length); 17.71 - print(b, i8.buffer, i8); 17.72 -})(); 17.73 - 17.74 -(function test_attributes() { 17.75 - var b = new ArrayBuffer(8); 17.76 - for (var i in types) { 17.77 - var x = new types[i](b); 17.78 - print(x.byteOffset, x.byteLength, x.length, x.constructor.BYTES_PER_ELEMENT); 17.79 - assertTrue(function(){ return x.constructor === types[i] }); 17.80 - } 17.81 -})(); 17.82 - 17.83 -(function() { 17.84 - var b = new ArrayBuffer(8); 17.85 - var i8 = new Int8Array(b); 17.86 - fillArray(i8, 0x70); 17.87 - 17.88 - var i8_2 = new Int8Array(b, 2); 17.89 - var i8_2_4 = new Uint8Array(b, 2, 4); 17.90 - 17.91 - i8_2_4[3] = 0x80; 17.92 - 17.93 - print(arrstr(i8, 8, 2) + " " + bufstr(i8)); 17.94 - print(arrstr(i8_2, 6) + " " + i8_2.byteOffset + " " + i8_2.byteLength); 17.95 - print(arrstr(i8_2_4, 4) + " " + i8_2_4.byteOffset + " " + i8_2_4.byteLength); 17.96 - 17.97 - var i8_1_5 = i8.subarray(1, 5); 17.98 - i8_2_4.subarray(1, 5); 17.99 - print(arrstr(i8_1_5, 4) + " " + i8_1_5.byteOffset + " " + i8_1_5.byteLength); 17.100 - 17.101 - print(bufstr(b.slice(1,7))); 17.102 -})(); 17.103 - 17.104 -(function() { 17.105 - var b = new ArrayBuffer(8); 17.106 - fillArray(new Int8Array(b), 0x70); 17.107 - new Int8Array(b)[5] = 0x80; 17.108 - 17.109 - var i32 = new Int32Array(b); 17.110 - var u32 = new Uint32Array(b); 17.111 - print(arrstr(i32), i32[0], i32[1]); 17.112 - i32[1] = 0xfefdfcfb; 17.113 - print(arrstr(i32), i32[0], i32[1]); 17.114 - print(arrstr(u32), u32[0], u32[1]); 17.115 - 17.116 - var pi = 3.1415926; 17.117 - var f32 = new Float32Array(b); 17.118 - var f64 = new Float64Array(b); 17.119 - f32[0] = pi; 17.120 - print(bufstr(b), f32.length); 17.121 - f64[0] = pi; 17.122 - print(bufstr(b), f64.length); 17.123 - print(arrstr(u32), u32[0], u32[1]); 17.124 - 17.125 - var d = new Int32Array(3); 17.126 - d.set(i32,1); 17.127 - print(bufstr(d)); 17.128 - 17.129 - var s = new Int16Array(b); 17.130 - var t = new Uint16Array(b); 17.131 - print(arrstr(s), arrstr(t)); 17.132 - s[0] = -1; s[1] = 0x80; 17.133 - print(arrstr(s), arrstr(t)); 17.134 -})(); 17.135 - 17.136 -(function enumerate_properties() { 17.137 - var i8 = new Int8Array(new ArrayBuffer(8)); 17.138 - var s = ""; for (var i in i8) { s += i + " "; } print(s.trim()); 17.139 -})(); 17.140 - 17.141 -// check that ScriptObject fallback is still working 17.142 -// DISABLED because correct behavior is unclear 17.143 -(function() { 17.144 - // NB: firefox will never set any out-of-bounds or non-array values although it does get both from prototype. 17.145 - var z = new Uint8Array(4); 17.146 - z["asdf"] = "asdf"; print(z["asdf"]); 17.147 - z[0x100000000] = "asdf"; print(z[0x100000000]); 17.148 - z[-1] = "asdf"; print(z[-1]); 17.149 - 17.150 - // v8 and nashorn disagree on out-of-bounds uint32 indices: v8 won't go to the prototype. 17.151 - z[0xf0000000] = "asdf"; print(z[0xf0000000]); 17.152 - z[0xffffffff] = "asdf"; print(z[0xffffffff]); 17.153 - z[0x70000000] = "asdf"; print(z[0x70000000]); 17.154 - 17.155 - // this will work in firefox and nashorn (not in v8). 17.156 - Uint8Array.prototype[4] = "asdf"; print(z[4]); 17.157 -}); 17.158 - 17.159 -(function test_exceptions() { 17.160 - assertFail(function() { new Int32Array(new ArrayBuffer(7)); }); 17.161 - assertFail(function() { new Int32Array(new ArrayBuffer(8), 0, 4); }); 17.162 - assertFail(function() { new Int32Array(new ArrayBuffer(8),-1, 2); }); 17.163 - assertFail(function() { new Int32Array(new ArrayBuffer(8), 0,-1); }); 17.164 -})(); 17.165 - 17.166 -(function test_subarray() { 17.167 - var x = fillArray(new Int8Array(8)); 17.168 - print(arrstr(x)); 17.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 17.170 - print(arrstr(x.subarray(-10, -2))); // negative index clamped to 0 17.171 - assertTrue(function(){ return arrstr(x.subarray(6, 4)) === ""; }); // negative length clamped to 0 17.172 - print(arrstr(x.subarray(1,-1).subarray(1,-1)), arrstr(x.subarray(1,-1).subarray(1,-1).subarray(1,-1))); // subarray of subarray 17.173 -})(); 17.174 - 17.175 -(function test_slice() { 17.176 - var b = new ArrayBuffer(16); 17.177 - fillArray(new Int8Array(b)); 17.178 - print(bufstr(b)); 17.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 17.180 - print(bufstr(b.slice(-20, -4))); // negative index clamped to 0 17.181 - assertTrue(function(){ return bufstr(b.slice(8, 4)) === ""; }); // negative length clamped to 0 17.182 - print(arrstr(new Int16Array(b.slice(1,-1).slice(2,-1).slice(1,-2).slice(1,-1)))); // slice of slice 17.183 -})(); 17.184 - 17.185 -(function test_clamped() { 17.186 - var a = new Uint8ClampedArray(10); 17.187 - a[0] = -17; // clamped to 0 17.188 - a[1] = 4711; // clamped to 255 17.189 - a[2] = 17.5; // clamped to 18 17.190 - a[3] = 16.5; // clamped to 16 17.191 - a[4] = 255.9; // clamped to 255 17.192 - a[5] = Infinity; // clamped to 255 17.193 - a[6] = -Infinity; // clamped to 0 17.194 - a[7] = NaN; // 0 17.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; }); 17.196 -})(); 17.197 - 17.198 -(function test_out_of_bounds() { 17.199 - var a = new Int32Array(10); 17.200 - a[10] = 10; 17.201 - a[100] = 100; 17.202 - a[1000] = 1000; 17.203 - assertTrue(function(){ return isUndefined(a[10]) && isUndefined(a[11]) && isUndefined(a[100]) && isUndefined(a[123]) && isUndefined(a[1000]); }); 17.204 -})(); 17.205 - 17.206 +var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__; 17.207 +load(dir + "NASHORN-377-payload.js");
18.1 --- a/test/script/basic/compile-octane-normal.js Wed Nov 26 08:00:20 2014 -0800 18.2 +++ b/test/script/basic/compile-octane-normal.js Wed Nov 26 13:57:43 2014 -0800 18.3 @@ -38,5 +38,5 @@ 18.4 */ 18.5 18.6 var fn = __DIR__ + 'compile-octane.js'; 18.7 -var url = "file://" + fn; 18.8 -loadWithNewGlobal(new java.net.URL(url)); 18.9 +var url = new java.io.File(fn).toURL(); 18.10 +loadWithNewGlobal(url);
19.1 --- a/test/script/basic/compile-octane-splitter.js Wed Nov 26 08:00:20 2014 -0800 19.2 +++ b/test/script/basic/compile-octane-splitter.js Wed Nov 26 13:57:43 2014 -0800 19.3 @@ -40,5 +40,5 @@ 19.4 */ 19.5 19.6 var fn = __DIR__ + 'compile-octane.js'; 19.7 -var url = "file://" + fn; 19.8 -loadWithNewGlobal(new java.net.URL(url)); 19.9 +var url = new java.io.File(fn).toURL(); 19.10 +loadWithNewGlobal(url);
20.1 --- a/test/script/basic/compile-octane.js Wed Nov 26 08:00:20 2014 -0800 20.2 +++ b/test/script/basic/compile-octane.js Wed Nov 26 13:57:43 2014 -0800 20.3 @@ -132,7 +132,7 @@ 20.4 str2 += " processing file: " + file + "..."; 20.5 print_if_verbose(str2); 20.6 } 20.7 - newGlobal.load("file://" + path + file); 20.8 + newGlobal.load(new java.io.File(path + file).toURL()); 20.9 } 20.10 } 20.11 print("Done.");
21.1 --- a/test/script/basic/es6/const-redeclare-extra.js.EXPECTED Wed Nov 26 08:00:20 2014 -0800 21.2 +++ b/test/script/basic/es6/const-redeclare-extra.js.EXPECTED Wed Nov 26 13:57:43 2014 -0800 21.3 @@ -1,9 +1,9 @@ 21.4 SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:3:8 Variable "x" has already been declared 21.5 var x = {}; 21.6 ^ 21.7 -SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:2:8 Variable "x" has already been declared 21.8 - var x = 2; 21.9 - ^ 21.10 -SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:2:13 Variable "x" has already been declared 21.11 - function x () {} 21.12 - ^ 21.13 +SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:3:10 Variable "x" has already been declared 21.14 + const x = {}; 21.15 + ^ 21.16 +SyntaxError: test/script/basic/es6/const-redeclare-extra.js#36:8<eval>:3:10 Variable "x" has already been declared 21.17 + const x = 5; 21.18 + ^
22.1 --- a/test/script/basic/es6/let-load.js Wed Nov 26 08:00:20 2014 -0800 22.2 +++ b/test/script/basic/es6/let-load.js Wed Nov 26 13:57:43 2014 -0800 22.3 @@ -26,7 +26,8 @@ 22.4 * 22.5 * @test 22.6 * @run 22.7 - * @option --language=es6 */ 22.8 + * @option --language=es6 22.9 + */ 22.10 22.11 "use strict"; 22.12
23.1 --- a/test/script/basic/es6/let-load.js.EXPECTED Wed Nov 26 08:00:20 2014 -0800 23.2 +++ b/test/script/basic/es6/let-load.js.EXPECTED Wed Nov 26 13:57:43 2014 -0800 23.3 @@ -2,7 +2,7 @@ 23.4 block function 23.5 print local defs: 20 30 23.6 imported var: 1 23.7 -ReferenceError: "b" is not defined 23.8 -ReferenceError: "c" is not defined 23.9 +imported let: 2 23.10 +imported const: 3 23.11 top level function 23.12 ReferenceError: "block" is not defined
24.1 --- a/test/script/basic/es6/let-redeclare-extra.js.EXPECTED Wed Nov 26 08:00:20 2014 -0800 24.2 +++ b/test/script/basic/es6/let-redeclare-extra.js.EXPECTED Wed Nov 26 13:57:43 2014 -0800 24.3 @@ -4,12 +4,12 @@ 24.4 SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:3:8 Variable "x" has already been declared 24.5 var x = 2; 24.6 ^ 24.7 -SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:2:8 Variable "x" has already been declared 24.8 - var x = 2; 24.9 +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:3:8 Variable "x" has already been declared 24.10 + let x = undefined; 24.11 ^ 24.12 SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:2:10 Variable "x" has already been declared 24.13 const x = function (){}; 24.14 ^ 24.15 -SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:3:13 Variable "a" has already been declared 24.16 - function a () {}; 24.17 - ^ 24.18 +SyntaxError: test/script/basic/es6/let-redeclare-extra.js#35:8<eval>:2:8 Variable "a" has already been declared 24.19 + let a = 2; 24.20 + ^
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/test/script/basic/es6/lexical-toplevel-def.js Wed Nov 26 13:57:43 2014 -0800 25.3 @@ -0,0 +1,34 @@ 25.4 +/* 25.5 + * Copyright (c) 2014, 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. 25.11 + * 25.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 25.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25.15 + * version 2 for more details (a copy is included in the LICENSE file that 25.16 + * accompanied this code). 25.17 + * 25.18 + * You should have received a copy of the GNU General Public License version 25.19 + * 2 along with this work; if not, write to the Free Software Foundation, 25.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 25.21 + * 25.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25.23 + * or visit www.oracle.com if you need additional information or have any 25.24 + * questions. 25.25 + */ 25.26 + 25.27 +/** 25.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 25.29 + * 25.30 + * @subtest 25.31 + */ 25.32 + 25.33 +var VAR = "VAR"; 25.34 +let LET = "LET"; 25.35 +const CONST = "CONST"; 25.36 +function FUNC() {} 25.37 +this.GLOBAL = "GLOBAL";
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/script/basic/es6/lexical-toplevel-print.js Wed Nov 26 13:57:43 2014 -0800 26.3 @@ -0,0 +1,51 @@ 26.4 +/* 26.5 + * Copyright (c) 2014, 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. 26.11 + * 26.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 26.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.15 + * version 2 for more details (a copy is included in the LICENSE file that 26.16 + * accompanied this code). 26.17 + * 26.18 + * You should have received a copy of the GNU General Public License version 26.19 + * 2 along with this work; if not, write to the Free Software Foundation, 26.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.21 + * 26.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 26.23 + * or visit www.oracle.com if you need additional information or have any 26.24 + * questions. 26.25 + */ 26.26 + 26.27 +/** 26.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 26.29 + * 26.30 + * @subtest 26.31 + */ 26.32 + 26.33 +print(VAR); 26.34 +print(LET); 26.35 +print(CONST); 26.36 +print(FUNC); 26.37 +print(GLOBAL); 26.38 +print(this.VAR); 26.39 +print(this.LET); // undefined 26.40 +print(this.CONST); // undefined 26.41 +print(this.FUNC); 26.42 +print(this.GLOBAL); 26.43 +print("VAR" in this); 26.44 +print("LET" in this); // false 26.45 +print("CONST" in this); // false 26.46 +print("FUNC" in this); 26.47 +print("GLOBAL" in this); 26.48 + 26.49 +try { 26.50 + LET = LET + "LET"; 26.51 + CONST = CONST + "CONST"; 26.52 +} catch (e) { 26.53 + print(String(e).replace(/\\/g, "/")); 26.54 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-func-on-let.js Wed Nov 26 13:57:43 2014 -0800 27.3 @@ -0,0 +1,31 @@ 27.4 +/* 27.5 + * Copyright (c) 2014, 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. 27.11 + * 27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.15 + * version 2 for more details (a copy is included in the LICENSE file that 27.16 + * accompanied this code). 27.17 + * 27.18 + * You should have received a copy of the GNU General Public License version 27.19 + * 2 along with this work; if not, write to the Free Software Foundation, 27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.21 + * 27.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27.23 + * or visit www.oracle.com if you need additional information or have any 27.24 + * questions. 27.25 + */ 27.26 + 27.27 +/** 27.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 27.29 + * 27.30 + * @subtest 27.31 + */ 27.32 + 27.33 +function LET() {} 27.34 +var SHOULD_NOT_EXIST = 10;
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-let-on-builtin.js Wed Nov 26 13:57:43 2014 -0800 28.3 @@ -0,0 +1,30 @@ 28.4 +/* 28.5 + * Copyright (c) 2014, 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. 28.11 + * 28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28.15 + * version 2 for more details (a copy is included in the LICENSE file that 28.16 + * accompanied this code). 28.17 + * 28.18 + * You should have received a copy of the GNU General Public License version 28.19 + * 2 along with this work; if not, write to the Free Software Foundation, 28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 28.21 + * 28.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 28.23 + * or visit www.oracle.com if you need additional information or have any 28.24 + * questions. 28.25 + */ 28.26 + 28.27 +/** 28.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 28.29 + * 28.30 + * @subtest 28.31 + */ 28.32 + 28.33 +let Object = "LEXICAL BUILTIN";
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-let-on-func.js Wed Nov 26 13:57:43 2014 -0800 29.3 @@ -0,0 +1,31 @@ 29.4 +/* 29.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.7 + * 29.8 + * This code is free software; you can redistribute it and/or modify it 29.9 + * under the terms of the GNU General Public License version 2 only, as 29.10 + * published by the Free Software Foundation. 29.11 + * 29.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.15 + * version 2 for more details (a copy is included in the LICENSE file that 29.16 + * accompanied this code). 29.17 + * 29.18 + * You should have received a copy of the GNU General Public License version 29.19 + * 2 along with this work; if not, write to the Free Software Foundation, 29.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.21 + * 29.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 29.23 + * or visit www.oracle.com if you need additional information or have any 29.24 + * questions. 29.25 + */ 29.26 + 29.27 +/** 29.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 29.29 + * 29.30 + * @subtest 29.31 + */ 29.32 + 29.33 +let FUNC = 10; 29.34 +var SHOULD_NOT_EXIST = 10;
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-let-on-global.js Wed Nov 26 13:57:43 2014 -0800 30.3 @@ -0,0 +1,30 @@ 30.4 +/* 30.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.7 + * 30.8 + * This code is free software; you can redistribute it and/or modify it 30.9 + * under the terms of the GNU General Public License version 2 only, as 30.10 + * published by the Free Software Foundation. 30.11 + * 30.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 30.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 30.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 30.15 + * version 2 for more details (a copy is included in the LICENSE file that 30.16 + * accompanied this code). 30.17 + * 30.18 + * You should have received a copy of the GNU General Public License version 30.19 + * 2 along with this work; if not, write to the Free Software Foundation, 30.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 30.21 + * 30.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 30.23 + * or visit www.oracle.com if you need additional information or have any 30.24 + * questions. 30.25 + */ 30.26 + 30.27 +/** 30.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 30.29 + * 30.30 + * @subtest 30.31 + */ 30.32 + 30.33 +let GLOBAL = "LEXICAL GLOBAL";
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-let-on-var.js Wed Nov 26 13:57:43 2014 -0800 31.3 @@ -0,0 +1,31 @@ 31.4 +/* 31.5 + * Copyright (c) 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 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 31.29 + * 31.30 + * @subtest 31.31 + */ 31.32 + 31.33 +let VAR = 10; 31.34 +var SHOULD_NOT_EXIST = 10;
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare-var-on-let.js Wed Nov 26 13:57:43 2014 -0800 32.3 @@ -0,0 +1,31 @@ 32.4 +/* 32.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.7 + * 32.8 + * This code is free software; you can redistribute it and/or modify it 32.9 + * under the terms of the GNU General Public License version 2 only, as 32.10 + * published by the Free Software Foundation. 32.11 + * 32.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 32.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.15 + * version 2 for more details (a copy is included in the LICENSE file that 32.16 + * accompanied this code). 32.17 + * 32.18 + * You should have received a copy of the GNU General Public License version 32.19 + * 2 along with this work; if not, write to the Free Software Foundation, 32.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.21 + * 32.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 32.23 + * or visit www.oracle.com if you need additional information or have any 32.24 + * questions. 32.25 + */ 32.26 + 32.27 +/** 32.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 32.29 + * 32.30 + * @subtest 32.31 + */ 32.32 + 32.33 +var LET = 10; 32.34 +var SHOULD_NOT_EXIST = 10;
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare.js Wed Nov 26 13:57:43 2014 -0800 33.3 @@ -0,0 +1,78 @@ 33.4 +/* 33.5 + * Copyright (c) 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 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 33.29 + * 33.30 + * @test 33.31 + * @run 33.32 + * @option -scripting 33.33 + * @option --language=es6 33.34 + */ 33.35 + 33.36 +load(__DIR__ + "lexical-toplevel-def.js"); 33.37 + 33.38 +var global = this; 33.39 + 33.40 +function tryIt (code) { 33.41 + try { 33.42 + eval(code) 33.43 + } catch (e) { 33.44 + print(String(e).replace(/\\/g, "/")) 33.45 + } 33.46 +} 33.47 + 33.48 +function loadScript(script) { 33.49 + print(script); 33.50 + try { 33.51 + load(__DIR__ + script); 33.52 + } catch (e) { 33.53 + print(String(e).replace(/\\/g, "/")); 33.54 + } 33.55 + print(VAR); 33.56 + print(LET); 33.57 + print(CONST); 33.58 + print(FUNC); 33.59 + print(GLOBAL); 33.60 + print(global.VAR); 33.61 + print(global.LET); 33.62 + print(global.CONST); 33.63 + print(global.FUNC); 33.64 + print(global.GLOBAL); 33.65 + try { 33.66 + print(SHOULD_NOT_EXIST); 33.67 + } catch (e) { 33.68 + print(String(e).replace(/\\/g, "/")); 33.69 + } 33.70 + print(global.SHOULD_NOT_EXIST); 33.71 + print(Object); 33.72 + print(global.Object); 33.73 + print(); 33.74 +} 33.75 + 33.76 +loadScript("lexical-toplevel-redeclare-var-on-let.js"); 33.77 +loadScript("lexical-toplevel-redeclare-func-on-let.js"); 33.78 +loadScript("lexical-toplevel-redeclare-let-on-var.js"); 33.79 +loadScript("lexical-toplevel-redeclare-let-on-func.js"); 33.80 +loadScript("lexical-toplevel-redeclare-let-on-builtin.js"); 33.81 +loadScript("lexical-toplevel-redeclare-let-on-global.js");
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/script/basic/es6/lexical-toplevel-redeclare.js.EXPECTED Wed Nov 26 13:57:43 2014 -0800 34.3 @@ -0,0 +1,100 @@ 34.4 +lexical-toplevel-redeclare-var-on-let.js 34.5 +SyntaxError: Variable "LET" has already been declared 34.6 +VAR 34.7 +LET 34.8 +CONST 34.9 +function FUNC() {} 34.10 +GLOBAL 34.11 +VAR 34.12 +undefined 34.13 +undefined 34.14 +function FUNC() {} 34.15 +GLOBAL 34.16 +ReferenceError: "SHOULD_NOT_EXIST" is not defined 34.17 +undefined 34.18 +function Object() { [native code] } 34.19 +function Object() { [native code] } 34.20 + 34.21 +lexical-toplevel-redeclare-func-on-let.js 34.22 +SyntaxError: Variable "LET" has already been declared 34.23 +VAR 34.24 +LET 34.25 +CONST 34.26 +function FUNC() {} 34.27 +GLOBAL 34.28 +VAR 34.29 +undefined 34.30 +undefined 34.31 +function FUNC() {} 34.32 +GLOBAL 34.33 +ReferenceError: "SHOULD_NOT_EXIST" is not defined 34.34 +undefined 34.35 +function Object() { [native code] } 34.36 +function Object() { [native code] } 34.37 + 34.38 +lexical-toplevel-redeclare-let-on-var.js 34.39 +SyntaxError: Variable "VAR" has already been declared 34.40 +VAR 34.41 +LET 34.42 +CONST 34.43 +function FUNC() {} 34.44 +GLOBAL 34.45 +VAR 34.46 +undefined 34.47 +undefined 34.48 +function FUNC() {} 34.49 +GLOBAL 34.50 +ReferenceError: "SHOULD_NOT_EXIST" is not defined 34.51 +undefined 34.52 +function Object() { [native code] } 34.53 +function Object() { [native code] } 34.54 + 34.55 +lexical-toplevel-redeclare-let-on-func.js 34.56 +SyntaxError: Variable "FUNC" has already been declared 34.57 +VAR 34.58 +LET 34.59 +CONST 34.60 +function FUNC() {} 34.61 +GLOBAL 34.62 +VAR 34.63 +undefined 34.64 +undefined 34.65 +function FUNC() {} 34.66 +GLOBAL 34.67 +ReferenceError: "SHOULD_NOT_EXIST" is not defined 34.68 +undefined 34.69 +function Object() { [native code] } 34.70 +function Object() { [native code] } 34.71 + 34.72 +lexical-toplevel-redeclare-let-on-builtin.js 34.73 +VAR 34.74 +LET 34.75 +CONST 34.76 +function FUNC() {} 34.77 +GLOBAL 34.78 +VAR 34.79 +undefined 34.80 +undefined 34.81 +function FUNC() {} 34.82 +GLOBAL 34.83 +ReferenceError: "SHOULD_NOT_EXIST" is not defined 34.84 +undefined 34.85 +LEXICAL BUILTIN 34.86 +function Object() { [native code] } 34.87 + 34.88 +lexical-toplevel-redeclare-let-on-global.js 34.89 +VAR 34.90 +LET 34.91 +CONST 34.92 +function FUNC() {} 34.93 +LEXICAL GLOBAL 34.94 +VAR 34.95 +undefined 34.96 +undefined 34.97 +function FUNC() {} 34.98 +GLOBAL 34.99 +ReferenceError: "SHOULD_NOT_EXIST" is not defined 34.100 +undefined 34.101 +LEXICAL BUILTIN 34.102 +function Object() { [native code] } 34.103 +
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/script/basic/es6/lexical-toplevel.js Wed Nov 26 13:57:43 2014 -0800 35.3 @@ -0,0 +1,35 @@ 35.4 +/* 35.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. 35.11 + * 35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.15 + * version 2 for more details (a copy is included in the LICENSE file that 35.16 + * accompanied this code). 35.17 + * 35.18 + * You should have received a copy of the GNU General Public License version 35.19 + * 2 along with this work; if not, write to the Free Software Foundation, 35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.21 + * 35.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 35.23 + * or visit www.oracle.com if you need additional information or have any 35.24 + * questions. 35.25 + */ 35.26 + 35.27 +/** 35.28 + * JDK-8057691: Nashorn: let & const declarations are not shared between scripts 35.29 + * 35.30 + * @test 35.31 + * @run 35.32 + * @option --language=es6 35.33 + */ 35.34 + 35.35 +load(__DIR__ + "lexical-toplevel-def.js"); 35.36 + 35.37 +load(__DIR__ + "lexical-toplevel-print.js"); 35.38 +load(__DIR__ + "lexical-toplevel-print.js");
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/script/basic/es6/lexical-toplevel.js.EXPECTED Wed Nov 26 13:57:43 2014 -0800 36.3 @@ -0,0 +1,30 @@ 36.4 +VAR 36.5 +LET 36.6 +CONST 36.7 +function FUNC() {} 36.8 +GLOBAL 36.9 +VAR 36.10 +undefined 36.11 +undefined 36.12 +function FUNC() {} 36.13 +GLOBAL 36.14 +true 36.15 +false 36.16 +false 36.17 +true 36.18 +true 36.19 +VAR 36.20 +LETLET 36.21 +CONST 36.22 +function FUNC() {} 36.23 +GLOBAL 36.24 +VAR 36.25 +undefined 36.26 +undefined 36.27 +function FUNC() {} 36.28 +GLOBAL 36.29 +true 36.30 +false 36.31 +false 36.32 +true 36.33 +true
37.1 --- a/test/script/nosecurity/JDK-8050964.js Wed Nov 26 08:00:20 2014 -0800 37.2 +++ b/test/script/nosecurity/JDK-8050964.js Wed Nov 26 13:57:43 2014 -0800 37.3 @@ -50,6 +50,7 @@ 37.4 var jdepsPath = javahome + "/../bin/jdeps".replaceAll(/\//g, File.separater); 37.5 37.6 // run jdep on nashorn.jar - only summary but print profile info 37.7 +$ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin 37.8 `${jdepsPath} -s -P ${nashornJar.absolutePath}` 37.9 37.10 // check for "(compact1)" in output from jdep tool
38.1 --- a/test/script/nosecurity/JDK-8055034.js Wed Nov 26 08:00:20 2014 -0800 38.2 +++ b/test/script/nosecurity/JDK-8055034.js Wed Nov 26 13:57:43 2014 -0800 38.3 @@ -49,7 +49,7 @@ 38.4 var jjsCmd = javahome + "/../bin/jjs"; 38.5 jjsCmd += " -J-Djava.ext.dirs=" + nashornJarDir; 38.6 jjsCmd = jjsCmd.toString().replaceAll(/\//g, File.separater); 38.7 - 38.8 +$ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin 38.9 $EXEC(jjsCmd, "var x = Object.create(null);\nx;\nprint('PASSED');\nexit(0)"); 38.10 38.11 // $ERR has all interactions including prompts! Just check for error substring.
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/src/jdk/nashorn/internal/runtime/LexicalBindingTest.java Wed Nov 26 13:57:43 2014 -0800 39.3 @@ -0,0 +1,212 @@ 39.4 +/* 39.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.7 + * 39.8 + * This code is free software; you can redistribute it and/or modify it 39.9 + * under the terms of the GNU General Public License version 2 only, as 39.10 + * published by the Free Software Foundation. Oracle designates this 39.11 + * particular file as subject to the "Classpath" exception as provided 39.12 + * by Oracle in the LICENSE file that accompanied this code. 39.13 + * 39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.17 + * version 2 for more details (a copy is included in the LICENSE file that 39.18 + * accompanied this code). 39.19 + * 39.20 + * You should have received a copy of the GNU General Public License version 39.21 + * 2 along with this work; if not, write to the Free Software Foundation, 39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.23 + * 39.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 39.25 + * or visit www.oracle.com if you need additional information or have any 39.26 + * questions. 39.27 + */ 39.28 + 39.29 +package jdk.nashorn.internal.runtime; 39.30 + 39.31 +import jdk.nashorn.api.scripting.NashornScriptEngineFactory; 39.32 +import org.testng.annotations.Test; 39.33 + 39.34 +import javax.script.Bindings; 39.35 +import javax.script.ScriptContext; 39.36 +import javax.script.ScriptEngine; 39.37 +import javax.script.ScriptException; 39.38 +import javax.script.SimpleScriptContext; 39.39 + 39.40 +import static org.testng.Assert.assertEquals; 39.41 + 39.42 +/** 39.43 + * Top-level lexical binding tests. 39.44 + * 39.45 + * @test 39.46 + * @run testng jdk.nashorn.internal.runtime.LexicalBindingTest 39.47 + */ 39.48 +@SuppressWarnings("javadoc") 39.49 +public class LexicalBindingTest { 39.50 + 39.51 + final static String LANGUAGE_ES6 = "--language=es6"; 39.52 + final static int NUMBER_OF_CONTEXTS = 20; 39.53 + final static int MEGAMORPHIC_LOOP_COUNT = 20; 39.54 + 39.55 + /** 39.56 + * Test access to global var-declared variables for shared script classes with multiple globals. 39.57 + */ 39.58 + @Test 39.59 + public static void megamorphicVarTest() throws ScriptException, InterruptedException { 39.60 + final NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); 39.61 + final ScriptEngine e = factory.getScriptEngine(); 39.62 + final ScriptContext[] contexts = new ScriptContext[NUMBER_OF_CONTEXTS]; 39.63 + final String sharedScript = "foo"; 39.64 + 39.65 + 39.66 + for (int i = 0; i < NUMBER_OF_CONTEXTS; i++) { 39.67 + final ScriptContext context = contexts[i] = new SimpleScriptContext(); 39.68 + final Bindings b = e.createBindings(); 39.69 + context.setBindings(b, ScriptContext.ENGINE_SCOPE); 39.70 + assertEquals(e.eval("var foo = '" + i + "';", context), null); 39.71 + } 39.72 + 39.73 + for (int i = 0; i < NUMBER_OF_CONTEXTS; i++) { 39.74 + final ScriptContext context = contexts[i]; 39.75 + assertEquals(e.eval(sharedScript, context), String.valueOf(i)); 39.76 + } 39.77 + } 39.78 + 39.79 + /** 39.80 + * Test access to global lexically declared variables for shared script classes with multiple globals. 39.81 + */ 39.82 + @Test 39.83 + public static void megamorphicMultiGlobalLetTest() throws ScriptException, InterruptedException { 39.84 + final NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); 39.85 + final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6); 39.86 + final ScriptContext[] contexts = new ScriptContext[NUMBER_OF_CONTEXTS]; 39.87 + final String sharedScript = "foo"; 39.88 + 39.89 + 39.90 + for (int i = 0; i < NUMBER_OF_CONTEXTS; i++) { 39.91 + final ScriptContext context = contexts[i] = new SimpleScriptContext(); 39.92 + final Bindings b = e.createBindings(); 39.93 + context.setBindings(b, ScriptContext.ENGINE_SCOPE); 39.94 + assertEquals(e.eval("let foo = '" + i + "';", context), null); 39.95 + } 39.96 + 39.97 + for (int i = 0; i < NUMBER_OF_CONTEXTS; i++) { 39.98 + final ScriptContext context = contexts[i]; 39.99 + assertEquals(e.eval(sharedScript, context), String.valueOf(i)); 39.100 + } 39.101 + } 39.102 + 39.103 + 39.104 + /** 39.105 + * Test access to global lexically declared variables for shared script classes with single global. 39.106 + */ 39.107 + @Test 39.108 + public static void megamorphicSingleGlobalLetTest() throws ScriptException, InterruptedException { 39.109 + final NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); 39.110 + final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6); 39.111 + final String sharedGetterScript = "foo"; 39.112 + final String sharedSetterScript = "foo = 1"; 39.113 + 39.114 + for (int i = 0; i < MEGAMORPHIC_LOOP_COUNT; i++) { 39.115 + assertEquals(e.eval(sharedSetterScript), 1); 39.116 + assertEquals(e.eval(sharedGetterScript), 1); 39.117 + assertEquals(e.eval("delete foo; a" + i + " = 1; foo = " + i + ";"), i); 39.118 + assertEquals(e.eval(sharedGetterScript), i); 39.119 + } 39.120 + 39.121 + assertEquals(e.eval("let foo = 'foo';"), null); 39.122 + assertEquals(e.eval(sharedGetterScript), "foo"); 39.123 + assertEquals(e.eval(sharedSetterScript), 1); 39.124 + assertEquals(e.eval(sharedGetterScript), 1); 39.125 + assertEquals(e.eval("this.foo"), MEGAMORPHIC_LOOP_COUNT - 1); 39.126 + } 39.127 + 39.128 + /** 39.129 + * Test access to global lexically declared variables for shared script classes with single global. 39.130 + */ 39.131 + @Test 39.132 + public static void megamorphicInheritedGlobalLetTest() throws ScriptException, InterruptedException { 39.133 + final NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); 39.134 + final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6); 39.135 + final String sharedGetterScript = "foo"; 39.136 + final String sharedSetterScript = "foo = 1"; 39.137 + 39.138 + for (int i = 0; i < MEGAMORPHIC_LOOP_COUNT; i++) { 39.139 + assertEquals(e.eval(sharedSetterScript), 1); 39.140 + assertEquals(e.eval(sharedGetterScript), 1); 39.141 + assertEquals(e.eval("delete foo; a" + i + " = 1; Object.prototype.foo = " + i + ";"), i); 39.142 + assertEquals(e.eval(sharedGetterScript), i); 39.143 + } 39.144 + 39.145 + assertEquals(e.eval("let foo = 'foo';"), null); 39.146 + assertEquals(e.eval(sharedGetterScript), "foo"); 39.147 + assertEquals(e.eval(sharedSetterScript), 1); 39.148 + assertEquals(e.eval(sharedGetterScript), 1); 39.149 + assertEquals(e.eval("this.foo"), MEGAMORPHIC_LOOP_COUNT - 1); 39.150 + } 39.151 + 39.152 + /** 39.153 + * Test multi-threaded access to global lexically declared variables for shared script classes with multiple globals. 39.154 + */ 39.155 + @Test 39.156 + public static void multiThreadedLetTest() throws ScriptException, InterruptedException { 39.157 + final NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); 39.158 + final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6); 39.159 + final Bindings b = e.createBindings(); 39.160 + final ScriptContext origContext = e.getContext(); 39.161 + final ScriptContext newCtxt = new SimpleScriptContext(); 39.162 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 39.163 + final String sharedScript = "foo"; 39.164 + 39.165 + assertEquals(e.eval("let foo = 'original context';", origContext), null); 39.166 + assertEquals(e.eval("let foo = 'new context';", newCtxt), null); 39.167 + 39.168 + final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000)); 39.169 + final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000)); 39.170 + t1.start(); 39.171 + t2.start(); 39.172 + t1.join(); 39.173 + t2.join(); 39.174 + 39.175 + assertEquals(e.eval("foo = 'newer context';", newCtxt), "newer context"); 39.176 + final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000)); 39.177 + final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000)); 39.178 + 39.179 + t3.start(); 39.180 + t4.start(); 39.181 + t3.join(); 39.182 + t4.join(); 39.183 + 39.184 + assertEquals(e.eval(sharedScript), "original context"); 39.185 + assertEquals(e.eval(sharedScript, newCtxt), "newer context"); 39.186 + } 39.187 + 39.188 + private static class ScriptRunner implements Runnable { 39.189 + 39.190 + final ScriptEngine engine; 39.191 + final ScriptContext context; 39.192 + final String source; 39.193 + final Object expected; 39.194 + final int iterations; 39.195 + 39.196 + ScriptRunner(final ScriptEngine engine, final ScriptContext context, final String source, final Object expected, final int iterations) { 39.197 + this.engine = engine; 39.198 + this.context = context; 39.199 + this.source = source; 39.200 + this.expected = expected; 39.201 + this.iterations = iterations; 39.202 + } 39.203 + 39.204 + @Override 39.205 + public void run() { 39.206 + try { 39.207 + for (int i = 0; i < iterations; i++) { 39.208 + assertEquals(engine.eval(source, context), expected); 39.209 + } 39.210 + } catch (final ScriptException se) { 39.211 + throw new RuntimeException(se); 39.212 + } 39.213 + } 39.214 + } 39.215 +}
40.1 --- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java Wed Nov 26 08:00:20 2014 -0800 40.2 +++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java Wed Nov 26 13:57:43 2014 -0800 40.3 @@ -46,6 +46,7 @@ 40.4 import java.io.File; 40.5 import java.io.FileReader; 40.6 import java.io.IOException; 40.7 +import java.nio.ByteOrder; 40.8 import java.nio.file.FileSystem; 40.9 import java.nio.file.FileSystems; 40.10 import java.nio.file.FileVisitOption; 40.11 @@ -264,6 +265,12 @@ 40.12 isTest = false; 40.13 isNotTest = true; 40.14 break; 40.15 + case "@bigendian": 40.16 + shouldRun = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN; 40.17 + break; 40.18 + case "@littleendian": 40.19 + shouldRun = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN; 40.20 + break; 40.21 case "@runif": { 40.22 final String prop = scanner.next(); 40.23 if (System.getProperty(prop) != null) {