2707 value = ScriptFunction.createBuiltin(execName, ScriptingFunctions.EXEC);
2708 addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
2709
2710 // Nashorn extension: global.echo (scripting-mode-only)
2711 // alias for "print"
2712 value = (ScriptObject)get("print");
2713 addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
2714
2715 // Nashorn extension: global.$OPTIONS (scripting-mode-only)
2716 final ScriptObject options = newObject();
2717 copyOptions(options, scriptEnv);
2718 addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
2719
2720 // Nashorn extension: global.$ENV (scripting-mode-only)
2721 final ScriptObject env = newObject();
2722 if (System.getSecurityManager() == null) {
2723 // do not fill $ENV if we have a security manager around
2724 // Retrieve current state of ENV variables.
2725 env.putAll(System.getenv(), scriptEnv._strict);
2726
2727 // Some platforms, e.g., Windows, do not define the PWD environment
2728 // variable, so that the $ENV.PWD property needs to be explicitly
2729 // set.
2730 if (!env.containsKey(ScriptingFunctions.PWD_NAME)) {
2731 env.put(ScriptingFunctions.PWD_NAME, System.getProperty("user.dir"), scriptEnv._strict);
2732 }
2733 }
2734 addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
2735
2736 // add other special properties for exec support
2737 addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
2738 addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
2739 addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
2740 }
2741
2742 private static void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) {
2743 for (final Field f : scriptEnv.getClass().getFields()) {
2744 try {
2745 options.set(f.getName(), f.get(scriptEnv), 0);
2746 } catch (final IllegalArgumentException | IllegalAccessException exp) {
2747 throw new RuntimeException(exp);
2748 }
2749 }
2750 }
2751
2752 private void copyBuiltins() {
2753 this.array = this.builtinArray;
|
2707 value = ScriptFunction.createBuiltin(execName, ScriptingFunctions.EXEC);
2708 addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);
2709
2710 // Nashorn extension: global.echo (scripting-mode-only)
2711 // alias for "print"
2712 value = (ScriptObject)get("print");
2713 addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
2714
2715 // Nashorn extension: global.$OPTIONS (scripting-mode-only)
2716 final ScriptObject options = newObject();
2717 copyOptions(options, scriptEnv);
2718 addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
2719
2720 // Nashorn extension: global.$ENV (scripting-mode-only)
2721 final ScriptObject env = newObject();
2722 if (System.getSecurityManager() == null) {
2723 // do not fill $ENV if we have a security manager around
2724 // Retrieve current state of ENV variables.
2725 env.putAll(System.getenv(), scriptEnv._strict);
2726
2727 // Set the PWD variable to a value that is guaranteed to be understood
2728 // by the underlying platform.
2729 env.put(ScriptingFunctions.PWD_NAME, System.getProperty("user.dir"), scriptEnv._strict);
2730 }
2731 addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
2732
2733 // add other special properties for exec support
2734 addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
2735 addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
2736 addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
2737 }
2738
2739 private static void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) {
2740 for (final Field f : scriptEnv.getClass().getFields()) {
2741 try {
2742 options.set(f.getName(), f.get(scriptEnv), 0);
2743 } catch (final IllegalArgumentException | IllegalAccessException exp) {
2744 throw new RuntimeException(exp);
2745 }
2746 }
2747 }
2748
2749 private void copyBuiltins() {
2750 this.array = this.builtinArray;
|