samples/consoleuse.js

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

author
mhaupt
date
Fri, 05 Jun 2015 12:38:53 +0200
changeset 1398
2f1b9f4daec1
parent 1373
4eabcac368d2
permissions
-rw-r--r--

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

sundar@1373 1 /*
sundar@1373 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
sundar@1373 3 *
sundar@1373 4 * Redistribution and use in source and binary forms, with or without
sundar@1373 5 * modification, are permitted provided that the following conditions
sundar@1373 6 * are met:
sundar@1373 7 *
sundar@1373 8 * - Redistributions of source code must retain the above copyright
sundar@1373 9 * notice, this list of conditions and the following disclaimer.
sundar@1373 10 *
sundar@1373 11 * - Redistributions in binary form must reproduce the above copyright
sundar@1373 12 * notice, this list of conditions and the following disclaimer in the
sundar@1373 13 * documentation and/or other materials provided with the distribution.
sundar@1373 14 *
sundar@1373 15 * - Neither the name of Oracle nor the names of its
sundar@1373 16 * contributors may be used to endorse or promote products derived
sundar@1373 17 * from this software without specific prior written permission.
sundar@1373 18 *
sundar@1373 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
sundar@1373 20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
sundar@1373 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
sundar@1373 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
sundar@1373 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sundar@1373 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
sundar@1373 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
sundar@1373 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
sundar@1373 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
sundar@1373 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
sundar@1373 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sundar@1373 30 */
sundar@1373 31
sundar@1373 32 load(__DIR__ + "console.js");
sundar@1373 33
sundar@1373 34 console.log("consoleuse.js started!");
sundar@1373 35
sundar@1373 36 function func() {
sundar@1373 37 console.count("func");
sundar@1373 38 }
sundar@1373 39
sundar@1373 40
sundar@1373 41 func();
sundar@1373 42 func();
sundar@1373 43 func();
sundar@1373 44 func();
sundar@1373 45
sundar@1373 46 // java.io.Console method
sundar@1373 47 console.readPassword("passworld please: ");
sundar@1373 48 console.error("Big error: %s!", "you revealed your password!");
sundar@1373 49 console.warn("You've done this %d times", 345);
sundar@1373 50 console.assert(arguments.length != 0, "no arguments!");
sundar@1373 51
sundar@1373 52 // java.io.Console methods
sundar@1373 53 var str = console.readLine("enter something: ");
sundar@1373 54 console.printf("you entered: %s\n", str);
sundar@1373 55

mercurial