() {
@Override
public ScriptLoader run() {
- // Generated code won't refer to any class generated by context
- // script loader and so parent loader can be the structure
- // loader -- which is parent of the context script loader.
- return new ScriptLoader((StructureLoader)scriptLoader.getParent(), Context.this);
+ return new ScriptLoader(sharedLoader, Context.this);
}
});
}
private ScriptObject newGlobalTrusted() {
- try {
- final Class> clazz = Class.forName("jdk.nashorn.internal.objects.Global", true, scriptLoader);
- final Constructor> cstr = clazz.getConstructor(Context.class);
- return (ScriptObject) cstr.newInstance(this);
- } catch (final Exception e) {
- printStackTrace(e);
- if (e instanceof RuntimeException) {
- throw (RuntimeException)e;
- }
- throw new RuntimeException(e);
- }
+ return new Global(this);
}
}
diff -r 8c4a6d9b8a23 -r ec84ba68ad39 src/jdk/nashorn/internal/runtime/GlobalFunctions.java
--- a/src/jdk/nashorn/internal/runtime/GlobalFunctions.java Thu Jul 04 17:28:04 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/GlobalFunctions.java Fri Jul 05 14:38:04 2013 +0530
@@ -34,9 +34,6 @@
/**
* Utilities used by Global class.
- *
- * These are actual implementation methods for functions exposed by global
- * scope. The code lives here to share the code across the contexts.
*/
public final class GlobalFunctions {
diff -r 8c4a6d9b8a23 -r ec84ba68ad39 src/jdk/nashorn/internal/runtime/GlobalObject.java
--- a/src/jdk/nashorn/internal/runtime/GlobalObject.java Thu Jul 04 17:28:04 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/GlobalObject.java Fri Jul 05 14:38:04 2013 +0530
@@ -30,14 +30,7 @@
import jdk.internal.dynalink.linker.LinkRequest;
/**
- * Runtime interface to the global scope of the current context.
- * NOTE: never access {@code jdk.nashorn.internal.objects.Global} class directly
- * from runtime/parser/codegen/ir etc. Always go through this interface.
- *
- * The reason for this is that all objects in the @{code jdk.nashorn.internal.objects.*} package
- * are different per Context and loaded separately by each Context class loader. Attempting
- * to directly refer to an object in this package from the rest of the runtime
- * will lead to {@code ClassNotFoundException} thrown upon link time
+ * Runtime interface to the global scope objects.
*/
public interface GlobalObject {
diff -r 8c4a6d9b8a23 -r ec84ba68ad39 src/jdk/nashorn/internal/runtime/ScriptObject.java
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Jul 04 17:28:04 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Fri Jul 05 14:38:04 2013 +0530
@@ -1027,6 +1027,15 @@
}
/**
+ * Set the current context.
+ * @param ctx context instance to set
+ */
+ protected final void setContext(final Context ctx) {
+ ctx.getClass();
+ this.context = ctx;
+ }
+
+ /**
* Return the map of an object.
* @return PropertyMap object.
*/
diff -r 8c4a6d9b8a23 -r ec84ba68ad39 src/jdk/nashorn/internal/runtime/StructureLoader.java
--- a/src/jdk/nashorn/internal/runtime/StructureLoader.java Thu Jul 04 17:28:04 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/StructureLoader.java Fri Jul 05 14:38:04 2013 +0530
@@ -25,30 +25,19 @@
package jdk.nashorn.internal.runtime;
-import static jdk.nashorn.internal.codegen.Compiler.OBJECTS_PACKAGE;
import static jdk.nashorn.internal.codegen.Compiler.SCRIPTS_PACKAGE;
import static jdk.nashorn.internal.codegen.Compiler.binaryName;
import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_PREFIX;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.CodeSigner;
-import java.security.CodeSource;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
import jdk.nashorn.internal.codegen.ObjectClassGenerator;
/**
- * Responsible for on the fly construction of structure classes as well
- * as loading jdk.nashorn.internal.objects.* classes.
+ * Responsible for on the fly construction of structure classes.
*
*/
final class StructureLoader extends NashornLoader {
private static final String JS_OBJECT_PREFIX_EXTERNAL = binaryName(SCRIPTS_PACKAGE) + '.' + JS_OBJECT_PREFIX.symbolName();
- private static final String OBJECTS_PACKAGE_EXTERNAL = binaryName(OBJECTS_PACKAGE);
/**
* Constructor.
@@ -68,45 +57,9 @@
return loadedClass;
}
- if (name.startsWith(binaryName(OBJECTS_PACKAGE_EXTERNAL))) {
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction>() {
- @Override
- public Class> run() throws ClassNotFoundException {
- final String source = name.replace('.','/') + ".clazz";
- final URL url = getResource(source);
- try (final InputStream is = getResourceAsStream(source)) {
- if (is == null) {
- throw new ClassNotFoundException(name);
- }
-
- byte[] code;
- try {
- code = Source.readBytes(is);
- } catch (final IOException e) {
- Context.printStackTrace(e);
- throw new ClassNotFoundException(name, e);
- }
-
- final Class> cl = defineClass(name, code, 0, code.length, new CodeSource(url, (CodeSigner[])null));
- if (resolve) {
- resolveClass(cl);
- }
- return cl;
- } catch (final IOException e) {
- throw new RuntimeException(e);
- }
- }
- });
- } catch (final PrivilegedActionException e) {
- throw new ClassNotFoundException(name, e);
- }
- }
-
return super.loadClassTrusted(name, resolve);
}
-
@Override
protected Class> findClass(final String name) throws ClassNotFoundException {
if (name.startsWith(JS_OBJECT_PREFIX_EXTERNAL)) {
diff -r 8c4a6d9b8a23 -r ec84ba68ad39 src/jdk/nashorn/internal/scripts/JO.java
--- a/src/jdk/nashorn/internal/scripts/JO.java Thu Jul 04 17:28:04 2013 +0200
+++ b/src/jdk/nashorn/internal/scripts/JO.java Fri Jul 05 14:38:04 2013 +0530
@@ -36,10 +36,11 @@
private static final PropertyMap map$ = PropertyMap.newMap(JO.class);
/**
- * Constructor
+ * Returns the initial property map to be used.
+ * @return the initial property map.
*/
- public JO() {
- super(map$);
+ public static PropertyMap getInitialMap() {
+ return map$;
}
/**
@@ -52,16 +53,17 @@
}
/**
- * Constructor given an initial prototype using the default property map
+ * Constructor given an initial prototype and an initial property map.
*
* @param proto the prototype object
+ * @param map the property map
*/
- public JO(final ScriptObject proto) {
- super(proto, map$);
+ public JO(final ScriptObject proto, final PropertyMap map) {
+ super(proto, map);
}
/**
- * Used by FunctionObjectCreator. A method handle of this method is passed to the ScriptFunction constructor.
+ * A method handle of this method is passed to the ScriptFunction constructor.
*
* @param map the property map to use for allocatorMap
*
diff -r 8c4a6d9b8a23 -r ec84ba68ad39 src/jdk/nashorn/tools/Shell.java
--- a/src/jdk/nashorn/tools/Shell.java Thu Jul 04 17:28:04 2013 +0200
+++ b/src/jdk/nashorn/tools/Shell.java Fri Jul 05 14:38:04 2013 +0530
@@ -47,6 +47,7 @@
import jdk.nashorn.internal.parser.Parser;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ErrorManager;
+import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.Property;
import jdk.nashorn.internal.runtime.ScriptEnvironment;
import jdk.nashorn.internal.runtime.ScriptFunction;
@@ -446,7 +447,7 @@
}
if (res != null && res != ScriptRuntime.UNDEFINED) {
- err.println(ScriptRuntime.safeToString(res));
+ err.println(JSType.toString(res));
}
}
} finally {
diff -r 8c4a6d9b8a23 -r ec84ba68ad39 test/script/basic/JDK-8019947.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8019947.js Fri Jul 05 14:38:04 2013 +0530
@@ -0,0 +1,68 @@
+/*
+ * 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-8019947: inherited property invalidation does not work with two globals in same context
+ *
+ * @test
+ * @option -scripting
+ * @run
+ */
+
+function func(arr) {
+ try {
+ print(arr.toString());
+ } catch (e) {
+ print(e.stack);
+ }
+}
+
+var arr = ["hello", "world"]
+
+func(arr);
+
+var global = loadWithNewGlobal({
+ name: "t",
+ script: <