# HG changeset patch # User adinn # Date 1437402659 -3600 # Node ID e05c0f6eacd261b4590407a01e3787fcad65e0fb # Parent 51d325277cba47910223f99a5533c082619a25ea# Parent 371f3f83f773ec97491d994bbcce834f0a2cca74 Merge diff -r 51d325277cba -r e05c0f6eacd2 .hgtags --- a/.hgtags Tue Jun 30 16:18:08 2015 +0100 +++ b/.hgtags Mon Jul 20 15:30:59 2015 +0100 @@ -348,6 +348,7 @@ ec36fa3b35eb00f053d624ae837579c6b8e446ac jdk8u31-b13 34a64e22b81bd78cf29603a80ff1f4cfc1694df8 jdk8u31-b31 d2b5784a3452a4fd9d1ccfefe93ee2d36662842c jdk8u31-b32 +c6dd08613a440ed8d0f1b14b85911d6f3826e1d4 jdk8u31-b33 f2925491b61b22ac42f8c30ee9c6723ffa401a4c jdk8u40-b00 62468d841b842769d875bd97d10370585c296eb7 jdk8u40-b01 bdd9c38d1e61edbf770b8733b70a37d0cf0e7055 jdk8u40-b02 @@ -376,6 +377,8 @@ fb7b6c2b95c5661f15e8e747a63ec6d95d49fe46 jdk8u40-b25 b142a2d8e35e54abb08a7ded1dbfb5d7ce534c93 jdk8u40-b26 c2dd88e89edc85b1bcb731d3296d0fcec1b78447 jdk8u40-b27 +e05552220ba82e465a1abfee90224b5b247e37bc jdk8u40-b31 +e1cc0fe0fd50fc4582e729897d7095ffce0f97ad jdk8u40-b32 05a3614ed5276e5db2a73cce918be04b1a2922fb jdk8u45-b00 21ec16eb7e6346c78b4fa67ccd6d2a9c58f0b696 jdk8u45-b01 37b3ef9a07323afd2556d6837824db154cccc874 jdk8u45-b02 @@ -391,6 +394,26 @@ 9b9fee0f99cd07fba62abaafe705665a5ab89067 jdk8u45-b12 6fda38586f73de706ecde311711a587ac49d51d8 jdk8u45-b13 d5477c6d1678547a9338707adc4b81d35c280454 jdk8u45-b14 +ea15c34524408bbd2fa2886e5ec5d7995d8e236a jdk8u45-b15 +d1c1e084430027bffb5bbb1b288660fbdb86627b jdk8u45-b31 +67dc09b4965989a65a97e0bfec73338cd4763f2a jdk8u45-b32 +2d1c01990ebd896f81f511aabf1e53cbe1fda11f jdk8u51-b00 +4323de82a85c378b08e24601b8f3cec6aafda6f4 jdk8u51-b01 +5ee412753fa08a1e9fa15221c4253886e822a94e jdk8u51-b02 +a6d6f7cf488c1e57df9e9f724547c0e0eae2ad9e jdk8u51-b03 +7512eafda1f90fbf6837dd29ae7585b19b9fbe3a jdk8u51-b04 +04aae4de5c5e2b1c51725a7181afa0085a78d7ee jdk8u51-b05 +a03caffca13caafe4e0a14b5c6cee333bdfce67c jdk8u51-b06 +8814ac4bd7bc1cf87b40f036dc306185343ddb76 jdk8u51-b07 +7fa927b4a47ab76204ec2befe3b8f52336c0a291 jdk8u51-b08 +77cee35f987167f6e97cc8f2b09349e743e7a9e7 jdk8u51-b09 +1480e27e4af65e809c1a5cc0310616c2c68392f2 jdk8u51-b10 +6e95b9bb2f67d4a77d28e5aa3c07281fc8424823 jdk8u51-b11 +bf2fe867628bf323262377f8312c85f440a9b246 jdk8u51-b12 +1ecbb6d582a6ccf9e0f6e359a925155c8c580bac jdk8u51-b13 +e9d85a30fd08425904a400add72212a010381aa8 jdk8u51-b14 +4cbc78843829b3f6de43b3c056565834008419a6 jdk8u51-b15 +f01ca5e6b907d1fc2c17068fb28a74411e833f16 jdk8u51-b16 6ec61d2494283fbaca6df227f1a5b45487dc1ca7 jdk8u60-b00 af290f203369ecf8e67b89c4a3a8df0bf535230e jdk8u60-b01 39e0c14d45c3fee93a29993f1415b3393d03483f jdk8u60-b02 @@ -412,3 +435,7 @@ 0b5c0f02a0b79ae0aa97520d65e5b520af8f1b2a jdk8u60-b18 3780124b6dbb100c2c4af2759b8f0e12a8bf1c4c jdk8u60-b19 46a3d8588ad227dc390d84dfc0f89b9291395a36 jdk8u60-b20 +7475a2bd3c012f7dfd0532a344eb7efca56ac6e6 jdk8u60-b21 +9ed906919b5d92067edcdd966a3f413fca0f70ab jdk8u60-b22 +23165e806566f01cdc56421ea82c7e74a6fd85d5 jdk8u60-b23 +68107693248469f7b4fdcc35c53e4206a0d55087 jdk8u60-b24 diff -r 51d325277cba -r e05c0f6eacd2 THIRD_PARTY_README --- a/THIRD_PARTY_README Tue Jun 30 16:18:08 2015 +0100 +++ b/THIRD_PARTY_README Mon Jul 20 15:30:59 2015 +0100 @@ -1140,37 +1140,6 @@ -------------------------------------------------------------------------------- -%% This notice is provided with respect to JSON, which may be included -with JRE 8 & JDK 8. - ---- begin of LICENSE --- - -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - ---- end of LICENSE --- - -------------------------------------------------------------------------------- - %% This notice is provided with respect to Kerberos functionality, which which may be included with JRE 8, JDK 8, and OpenJDK 8. @@ -1250,7 +1219,7 @@ ------------------------------------------------------------------------------- -%% This notice is provided with respect to libpng 1.6.16, which may be +%% This notice is provided with respect to libpng 1.6.16, which may be included with JRE 8, JDK 8, and OpenJDK 8. --- begin of LICENSE --- @@ -1370,7 +1339,7 @@ ------------------------------------------------------------------------------- -%% This notice is provided with respect to libungif 4.1.3, which may be +%% This notice is provided with respect to GIFLIB 5.1.1 & libungif 4.1.3, which may be included with JRE 8, JDK 8, and OpenJDK 8. --- begin of LICENSE --- @@ -1399,13 +1368,13 @@ ------------------------------------------------------------------------------- -%% This notice is provided with respect to Little CMS 2.5, which may be +%% This notice is provided with respect to Little CMS 2.7, which may be included with JRE 8, JDK 8, and OpenJDK 8. --- begin of LICENSE --- Little CMS -Copyright (c) 1998-2011 Marti Maria Saguer +Copyright (c) 1998-2015 Marti Maria Saguer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff -r 51d325277cba -r e05c0f6eacd2 buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java Tue Jun 30 16:18:08 2015 +0100 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java Mon Jul 20 15:30:59 2015 +0100 @@ -152,6 +152,7 @@ } if (constructor != null) { + initPrototype(mi); final int arity = constructor.getArity(); if (arity != MemberInfo.DEFAULT_ARITY) { mi.loadThis(); @@ -193,6 +194,7 @@ } private void initFunctionFields(final MethodGenerator mi) { + assert memberCount > 0; for (final MemberInfo memInfo : scriptClassInfo.getMembers()) { if (!memInfo.isConstructorFunction()) { continue; @@ -204,37 +206,39 @@ } private void initDataFields(final MethodGenerator mi) { - for (final MemberInfo memInfo : scriptClassInfo.getMembers()) { - if (!memInfo.isConstructorProperty() || memInfo.isFinal()) { - continue; - } - final Object value = memInfo.getValue(); - if (value != null) { - mi.loadThis(); - mi.loadLiteral(value); - mi.putField(className, memInfo.getJavaName(), memInfo.getJavaDesc()); - } else if (!memInfo.getInitClass().isEmpty()) { - final String clazz = memInfo.getInitClass(); - mi.loadThis(); - mi.newObject(clazz); - mi.dup(); - mi.invokeSpecial(clazz, INIT, DEFAULT_INIT_DESC); - mi.putField(className, memInfo.getJavaName(), memInfo.getJavaDesc()); - } + assert memberCount > 0; + for (final MemberInfo memInfo : scriptClassInfo.getMembers()) { + if (!memInfo.isConstructorProperty() || memInfo.isFinal()) { + continue; + } + final Object value = memInfo.getValue(); + if (value != null) { + mi.loadThis(); + mi.loadLiteral(value); + mi.putField(className, memInfo.getJavaName(), memInfo.getJavaDesc()); + } else if (!memInfo.getInitClass().isEmpty()) { + final String clazz = memInfo.getInitClass(); + mi.loadThis(); + mi.newObject(clazz); + mi.dup(); + mi.invokeSpecial(clazz, INIT, DEFAULT_INIT_DESC); + mi.putField(className, memInfo.getJavaName(), memInfo.getJavaDesc()); + } } + } - if (constructor != null) { - mi.loadThis(); - final String protoName = scriptClassInfo.getPrototypeClassName(); - mi.newObject(protoName); - mi.dup(); - mi.invokeSpecial(protoName, INIT, DEFAULT_INIT_DESC); - mi.dup(); - mi.loadThis(); - mi.invokeStatic(PROTOTYPEOBJECT_TYPE, PROTOTYPEOBJECT_SETCONSTRUCTOR, - PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC); - mi.invokeVirtual(SCRIPTFUNCTION_TYPE, SCRIPTFUNCTION_SETPROTOTYPE, SCRIPTFUNCTION_SETPROTOTYPE_DESC); - } + private void initPrototype(final MethodGenerator mi) { + assert constructor != null; + mi.loadThis(); + final String protoName = scriptClassInfo.getPrototypeClassName(); + mi.newObject(protoName); + mi.dup(); + mi.invokeSpecial(protoName, INIT, DEFAULT_INIT_DESC); + mi.dup(); + mi.loadThis(); + mi.invokeStatic(PROTOTYPEOBJECT_TYPE, PROTOTYPEOBJECT_SETCONSTRUCTOR, + PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC); + mi.invokeVirtual(SCRIPTFUNCTION_TYPE, SCRIPTFUNCTION_SETPROTOTYPE, SCRIPTFUNCTION_SETPROTOTYPE_DESC); } /** diff -r 51d325277cba -r e05c0f6eacd2 buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/Main.java --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/Main.java Tue Jun 30 16:18:08 2015 +0100 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/Main.java Mon Jul 20 15:30:59 2015 +0100 @@ -134,7 +134,7 @@ String simpleName = inFile.getName(); simpleName = simpleName.substring(0, simpleName.indexOf(".class")); - if (sci.getPrototypeMemberCount() > 0) { + if (sci.isPrototypeNeeded()) { // generate prototype class final PrototypeGenerator protGen = new PrototypeGenerator(sci); buf = protGen.getClassBytes(); @@ -146,7 +146,7 @@ } } - if (sci.getConstructorMemberCount() > 0 || sci.getConstructor() != null) { + if (sci.isConstructorNeeded()) { // generate constructor class final ConstructorGenerator consGen = new ConstructorGenerator(sci); buf = consGen.getClassBytes(); diff -r 51d325277cba -r e05c0f6eacd2 buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInfo.java --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInfo.java Tue Jun 30 16:18:08 2015 +0100 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInfo.java Mon Jul 20 15:30:59 2015 +0100 @@ -126,10 +126,42 @@ return Collections.unmodifiableList(res); } + boolean isConstructorNeeded() { + // Constructor class generation is needed if we one or + // more constructor properties are defined or @Constructor + // is defined in the class. + for (final MemberInfo memInfo : members) { + if (memInfo.getKind() == Kind.CONSTRUCTOR || + memInfo.getWhere() == Where.CONSTRUCTOR) { + return true; + } + } + return false; + } + + boolean isPrototypeNeeded() { + // Prototype class generation is needed if we have atleast one + // prototype property or @Constructor defined in the class. + for (final MemberInfo memInfo : members) { + if (memInfo.getWhere() == Where.PROTOTYPE || memInfo.isConstructor()) { + return true; + } + } + return false; + } + int getPrototypeMemberCount() { int count = 0; for (final MemberInfo memInfo : members) { - if (memInfo.getWhere() == Where.PROTOTYPE || memInfo.isConstructor()) { + switch (memInfo.getKind()) { + case SETTER: + case SPECIALIZED_FUNCTION: + // SETTER was counted when GETTER was encountered. + // SPECIALIZED_FUNCTION was counted as FUNCTION already. + continue; + } + + if (memInfo.getWhere() == Where.PROTOTYPE) { count++; } } @@ -139,6 +171,16 @@ int getConstructorMemberCount() { int count = 0; for (final MemberInfo memInfo : members) { + switch (memInfo.getKind()) { + case CONSTRUCTOR: + case SETTER: + case SPECIALIZED_FUNCTION: + // SETTER was counted when GETTER was encountered. + // Constructor and constructor SpecializedFunctions + // are not added as members and so not counted. + continue; + } + if (memInfo.getWhere() == Where.CONSTRUCTOR) { count++; } @@ -149,6 +191,14 @@ int getInstancePropertyCount() { int count = 0; for (final MemberInfo memInfo : members) { + switch (memInfo.getKind()) { + case SETTER: + case SPECIALIZED_FUNCTION: + // SETTER was counted when GETTER was encountered. + // SPECIALIZED_FUNCTION was counted as FUNCTION already. + continue; + } + if (memInfo.getWhere() == Where.INSTANCE) { count++; } diff -r 51d325277cba -r e05c0f6eacd2 buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInfoCollector.java --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInfoCollector.java Tue Jun 30 16:18:08 2015 +0100 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInfoCollector.java Mon Jul 20 15:30:59 2015 +0100 @@ -288,9 +288,7 @@ where = Where.PROTOTYPE; break; case SPECIALIZED_FUNCTION: - if (isSpecializedConstructor) { - where = Where.CONSTRUCTOR; - } + where = isSpecializedConstructor? Where.CONSTRUCTOR : Where.PROTOTYPE; //fallthru default: break; diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/codegen/Compiler.java --- a/src/jdk/nashorn/internal/codegen/Compiler.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/codegen/Compiler.java Mon Jul 20 15:30:59 2015 +0100 @@ -103,7 +103,7 @@ private final CodeInstaller installer; - /** logger for compiler, trampolines, splits and related code generation events + /** logger for compiler, trampolines and related code generation events * that affect classes */ private final DebugLogger log; diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/codegen/Splitter.java --- a/src/jdk/nashorn/internal/codegen/Splitter.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/codegen/Splitter.java Mon Jul 20 15:30:59 2015 +0100 @@ -42,13 +42,17 @@ import jdk.nashorn.internal.ir.SplitNode; import jdk.nashorn.internal.ir.Statement; import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.logging.DebugLogger; +import jdk.nashorn.internal.runtime.logging.Loggable; +import jdk.nashorn.internal.runtime.logging.Logger; import jdk.nashorn.internal.runtime.options.Options; /** * Split the IR into smaller compile units. */ -final class Splitter extends NodeVisitor { +@Logger(name="splitter") +final class Splitter extends NodeVisitor implements Loggable { /** Current compiler. */ private final Compiler compiler; @@ -78,7 +82,17 @@ this.compiler = compiler; this.outermost = functionNode; this.outermostCompileUnit = outermostCompileUnit; - this.log = compiler.getLogger(); + this.log = initLogger(compiler.getContext()); + } + + @Override + public DebugLogger initLogger(final Context context) { + return context.getLogger(this.getClass()); + } + + @Override + public DebugLogger getLogger() { + return log; } /** @@ -89,7 +103,7 @@ FunctionNode split(final FunctionNode fn, final boolean top) { FunctionNode functionNode = fn; - log.finest("Initiating split of '", functionNode.getName(), "'"); + log.fine("Initiating split of '", functionNode.getName(), "'"); long weight = WeighNodes.weigh(functionNode); @@ -98,7 +112,7 @@ assert lc.isEmpty() : "LexicalContext not empty"; if (weight >= SPLIT_THRESHOLD) { - log.finest("Splitting '", functionNode.getName(), "' as its weight ", weight, " exceeds split threshold ", SPLIT_THRESHOLD); + log.info("Splitting '", functionNode.getName(), "' as its weight ", weight, " exceeds split threshold ", SPLIT_THRESHOLD); functionNode = (FunctionNode)functionNode.accept(this); if (functionNode.isSplit()) { diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/codegen/types/BooleanType.java --- a/src/jdk/nashorn/internal/codegen/types/BooleanType.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/codegen/types/BooleanType.java Mon Jul 20 15:30:59 2015 +0100 @@ -1,28 +1,3 @@ -/* - * 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. - */ - /* * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/objects/Global.java --- a/src/jdk/nashorn/internal/objects/Global.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/objects/Global.java Mon Jul 20 15:30:59 2015 +0100 @@ -87,7 +87,7 @@ * Representation of global scope. */ @ScriptClass("Global") -public final class Global extends ScriptObject implements Scope { +public final class Global extends Scope { // Placeholder value used in place of a location property (__FILE__, __DIR__, __LINE__) private static final Object LOCATION_PROPERTY_PLACEHOLDER = new Object(); private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); @@ -906,9 +906,6 @@ */ private ScriptFunction typeErrorThrower; - // Flag to indicate that a split method issued a return statement - private int splitState = -1; - // Used to store the last RegExp result to support deprecated RegExp constructor properties private RegExpResult lastRegExpResult; @@ -995,7 +992,6 @@ public Global(final Context context) { super(checkAndGetMap(context)); this.context = context; - this.setIsScope(); this.lexicalScope = context.getEnv()._es6 ? new LexicalScope(this) : null; } @@ -1502,26 +1498,53 @@ } /** - * Global load implementation - Nashorn extension + * Global load implementation - Nashorn extension. * - * @param self scope - * @param source source to load + *

