8007545: jjs input evalinput need to be NOT_ENUMERABLE

Wed, 06 Feb 2013 08:42:19 -0400

author
jlaskey
date
Wed, 06 Feb 2013 08:42:19 -0400
changeset 74
ec4d59c9b8d2
parent 73
fcf541418304
child 75
2ca25bf25d0c

8007545: jjs input evalinput need to be NOT_ENUMERABLE
Reviewed-by: sundar, lagergren
Contributed-by: james.laskey@oracle.com

src/jdk/nashorn/tools/resources/shell.js file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/tools/resources/shell.js	Wed Feb 06 17:56:12 2013 +0530
     1.2 +++ b/src/jdk/nashorn/tools/resources/shell.js	Wed Feb 06 08:42:19 2013 -0400
     1.3 @@ -1,21 +1,21 @@
     1.4  /*
     1.5   * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - * 
     1.8 + *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10   * under the terms of the GNU General Public License version 2 only, as
    1.11   * published by the Free Software Foundation.
    1.12 - * 
    1.13 + *
    1.14   * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17   * version 2 for more details (a copy is included in the LICENSE file that
    1.18   * accompanied this code).
    1.19 - * 
    1.20 + *
    1.21   * You should have received a copy of the GNU General Public License version
    1.22   * 2 along with this work; if not, write to the Free Software Foundation,
    1.23   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.24 - * 
    1.25 + *
    1.26   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.27   * or visit www.oracle.com if you need additional information or have any
    1.28   * questions.
    1.29 @@ -27,46 +27,72 @@
    1.30  
    1.31  /**
    1.32   * Reads zero or more lines from standard input and returns concatenated string
    1.33 - * 
    1.34 + *
    1.35   * @param endMarker marker string that signals end of input
    1.36   * @param prompt prompt printed for each line
    1.37   */
    1.38 -function input(endMarker, prompt) {
    1.39 -    if (!endMarker) {
    1.40 -        endMarker = "";
    1.41 -    }
    1.42 -    
    1.43 -    if (!prompt) {
    1.44 -        prompt = " >> ";
    1.45 -    }
    1.46 -    
    1.47 -    var imports = new JavaImporter(java.io, java.lang);
    1.48 -    var str = "";
    1.49 -    with (imports) {
    1.50 -        var reader = new BufferedReader(new InputStreamReader(System['in']));
    1.51 -        var line;
    1.52 -        while (true) {
    1.53 -            System.out.print(prompt);
    1.54 -            line = reader.readLine();
    1.55 -            if (line == null || line == endMarker) {
    1.56 -                break;
    1.57 +Object.defineProperty(this, "input", {
    1.58 +    value: function input(endMarker, prompt) {
    1.59 +        if (!endMarker) {
    1.60 +            endMarker = "";
    1.61 +        }
    1.62 +
    1.63 +        if (!prompt) {
    1.64 +            prompt = " >> ";
    1.65 +        }
    1.66 +
    1.67 +        var imports = new JavaImporter(java.io, java.lang);
    1.68 +        var str = "";
    1.69 +        with (imports) {
    1.70 +            var reader = new BufferedReader(new InputStreamReader(System['in']));
    1.71 +            var line;
    1.72 +            while (true) {
    1.73 +                System.out.print(prompt);
    1.74 +                line = reader.readLine();
    1.75 +                if (line == null || line == endMarker) {
    1.76 +                    break;
    1.77 +                }
    1.78 +                str += line + "\n";
    1.79              }
    1.80 -            str += line + "\n";
    1.81          }
    1.82 -    }
    1.83 -    
    1.84 -    return str;
    1.85 -}
    1.86 +
    1.87 +        return str;
    1.88 +    },
    1.89 +    enumerable: false,
    1.90 +    writable: true,
    1.91 +    configurable: true
    1.92 +});
    1.93 +
    1.94  
    1.95  /**
    1.96   * Reads zero or more lines from standard input and evaluates the concatenated
    1.97   * string as code
    1.98 - * 
    1.99 + *
   1.100   * @param endMarker marker string that signals end of input
   1.101   * @param prompt prompt printed for each line
   1.102   */
   1.103 -function evalinput(endMarker, prompt) {
   1.104 -    var code = input(endMarker, prompt);
   1.105 -    // make sure everything is evaluated in global scope!
   1.106 -    return this.eval(code);
   1.107 +Object.defineProperty(this, "evalinput", {
   1.108 +    value: function evalinput(endMarker, prompt) {
   1.109 +        var code = input(endMarker, prompt);
   1.110 +        // make sure everything is evaluated in global scope!
   1.111 +        return this.eval(code);
   1.112 +    },
   1.113 +    enumerable: false,
   1.114 +    writable: true,
   1.115 +    configurable: true
   1.116 +});
   1.117 +
   1.118 +
   1.119 +/**
   1.120 + * Elegantly exits the current session
   1.121 + */
   1.122 +if (!quit) {
   1.123 +Object.defineProperty(this, "quit", {
   1.124 +    value: function quit() {
   1.125 +        java.lang.System.exit(0);
   1.126 +    },
   1.127 +    enumerable: false,
   1.128 +    writable: true,
   1.129 +    configurable: true
   1.130 +});
   1.131  }

mercurial