diff options
Diffstat (limited to 'src/jdk/nashorn/internal/objects/Global.java')
-rw-r--r-- | src/jdk/nashorn/internal/objects/Global.java | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/jdk/nashorn/internal/objects/Global.java b/src/jdk/nashorn/internal/objects/Global.java index b89d2073..e079248b 100644 --- a/src/jdk/nashorn/internal/objects/Global.java +++ b/src/jdk/nashorn/internal/objects/Global.java @@ -34,6 +34,9 @@ import java.io.PrintWriter; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.ref.SoftReference; +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -256,13 +259,29 @@ public final class Global extends ScriptObject implements GlobalObject, Scope { @Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE) public volatile Object packages; + /** Nashorn extension: Java access - global.com */ + @Property(attributes = Attribute.NOT_ENUMERABLE) + public volatile Object com; + + /** Nashorn extension: Java access - global.edu */ + @Property(attributes = Attribute.NOT_ENUMERABLE) + public volatile Object edu; + /** Nashorn extension: Java access - global.java */ @Property(attributes = Attribute.NOT_ENUMERABLE) public volatile Object java; + /** Nashorn extension: Java access - global.javafx */ + @Property(attributes = Attribute.NOT_ENUMERABLE) + public volatile Object javafx; + /** Nashorn extension: Java access - global.javax */ @Property(attributes = Attribute.NOT_ENUMERABLE) - public Object javax; + public volatile Object javax; + + /** Nashorn extension: Java access - global.org */ + @Property(attributes = Attribute.NOT_ENUMERABLE) + public volatile Object org; /** Nashorn extension: Java access - global.javaImporter */ @Property(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) @@ -317,8 +336,12 @@ public final class Global extends ScriptObject implements GlobalObject, Scope { private ScriptFunction builtinTypeError; private ScriptFunction builtinURIError; private ScriptObject builtinPackages; + private ScriptObject builtinCom; + private ScriptObject builtinEdu; private ScriptObject builtinJava; + private ScriptObject builtinJavafx; private ScriptObject builtinJavax; + private ScriptObject builtinOrg; private ScriptObject builtinJavaImporter; private ScriptObject builtinJavaApi; private ScriptObject builtinArrayBuffer; @@ -1479,8 +1502,12 @@ public final class Global extends ScriptObject implements GlobalObject, Scope { private void initJavaAccess() { final ScriptObject objectProto = getObjectPrototype(); this.builtinPackages = new NativeJavaPackage("", objectProto); + this.builtinCom = new NativeJavaPackage("com", objectProto); + this.builtinEdu = new NativeJavaPackage("edu", objectProto); this.builtinJava = new NativeJavaPackage("java", objectProto); + this.builtinJavafx = new NativeJavaPackage("javafx", objectProto); this.builtinJavax = new NativeJavaPackage("javax", objectProto); + this.builtinOrg = new NativeJavaPackage("org", objectProto); this.builtinJavaImporter = initConstructor("JavaImporter"); this.builtinJavaApi = initConstructor("Java"); } @@ -1503,8 +1530,10 @@ public final class Global extends ScriptObject implements GlobalObject, Scope { addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value); // Nashorn extension: global.$OPTIONS (scripting-mode-only) - value = context.getEnv(); - addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, value); + final ScriptObject options = newEmptyInstance(); + final ScriptEnvironment scriptEnv = context.getEnv(); + copyOptions(options, scriptEnv); + addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options); // Nashorn extension: global.$ENV (scripting-mode-only) if (System.getSecurityManager() == null) { @@ -1523,6 +1552,22 @@ public final class Global extends ScriptObject implements GlobalObject, Scope { addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); } + private static void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + for (Field f : scriptEnv.getClass().getFields()) { + try { + options.set(f.getName(), f.get(scriptEnv), false); + } catch (final IllegalArgumentException | IllegalAccessException exp) { + throw new RuntimeException(exp); + } + } + return null; + } + }); + } + private void initTypedArray() { this.builtinArrayBuffer = initConstructor("ArrayBuffer"); this.builtinInt8Array = initConstructor("Int8Array"); @@ -1545,8 +1590,12 @@ public final class Global extends ScriptObject implements GlobalObject, Scope { this.function = this.builtinFunction; this.jsadapter = this.builtinJSAdapter; this.json = this.builtinJSON; + this.com = this.builtinCom; + this.edu = this.builtinEdu; this.java = this.builtinJava; + this.javafx = this.builtinJavafx; this.javax = this.builtinJavax; + this.org = this.builtinOrg; this.javaImporter = this.builtinJavaImporter; this.javaApi = this.builtinJavaApi; this.math = this.builtinMath; |