8080087: Nashorn $ENV.PWD is originally undefined

Fri, 05 Jun 2015 12:38:53 +0200

author
mhaupt
date
Fri, 05 Jun 2015 12:38:53 +0200
changeset 1398
2f1b9f4daec1
parent 1397
19263eb2ff0c
child 1399
22640d19073c

8080087: Nashorn $ENV.PWD is originally undefined
Summary: On Windows, the PWD environment variable does not exist and cannot be imported in scripting mode, so it is set explicitly.
Reviewed-by: lagergren, sundar

src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptingFunctions.java file | annotate | diff | comparison | revisions
test/script/nosecurity/JDK-8080087.js file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Fri Jun 05 14:46:52 2015 +0530
     1.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Fri Jun 05 12:38:53 2015 +0200
     1.3 @@ -2713,6 +2713,14 @@
     1.4              // Retrieve current state of ENV variables.
     1.5              final ScriptObject env = newObject();
     1.6              env.putAll(System.getenv(), scriptEnv._strict);
     1.7 +
     1.8 +            // Some platforms, e.g., Windows, do not define the PWD environment
     1.9 +            // variable, so that the $ENV.PWD property needs to be explicitly
    1.10 +            // set.
    1.11 +            if (!env.containsKey(ScriptingFunctions.PWD_NAME)) {
    1.12 +                env.put(ScriptingFunctions.PWD_NAME, System.getProperty("user.dir"), scriptEnv._strict);
    1.13 +            }
    1.14 +
    1.15              addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
    1.16          } else {
    1.17              addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
     2.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Fri Jun 05 14:46:52 2015 +0530
     2.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Fri Jun 05 12:38:53 2015 +0200
     2.3 @@ -71,7 +71,8 @@
     2.4      /** Names of special properties used by $ENV API. */
     2.5      public  static final String ENV_NAME  = "$ENV";
     2.6  
     2.7 -    private static final String PWD_NAME  = "PWD";
     2.8 +    /** Name of the environment variable for the current working directory. */
     2.9 +    public static final String PWD_NAME  = "PWD";
    2.10  
    2.11      private ScriptingFunctions() {
    2.12      }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/nosecurity/JDK-8080087.js	Fri Jun 05 12:38:53 2015 +0200
     3.3 @@ -0,0 +1,38 @@
     3.4 +/*
     3.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/**
    3.28 + * JDK-8080087: Nashorn $ENV.PWD is originally undefined
    3.29 + *
    3.30 + * This is to ensure that $ENV.PWD is correctly set on Windows as well as on all
    3.31 + * other platforms.
    3.32 + *
    3.33 + * @test
    3.34 + * @option -scripting
    3.35 + * @run
    3.36 + */
    3.37 +
    3.38 +if (typeof($ENV.PWD) === 'undefined') {
    3.39 +    fail('$ENV.PWD is undefined')
    3.40 +}
    3.41 +

mercurial