+ * load builtin loads the given script. Script source can be a URL or a File + * or a script object with name and script properties. Evaluated code gets + * global object "this" and uses global object as scope for evaluation. + *

+ *

+ * If self is undefined or null or global, then global object is used + * as scope as well as "this" for the evaluated code. If self is any other + * object, then it is indirect load call. With indirect load call, the + * properties of scope are available to evaluated script as variables. Also, + * global scope properties are accessible. Any var, function definition in + * evaluated script goes into an object that is not accessible to user scripts. + *

+ * Thus the indirect load call is equivalent to the following: + *
+     * 
+     * (function (scope, source) {
+     *    with(scope) {
+     *        eval(<script_from_source>);
+     *    }
+     * })(self, source);
+     * 
+     * 
* - * @return result of load (undefined) + * @param self scope to use for the script evaluation + * @param source script source + * + * @return result of load (may be undefined) * * @throws IOException if source could not be read */ public static Object load(final Object self, final Object source) throws IOException { final Global global = Global.instanceFrom(self); - final ScriptObject scope = self instanceof ScriptObject ? (ScriptObject)self : global; - return global.getContext().load(scope, source); + return global.getContext().load(self, source); } /** - * Global loadWithNewGlobal implementation - Nashorn extension + * Global loadWithNewGlobal implementation - Nashorn extension. * - * @param self scope - * @param args from plus (optional) arguments to be passed to the loaded script + * loadWithNewGlobal builtin loads the given script from a URL or a File + * or a script object with name and script properties. Evaluated code gets + * new global object "this" and uses that new global object as scope for evaluation. + * + * @param self self This value is ignored by this function + * @param args optional arguments to be passed to the loaded script * * @return result of load (may be undefined) * @@ -2328,26 +2351,6 @@ } /** - * Get the current split state. - * - * @return current split state - */ - @Override - public int getSplitState() { - return splitState; - } - - /** - * Set the current split state. - * - * @param state current split state - */ - @Override - public void setSplitState(final int state) { - splitState = state; - } - - /** * Return the ES6 global scope for lexically declared bindings. * @return the ES6 lexical global scope. */ diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/objects/NativeDebug.java --- a/src/jdk/nashorn/internal/objects/NativeDebug.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/objects/NativeDebug.java Mon Jul 20 15:30:59 2015 +0100 @@ -37,6 +37,7 @@ import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.PropertyListeners; import jdk.nashorn.internal.runtime.PropertyMap; +import jdk.nashorn.internal.runtime.Scope; import jdk.nashorn.internal.runtime.ScriptFunction; import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptRuntime; @@ -245,7 +246,7 @@ final PrintWriter out = Context.getCurrentErr(); out.println("ScriptObject count " + ScriptObject.getCount()); - out.println("Scope count " + ScriptObject.getScopeCount()); + out.println("Scope count " + Scope.getCount()); out.println("ScriptObject listeners added " + PropertyListeners.getListenersAdded()); out.println("ScriptObject listeners removed " + PropertyListeners.getListenersRemoved()); out.println("ScriptFunction constructor calls " + ScriptFunction.getConstructorCount()); diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/parser/AbstractParser.java --- a/src/jdk/nashorn/internal/parser/AbstractParser.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/parser/AbstractParser.java Mon Jul 20 15:30:59 2015 +0100 @@ -459,6 +459,19 @@ if (kind == TokenKind.KEYWORD || kind == TokenKind.FUTURE || kind == TokenKind.FUTURESTRICT) { return true; } + + // only literals allowed are null, false and true + if (kind == TokenKind.LITERAL) { + switch (type) { + case FALSE: + case NULL: + case TRUE: + return true; + default: + return false; + } + } + // Fake out identifier. final long identToken = Token.recast(token, IDENT); // Get IDENT. diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/runtime/Context.java --- a/src/jdk/nashorn/internal/runtime/Context.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/Context.java Mon Jul 20 15:30:59 2015 +0100 @@ -724,16 +724,8 @@ // In strict mode, eval does not instantiate variables and functions // in the caller's environment. A new environment is created! if (strictFlag) { - // Create a new scope object - final ScriptObject strictEvalScope = global.newObject(); - - // bless it as a "scope" - strictEvalScope.setIsScope(); - - // set given scope to be it's proto so that eval can still - // access caller environment vars in the new environment. - strictEvalScope.setProto(scope); - scope = strictEvalScope; + // Create a new scope object with given scope as its prototype + scope = newScope(scope); } final ScriptFunction func = getProgramFunction(clazz, scope); @@ -748,6 +740,10 @@ return ScriptRuntime.apply(func, evalThis); } + private static ScriptObject newScope(final ScriptObject callerScope) { + return new Scope(callerScope, PropertyMap.newMap(Scope.class)); + } + private static Source loadInternal(final String srcStr, final String prefix, final String resourcePath) { if (srcStr.startsWith(prefix)) { final String resource = resourcePath + srcStr.substring(prefix.length()); @@ -781,7 +777,7 @@ * * @throws IOException if source cannot be found or loaded */ - public Object load(final ScriptObject scope, final Object from) throws IOException { + public Object load(final Object scope, final Object from) throws IOException { final Object src = from instanceof ConsString ? from.toString() : from; Source source = null; @@ -833,7 +829,42 @@ } if (source != null) { - return evaluateSource(source, scope, scope); + if (scope instanceof ScriptObject && ((ScriptObject)scope).isScope()) { + final ScriptObject sobj = (ScriptObject)scope; + // passed object is a script object + // Global is the only user accessible scope ScriptObject + assert sobj.isGlobal() : "non-Global scope object!!"; + return evaluateSource(source, sobj, sobj); + } else if (scope == null || scope == UNDEFINED) { + // undefined or null scope. Use current global instance. + final Global global = getGlobal(); + return evaluateSource(source, global, global); + } else { + /* + * Arbitrary object passed for scope. + * Indirect load that is equivalent to: + * + * (function(scope, source) { + * with (scope) { + * eval(); + * } + * })(scope, source); + */ + final Global global = getGlobal(); + // Create a new object. This is where all declarations + // (var, function) from the evaluated code go. + // make global to be its __proto__ so that global + // definitions are accessible to the evaluated code. + final ScriptObject evalScope = newScope(global); + + // finally, make a WithObject around user supplied scope object + // so that it's properties are accessible as variables. + final ScriptObject withObj = ScriptRuntime.openWith(evalScope, scope); + + // evaluate given source with 'withObj' as scope + // but use global object as "this". + return evaluateSource(source, withObj, global); + } } throw typeError("cant.load.script", ScriptRuntime.safeToString(from)); diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/runtime/FunctionScope.java --- a/src/jdk/nashorn/internal/runtime/FunctionScope.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/FunctionScope.java Mon Jul 20 15:30:59 2015 +0100 @@ -35,17 +35,12 @@ * * The constructor of this class is responsible for any function prologue * involving the scope. - * - * TODO see NASHORN-715. */ -public class FunctionScope extends ScriptObject implements Scope { +public class FunctionScope extends Scope { /** Area to store scope arguments. (public for access from scripts.) */ public final ScriptObject arguments; - /** Flag to indicate that a split method issued a return statement */ - private int splitState = -1; - /** * Constructor * @@ -56,7 +51,6 @@ public FunctionScope(final PropertyMap map, final ScriptObject callerScope, final ScriptObject arguments) { super(callerScope, map); this.arguments = arguments; - setIsScope(); } /** @@ -68,7 +62,6 @@ public FunctionScope(final PropertyMap map, final ScriptObject callerScope) { super(callerScope, map); this.arguments = null; - setIsScope(); } /** @@ -82,23 +75,4 @@ super(map, primitiveSpill, objectSpill); this.arguments = null; } - - - /** - * Get the current split state. - * @return current split state - */ - @Override - public int getSplitState() { - return splitState; - } - - /** - * Set the current split state. - * @param state current split state - */ - @Override - public void setSplitState(final int state) { - splitState = state; - } } diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/runtime/Scope.java --- a/src/jdk/nashorn/internal/runtime/Scope.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/Scope.java Mon Jul 20 15:30:59 2015 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -25,30 +25,105 @@ package jdk.nashorn.internal.runtime; -import static jdk.nashorn.internal.codegen.CompilerConstants.interfaceCallNoLookup; +import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup; import jdk.nashorn.internal.codegen.CompilerConstants; /** - * Interface implemented by {@link ScriptObject}s that act as scope. + * A {@link ScriptObject} subclass for objects that act as scope. */ -public interface Scope { +public class Scope extends ScriptObject { + + /* This is used to store return state of split functions. */ + private int splitState = -1; + + /** This is updated only in debug mode - counts number of {@code ScriptObject} instances created that are scope */ + private static int count; /** Method handle that points to {@link Scope#getSplitState}. */ - public static final CompilerConstants.Call GET_SPLIT_STATE = interfaceCallNoLookup(Scope.class, "getSplitState", int.class); + public static final CompilerConstants.Call GET_SPLIT_STATE = virtualCallNoLookup(Scope.class, "getSplitState", int.class); + /** Method handle that points to {@link Scope#setSplitState(int)}. */ + public static final CompilerConstants.Call SET_SPLIT_STATE = virtualCallNoLookup(Scope.class, "setSplitState", void.class, int.class); + + /** + * Constructor + * + * @param map initial property map + */ + public Scope(final PropertyMap map) { + super(map); + if (Context.DEBUG) { + count++; + } + } + + /** + * Constructor + * + * @param proto parent scope + * @param map initial property map + */ + public Scope(final ScriptObject proto, final PropertyMap map) { + super(proto, map); + if (Context.DEBUG) { + count++; + } + } - /** Method handle that points to {@link Scope#setSplitState(int)}. */ - public static final CompilerConstants.Call SET_SPLIT_STATE = interfaceCallNoLookup(Scope.class, "setSplitState", void.class, int.class); + /** + * Constructor + * + * @param map property map + * @param primitiveSpill primitive spill array + * @param objectSpill reference spill array + */ + public Scope(final PropertyMap map, final long[] primitiveSpill, final Object[] objectSpill) { + super(map, primitiveSpill, objectSpill); + if (Context.DEBUG) { + count++; + } + } + + @Override + public boolean isScope() { + return true; + } + + @Override + boolean hasWithScope() { + for (ScriptObject obj = this; obj != null; obj = obj.getProto()) { + if (obj instanceof WithObject) { + return true; + } + } + return false; + } /** * Get the scope's split method state. - * @return the current state + * + * @return current split state */ - public int getSplitState(); + public int getSplitState() { + return splitState; + } /** * Set the scope's split method state. - * @param state the new state. + * + * @param state current split state */ - public void setSplitState(int state); + public void setSplitState(final int state) { + splitState = state; + } + + /** + * Get number of {@code Scope} instances created. If not running in debug + * mode this is always 0. + * + * @return number of scope ScriptObjects created + */ + public static int getScopeCount() { + return count; + } } diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/runtime/ScriptObject.java --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Jul 20 15:30:59 2015 +0100 @@ -109,20 +109,17 @@ /** Search fall back routine name for "no such property" */ public static final String NO_SUCH_PROPERTY_NAME = "__noSuchProperty__"; - /** Per ScriptObject flag - is this a scope object? */ - public static final int IS_SCOPE = 1 << 0; - /** Per ScriptObject flag - is this an array object? */ - public static final int IS_ARRAY = 1 << 1; + public static final int IS_ARRAY = 1 << 0; /** Per ScriptObject flag - is this an arguments object? */ - public static final int IS_ARGUMENTS = 1 << 2; + public static final int IS_ARGUMENTS = 1 << 1; /** Is length property not-writable? */ - public static final int IS_LENGTH_NOT_WRITABLE = 1 << 3; + public static final int IS_LENGTH_NOT_WRITABLE = 1 << 2; /** Is this a builtin object? */ - public static final int IS_BUILTIN = 1 << 4; + public static final int IS_BUILTIN = 1 << 3; /** * Spill growth rate - by how many elements does {@link ScriptObject#primitiveSpill} and @@ -396,14 +393,6 @@ } /** - * ECMA 8.10.3 IsGenericDescriptor ( Desc ) - * @return true if this has a descriptor describing an {@link AccessorPropertyDescriptor} or {@link DataPropertyDescriptor} - */ - public final boolean isGenericDescriptor() { - return isAccessorDescriptor() || isDataDescriptor(); - } - - /** * ECMA 8.10.5 ToPropertyDescriptor ( Obj ) * * @return property descriptor @@ -1630,23 +1619,12 @@ return getMap().isFrozen(); } - - /** - * Flag this ScriptObject as scope - */ - public final void setIsScope() { - if (Context.DEBUG) { - scopeCount++; - } - flags |= IS_SCOPE; - } - /** * Check whether this ScriptObject is scope * @return true if scope */ - public final boolean isScope() { - return (flags & IS_SCOPE) != 0; + public boolean isScope() { + return false; } /** @@ -1921,14 +1899,7 @@ * Test whether this object contains in its prototype chain or is itself a with-object. * @return true if a with-object was found */ - final boolean hasWithScope() { - if (isScope()) { - for (ScriptObject obj = this; obj != null; obj = obj.getProto()) { - if (obj instanceof WithObject) { - return true; - } - } - } + boolean hasWithScope() { return false; } @@ -3817,9 +3788,6 @@ /** This is updated only in debug mode - counts number of {@code ScriptObject} instances created */ private static int count; - /** This is updated only in debug mode - counts number of {@code ScriptObject} instances created that are scope */ - private static int scopeCount; - /** * Get number of {@code ScriptObject} instances created. If not running in debug * mode this is always 0 @@ -3829,15 +3797,4 @@ public static int getCount() { return count; } - - /** - * Get number of scope {@code ScriptObject} instances created. If not running in debug - * mode this is always 0 - * - * @return number of scope ScriptObjects created - */ - public static int getScopeCount() { - return scopeCount; - } - } diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/runtime/ScriptRuntime.java --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Mon Jul 20 15:30:59 2015 +0100 @@ -373,9 +373,9 @@ * @return prototype object after merge */ public static ScriptObject mergeScope(final ScriptObject scope) { - final ScriptObject global = scope.getProto(); - global.addBoundProperties(scope); - return global; + final ScriptObject parentScope = scope.getProto(); + parentScope.addBoundProperties(scope); + return parentScope; } /** diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/runtime/WithObject.java --- a/src/jdk/nashorn/internal/runtime/WithObject.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Mon Jul 20 15:30:59 2015 +0100 @@ -44,7 +44,7 @@ * This class supports the handling of scope in a with body. * */ -public final class WithObject extends ScriptObject implements Scope { +public final class WithObject extends Scope { private static final MethodHandle WITHEXPRESSIONGUARD = findOwnMH("withExpressionGuard", boolean.class, Object.class, PropertyMap.class, SwitchPoint.class); private static final MethodHandle WITHEXPRESSIONFILTER = findOwnMH("withFilterExpression", Object.class, Object.class); private static final MethodHandle WITHSCOPEFILTER = findOwnMH("withFilterScope", Object.class, Object.class); @@ -62,7 +62,6 @@ */ WithObject(final ScriptObject scope, final ScriptObject expression) { super(scope, null); - setIsScope(); this.expression = expression; } @@ -224,29 +223,33 @@ @Override public void setSplitState(final int state) { - getNonWithParent().setSplitState(state); + ((Scope) getNonWithParent()).setSplitState(state); } @Override public int getSplitState() { - return getNonWithParent().getSplitState(); + return ((Scope) getNonWithParent()).getSplitState(); + } + + @Override + public void addBoundProperties(final ScriptObject source, final Property[] properties) { + // Declared variables in nested eval go to first normal (non-with) parent scope. + getNonWithParent().addBoundProperties(source, properties); } /** * Get first parent scope that is not an instance of WithObject. */ - private Scope getNonWithParent() { - ScriptObject proto = getParentScope(); + private ScriptObject getNonWithParent() { + ScriptObject proto = getProto(); while (proto != null && proto instanceof WithObject) { - proto = ((WithObject)proto).getParentScope(); + proto = proto.getProto(); } - assert proto instanceof Scope : "with scope without parent scope"; - return (Scope) proto; + return proto; } - private static GuardedInvocation fixReceiverType(final GuardedInvocation link, final MethodHandle filter) { // The receiver may be an Object or a ScriptObject. final MethodType invType = link.getInvocation().type(); @@ -380,14 +383,6 @@ return expression; } - /** - * Get the parent scope for this {@code WithObject} - * @return the parent scope - */ - public ScriptObject getParentScope() { - return getProto(); - } - private static MethodHandle findOwnMH(final String name, final Class rtype, final Class... types) { return MH.findStatic(MethodHandles.lookup(), WithObject.class, name, MH.type(rtype, types)); } diff -r 51d325277cba -r e05c0f6eacd2 src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Tue Jun 30 16:18:08 2015 +0100 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Mon Jul 20 15:30:59 2015 +0100 @@ -106,7 +106,9 @@ *
  • * If the adapter being generated can have class-level overrides, constructors taking same arguments as the superclass * constructors are created. These constructors simply delegate to the superclass constructor. They are simply used to - * create instances of the adapter class, with no instance-level overrides, as they don't have them. + * create instances of the adapter class, with no instance-level overrides, as they don't have them. If the original + * class' constructor was variable arity, the adapter constructor will also be variable arity. Protected constructors + * are exposed as public. *
  • * *

    @@ -190,7 +192,6 @@ private static final int MAX_GENERATED_TYPE_NAME_LENGTH = 255; private static final String CLASS_INIT = ""; - static final String CONVERTER_INIT = ""; // Method name prefix for invoking super-methods static final String SUPER_PREFIX = "super$"; @@ -494,7 +495,8 @@ final Type[] argTypes = originalCtorType.getArgumentTypes(); // All constructors must be public, even if in the superclass they were protected. - final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT, + final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | + (ctor.isVarArgs() ? ACC_VARARGS : 0), INIT, Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null)); mv.visitCode(); @@ -543,7 +545,8 @@ System.arraycopy(originalArgTypes, 0, newArgTypes, 0, argLen); // All constructors must be public, even if in the superclass they were protected. - // Existing super constructor (this, args...) triggers generating (this, scriptObj, args...). + // Existing super constructor (this, args...) triggers generating (this, args..., scriptObj). + // Any variable arity constructors become fixed-arity with explicit array arguments. final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT, Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null)); @@ -593,7 +596,7 @@ if (! fromFunction) { newArgTypes[argLen] = OBJECT_TYPE; final InstructionAdapter mv2 = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT, - Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null)); + Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null)); generateOverridingConstructorWithObjectParam(mv2, ctor, originalCtorType.getDescriptor()); } } diff -r 51d325277cba -r e05c0f6eacd2 test/script/basic/JDK-8098546.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8098546.js Mon Jul 20 15:30:59 2015 +0100 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, 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-8098546: eval within a 'with' leaks definitions into global scope + * + * @test + * @run + */ + +function func() { + var obj = { foo: 344 }; + with (obj) { + eval("var x = foo + 3"); + } + Assert.assertTrue(obj.x === undefined); + Assert.assertTrue(x === 347); +} + +func(); + +// x should be undefined here +Assert.assertTrue(typeof x === "undefined"); + diff -r 51d325277cba -r e05c0f6eacd2 test/script/basic/JDK-8098578.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8098578.js Mon Jul 20 15:30:59 2015 +0100 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015 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-8098578: Global scope is not accessible with indirect load call + * + * @test + * @run + */ + +var obj = { foo: 343 }; +var global = this; +var x = 434; + +// indirect load call +var res = load.call(obj, { + name: "t.js", + // global is accessible. All declarations go into + // intermediate inaccessible scope. "this" is global + // User's passed object's properties are accessible + // as variables. + script: "foo -= 300; var bar = x; Assert.assertTrue(bar == 434); function func() {}; this" +}) + +// 'this' for the evaluated code is global +Assert.assertTrue(res === global); + +// properties of passed object are accessible in evaluated code +Assert.assertTrue(obj.foo == 43); + +// vars, functions definined in evaluated code don't go into passed object +Assert.assertTrue(typeof obj.bar == "undefined"); +Assert.assertTrue(typeof obj.func == "undefined"); + +// vars, functions definined in evaluated code don't go leak into global +Assert.assertTrue(typeof bar == "undefined"); +Assert.assertTrue(typeof func == "undefined"); +Assert.assertTrue(typeof foo == "undefined"); + +var res = load.call(undefined, { + name: "t1.js", + // still global is accessible and 'this' is global + script: "Assert.assertTrue(x == 434); this" +}); + +// indirect load with 'undefined' this is same as as direct load +// or load on global itself. +Assert.assertTrue(res === global); + +// indirect load with 'undefined' this is same as as direct load +// or load on global itself. +var res = load.call(null, { + name: "t2.js", + // still global is accessible and 'this' is global + script: "Assert.assertTrue(x == 434); this" +}); +Assert.assertTrue(res === global); + +// indirect load with mirror object +var mirror = loadWithNewGlobal({ + name: "t3.js", + script: "({ foo: 'hello', x: Math.PI })" +}); + +var res = load.call(mirror, { + name: "t4.js", + script: "Assert.assertTrue(foo == 'hello'); Assert.assertTrue(x == Math.PI); this" +}); +Assert.assertTrue(res === global); + +// indirect load on non-script object, non-mirror results in TypeError +function tryLoad(obj) { + try { + load.call(obj, { + name: "t5.js", script: "this" + }); + throw new Error("should thrown TypeError for: " + obj); + } catch (e if TypeError) {} +} + +tryLoad("hello"); +tryLoad(Math.E); +tryLoad(true); +tryLoad(false); + +// indirect load of a large script +load.call({}, __DIR__ + "JDK-8098807-payload.js"); diff -r 51d325277cba -r e05c0f6eacd2 test/script/basic/JDK-8098807-payload.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8098807-payload.js Mon Jul 20 15:30:59 2015 +0100 @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2015, 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-8098807: Strict eval throws ClassCastException with large scripts + * + * @subtest + */ + +function f() {} + +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); +f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); f(); diff -r 51d325277cba -r e05c0f6eacd2 test/script/basic/JDK-8098807.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8098807.js Mon Jul 20 15:30:59 2015 +0100 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, 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-8098807: Strict eval throws ClassCastException with large scripts + * + * @test + * @run + * @option -scripting + */ + +"use strict"; + +var path = __DIR__ + "JDK-8098807-payload.js" +var source = readFully(path); +eval(source); diff -r 51d325277cba -r e05c0f6eacd2 test/script/basic/JDK-8129410.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8129410.js Mon Jul 20 15:30:59 2015 +0100 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 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-8129410: Java adapters with class-level overrides should preserve variable arity constructors + * + * @test + * @run + */ + +var VarArgConstructor = Java.type("jdk.nashorn.test.models.VarArgConstructor"); +var VarArgConstructorExtended = Java.extend(VarArgConstructor, {}); + +// If the fix didn't work we wouldn't even get past the constructor invocation +// as it'd complain there's no matching arity constructor. +var newExtended = new VarArgConstructorExtended(1, true, "a", "b"); + +// Assert the expected constructor was invoked. +Assert.assertEquals("vararg", newExtended.indicator); diff -r 51d325277cba -r e05c0f6eacd2 test/script/error/JDK-8098847.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/error/JDK-8098847.js Mon Jul 20 15:30:59 2015 +0100 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, 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-8098847: obj."prop" and obj.'prop' should result in SyntaxError + * + * @test/compile-error + */ + +var obj = { "prop": 45 }; + +obj."prop" = "hello"; +obj.'prop' = "hello"; diff -r 51d325277cba -r e05c0f6eacd2 test/script/error/JDK-8098847.js.EXPECTED --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/error/JDK-8098847.js.EXPECTED Mon Jul 20 15:30:59 2015 +0100 @@ -0,0 +1,6 @@ +test/script/error/JDK-8098847.js:32:5 Expected ident but found prop +obj."prop" = "hello"; + ^ +test/script/error/JDK-8098847.js:33:5 Expected ident but found prop +obj.'prop' = "hello"; + ^