Mercurial > people > rkennke > jdk9-shenandoah-final > nashorn
changeset 506:e628aefac504
Merge
author | sundar |
---|---|
date | Mon, 19 Aug 2013 19:37:29 +0530 |
parents | 8ecf68b292d0 (current diff) bd0174b1a42f (diff) |
children | 1f2394beecf7 2ce55025a37d |
files | src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java src/jdk/nashorn/internal/runtime/arrays/MapIterator.java src/jdk/nashorn/internal/runtime/arrays/ReverseArrayIterator.java src/jdk/nashorn/internal/runtime/arrays/ReverseMapIterator.java |
diffstat | 40 files changed, 916 insertions(+), 344 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java Mon Aug 19 19:37:29 2013 +0530 @@ -317,7 +317,8 @@ final String className = getClassName(fieldCount); final String superName = className(ScriptObject.class); final ClassEmitter classEmitter = newClassEmitter(className, superName); - final List<String> initFields = addFields(classEmitter, fieldCount); + + addFields(classEmitter, fieldCount); final MethodEmitter init = newInitMethod(classEmitter); init.returnVoid();
--- a/src/jdk/nashorn/internal/codegen/ObjectCreator.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/codegen/ObjectCreator.java Mon Aug 19 19:37:29 2013 +0530 @@ -45,9 +45,11 @@ /** Code generator */ protected final CodeGenerator codegen; - private final boolean isScope; - private final boolean hasArguments; - protected PropertyMap propertyMap; + /** Property map */ + protected PropertyMap propertyMap; + + private final boolean isScope; + private final boolean hasArguments; /** * Constructor
--- a/src/jdk/nashorn/internal/ir/BinaryNode.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/ir/BinaryNode.java Mon Aug 19 19:37:29 2013 +0530 @@ -99,6 +99,7 @@ case DIV: case MOD: case MUL: + case SUB: case ASSIGN_DIV: case ASSIGN_MOD: case ASSIGN_MUL:
--- a/src/jdk/nashorn/internal/ir/BreakableNode.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/ir/BreakableNode.java Mon Aug 19 19:37:29 2013 +0530 @@ -33,6 +33,14 @@ * a {@code break} statement */ public interface BreakableNode extends LexicalContextNode { + /** + * Ensure that any labels in this breakable node are unique so + * that new jumps won't go to old parts of the tree. Used for + * example for cloning finally blocks + * + * @param lc the lexical context + * @return node after labels have been made unique + */ public abstract Node ensureUniqueLabels(final LexicalContext lc); /**
--- a/src/jdk/nashorn/internal/ir/IdentNode.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/ir/IdentNode.java Mon Aug 19 19:37:29 2013 +0530 @@ -161,13 +161,13 @@ * converting to object, for example if the symbol is used as the left hand side of an * assignment such as in the code below.</p> * - * <pre>{@code + * <pre> * try { * return 2; * } finally { * return 3; * } - * }</pre> + * } * * @return true if can have callsite type */
--- a/src/jdk/nashorn/internal/ir/LexicalContextNode.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/ir/LexicalContextNode.java Mon Aug 19 19:37:29 2013 +0530 @@ -44,8 +44,14 @@ Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor); // Would be a default method on Java 8 + /** + * Helper class for accept for items of this lexical context, delegates to the + * subclass accept and makes sure that the node is on the context before accepting + * and gets popped after accepting (and that the stack is consistent in that the + * node has been replaced with the possible new node resulting in visitation) + */ static class Acceptor { - static Node accept(LexicalContextNode node, final NodeVisitor<? extends LexicalContext> visitor) { + static Node accept(final LexicalContextNode node, final NodeVisitor<? extends LexicalContext> visitor) { final LexicalContext lc = visitor.getLexicalContext(); lc.push(node); final LexicalContextNode newNode = (LexicalContextNode)node.accept(lc, visitor);
--- a/src/jdk/nashorn/internal/objects/NativeArguments.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/objects/NativeArguments.java Mon Aug 19 19:37:29 2013 +0530 @@ -266,9 +266,8 @@ final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap()); - } else { - return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); } + return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); } /**
--- a/src/jdk/nashorn/internal/objects/NativeArray.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java Mon Aug 19 19:37:29 2013 +0530 @@ -638,9 +638,9 @@ if (isScriptArray || obj instanceof Iterable || (obj != null && obj.getClass().isArray())) { final Iterator<Object> iter = arrayLikeIterator(obj, true); if (iter.hasNext()) { - for(int i = 0; iter.hasNext(); ++i) { + for (int i = 0; iter.hasNext(); ++i) { final Object value = iter.next(); - if(value == ScriptRuntime.UNDEFINED && isScriptObject && !((ScriptObject)obj).has(i)) { + if (value == ScriptRuntime.UNDEFINED && isScriptObject && !((ScriptObject)obj).has(i)) { // TODO: eventually rewrite arrayLikeIterator to use a three-state enum for handling // UNDEFINED instead of an "includeUndefined" boolean with states SKIP, INCLUDE, // RETURN_EMPTY. Until then, this is how we'll make sure that empty elements don't make it
--- a/src/jdk/nashorn/internal/parser/DateParser.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/parser/DateParser.java Mon Aug 19 19:37:29 2013 +0530 @@ -141,7 +141,7 @@ * Try parsing the date string according to the rules laid out in ES5 15.9.1.15. * The date string must conform to the following format: * - * <pre> [('-'|'+')yy]yyyy[-MM[-dd]][hh:mm[:ss[.sss]][Z|(+|-)hh:mm]] </pre> + * <pre> [('-'|'+')yy]yyyy[-MM[-dd]][Thh:mm[:ss[.sss]][Z|(+|-)hh:mm]] </pre> * * <p>If the string does not contain a time zone offset, the <tt>TIMEZONE</tt> field * is set to <tt>0</tt> (GMT).</p> @@ -249,7 +249,7 @@ switch (token) { case NUMBER: - if (skip(':')) { + if (skipDelimiter(':')) { // A number followed by ':' is parsed as time if (!setTimeField(numValue)) { return false; @@ -260,14 +260,14 @@ if (token != Token.NUMBER || !setTimeField(numValue)) { return false; } - } while (skip(isSet(SECOND) ? '.' : ':')); + } while (skipDelimiter(isSet(SECOND) ? '.' : ':')); } else { // Parse as date token if (!setDateField(numValue)) { return false; } - skip('-'); + skipDelimiter('-'); } break; @@ -297,7 +297,7 @@ break; } if (nameValue.type != Name.TIMEZONE_ID) { - skip('-'); + skipDelimiter('-'); } break; @@ -359,7 +359,18 @@ return pos < length ? string.charAt(pos) : -1; } - private boolean skip(final char c) { + // Skip delimiter if followed by a number. Used for ISO 8601 formatted dates + private boolean skipNumberDelimiter(final char c) { + if (pos < length - 1 && string.charAt(pos) == c + && Character.getType(string.charAt(pos + 1)) == DECIMAL_DIGIT_NUMBER) { + token = null; + pos++; + return true; + } + return false; + } + + private boolean skipDelimiter(final char c) { if (pos < length && string.charAt(pos) == c) { token = null; pos++; @@ -452,14 +463,14 @@ switch (currentField) { case YEAR: case MONTH: - return skip('-') || peek() == 'T' || peek() == -1; + return skipNumberDelimiter('-') || peek() == 'T' || peek() == -1; case DAY: return peek() == 'T' || peek() == -1; case HOUR: case MINUTE: - return skip(':') || endOfTime(); + return skipNumberDelimiter(':') || endOfTime(); case SECOND: - return skip('.') || endOfTime(); + return skipNumberDelimiter('.') || endOfTime(); default: return true; } @@ -515,7 +526,7 @@ private int readTimeZoneOffset() { final int sign = string.charAt(pos - 1) == '+' ? 1 : -1; int offset = readNumber(2); - skip(':'); + skipDelimiter(':'); offset = offset * 60 + readNumber(2); return sign * offset; }
--- a/src/jdk/nashorn/internal/parser/Parser.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/parser/Parser.java Mon Aug 19 19:37:29 2013 +0530 @@ -160,10 +160,10 @@ if (this.scripting) { this.lineInfoReceiver = new Lexer.LineInfoReceiver() { @Override - public void lineInfo(final int line, final int linePosition) { + public void lineInfo(final int receiverLine, final int receiverLinePosition) { // update the parser maintained line information - Parser.this.line = line; - Parser.this.linePosition = linePosition; + Parser.this.line = receiverLine; + Parser.this.linePosition = receiverLinePosition; } }; } else {
--- a/src/jdk/nashorn/internal/runtime/Context.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/Context.java Mon Aug 19 19:37:29 2013 +0530 @@ -48,6 +48,7 @@ import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.util.Map; + import jdk.internal.org.objectweb.asm.ClassReader; import jdk.internal.org.objectweb.asm.util.CheckClassAdapter; import jdk.nashorn.api.scripting.ScriptObjectMirror; @@ -888,6 +889,7 @@ return script; } + @SuppressWarnings("static-method") private ScriptLoader createNewLoader() { return AccessController.doPrivileged( new PrivilegedAction<ScriptLoader>() {
--- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Mon Aug 19 19:37:29 2013 +0530 @@ -47,7 +47,7 @@ * This is a subclass that represents a script function that may be regenerated, * for example with specialization based on call site types, or lazily generated. * The common denominator is that it can get new invokers during its lifespan, - * unlike {@link FinalScriptFunctionData} + * unlike {@code FinalScriptFunctionData} */ public final class RecompilableScriptFunctionData extends ScriptFunctionData {
--- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Mon Aug 19 19:37:29 2013 +0530 @@ -553,19 +553,18 @@ private static MethodHandle bindToNameIfNeeded(final MethodHandle methodHandle, final String bindName) { if (bindName == null) { return methodHandle; - } else { - // if it is vararg method, we need to extend argument array with - // a new zeroth element that is set to bindName value. - final MethodType methodType = methodHandle.type(); - final int parameterCount = methodType.parameterCount(); - final boolean isVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray(); + } - if (isVarArg) { - return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName)); - } else { - return MH.insertArguments(methodHandle, 1, bindName); - } + // if it is vararg method, we need to extend argument array with + // a new zeroth element that is set to bindName value. + final MethodType methodType = methodHandle.type(); + final int parameterCount = methodType.parameterCount(); + final boolean isVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray(); + + if (isVarArg) { + return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName)); } + return MH.insertArguments(methodHandle, 1, bindName); } /**
--- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Mon Aug 19 19:37:29 2013 +0530 @@ -250,9 +250,18 @@ final int length = args == null ? 0 : args.length; CompiledFunctions boundList = new CompiledFunctions(); - for (final CompiledFunction inv : code) { + if (code.size() == 1) { + // only one variant - bind that + boundList.add(bind(code.first(), fn, self, allArgs)); + } else { + // There are specialized versions. Get the most generic one. + // This is to avoid ambiguous overloaded versions of bound and + // specialized variants and choosing wrong overload. + final MethodHandle genInvoker = getGenericInvoker(); + final CompiledFunction inv = new CompiledFunction(genInvoker.type(), genInvoker, getGenericConstructor()); boundList.add(bind(inv, fn, self, allArgs)); } + ScriptFunctionData boundData = new FinalScriptFunctionData(name, arity == -1 ? -1 : Math.max(0, arity - length), boundList, isStrict(), isBuiltin(), isConstructor()); return boundData; }
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Aug 19 19:37:29 2013 +0530 @@ -2012,9 +2012,10 @@ final boolean scopeAccess = isScope() && NashornCallSiteDescriptor.isScope(desc); if (find != null) { - final Object value = getObjectValue(find); - ScriptFunction func = null; - MethodHandle methodHandle = null; + final Object value = getObjectValue(find); + ScriptFunction func = null; + MethodHandle methodHandle = null; + if (value instanceof ScriptFunction) { func = (ScriptFunction)value; methodHandle = getCallMethodHandle(func, desc.getMethodType(), name); @@ -3219,6 +3220,11 @@ return property; } + /** + * Write a value to a spill slot + * @param slot the slot index + * @param value the value + */ protected final void setSpill(final int slot, final Object value) { if (spill == null) { // create new spill. @@ -3233,6 +3239,11 @@ spill[slot] = value; } + /** + * Get a value from a spill slot + * @param slot the slot index + * @return the value in the spill slot with the given index + */ protected Object getSpill(final int slot) { return spill != null && slot < spill.length ? spill[slot] : null; }
--- a/src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java Tue Aug 13 18:34:12 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.nashorn.internal.runtime.arrays; - -import jdk.nashorn.internal.runtime.ScriptObject; - -/** - * Iterator over a NativeArray - */ -class ArrayIterator extends ArrayLikeIterator<Object> { - - /** Array {@link ScriptObject} to iterate over */ - protected final ScriptObject array; - - /** length of array */ - protected final long length; - - /** - * Constructor - * @param array array to iterate over - * @param includeUndefined should undefined elements be included in iteration - */ - protected ArrayIterator(final ScriptObject array, final boolean includeUndefined) { - super(includeUndefined); - this.array = array; - this.length = array.getArray().length(); - } - - /** - * Is the current index still inside the array - * @return true if inside the array - */ - protected boolean indexInArray() { - return index < length; - } - - @Override - public Object next() { - return array.get(bumpIndex()); - } - - @Override - public long getLength() { - return length; - } - - @Override - public boolean hasNext() { - if (!includeUndefined) { - while (indexInArray()) { - if (array.has(index)) { - break; - } - bumpIndex(); - } - } - - return indexInArray(); - } - - @Override - public void remove() { - array.delete(index, false); - } -}
--- a/src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -26,6 +26,7 @@ package jdk.nashorn.internal.runtime.arrays; import java.util.Iterator; +import java.util.List; import jdk.nashorn.api.scripting.ScriptObjectMirror; import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.ScriptObject; @@ -49,7 +50,7 @@ * * @param includeUndefined should undefined elements be included in the iteration? */ - protected ArrayLikeIterator(final boolean includeUndefined) { + ArrayLikeIterator(final boolean includeUndefined) { this.includeUndefined = includeUndefined; this.index = 0; } @@ -118,18 +119,26 @@ Object obj = object; if (ScriptObject.isArray(obj)) { - return new ArrayIterator((ScriptObject) obj, includeUndefined); + return new ScriptArrayIterator((ScriptObject) obj, includeUndefined); } obj = JSType.toScriptObject(obj); if (obj instanceof ScriptObject) { - return new MapIterator((ScriptObject)obj, includeUndefined); + return new ScriptObjectIterator((ScriptObject)obj, includeUndefined); } if (obj instanceof ScriptObjectMirror) { return new ScriptObjectMirrorIterator((ScriptObjectMirror)obj, includeUndefined); } + if (obj instanceof List) { + return new JavaListIterator((List<?>)obj, includeUndefined); + } + + if (obj != null && obj.getClass().isArray()) { + return new JavaArrayIterator(obj, includeUndefined); + } + return new EmptyArrayLikeIterator(); } @@ -143,19 +152,25 @@ Object obj = object; if (ScriptObject.isArray(obj)) { - return new ReverseArrayIterator((ScriptObject) obj, includeUndefined); + return new ReverseScriptArrayIterator((ScriptObject) obj, includeUndefined); } obj = JSType.toScriptObject(obj); if (obj instanceof ScriptObject) { - return new ReverseMapIterator((ScriptObject)obj, includeUndefined); + return new ReverseScriptObjectIterator((ScriptObject)obj, includeUndefined); } if (obj instanceof ScriptObjectMirror) { return new ReverseScriptObjectMirrorIterator((ScriptObjectMirror)obj, includeUndefined); } - assert !obj.getClass().isArray(); + if (obj instanceof List) { + return new ReverseJavaListIterator((List<?>)obj, includeUndefined); + } + + if (obj != null && obj.getClass().isArray()) { + return new ReverseJavaArrayIterator(obj, includeUndefined); + } return new EmptyArrayLikeIterator(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/runtime/arrays/JavaArrayIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.runtime.arrays; + +import java.lang.reflect.Array; + +/** + * Iterator over a Java List. + */ +class JavaArrayIterator extends ArrayLikeIterator<Object> { + + /** Array to iterate over */ + protected final Object array; + + /** length of array */ + protected final long length; + + /** + * Constructor + * @param array array to iterate over + * @param includeUndefined should undefined elements be included in iteration + */ + protected JavaArrayIterator(final Object array, final boolean includeUndefined) { + super(includeUndefined); + assert array.getClass().isArray() : "expecting Java array object"; + this.array = array; + this.length = Array.getLength(array); + } + + /** + * Is the current index still inside the array + * @return true if inside the array + */ + protected boolean indexInArray() { + return index < length; + } + + @Override + public Object next() { + return Array.get(array, (int)bumpIndex()); + } + + @Override + public long getLength() { + return length; + } + + @Override + public boolean hasNext() { + return indexInArray(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException("remove"); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/runtime/arrays/JavaListIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.runtime.arrays; + +import java.util.List; + +/** + * Iterator over a Java List. + */ +class JavaListIterator extends ArrayLikeIterator<Object> { + + /** {@link java.util.List} to iterate over */ + protected final List<?> list; + + /** length of array */ + protected final long length; + + /** + * Constructor + * @param list list to iterate over + * @param includeUndefined should undefined elements be included in iteration + */ + protected JavaListIterator(final List<?> list, final boolean includeUndefined) { + super(includeUndefined); + this.list = list; + this.length = list.size(); + } + + /** + * Is the current index still inside the array + * @return true if inside the array + */ + protected boolean indexInArray() { + return index < length; + } + + @Override + public Object next() { + return list.get((int)bumpIndex()); + } + + @Override + public long getLength() { + return length; + } + + @Override + public boolean hasNext() { + return indexInArray(); + } + + @Override + public void remove() { + list.remove(index); + } +}
--- a/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Mon Aug 19 19:37:29 2013 +0530 @@ -98,9 +98,8 @@ final int length = (int) length(); if (type == Double.class) { return new NumberArrayData(LongArrayData.toDoubleArray(array, length), length); - } else { - return new ObjectArrayData(LongArrayData.toObjectArray(array, length), length); } + return new ObjectArrayData(LongArrayData.toObjectArray(array, length), length); } @Override
--- a/src/jdk/nashorn/internal/runtime/arrays/MapIterator.java Tue Aug 13 18:34:12 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.nashorn.internal.runtime.arrays; - -import java.util.NoSuchElementException; -import jdk.nashorn.internal.runtime.JSType; -import jdk.nashorn.internal.runtime.ScriptObject; - -/** - * Iterator over a map - */ -class MapIterator extends ArrayLikeIterator<Object> { - - protected final ScriptObject obj; - private final long length; - - MapIterator(final ScriptObject obj, final boolean includeUndefined) { - super(includeUndefined); - this.obj = obj; - this.length = JSType.toUint32(obj.getLength()); - this.index = 0; - } - - protected boolean indexInArray() { - return index < length; - } - - @Override - public long getLength() { - return length; - } - - @Override - public boolean hasNext() { - if (length == 0L) { - return false; //return empty string if toUint32(length) == 0 - } - - while (indexInArray()) { - if (obj.has(index) || includeUndefined) { - break; - } - bumpIndex(); - } - - return indexInArray(); - } - - @Override - public Object next() { - if (indexInArray()) { - return obj.get(bumpIndex()); - } - - throw new NoSuchElementException(); - } -}
--- a/src/jdk/nashorn/internal/runtime/arrays/ReverseArrayIterator.java Tue Aug 13 18:34:12 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.nashorn.internal.runtime.arrays; - -import jdk.nashorn.internal.runtime.ScriptObject; - -/** - * Reverse iterator over a NativeArray - */ -final class ReverseArrayIterator extends ArrayIterator { - - /** - * Constructor - * @param array array to iterate over - * @param includeUndefined should undefined elements be included in iteration - */ - public ReverseArrayIterator(final ScriptObject array, final boolean includeUndefined) { - super(array, includeUndefined); - this.index = array.getArray().length() - 1; - } - - @Override - public boolean isReverse() { - return true; - } - - @Override - protected boolean indexInArray() { - return index >= 0; - } - - @Override - protected long bumpIndex() { - return index--; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseJavaArrayIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.runtime.arrays; + +import java.lang.reflect.Array; + +/** + * Reverse iterator over a array + */ +final class ReverseJavaArrayIterator extends JavaArrayIterator { + /** + * Constructor + * @param array array to iterate over + * @param includeUndefined should undefined elements be included in iteration + */ + public ReverseJavaArrayIterator(final Object array, final boolean includeUndefined) { + super(array, includeUndefined); + this.index = Array.getLength(array) - 1; + } + + @Override + public boolean isReverse() { + return true; + } + + @Override + protected boolean indexInArray() { + return index >= 0; + } + + @Override + protected long bumpIndex() { + return index--; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseJavaListIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.runtime.arrays; + +import java.util.List; + +/** + * Reverse iterator over a List + */ +final class ReverseJavaListIterator extends JavaListIterator { + /** + * Constructor + * @param list list to iterate over + * @param includeUndefined should undefined elements be included in iteration + */ + public ReverseJavaListIterator(final List<?> list, final boolean includeUndefined) { + super(list, includeUndefined); + this.index = list.size() - 1; + } + + @Override + public boolean isReverse() { + return true; + } + + @Override + protected boolean indexInArray() { + return index >= 0; + } + + @Override + protected long bumpIndex() { + return index--; + } +}
--- a/src/jdk/nashorn/internal/runtime/arrays/ReverseMapIterator.java Tue Aug 13 18:34:12 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.nashorn.internal.runtime.arrays; - -import jdk.nashorn.internal.runtime.JSType; -import jdk.nashorn.internal.runtime.ScriptObject; - -/** - * Reverse iterator over a map - */ -final class ReverseMapIterator extends MapIterator { - - ReverseMapIterator(final ScriptObject obj, final boolean includeUndefined) { - super(obj, includeUndefined); - this.index = JSType.toUint32(obj.getLength()) - 1; - } - - @Override - public boolean isReverse() { - return true; - } - - @Override - protected boolean indexInArray() { - return index >= 0; - } - - @Override - protected long bumpIndex() { - return index--; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseScriptArrayIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.runtime.arrays; + +import jdk.nashorn.internal.runtime.ScriptObject; + +/** + * Reverse iterator over a NativeArray + */ +final class ReverseScriptArrayIterator extends ScriptArrayIterator { + + /** + * Constructor + * @param array array to iterate over + * @param includeUndefined should undefined elements be included in iteration + */ + public ReverseScriptArrayIterator(final ScriptObject array, final boolean includeUndefined) { + super(array, includeUndefined); + this.index = array.getArray().length() - 1; + } + + @Override + public boolean isReverse() { + return true; + } + + @Override + protected boolean indexInArray() { + return index >= 0; + } + + @Override + protected long bumpIndex() { + return index--; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseScriptObjectIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.runtime.arrays; + +import jdk.nashorn.internal.runtime.JSType; +import jdk.nashorn.internal.runtime.ScriptObject; + +/** + * Reverse iterator over a map + */ +final class ReverseScriptObjectIterator extends ScriptObjectIterator { + + ReverseScriptObjectIterator(final ScriptObject obj, final boolean includeUndefined) { + super(obj, includeUndefined); + this.index = JSType.toUint32(obj.getLength()) - 1; + } + + @Override + public boolean isReverse() { + return true; + } + + @Override + protected boolean indexInArray() { + return index >= 0; + } + + @Override + protected long bumpIndex() { + return index--; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/runtime/arrays/ScriptArrayIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.runtime.arrays; + +import jdk.nashorn.internal.runtime.ScriptObject; + +/** + * Iterator over a NativeArray + */ +class ScriptArrayIterator extends ArrayLikeIterator<Object> { + + /** Array {@link ScriptObject} to iterate over */ + protected final ScriptObject array; + + /** length of array */ + protected final long length; + + /** + * Constructor + * @param array array to iterate over + * @param includeUndefined should undefined elements be included in iteration + */ + protected ScriptArrayIterator(final ScriptObject array, final boolean includeUndefined) { + super(includeUndefined); + this.array = array; + this.length = array.getArray().length(); + } + + /** + * Is the current index still inside the array + * @return true if inside the array + */ + protected boolean indexInArray() { + return index < length; + } + + @Override + public Object next() { + return array.get(bumpIndex()); + } + + @Override + public long getLength() { + return length; + } + + @Override + public boolean hasNext() { + if (!includeUndefined) { + while (indexInArray()) { + if (array.has(index)) { + break; + } + bumpIndex(); + } + } + + return indexInArray(); + } + + @Override + public void remove() { + array.delete(index, false); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/runtime/arrays/ScriptObjectIterator.java Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.runtime.arrays; + +import java.util.NoSuchElementException; +import jdk.nashorn.internal.runtime.JSType; +import jdk.nashorn.internal.runtime.ScriptObject; + +/** + * Iterator over a map + */ +class ScriptObjectIterator extends ArrayLikeIterator<Object> { + + protected final ScriptObject obj; + private final long length; + + ScriptObjectIterator(final ScriptObject obj, final boolean includeUndefined) { + super(includeUndefined); + this.obj = obj; + this.length = JSType.toUint32(obj.getLength()); + this.index = 0; + } + + protected boolean indexInArray() { + return index < length; + } + + @Override + public long getLength() { + return length; + } + + @Override + public boolean hasNext() { + if (length == 0L) { + return false; //return empty string if toUint32(length) == 0 + } + + while (indexInArray()) { + if (obj.has(index) || includeUndefined) { + break; + } + bumpIndex(); + } + + return indexInArray(); + } + + @Override + public Object next() { + if (indexInArray()) { + return obj.get(bumpIndex()); + } + + throw new NoSuchElementException(); + } +}
--- a/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Mon Aug 19 19:37:29 2013 +0530 @@ -60,7 +60,7 @@ @Override public ArrayData copy() { - return new SparseArrayData(underlying.copy(), length(), new TreeMap<Long, Object>(sparseMap)); + return new SparseArrayData(underlying.copy(), length(), new TreeMap<>(sparseMap)); } @Override
--- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethod.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethod.java Mon Aug 19 19:37:29 2013 +0530 @@ -29,7 +29,7 @@ /** * Represents a Dynalink dynamic method bound to a receiver. Note that objects of this class are just the tuples of - * a method and a bound this, without any behavior. All the behavior is defined in the {@link BoundDynamicMethodLinker}. + * a method and a bound this, without any behavior. All the behavior is defined in the {@code BoundDynamicMethodLinker}. */ final class BoundDynamicMethod { private final Object dynamicMethod;
--- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java Mon Aug 19 19:37:29 2013 +0530 @@ -37,7 +37,7 @@ import jdk.internal.dynalink.support.Guards; /** - * Links {@link BoundDynamicMethod} objects. Passes through to Dynalink's BeansLinker for linking a dynamic method + * Links {@code BoundDynamicMethod} objects. Passes through to Dynalink's BeansLinker for linking a dynamic method * (they only respond to "dyn:call"), and modifies the returned invocation to deal with the receiver binding. */ final class BoundDynamicMethodLinker implements TypeBasedGuardingDynamicLinker {
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Mon Aug 19 19:37:29 2013 +0530 @@ -114,9 +114,8 @@ if(name.equals(className)) { assert classBytes != null : "what? already cleared .class bytes!!"; return defineClass(name, classBytes, 0, classBytes.length, GENERATED_PROTECTION_DOMAIN); - } else { - throw new ClassNotFoundException(name); } + throw new ClassNotFoundException(name); } }; }
--- a/src/jdk/nashorn/internal/runtime/options/Options.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/options/Options.java Mon Aug 19 19:37:29 2013 +0530 @@ -408,13 +408,13 @@ final LinkedList<String> argList = new LinkedList<>(); Collections.addAll(argList, args); - final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null); - if (extra != null) { - final StringTokenizer st = new StringTokenizer(extra); - while (st.hasMoreTokens()) { - argList.add(st.nextToken()); + final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null); + if (extra != null) { + final StringTokenizer st = new StringTokenizer(extra); + while (st.hasMoreTokens()) { + argList.add(st.nextToken()); + } } - } while (!argList.isEmpty()) { final String arg = argList.remove(0); @@ -431,8 +431,9 @@ continue; } - // if it doesn't start with -, it's a file - if (!arg.startsWith("-")) { + // If it doesn't start with -, it's a file. But, if it is just "-", + // then it is a file representing standard input. + if (!arg.startsWith("-") || arg.length() == 1) { files.add(arg); continue; }
--- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Mon Aug 19 19:37:29 2013 +0530 @@ -100,7 +100,7 @@ type.error.inconsistent.property.descriptor=inconsistent property descriptor type.error.bad.default.value=bad default value: {0} type.error.function.apply.expects.array=Function.prototype.apply expects an Array for second argument -type.error.instanceof.on.non.object=instanceof cannot be used on objects without [[HasInstance]] +type.error.instanceof.on.non.object=instanceof must be called with a javascript or java object as the right-hand argument type.error.cannot.convert.to.interface=object {0} cannot be converted to {1} due to "{2}" type.error.array.reduce.invalid.init=invalid initialValue for Array.prototype.reduce type.error.array.reduceright.invalid.init=invalid initialValue for Array.prototype.reduceRight
--- a/src/jdk/nashorn/tools/Shell.java Tue Aug 13 18:34:12 2013 -0700 +++ b/src/jdk/nashorn/tools/Shell.java Mon Aug 19 19:37:29 2013 +0530 @@ -292,6 +292,14 @@ // For each file on the command line. for (final String fileName : files) { + if ("-".equals(fileName)) { + final int res = readEvalPrint(context, global); + if (res != SUCCESS) { + return res; + } + continue; + } + final File file = new File(fileName); final ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global); if (script == null || errors.getNumberOfErrors() != 0) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8019985.js Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8019985: Date.parse("2000-01-01T00:00:00.Z") should return NaN + * + * @test + * @run + */ + +function testFail(str) { + if (!isNaN(Date.parse(str))) { + throw new Error("Parsed invalid date string: " + str); + } +} + +function testOk(str) { + if (isNaN(Date.parse(str))) { + throw new Error("Failed to parse valid date string: " + str); + } +} + +testFail("2000-01-01T00:00:00.Z"); +testFail("2000-01-01T00:00:Z"); +testFail("2000-01-01T00:Z"); +testFail("2000-01-01T00Z"); +testOk("2000-01-01T00:00:00.000Z"); +testOk("2000-01-01T00:00:00.0Z"); +testOk("2000-01-01T00:00:00Z"); +testOk("2000-01-01T00:00Z");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8020355.js Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8020355: bind on built-in constructors don't use bound argument values + * + * @test + * @run + */ + +if (Array.bind(null, 2)().length != 2) { + fail("Expected Array.bind(null, 2)().length to be 2"); +} + +if (RegExp.bind(null, "a")().source.length != 1) { + fail("Expected RegExp.bind(null, 'a')().source.length to be 1"); +} + +// check user defined functions as well + +var res = (function(x, y) { return x*y }).bind(null, 20, 30)(); +if (res != 600) { + fail("Expected 600, but got " + res); +} + +var obj = new ((function(x, y) { this.foo = x*y }).bind({}, 20, 30))(); +if (obj.foo != 600) { + fail("Expected this.foo = 600, but got " + res); +} + +// try variadic function as well + +var res = (function() { return arguments[0]*arguments[1] }).bind(null, 20, 30)(); +if (res != 600) { + fail("Expected 600, but got " + res); +} + +var obj = new ((function(x, y) { this.foo = arguments[0]*arguments[1] }).bind({}, 20, 30))(); +if (obj.foo != 600) { + fail("Expected this.foo = 600, but got " + res); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8023026.js Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists + * + * @test + * @run + */ + +function checkIterations(obj) { + if (typeof obj.getClass == 'function') { + print("iterating on an object of " + obj.getClass()); + } else { + print("iterating on " + String(obj)); + } + + Array.prototype.forEach.call(obj, + function(x) { print("forEach " + x); }); + + print("left sum " + Array.prototype.reduce.call(obj, + function(x, y) { print("reduce", x, y); return x + y; })); + + print("right sum " + Array.prototype.reduceRight.call(obj, + function(x, y) { print("reduceRight", x, y); return x + y; })); + + print("squared " + Array.prototype.map.call(obj, + function(x) x*x)); +} + +var array = new (Java.type("[I"))(4); +for (var i in array) { + array[i] = i; +} + +checkIterations(array); + +var list = new java.util.ArrayList(); +list.add(1); +list.add(3); +list.add(5); +list.add(7); + +checkIterations(list); + +var mirror = loadWithNewGlobal({ + name: "test", + script: "[2, 4, 6, 8]" +}); + +checkIterations(mirror);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8023026.js.EXPECTED Mon Aug 19 19:37:29 2013 +0530 @@ -0,0 +1,42 @@ +iterating on an object of class [I +forEach 0 +forEach 1 +forEach 2 +forEach 3 +reduce 0 1 +reduce 1 2 +reduce 3 3 +left sum 6 +reduceRight 3 2 +reduceRight 5 1 +reduceRight 6 0 +right sum 6 +squared 0,1,4,9 +iterating on an object of class java.util.ArrayList +forEach 1 +forEach 3 +forEach 5 +forEach 7 +reduce 1 3 +reduce 4 5 +reduce 9 7 +left sum 16 +reduceRight 7 5 +reduceRight 12 3 +reduceRight 15 1 +right sum 16 +squared 1,9,25,49 +iterating on [object Array] +forEach 2 +forEach 4 +forEach 6 +forEach 8 +reduce 2 4 +reduce 6 6 +reduce 12 8 +left sum 20 +reduceRight 8 6 +reduceRight 14 4 +reduceRight 18 2 +right sum 20 +squared 4,16,36,64