test/script/basic/NASHORN-424.js

Fri, 04 Jan 2013 09:58:33 -0400

author
jlaskey
date
Fri, 04 Jan 2013 09:58:33 -0400
changeset 7
5a1b0714df0e
parent 3
da1e581c933b
child 952
6d5471a497fb
child 962
ac62e33a99b0
permissions
-rw-r--r--

8005663: Update copyright year to 2013
Reviewed-by: sundar
Contributed-by: james.laskey@oracle.com

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * 
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  * 
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  * 
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  * 
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * NASHORN-424: Sparse array cause OutOfMemory exception.
    26  *
    27  * @test
    28  * @run
    29  */
    31 if (typeof print === 'undefined') {
    32     print = console.log;
    33 }
    35 var l = -1
    36   , LEVEL = { silly   : l++
    37             , verbose : l++
    38             , info    : l++
    39             , "http"  : l++
    40             , WARN    : l++
    41             , "ERR!"  : l++
    42             , ERROR   : "ERR!"
    43             , ERR     : "ERR!"
    44             , win     : 0x15AAC5
    45             , paused  : 0x19790701
    46             , silent  : 0xDECAFBAD
    47             }
    49 Object.keys(LEVEL).forEach(function (l) {
    50   if (typeof LEVEL[l] === "string") LEVEL[l] = LEVEL[LEVEL[l]]
    51   else LEVEL[LEVEL[l]] = l
    52   LEVEL[l.toLowerCase()] = LEVEL[l]
    53   if (l === "silent" || l === "paused") return
    54   log[l] = log[l.toLowerCase()] =
    55     function (msg, pref, cb) { return log(msg, pref, l, cb) }
    56 })
    58 function log(msg, pref, level, cb) {
    59     print("[" +level + "] " + msg);
    60 }
    62 Object.keys(LEVEL).forEach(function(l) {
    63     log("has value " + LEVEL[l], null, l, null);
    64 });
    68 var ar = [ "Hello", "World", 0xDECAFBAD ]
    70 Object.keys(ar).forEach(function(e) {
    71     print("ar[" + e + "] = " + ar[e]);
    72 });
    74 ar[34254236] = 17;
    75 ar[-1] = "boom";
    76 ar[0xDECAFBAD] = "ka-boom";
    78 ar[ar[2]] = "bye";
    80 Object.keys(ar).forEach(function(e) {
    81     print("ar[" + e + "] = " + ar[e]);
    82 });

mercurial