Mon, 19 Aug 2013 19:37:29 +0530
Merge
src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/arrays/MapIterator.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/arrays/ReverseArrayIterator.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/arrays/ReverseMapIterator.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java Tue Aug 13 18:34:12 2013 -0700 1.2 +++ b/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java Mon Aug 19 19:37:29 2013 +0530 1.3 @@ -317,7 +317,8 @@ 1.4 final String className = getClassName(fieldCount); 1.5 final String superName = className(ScriptObject.class); 1.6 final ClassEmitter classEmitter = newClassEmitter(className, superName); 1.7 - final List<String> initFields = addFields(classEmitter, fieldCount); 1.8 + 1.9 + addFields(classEmitter, fieldCount); 1.10 1.11 final MethodEmitter init = newInitMethod(classEmitter); 1.12 init.returnVoid();
2.1 --- a/src/jdk/nashorn/internal/codegen/ObjectCreator.java Tue Aug 13 18:34:12 2013 -0700 2.2 +++ b/src/jdk/nashorn/internal/codegen/ObjectCreator.java Mon Aug 19 19:37:29 2013 +0530 2.3 @@ -45,9 +45,11 @@ 2.4 /** Code generator */ 2.5 protected final CodeGenerator codegen; 2.6 2.7 - private final boolean isScope; 2.8 - private final boolean hasArguments; 2.9 - protected PropertyMap propertyMap; 2.10 + /** Property map */ 2.11 + protected PropertyMap propertyMap; 2.12 + 2.13 + private final boolean isScope; 2.14 + private final boolean hasArguments; 2.15 2.16 /** 2.17 * Constructor
3.1 --- a/src/jdk/nashorn/internal/ir/BinaryNode.java Tue Aug 13 18:34:12 2013 -0700 3.2 +++ b/src/jdk/nashorn/internal/ir/BinaryNode.java Mon Aug 19 19:37:29 2013 +0530 3.3 @@ -99,6 +99,7 @@ 3.4 case DIV: 3.5 case MOD: 3.6 case MUL: 3.7 + case SUB: 3.8 case ASSIGN_DIV: 3.9 case ASSIGN_MOD: 3.10 case ASSIGN_MUL:
4.1 --- a/src/jdk/nashorn/internal/ir/BreakableNode.java Tue Aug 13 18:34:12 2013 -0700 4.2 +++ b/src/jdk/nashorn/internal/ir/BreakableNode.java Mon Aug 19 19:37:29 2013 +0530 4.3 @@ -33,6 +33,14 @@ 4.4 * a {@code break} statement 4.5 */ 4.6 public interface BreakableNode extends LexicalContextNode { 4.7 + /** 4.8 + * Ensure that any labels in this breakable node are unique so 4.9 + * that new jumps won't go to old parts of the tree. Used for 4.10 + * example for cloning finally blocks 4.11 + * 4.12 + * @param lc the lexical context 4.13 + * @return node after labels have been made unique 4.14 + */ 4.15 public abstract Node ensureUniqueLabels(final LexicalContext lc); 4.16 4.17 /**
5.1 --- a/src/jdk/nashorn/internal/ir/IdentNode.java Tue Aug 13 18:34:12 2013 -0700 5.2 +++ b/src/jdk/nashorn/internal/ir/IdentNode.java Mon Aug 19 19:37:29 2013 +0530 5.3 @@ -161,13 +161,13 @@ 5.4 * converting to object, for example if the symbol is used as the left hand side of an 5.5 * assignment such as in the code below.</p> 5.6 * 5.7 - * <pre>{@code 5.8 + * <pre> 5.9 * try { 5.10 * return 2; 5.11 * } finally { 5.12 * return 3; 5.13 * } 5.14 - * }</pre> 5.15 + * } 5.16 * 5.17 * @return true if can have callsite type 5.18 */
6.1 --- a/src/jdk/nashorn/internal/ir/LexicalContextNode.java Tue Aug 13 18:34:12 2013 -0700 6.2 +++ b/src/jdk/nashorn/internal/ir/LexicalContextNode.java Mon Aug 19 19:37:29 2013 +0530 6.3 @@ -44,8 +44,14 @@ 6.4 Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor); 6.5 6.6 // Would be a default method on Java 8 6.7 + /** 6.8 + * Helper class for accept for items of this lexical context, delegates to the 6.9 + * subclass accept and makes sure that the node is on the context before accepting 6.10 + * and gets popped after accepting (and that the stack is consistent in that the 6.11 + * node has been replaced with the possible new node resulting in visitation) 6.12 + */ 6.13 static class Acceptor { 6.14 - static Node accept(LexicalContextNode node, final NodeVisitor<? extends LexicalContext> visitor) { 6.15 + static Node accept(final LexicalContextNode node, final NodeVisitor<? extends LexicalContext> visitor) { 6.16 final LexicalContext lc = visitor.getLexicalContext(); 6.17 lc.push(node); 6.18 final LexicalContextNode newNode = (LexicalContextNode)node.accept(lc, visitor);
7.1 --- a/src/jdk/nashorn/internal/objects/NativeArguments.java Tue Aug 13 18:34:12 2013 -0700 7.2 +++ b/src/jdk/nashorn/internal/objects/NativeArguments.java Mon Aug 19 19:37:29 2013 +0530 7.3 @@ -266,9 +266,8 @@ 7.4 final ScriptObject proto = global.getObjectPrototype(); 7.5 if (isStrict) { 7.6 return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap()); 7.7 - } else { 7.8 - return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); 7.9 } 7.10 + return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); 7.11 } 7.12 7.13 /**
8.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java Tue Aug 13 18:34:12 2013 -0700 8.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java Mon Aug 19 19:37:29 2013 +0530 8.3 @@ -638,9 +638,9 @@ 8.4 if (isScriptArray || obj instanceof Iterable || (obj != null && obj.getClass().isArray())) { 8.5 final Iterator<Object> iter = arrayLikeIterator(obj, true); 8.6 if (iter.hasNext()) { 8.7 - for(int i = 0; iter.hasNext(); ++i) { 8.8 + for (int i = 0; iter.hasNext(); ++i) { 8.9 final Object value = iter.next(); 8.10 - if(value == ScriptRuntime.UNDEFINED && isScriptObject && !((ScriptObject)obj).has(i)) { 8.11 + if (value == ScriptRuntime.UNDEFINED && isScriptObject && !((ScriptObject)obj).has(i)) { 8.12 // TODO: eventually rewrite arrayLikeIterator to use a three-state enum for handling 8.13 // UNDEFINED instead of an "includeUndefined" boolean with states SKIP, INCLUDE, 8.14 // RETURN_EMPTY. Until then, this is how we'll make sure that empty elements don't make it
9.1 --- a/src/jdk/nashorn/internal/parser/DateParser.java Tue Aug 13 18:34:12 2013 -0700 9.2 +++ b/src/jdk/nashorn/internal/parser/DateParser.java Mon Aug 19 19:37:29 2013 +0530 9.3 @@ -141,7 +141,7 @@ 9.4 * Try parsing the date string according to the rules laid out in ES5 15.9.1.15. 9.5 * The date string must conform to the following format: 9.6 * 9.7 - * <pre> [('-'|'+')yy]yyyy[-MM[-dd]][hh:mm[:ss[.sss]][Z|(+|-)hh:mm]] </pre> 9.8 + * <pre> [('-'|'+')yy]yyyy[-MM[-dd]][Thh:mm[:ss[.sss]][Z|(+|-)hh:mm]] </pre> 9.9 * 9.10 * <p>If the string does not contain a time zone offset, the <tt>TIMEZONE</tt> field 9.11 * is set to <tt>0</tt> (GMT).</p> 9.12 @@ -249,7 +249,7 @@ 9.13 9.14 switch (token) { 9.15 case NUMBER: 9.16 - if (skip(':')) { 9.17 + if (skipDelimiter(':')) { 9.18 // A number followed by ':' is parsed as time 9.19 if (!setTimeField(numValue)) { 9.20 return false; 9.21 @@ -260,14 +260,14 @@ 9.22 if (token != Token.NUMBER || !setTimeField(numValue)) { 9.23 return false; 9.24 } 9.25 - } while (skip(isSet(SECOND) ? '.' : ':')); 9.26 + } while (skipDelimiter(isSet(SECOND) ? '.' : ':')); 9.27 9.28 } else { 9.29 // Parse as date token 9.30 if (!setDateField(numValue)) { 9.31 return false; 9.32 } 9.33 - skip('-'); 9.34 + skipDelimiter('-'); 9.35 } 9.36 break; 9.37 9.38 @@ -297,7 +297,7 @@ 9.39 break; 9.40 } 9.41 if (nameValue.type != Name.TIMEZONE_ID) { 9.42 - skip('-'); 9.43 + skipDelimiter('-'); 9.44 } 9.45 break; 9.46 9.47 @@ -359,7 +359,18 @@ 9.48 return pos < length ? string.charAt(pos) : -1; 9.49 } 9.50 9.51 - private boolean skip(final char c) { 9.52 + // Skip delimiter if followed by a number. Used for ISO 8601 formatted dates 9.53 + private boolean skipNumberDelimiter(final char c) { 9.54 + if (pos < length - 1 && string.charAt(pos) == c 9.55 + && Character.getType(string.charAt(pos + 1)) == DECIMAL_DIGIT_NUMBER) { 9.56 + token = null; 9.57 + pos++; 9.58 + return true; 9.59 + } 9.60 + return false; 9.61 + } 9.62 + 9.63 + private boolean skipDelimiter(final char c) { 9.64 if (pos < length && string.charAt(pos) == c) { 9.65 token = null; 9.66 pos++; 9.67 @@ -452,14 +463,14 @@ 9.68 switch (currentField) { 9.69 case YEAR: 9.70 case MONTH: 9.71 - return skip('-') || peek() == 'T' || peek() == -1; 9.72 + return skipNumberDelimiter('-') || peek() == 'T' || peek() == -1; 9.73 case DAY: 9.74 return peek() == 'T' || peek() == -1; 9.75 case HOUR: 9.76 case MINUTE: 9.77 - return skip(':') || endOfTime(); 9.78 + return skipNumberDelimiter(':') || endOfTime(); 9.79 case SECOND: 9.80 - return skip('.') || endOfTime(); 9.81 + return skipNumberDelimiter('.') || endOfTime(); 9.82 default: 9.83 return true; 9.84 } 9.85 @@ -515,7 +526,7 @@ 9.86 private int readTimeZoneOffset() { 9.87 final int sign = string.charAt(pos - 1) == '+' ? 1 : -1; 9.88 int offset = readNumber(2); 9.89 - skip(':'); 9.90 + skipDelimiter(':'); 9.91 offset = offset * 60 + readNumber(2); 9.92 return sign * offset; 9.93 }
10.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Tue Aug 13 18:34:12 2013 -0700 10.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Mon Aug 19 19:37:29 2013 +0530 10.3 @@ -160,10 +160,10 @@ 10.4 if (this.scripting) { 10.5 this.lineInfoReceiver = new Lexer.LineInfoReceiver() { 10.6 @Override 10.7 - public void lineInfo(final int line, final int linePosition) { 10.8 + public void lineInfo(final int receiverLine, final int receiverLinePosition) { 10.9 // update the parser maintained line information 10.10 - Parser.this.line = line; 10.11 - Parser.this.linePosition = linePosition; 10.12 + Parser.this.line = receiverLine; 10.13 + Parser.this.linePosition = receiverLinePosition; 10.14 } 10.15 }; 10.16 } else {
11.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Tue Aug 13 18:34:12 2013 -0700 11.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Mon Aug 19 19:37:29 2013 +0530 11.3 @@ -48,6 +48,7 @@ 11.4 import java.security.PrivilegedAction; 11.5 import java.security.ProtectionDomain; 11.6 import java.util.Map; 11.7 + 11.8 import jdk.internal.org.objectweb.asm.ClassReader; 11.9 import jdk.internal.org.objectweb.asm.util.CheckClassAdapter; 11.10 import jdk.nashorn.api.scripting.ScriptObjectMirror; 11.11 @@ -888,6 +889,7 @@ 11.12 return script; 11.13 } 11.14 11.15 + @SuppressWarnings("static-method") 11.16 private ScriptLoader createNewLoader() { 11.17 return AccessController.doPrivileged( 11.18 new PrivilegedAction<ScriptLoader>() {
12.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Tue Aug 13 18:34:12 2013 -0700 12.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Mon Aug 19 19:37:29 2013 +0530 12.3 @@ -47,7 +47,7 @@ 12.4 * This is a subclass that represents a script function that may be regenerated, 12.5 * for example with specialization based on call site types, or lazily generated. 12.6 * The common denominator is that it can get new invokers during its lifespan, 12.7 - * unlike {@link FinalScriptFunctionData} 12.8 + * unlike {@code FinalScriptFunctionData} 12.9 */ 12.10 public final class RecompilableScriptFunctionData extends ScriptFunctionData { 12.11
13.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Tue Aug 13 18:34:12 2013 -0700 13.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Mon Aug 19 19:37:29 2013 +0530 13.3 @@ -553,19 +553,18 @@ 13.4 private static MethodHandle bindToNameIfNeeded(final MethodHandle methodHandle, final String bindName) { 13.5 if (bindName == null) { 13.6 return methodHandle; 13.7 - } else { 13.8 - // if it is vararg method, we need to extend argument array with 13.9 - // a new zeroth element that is set to bindName value. 13.10 - final MethodType methodType = methodHandle.type(); 13.11 - final int parameterCount = methodType.parameterCount(); 13.12 - final boolean isVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray(); 13.13 + } 13.14 13.15 - if (isVarArg) { 13.16 - return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName)); 13.17 - } else { 13.18 - return MH.insertArguments(methodHandle, 1, bindName); 13.19 - } 13.20 + // if it is vararg method, we need to extend argument array with 13.21 + // a new zeroth element that is set to bindName value. 13.22 + final MethodType methodType = methodHandle.type(); 13.23 + final int parameterCount = methodType.parameterCount(); 13.24 + final boolean isVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray(); 13.25 + 13.26 + if (isVarArg) { 13.27 + return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName)); 13.28 } 13.29 + return MH.insertArguments(methodHandle, 1, bindName); 13.30 } 13.31 13.32 /**
14.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Tue Aug 13 18:34:12 2013 -0700 14.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Mon Aug 19 19:37:29 2013 +0530 14.3 @@ -250,9 +250,18 @@ 14.4 final int length = args == null ? 0 : args.length; 14.5 14.6 CompiledFunctions boundList = new CompiledFunctions(); 14.7 - for (final CompiledFunction inv : code) { 14.8 + if (code.size() == 1) { 14.9 + // only one variant - bind that 14.10 + boundList.add(bind(code.first(), fn, self, allArgs)); 14.11 + } else { 14.12 + // There are specialized versions. Get the most generic one. 14.13 + // This is to avoid ambiguous overloaded versions of bound and 14.14 + // specialized variants and choosing wrong overload. 14.15 + final MethodHandle genInvoker = getGenericInvoker(); 14.16 + final CompiledFunction inv = new CompiledFunction(genInvoker.type(), genInvoker, getGenericConstructor()); 14.17 boundList.add(bind(inv, fn, self, allArgs)); 14.18 } 14.19 + 14.20 ScriptFunctionData boundData = new FinalScriptFunctionData(name, arity == -1 ? -1 : Math.max(0, arity - length), boundList, isStrict(), isBuiltin(), isConstructor()); 14.21 return boundData; 14.22 }
15.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Tue Aug 13 18:34:12 2013 -0700 15.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Aug 19 19:37:29 2013 +0530 15.3 @@ -2012,9 +2012,10 @@ 15.4 final boolean scopeAccess = isScope() && NashornCallSiteDescriptor.isScope(desc); 15.5 15.6 if (find != null) { 15.7 - final Object value = getObjectValue(find); 15.8 - ScriptFunction func = null; 15.9 - MethodHandle methodHandle = null; 15.10 + final Object value = getObjectValue(find); 15.11 + ScriptFunction func = null; 15.12 + MethodHandle methodHandle = null; 15.13 + 15.14 if (value instanceof ScriptFunction) { 15.15 func = (ScriptFunction)value; 15.16 methodHandle = getCallMethodHandle(func, desc.getMethodType(), name); 15.17 @@ -3219,6 +3220,11 @@ 15.18 return property; 15.19 } 15.20 15.21 + /** 15.22 + * Write a value to a spill slot 15.23 + * @param slot the slot index 15.24 + * @param value the value 15.25 + */ 15.26 protected final void setSpill(final int slot, final Object value) { 15.27 if (spill == null) { 15.28 // create new spill. 15.29 @@ -3233,6 +3239,11 @@ 15.30 spill[slot] = value; 15.31 } 15.32 15.33 + /** 15.34 + * Get a value from a spill slot 15.35 + * @param slot the slot index 15.36 + * @return the value in the spill slot with the given index 15.37 + */ 15.38 protected Object getSpill(final int slot) { 15.39 return spill != null && slot < spill.length ? spill[slot] : null; 15.40 }
16.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java Tue Aug 13 18:34:12 2013 -0700 16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 16.3 @@ -1,88 +0,0 @@ 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. Oracle designates this 16.11 - * particular file as subject to the "Classpath" exception as provided 16.12 - * by Oracle in the LICENSE file that accompanied this code. 16.13 - * 16.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 16.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.17 - * version 2 for more details (a copy is included in the LICENSE file that 16.18 - * accompanied this code). 16.19 - * 16.20 - * You should have received a copy of the GNU General Public License version 16.21 - * 2 along with this work; if not, write to the Free Software Foundation, 16.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.23 - * 16.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.25 - * or visit www.oracle.com if you need additional information or have any 16.26 - * questions. 16.27 - */ 16.28 - 16.29 -package jdk.nashorn.internal.runtime.arrays; 16.30 - 16.31 -import jdk.nashorn.internal.runtime.ScriptObject; 16.32 - 16.33 -/** 16.34 - * Iterator over a NativeArray 16.35 - */ 16.36 -class ArrayIterator extends ArrayLikeIterator<Object> { 16.37 - 16.38 - /** Array {@link ScriptObject} to iterate over */ 16.39 - protected final ScriptObject array; 16.40 - 16.41 - /** length of array */ 16.42 - protected final long length; 16.43 - 16.44 - /** 16.45 - * Constructor 16.46 - * @param array array to iterate over 16.47 - * @param includeUndefined should undefined elements be included in iteration 16.48 - */ 16.49 - protected ArrayIterator(final ScriptObject array, final boolean includeUndefined) { 16.50 - super(includeUndefined); 16.51 - this.array = array; 16.52 - this.length = array.getArray().length(); 16.53 - } 16.54 - 16.55 - /** 16.56 - * Is the current index still inside the array 16.57 - * @return true if inside the array 16.58 - */ 16.59 - protected boolean indexInArray() { 16.60 - return index < length; 16.61 - } 16.62 - 16.63 - @Override 16.64 - public Object next() { 16.65 - return array.get(bumpIndex()); 16.66 - } 16.67 - 16.68 - @Override 16.69 - public long getLength() { 16.70 - return length; 16.71 - } 16.72 - 16.73 - @Override 16.74 - public boolean hasNext() { 16.75 - if (!includeUndefined) { 16.76 - while (indexInArray()) { 16.77 - if (array.has(index)) { 16.78 - break; 16.79 - } 16.80 - bumpIndex(); 16.81 - } 16.82 - } 16.83 - 16.84 - return indexInArray(); 16.85 - } 16.86 - 16.87 - @Override 16.88 - public void remove() { 16.89 - array.delete(index, false); 16.90 - } 16.91 -}
17.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java Tue Aug 13 18:34:12 2013 -0700 17.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java Mon Aug 19 19:37:29 2013 +0530 17.3 @@ -26,6 +26,7 @@ 17.4 package jdk.nashorn.internal.runtime.arrays; 17.5 17.6 import java.util.Iterator; 17.7 +import java.util.List; 17.8 import jdk.nashorn.api.scripting.ScriptObjectMirror; 17.9 import jdk.nashorn.internal.runtime.JSType; 17.10 import jdk.nashorn.internal.runtime.ScriptObject; 17.11 @@ -49,7 +50,7 @@ 17.12 * 17.13 * @param includeUndefined should undefined elements be included in the iteration? 17.14 */ 17.15 - protected ArrayLikeIterator(final boolean includeUndefined) { 17.16 + ArrayLikeIterator(final boolean includeUndefined) { 17.17 this.includeUndefined = includeUndefined; 17.18 this.index = 0; 17.19 } 17.20 @@ -118,18 +119,26 @@ 17.21 Object obj = object; 17.22 17.23 if (ScriptObject.isArray(obj)) { 17.24 - return new ArrayIterator((ScriptObject) obj, includeUndefined); 17.25 + return new ScriptArrayIterator((ScriptObject) obj, includeUndefined); 17.26 } 17.27 17.28 obj = JSType.toScriptObject(obj); 17.29 if (obj instanceof ScriptObject) { 17.30 - return new MapIterator((ScriptObject)obj, includeUndefined); 17.31 + return new ScriptObjectIterator((ScriptObject)obj, includeUndefined); 17.32 } 17.33 17.34 if (obj instanceof ScriptObjectMirror) { 17.35 return new ScriptObjectMirrorIterator((ScriptObjectMirror)obj, includeUndefined); 17.36 } 17.37 17.38 + if (obj instanceof List) { 17.39 + return new JavaListIterator((List<?>)obj, includeUndefined); 17.40 + } 17.41 + 17.42 + if (obj != null && obj.getClass().isArray()) { 17.43 + return new JavaArrayIterator(obj, includeUndefined); 17.44 + } 17.45 + 17.46 return new EmptyArrayLikeIterator(); 17.47 } 17.48 17.49 @@ -143,19 +152,25 @@ 17.50 Object obj = object; 17.51 17.52 if (ScriptObject.isArray(obj)) { 17.53 - return new ReverseArrayIterator((ScriptObject) obj, includeUndefined); 17.54 + return new ReverseScriptArrayIterator((ScriptObject) obj, includeUndefined); 17.55 } 17.56 17.57 obj = JSType.toScriptObject(obj); 17.58 if (obj instanceof ScriptObject) { 17.59 - return new ReverseMapIterator((ScriptObject)obj, includeUndefined); 17.60 + return new ReverseScriptObjectIterator((ScriptObject)obj, includeUndefined); 17.61 } 17.62 17.63 if (obj instanceof ScriptObjectMirror) { 17.64 return new ReverseScriptObjectMirrorIterator((ScriptObjectMirror)obj, includeUndefined); 17.65 } 17.66 17.67 - assert !obj.getClass().isArray(); 17.68 + if (obj instanceof List) { 17.69 + return new ReverseJavaListIterator((List<?>)obj, includeUndefined); 17.70 + } 17.71 + 17.72 + if (obj != null && obj.getClass().isArray()) { 17.73 + return new ReverseJavaArrayIterator(obj, includeUndefined); 17.74 + } 17.75 17.76 return new EmptyArrayLikeIterator(); 17.77 }
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/JavaArrayIterator.java Mon Aug 19 19:37:29 2013 +0530 18.3 @@ -0,0 +1,80 @@ 18.4 +/* 18.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 + * 18.8 + * This code is free software; you can redistribute it and/or modify it 18.9 + * under the terms of the GNU General Public License version 2 only, as 18.10 + * published by the Free Software Foundation. Oracle designates this 18.11 + * particular file as subject to the "Classpath" exception as provided 18.12 + * by Oracle in the LICENSE file that accompanied this code. 18.13 + * 18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.17 + * version 2 for more details (a copy is included in the LICENSE file that 18.18 + * accompanied this code). 18.19 + * 18.20 + * You should have received a copy of the GNU General Public License version 18.21 + * 2 along with this work; if not, write to the Free Software Foundation, 18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.23 + * 18.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 18.25 + * or visit www.oracle.com if you need additional information or have any 18.26 + * questions. 18.27 + */ 18.28 + 18.29 +package jdk.nashorn.internal.runtime.arrays; 18.30 + 18.31 +import java.lang.reflect.Array; 18.32 + 18.33 +/** 18.34 + * Iterator over a Java List. 18.35 + */ 18.36 +class JavaArrayIterator extends ArrayLikeIterator<Object> { 18.37 + 18.38 + /** Array to iterate over */ 18.39 + protected final Object array; 18.40 + 18.41 + /** length of array */ 18.42 + protected final long length; 18.43 + 18.44 + /** 18.45 + * Constructor 18.46 + * @param array array to iterate over 18.47 + * @param includeUndefined should undefined elements be included in iteration 18.48 + */ 18.49 + protected JavaArrayIterator(final Object array, final boolean includeUndefined) { 18.50 + super(includeUndefined); 18.51 + assert array.getClass().isArray() : "expecting Java array object"; 18.52 + this.array = array; 18.53 + this.length = Array.getLength(array); 18.54 + } 18.55 + 18.56 + /** 18.57 + * Is the current index still inside the array 18.58 + * @return true if inside the array 18.59 + */ 18.60 + protected boolean indexInArray() { 18.61 + return index < length; 18.62 + } 18.63 + 18.64 + @Override 18.65 + public Object next() { 18.66 + return Array.get(array, (int)bumpIndex()); 18.67 + } 18.68 + 18.69 + @Override 18.70 + public long getLength() { 18.71 + return length; 18.72 + } 18.73 + 18.74 + @Override 18.75 + public boolean hasNext() { 18.76 + return indexInArray(); 18.77 + } 18.78 + 18.79 + @Override 18.80 + public void remove() { 18.81 + throw new UnsupportedOperationException("remove"); 18.82 + } 18.83 +} 18.84 \ No newline at end of file
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/JavaListIterator.java Mon Aug 19 19:37:29 2013 +0530 19.3 @@ -0,0 +1,79 @@ 19.4 +/* 19.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. Oracle designates this 19.11 + * particular file as subject to the "Classpath" exception as provided 19.12 + * by Oracle in the LICENSE file that accompanied this code. 19.13 + * 19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.17 + * version 2 for more details (a copy is included in the LICENSE file that 19.18 + * accompanied this code). 19.19 + * 19.20 + * You should have received a copy of the GNU General Public License version 19.21 + * 2 along with this work; if not, write to the Free Software Foundation, 19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.23 + * 19.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.25 + * or visit www.oracle.com if you need additional information or have any 19.26 + * questions. 19.27 + */ 19.28 + 19.29 +package jdk.nashorn.internal.runtime.arrays; 19.30 + 19.31 +import java.util.List; 19.32 + 19.33 +/** 19.34 + * Iterator over a Java List. 19.35 + */ 19.36 +class JavaListIterator extends ArrayLikeIterator<Object> { 19.37 + 19.38 + /** {@link java.util.List} to iterate over */ 19.39 + protected final List<?> list; 19.40 + 19.41 + /** length of array */ 19.42 + protected final long length; 19.43 + 19.44 + /** 19.45 + * Constructor 19.46 + * @param list list to iterate over 19.47 + * @param includeUndefined should undefined elements be included in iteration 19.48 + */ 19.49 + protected JavaListIterator(final List<?> list, final boolean includeUndefined) { 19.50 + super(includeUndefined); 19.51 + this.list = list; 19.52 + this.length = list.size(); 19.53 + } 19.54 + 19.55 + /** 19.56 + * Is the current index still inside the array 19.57 + * @return true if inside the array 19.58 + */ 19.59 + protected boolean indexInArray() { 19.60 + return index < length; 19.61 + } 19.62 + 19.63 + @Override 19.64 + public Object next() { 19.65 + return list.get((int)bumpIndex()); 19.66 + } 19.67 + 19.68 + @Override 19.69 + public long getLength() { 19.70 + return length; 19.71 + } 19.72 + 19.73 + @Override 19.74 + public boolean hasNext() { 19.75 + return indexInArray(); 19.76 + } 19.77 + 19.78 + @Override 19.79 + public void remove() { 19.80 + list.remove(index); 19.81 + } 19.82 +}
20.1 --- a/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Tue Aug 13 18:34:12 2013 -0700 20.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Mon Aug 19 19:37:29 2013 +0530 20.3 @@ -98,9 +98,8 @@ 20.4 final int length = (int) length(); 20.5 if (type == Double.class) { 20.6 return new NumberArrayData(LongArrayData.toDoubleArray(array, length), length); 20.7 - } else { 20.8 - return new ObjectArrayData(LongArrayData.toObjectArray(array, length), length); 20.9 } 20.10 + return new ObjectArrayData(LongArrayData.toObjectArray(array, length), length); 20.11 } 20.12 20.13 @Override
21.1 --- a/src/jdk/nashorn/internal/runtime/arrays/MapIterator.java Tue Aug 13 18:34:12 2013 -0700 21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 21.3 @@ -1,80 +0,0 @@ 21.4 -/* 21.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 21.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 - * 21.8 - * This code is free software; you can redistribute it and/or modify it 21.9 - * under the terms of the GNU General Public License version 2 only, as 21.10 - * published by the Free Software Foundation. Oracle designates this 21.11 - * particular file as subject to the "Classpath" exception as provided 21.12 - * by Oracle in the LICENSE file that accompanied this code. 21.13 - * 21.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 21.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.17 - * version 2 for more details (a copy is included in the LICENSE file that 21.18 - * accompanied this code). 21.19 - * 21.20 - * You should have received a copy of the GNU General Public License version 21.21 - * 2 along with this work; if not, write to the Free Software Foundation, 21.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.23 - * 21.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.25 - * or visit www.oracle.com if you need additional information or have any 21.26 - * questions. 21.27 - */ 21.28 - 21.29 -package jdk.nashorn.internal.runtime.arrays; 21.30 - 21.31 -import java.util.NoSuchElementException; 21.32 -import jdk.nashorn.internal.runtime.JSType; 21.33 -import jdk.nashorn.internal.runtime.ScriptObject; 21.34 - 21.35 -/** 21.36 - * Iterator over a map 21.37 - */ 21.38 -class MapIterator extends ArrayLikeIterator<Object> { 21.39 - 21.40 - protected final ScriptObject obj; 21.41 - private final long length; 21.42 - 21.43 - MapIterator(final ScriptObject obj, final boolean includeUndefined) { 21.44 - super(includeUndefined); 21.45 - this.obj = obj; 21.46 - this.length = JSType.toUint32(obj.getLength()); 21.47 - this.index = 0; 21.48 - } 21.49 - 21.50 - protected boolean indexInArray() { 21.51 - return index < length; 21.52 - } 21.53 - 21.54 - @Override 21.55 - public long getLength() { 21.56 - return length; 21.57 - } 21.58 - 21.59 - @Override 21.60 - public boolean hasNext() { 21.61 - if (length == 0L) { 21.62 - return false; //return empty string if toUint32(length) == 0 21.63 - } 21.64 - 21.65 - while (indexInArray()) { 21.66 - if (obj.has(index) || includeUndefined) { 21.67 - break; 21.68 - } 21.69 - bumpIndex(); 21.70 - } 21.71 - 21.72 - return indexInArray(); 21.73 - } 21.74 - 21.75 - @Override 21.76 - public Object next() { 21.77 - if (indexInArray()) { 21.78 - return obj.get(bumpIndex()); 21.79 - } 21.80 - 21.81 - throw new NoSuchElementException(); 21.82 - } 21.83 -}
22.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ReverseArrayIterator.java Tue Aug 13 18:34:12 2013 -0700 22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 22.3 @@ -1,59 +0,0 @@ 22.4 -/* 22.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 22.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 - * 22.8 - * This code is free software; you can redistribute it and/or modify it 22.9 - * under the terms of the GNU General Public License version 2 only, as 22.10 - * published by the Free Software Foundation. Oracle designates this 22.11 - * particular file as subject to the "Classpath" exception as provided 22.12 - * by Oracle in the LICENSE file that accompanied this code. 22.13 - * 22.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 22.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.17 - * version 2 for more details (a copy is included in the LICENSE file that 22.18 - * accompanied this code). 22.19 - * 22.20 - * You should have received a copy of the GNU General Public License version 22.21 - * 2 along with this work; if not, write to the Free Software Foundation, 22.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.23 - * 22.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.25 - * or visit www.oracle.com if you need additional information or have any 22.26 - * questions. 22.27 - */ 22.28 - 22.29 -package jdk.nashorn.internal.runtime.arrays; 22.30 - 22.31 -import jdk.nashorn.internal.runtime.ScriptObject; 22.32 - 22.33 -/** 22.34 - * Reverse iterator over a NativeArray 22.35 - */ 22.36 -final class ReverseArrayIterator extends ArrayIterator { 22.37 - 22.38 - /** 22.39 - * Constructor 22.40 - * @param array array to iterate over 22.41 - * @param includeUndefined should undefined elements be included in iteration 22.42 - */ 22.43 - public ReverseArrayIterator(final ScriptObject array, final boolean includeUndefined) { 22.44 - super(array, includeUndefined); 22.45 - this.index = array.getArray().length() - 1; 22.46 - } 22.47 - 22.48 - @Override 22.49 - public boolean isReverse() { 22.50 - return true; 22.51 - } 22.52 - 22.53 - @Override 22.54 - protected boolean indexInArray() { 22.55 - return index >= 0; 22.56 - } 22.57 - 22.58 - @Override 22.59 - protected long bumpIndex() { 22.60 - return index--; 22.61 - } 22.62 -}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseJavaArrayIterator.java Mon Aug 19 19:37:29 2013 +0530 23.3 @@ -0,0 +1,58 @@ 23.4 +/* 23.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 + * 23.8 + * This code is free software; you can redistribute it and/or modify it 23.9 + * under the terms of the GNU General Public License version 2 only, as 23.10 + * published by the Free Software Foundation. Oracle designates this 23.11 + * particular file as subject to the "Classpath" exception as provided 23.12 + * by Oracle in the LICENSE file that accompanied this code. 23.13 + * 23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.17 + * version 2 for more details (a copy is included in the LICENSE file that 23.18 + * accompanied this code). 23.19 + * 23.20 + * You should have received a copy of the GNU General Public License version 23.21 + * 2 along with this work; if not, write to the Free Software Foundation, 23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.23 + * 23.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23.25 + * or visit www.oracle.com if you need additional information or have any 23.26 + * questions. 23.27 + */ 23.28 + 23.29 +package jdk.nashorn.internal.runtime.arrays; 23.30 + 23.31 +import java.lang.reflect.Array; 23.32 + 23.33 +/** 23.34 + * Reverse iterator over a array 23.35 + */ 23.36 +final class ReverseJavaArrayIterator extends JavaArrayIterator { 23.37 + /** 23.38 + * Constructor 23.39 + * @param array array to iterate over 23.40 + * @param includeUndefined should undefined elements be included in iteration 23.41 + */ 23.42 + public ReverseJavaArrayIterator(final Object array, final boolean includeUndefined) { 23.43 + super(array, includeUndefined); 23.44 + this.index = Array.getLength(array) - 1; 23.45 + } 23.46 + 23.47 + @Override 23.48 + public boolean isReverse() { 23.49 + return true; 23.50 + } 23.51 + 23.52 + @Override 23.53 + protected boolean indexInArray() { 23.54 + return index >= 0; 23.55 + } 23.56 + 23.57 + @Override 23.58 + protected long bumpIndex() { 23.59 + return index--; 23.60 + } 23.61 +} 23.62 \ No newline at end of file
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseJavaListIterator.java Mon Aug 19 19:37:29 2013 +0530 24.3 @@ -0,0 +1,58 @@ 24.4 +/* 24.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.7 + * 24.8 + * This code is free software; you can redistribute it and/or modify it 24.9 + * under the terms of the GNU General Public License version 2 only, as 24.10 + * published by the Free Software Foundation. Oracle designates this 24.11 + * particular file as subject to the "Classpath" exception as provided 24.12 + * by Oracle in the LICENSE file that accompanied this code. 24.13 + * 24.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 24.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24.17 + * version 2 for more details (a copy is included in the LICENSE file that 24.18 + * accompanied this code). 24.19 + * 24.20 + * You should have received a copy of the GNU General Public License version 24.21 + * 2 along with this work; if not, write to the Free Software Foundation, 24.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24.23 + * 24.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24.25 + * or visit www.oracle.com if you need additional information or have any 24.26 + * questions. 24.27 + */ 24.28 + 24.29 +package jdk.nashorn.internal.runtime.arrays; 24.30 + 24.31 +import java.util.List; 24.32 + 24.33 +/** 24.34 + * Reverse iterator over a List 24.35 + */ 24.36 +final class ReverseJavaListIterator extends JavaListIterator { 24.37 + /** 24.38 + * Constructor 24.39 + * @param list list to iterate over 24.40 + * @param includeUndefined should undefined elements be included in iteration 24.41 + */ 24.42 + public ReverseJavaListIterator(final List<?> list, final boolean includeUndefined) { 24.43 + super(list, includeUndefined); 24.44 + this.index = list.size() - 1; 24.45 + } 24.46 + 24.47 + @Override 24.48 + public boolean isReverse() { 24.49 + return true; 24.50 + } 24.51 + 24.52 + @Override 24.53 + protected boolean indexInArray() { 24.54 + return index >= 0; 24.55 + } 24.56 + 24.57 + @Override 24.58 + protected long bumpIndex() { 24.59 + return index--; 24.60 + } 24.61 +}
25.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ReverseMapIterator.java Tue Aug 13 18:34:12 2013 -0700 25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 25.3 @@ -1,55 +0,0 @@ 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.arrays; 25.30 - 25.31 -import jdk.nashorn.internal.runtime.JSType; 25.32 -import jdk.nashorn.internal.runtime.ScriptObject; 25.33 - 25.34 -/** 25.35 - * Reverse iterator over a map 25.36 - */ 25.37 -final class ReverseMapIterator extends MapIterator { 25.38 - 25.39 - ReverseMapIterator(final ScriptObject obj, final boolean includeUndefined) { 25.40 - super(obj, includeUndefined); 25.41 - this.index = JSType.toUint32(obj.getLength()) - 1; 25.42 - } 25.43 - 25.44 - @Override 25.45 - public boolean isReverse() { 25.46 - return true; 25.47 - } 25.48 - 25.49 - @Override 25.50 - protected boolean indexInArray() { 25.51 - return index >= 0; 25.52 - } 25.53 - 25.54 - @Override 25.55 - protected long bumpIndex() { 25.56 - return index--; 25.57 - } 25.58 -}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseScriptArrayIterator.java Mon Aug 19 19:37:29 2013 +0530 26.3 @@ -0,0 +1,59 @@ 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.arrays; 26.30 + 26.31 +import jdk.nashorn.internal.runtime.ScriptObject; 26.32 + 26.33 +/** 26.34 + * Reverse iterator over a NativeArray 26.35 + */ 26.36 +final class ReverseScriptArrayIterator extends ScriptArrayIterator { 26.37 + 26.38 + /** 26.39 + * Constructor 26.40 + * @param array array to iterate over 26.41 + * @param includeUndefined should undefined elements be included in iteration 26.42 + */ 26.43 + public ReverseScriptArrayIterator(final ScriptObject array, final boolean includeUndefined) { 26.44 + super(array, includeUndefined); 26.45 + this.index = array.getArray().length() - 1; 26.46 + } 26.47 + 26.48 + @Override 26.49 + public boolean isReverse() { 26.50 + return true; 26.51 + } 26.52 + 26.53 + @Override 26.54 + protected boolean indexInArray() { 26.55 + return index >= 0; 26.56 + } 26.57 + 26.58 + @Override 26.59 + protected long bumpIndex() { 26.60 + return index--; 26.61 + } 26.62 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseScriptObjectIterator.java Mon Aug 19 19:37:29 2013 +0530 27.3 @@ -0,0 +1,55 @@ 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.arrays; 27.30 + 27.31 +import jdk.nashorn.internal.runtime.JSType; 27.32 +import jdk.nashorn.internal.runtime.ScriptObject; 27.33 + 27.34 +/** 27.35 + * Reverse iterator over a map 27.36 + */ 27.37 +final class ReverseScriptObjectIterator extends ScriptObjectIterator { 27.38 + 27.39 + ReverseScriptObjectIterator(final ScriptObject obj, final boolean includeUndefined) { 27.40 + super(obj, includeUndefined); 27.41 + this.index = JSType.toUint32(obj.getLength()) - 1; 27.42 + } 27.43 + 27.44 + @Override 27.45 + public boolean isReverse() { 27.46 + return true; 27.47 + } 27.48 + 27.49 + @Override 27.50 + protected boolean indexInArray() { 27.51 + return index >= 0; 27.52 + } 27.53 + 27.54 + @Override 27.55 + protected long bumpIndex() { 27.56 + return index--; 27.57 + } 27.58 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ScriptArrayIterator.java Mon Aug 19 19:37:29 2013 +0530 28.3 @@ -0,0 +1,88 @@ 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.arrays; 28.30 + 28.31 +import jdk.nashorn.internal.runtime.ScriptObject; 28.32 + 28.33 +/** 28.34 + * Iterator over a NativeArray 28.35 + */ 28.36 +class ScriptArrayIterator extends ArrayLikeIterator<Object> { 28.37 + 28.38 + /** Array {@link ScriptObject} to iterate over */ 28.39 + protected final ScriptObject array; 28.40 + 28.41 + /** length of array */ 28.42 + protected final long length; 28.43 + 28.44 + /** 28.45 + * Constructor 28.46 + * @param array array to iterate over 28.47 + * @param includeUndefined should undefined elements be included in iteration 28.48 + */ 28.49 + protected ScriptArrayIterator(final ScriptObject array, final boolean includeUndefined) { 28.50 + super(includeUndefined); 28.51 + this.array = array; 28.52 + this.length = array.getArray().length(); 28.53 + } 28.54 + 28.55 + /** 28.56 + * Is the current index still inside the array 28.57 + * @return true if inside the array 28.58 + */ 28.59 + protected boolean indexInArray() { 28.60 + return index < length; 28.61 + } 28.62 + 28.63 + @Override 28.64 + public Object next() { 28.65 + return array.get(bumpIndex()); 28.66 + } 28.67 + 28.68 + @Override 28.69 + public long getLength() { 28.70 + return length; 28.71 + } 28.72 + 28.73 + @Override 28.74 + public boolean hasNext() { 28.75 + if (!includeUndefined) { 28.76 + while (indexInArray()) { 28.77 + if (array.has(index)) { 28.78 + break; 28.79 + } 28.80 + bumpIndex(); 28.81 + } 28.82 + } 28.83 + 28.84 + return indexInArray(); 28.85 + } 28.86 + 28.87 + @Override 28.88 + public void remove() { 28.89 + array.delete(index, false); 28.90 + } 28.91 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ScriptObjectIterator.java Mon Aug 19 19:37:29 2013 +0530 29.3 @@ -0,0 +1,80 @@ 29.4 +/* 29.5 + * Copyright (c) 2010, 2013, 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. Oracle designates this 29.11 + * particular file as subject to the "Classpath" exception as provided 29.12 + * by Oracle in the LICENSE file that accompanied this code. 29.13 + * 29.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.17 + * version 2 for more details (a copy is included in the LICENSE file that 29.18 + * accompanied this code). 29.19 + * 29.20 + * You should have received a copy of the GNU General Public License version 29.21 + * 2 along with this work; if not, write to the Free Software Foundation, 29.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.23 + * 29.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 29.25 + * or visit www.oracle.com if you need additional information or have any 29.26 + * questions. 29.27 + */ 29.28 + 29.29 +package jdk.nashorn.internal.runtime.arrays; 29.30 + 29.31 +import java.util.NoSuchElementException; 29.32 +import jdk.nashorn.internal.runtime.JSType; 29.33 +import jdk.nashorn.internal.runtime.ScriptObject; 29.34 + 29.35 +/** 29.36 + * Iterator over a map 29.37 + */ 29.38 +class ScriptObjectIterator extends ArrayLikeIterator<Object> { 29.39 + 29.40 + protected final ScriptObject obj; 29.41 + private final long length; 29.42 + 29.43 + ScriptObjectIterator(final ScriptObject obj, final boolean includeUndefined) { 29.44 + super(includeUndefined); 29.45 + this.obj = obj; 29.46 + this.length = JSType.toUint32(obj.getLength()); 29.47 + this.index = 0; 29.48 + } 29.49 + 29.50 + protected boolean indexInArray() { 29.51 + return index < length; 29.52 + } 29.53 + 29.54 + @Override 29.55 + public long getLength() { 29.56 + return length; 29.57 + } 29.58 + 29.59 + @Override 29.60 + public boolean hasNext() { 29.61 + if (length == 0L) { 29.62 + return false; //return empty string if toUint32(length) == 0 29.63 + } 29.64 + 29.65 + while (indexInArray()) { 29.66 + if (obj.has(index) || includeUndefined) { 29.67 + break; 29.68 + } 29.69 + bumpIndex(); 29.70 + } 29.71 + 29.72 + return indexInArray(); 29.73 + } 29.74 + 29.75 + @Override 29.76 + public Object next() { 29.77 + if (indexInArray()) { 29.78 + return obj.get(bumpIndex()); 29.79 + } 29.80 + 29.81 + throw new NoSuchElementException(); 29.82 + } 29.83 +}
30.1 --- a/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Tue Aug 13 18:34:12 2013 -0700 30.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Mon Aug 19 19:37:29 2013 +0530 30.3 @@ -60,7 +60,7 @@ 30.4 30.5 @Override 30.6 public ArrayData copy() { 30.7 - return new SparseArrayData(underlying.copy(), length(), new TreeMap<Long, Object>(sparseMap)); 30.8 + return new SparseArrayData(underlying.copy(), length(), new TreeMap<>(sparseMap)); 30.9 } 30.10 30.11 @Override
31.1 --- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethod.java Tue Aug 13 18:34:12 2013 -0700 31.2 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethod.java Mon Aug 19 19:37:29 2013 +0530 31.3 @@ -29,7 +29,7 @@ 31.4 31.5 /** 31.6 * Represents a Dynalink dynamic method bound to a receiver. Note that objects of this class are just the tuples of 31.7 - * a method and a bound this, without any behavior. All the behavior is defined in the {@link BoundDynamicMethodLinker}. 31.8 + * a method and a bound this, without any behavior. All the behavior is defined in the {@code BoundDynamicMethodLinker}. 31.9 */ 31.10 final class BoundDynamicMethod { 31.11 private final Object dynamicMethod;
32.1 --- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java Tue Aug 13 18:34:12 2013 -0700 32.2 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java Mon Aug 19 19:37:29 2013 +0530 32.3 @@ -37,7 +37,7 @@ 32.4 import jdk.internal.dynalink.support.Guards; 32.5 32.6 /** 32.7 - * Links {@link BoundDynamicMethod} objects. Passes through to Dynalink's BeansLinker for linking a dynamic method 32.8 + * Links {@code BoundDynamicMethod} objects. Passes through to Dynalink's BeansLinker for linking a dynamic method 32.9 * (they only respond to "dyn:call"), and modifies the returned invocation to deal with the receiver binding. 32.10 */ 32.11 final class BoundDynamicMethodLinker implements TypeBasedGuardingDynamicLinker {
33.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Tue Aug 13 18:34:12 2013 -0700 33.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Mon Aug 19 19:37:29 2013 +0530 33.3 @@ -114,9 +114,8 @@ 33.4 if(name.equals(className)) { 33.5 assert classBytes != null : "what? already cleared .class bytes!!"; 33.6 return defineClass(name, classBytes, 0, classBytes.length, GENERATED_PROTECTION_DOMAIN); 33.7 - } else { 33.8 - throw new ClassNotFoundException(name); 33.9 } 33.10 + throw new ClassNotFoundException(name); 33.11 } 33.12 }; 33.13 }
34.1 --- a/src/jdk/nashorn/internal/runtime/options/Options.java Tue Aug 13 18:34:12 2013 -0700 34.2 +++ b/src/jdk/nashorn/internal/runtime/options/Options.java Mon Aug 19 19:37:29 2013 +0530 34.3 @@ -408,13 +408,13 @@ 34.4 final LinkedList<String> argList = new LinkedList<>(); 34.5 Collections.addAll(argList, args); 34.6 34.7 - final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null); 34.8 - if (extra != null) { 34.9 - final StringTokenizer st = new StringTokenizer(extra); 34.10 - while (st.hasMoreTokens()) { 34.11 - argList.add(st.nextToken()); 34.12 + final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null); 34.13 + if (extra != null) { 34.14 + final StringTokenizer st = new StringTokenizer(extra); 34.15 + while (st.hasMoreTokens()) { 34.16 + argList.add(st.nextToken()); 34.17 + } 34.18 } 34.19 - } 34.20 34.21 while (!argList.isEmpty()) { 34.22 final String arg = argList.remove(0); 34.23 @@ -431,8 +431,9 @@ 34.24 continue; 34.25 } 34.26 34.27 - // if it doesn't start with -, it's a file 34.28 - if (!arg.startsWith("-")) { 34.29 + // If it doesn't start with -, it's a file. But, if it is just "-", 34.30 + // then it is a file representing standard input. 34.31 + if (!arg.startsWith("-") || arg.length() == 1) { 34.32 files.add(arg); 34.33 continue; 34.34 }
35.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Tue Aug 13 18:34:12 2013 -0700 35.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Mon Aug 19 19:37:29 2013 +0530 35.3 @@ -100,7 +100,7 @@ 35.4 type.error.inconsistent.property.descriptor=inconsistent property descriptor 35.5 type.error.bad.default.value=bad default value: {0} 35.6 type.error.function.apply.expects.array=Function.prototype.apply expects an Array for second argument 35.7 -type.error.instanceof.on.non.object=instanceof cannot be used on objects without [[HasInstance]] 35.8 +type.error.instanceof.on.non.object=instanceof must be called with a javascript or java object as the right-hand argument 35.9 type.error.cannot.convert.to.interface=object {0} cannot be converted to {1} due to "{2}" 35.10 type.error.array.reduce.invalid.init=invalid initialValue for Array.prototype.reduce 35.11 type.error.array.reduceright.invalid.init=invalid initialValue for Array.prototype.reduceRight
36.1 --- a/src/jdk/nashorn/tools/Shell.java Tue Aug 13 18:34:12 2013 -0700 36.2 +++ b/src/jdk/nashorn/tools/Shell.java Mon Aug 19 19:37:29 2013 +0530 36.3 @@ -292,6 +292,14 @@ 36.4 36.5 // For each file on the command line. 36.6 for (final String fileName : files) { 36.7 + if ("-".equals(fileName)) { 36.8 + final int res = readEvalPrint(context, global); 36.9 + if (res != SUCCESS) { 36.10 + return res; 36.11 + } 36.12 + continue; 36.13 + } 36.14 + 36.15 final File file = new File(fileName); 36.16 final ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global); 36.17 if (script == null || errors.getNumberOfErrors() != 0) {
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/test/script/basic/JDK-8019985.js Mon Aug 19 19:37:29 2013 +0530 37.3 @@ -0,0 +1,50 @@ 37.4 +/* 37.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.7 + * 37.8 + * This code is free software; you can redistribute it and/or modify it 37.9 + * under the terms of the GNU General Public License version 2 only, as 37.10 + * published by the Free Software Foundation. 37.11 + * 37.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 37.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 37.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 37.15 + * version 2 for more details (a copy is included in the LICENSE file that 37.16 + * accompanied this code). 37.17 + * 37.18 + * You should have received a copy of the GNU General Public License version 37.19 + * 2 along with this work; if not, write to the Free Software Foundation, 37.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 37.21 + * 37.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 37.23 + * or visit www.oracle.com if you need additional information or have any 37.24 + * questions. 37.25 + */ 37.26 + 37.27 +/** 37.28 + * JDK-8019985: Date.parse("2000-01-01T00:00:00.Z") should return NaN 37.29 + * 37.30 + * @test 37.31 + * @run 37.32 + */ 37.33 + 37.34 +function testFail(str) { 37.35 + if (!isNaN(Date.parse(str))) { 37.36 + throw new Error("Parsed invalid date string: " + str); 37.37 + } 37.38 +} 37.39 + 37.40 +function testOk(str) { 37.41 + if (isNaN(Date.parse(str))) { 37.42 + throw new Error("Failed to parse valid date string: " + str); 37.43 + } 37.44 +} 37.45 + 37.46 +testFail("2000-01-01T00:00:00.Z"); 37.47 +testFail("2000-01-01T00:00:Z"); 37.48 +testFail("2000-01-01T00:Z"); 37.49 +testFail("2000-01-01T00Z"); 37.50 +testOk("2000-01-01T00:00:00.000Z"); 37.51 +testOk("2000-01-01T00:00:00.0Z"); 37.52 +testOk("2000-01-01T00:00:00Z"); 37.53 +testOk("2000-01-01T00:00Z");
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/script/basic/JDK-8020355.js Mon Aug 19 19:37:29 2013 +0530 38.3 @@ -0,0 +1,63 @@ 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 + * JDK-8020355: bind on built-in constructors don't use bound argument values 38.29 + * 38.30 + * @test 38.31 + * @run 38.32 + */ 38.33 + 38.34 +if (Array.bind(null, 2)().length != 2) { 38.35 + fail("Expected Array.bind(null, 2)().length to be 2"); 38.36 +} 38.37 + 38.38 +if (RegExp.bind(null, "a")().source.length != 1) { 38.39 + fail("Expected RegExp.bind(null, 'a')().source.length to be 1"); 38.40 +} 38.41 + 38.42 +// check user defined functions as well 38.43 + 38.44 +var res = (function(x, y) { return x*y }).bind(null, 20, 30)(); 38.45 +if (res != 600) { 38.46 + fail("Expected 600, but got " + res); 38.47 +} 38.48 + 38.49 +var obj = new ((function(x, y) { this.foo = x*y }).bind({}, 20, 30))(); 38.50 +if (obj.foo != 600) { 38.51 + fail("Expected this.foo = 600, but got " + res); 38.52 +} 38.53 + 38.54 +// try variadic function as well 38.55 + 38.56 +var res = (function() { return arguments[0]*arguments[1] }).bind(null, 20, 30)(); 38.57 +if (res != 600) { 38.58 + fail("Expected 600, but got " + res); 38.59 +} 38.60 + 38.61 +var obj = new ((function(x, y) { this.foo = arguments[0]*arguments[1] }).bind({}, 20, 30))(); 38.62 +if (obj.foo != 600) { 38.63 + fail("Expected this.foo = 600, but got " + res); 38.64 +} 38.65 + 38.66 +
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/script/basic/JDK-8023026.js Mon Aug 19 19:37:29 2013 +0530 39.3 @@ -0,0 +1,71 @@ 39.4 +/* 39.5 + * Copyright (c) 2010, 2013, 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. 39.11 + * 39.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.15 + * version 2 for more details (a copy is included in the LICENSE file that 39.16 + * accompanied this code). 39.17 + * 39.18 + * You should have received a copy of the GNU General Public License version 39.19 + * 2 along with this work; if not, write to the Free Software Foundation, 39.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.21 + * 39.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 39.23 + * or visit www.oracle.com if you need additional information or have any 39.24 + * questions. 39.25 + */ 39.26 + 39.27 +/** 39.28 + * JDK-8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists 39.29 + * 39.30 + * @test 39.31 + * @run 39.32 + */ 39.33 + 39.34 +function checkIterations(obj) { 39.35 + if (typeof obj.getClass == 'function') { 39.36 + print("iterating on an object of " + obj.getClass()); 39.37 + } else { 39.38 + print("iterating on " + String(obj)); 39.39 + } 39.40 + 39.41 + Array.prototype.forEach.call(obj, 39.42 + function(x) { print("forEach " + x); }); 39.43 + 39.44 + print("left sum " + Array.prototype.reduce.call(obj, 39.45 + function(x, y) { print("reduce", x, y); return x + y; })); 39.46 + 39.47 + print("right sum " + Array.prototype.reduceRight.call(obj, 39.48 + function(x, y) { print("reduceRight", x, y); return x + y; })); 39.49 + 39.50 + print("squared " + Array.prototype.map.call(obj, 39.51 + function(x) x*x)); 39.52 +} 39.53 + 39.54 +var array = new (Java.type("[I"))(4); 39.55 +for (var i in array) { 39.56 + array[i] = i; 39.57 +} 39.58 + 39.59 +checkIterations(array); 39.60 + 39.61 +var list = new java.util.ArrayList(); 39.62 +list.add(1); 39.63 +list.add(3); 39.64 +list.add(5); 39.65 +list.add(7); 39.66 + 39.67 +checkIterations(list); 39.68 + 39.69 +var mirror = loadWithNewGlobal({ 39.70 + name: "test", 39.71 + script: "[2, 4, 6, 8]" 39.72 +}); 39.73 + 39.74 +checkIterations(mirror);
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/script/basic/JDK-8023026.js.EXPECTED Mon Aug 19 19:37:29 2013 +0530 40.3 @@ -0,0 +1,42 @@ 40.4 +iterating on an object of class [I 40.5 +forEach 0 40.6 +forEach 1 40.7 +forEach 2 40.8 +forEach 3 40.9 +reduce 0 1 40.10 +reduce 1 2 40.11 +reduce 3 3 40.12 +left sum 6 40.13 +reduceRight 3 2 40.14 +reduceRight 5 1 40.15 +reduceRight 6 0 40.16 +right sum 6 40.17 +squared 0,1,4,9 40.18 +iterating on an object of class java.util.ArrayList 40.19 +forEach 1 40.20 +forEach 3 40.21 +forEach 5 40.22 +forEach 7 40.23 +reduce 1 3 40.24 +reduce 4 5 40.25 +reduce 9 7 40.26 +left sum 16 40.27 +reduceRight 7 5 40.28 +reduceRight 12 3 40.29 +reduceRight 15 1 40.30 +right sum 16 40.31 +squared 1,9,25,49 40.32 +iterating on [object Array] 40.33 +forEach 2 40.34 +forEach 4 40.35 +forEach 6 40.36 +forEach 8 40.37 +reduce 2 4 40.38 +reduce 6 6 40.39 +reduce 12 8 40.40 +left sum 20 40.41 +reduceRight 8 6 40.42 +reduceRight 14 4 40.43 +reduceRight 18 2 40.44 +right sum 20 40.45 +squared 4,16,36,64