nashorn/test/script/basic/JDK-8011365.js
author psandoz
Tue, 13 Aug 2013 11:16:37 +0200
changeset 19424 c4524285927f
parent 16769 f0d7cca4e7fd
child 24778 2ff5d7041566
permissions -rw-r--r--
8022797: Clarify spliterator characteristics for collections containing no elements Reviewed-by: alanb, mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16769
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     1
/*
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     4
 * 
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     8
 * 
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    13
 * accompanied this code).
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    14
 * 
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    18
 * 
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    21
 * questions.
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    22
 */
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    23
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    24
/**
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    25
 * JDK-8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    26
 *
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    27
 * @test
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    28
 * @run
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    29
 */
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    30
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    31
try {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    32
    Array.prototype.join.call(null, { toString:function() { throw 2 } });
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    33
    fail("should have thrown TypeError");    
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    34
} catch (e) {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    35
    if (! (e instanceof TypeError)) {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    36
        fail("TypeError expected, got " + e);
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    37
    }
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    38
}
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    39
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    40
// check all Array.prototype functions to be sure
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    41
var names = Object.getOwnPropertyNames(Array.prototype);
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    42
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    43
for (var n in names) {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    44
    var funcName = names[n];
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    45
    // ignore constructor
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    46
    if (funcName == "constructor") {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    47
        continue;
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    48
    }
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    49
   
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    50
    var prop = Array.prototype[funcName];
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    51
    if (prop instanceof Function) {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    52
        // try 'null' this
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    53
        try {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    54
            prop.call(null);
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    55
            fail(funcName + " does not throw TypeError on 'null' this");
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    56
        } catch (e) {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    57
            if (! (e instanceof TypeError)) {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    58
                fail("TypeError expected from " + funcName + ", got " + e);
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    59
            }
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    60
        }
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    61
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    62
        // try 'undefined' this
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    63
        try {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    64
            prop.call(undefined);
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    65
            fail(funcName + " does not throw TypeError on 'undefined' this");
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    66
        } catch (e) {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    67
            if (! (e instanceof TypeError)) {
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    68
                fail("TypeError expected from " + funcName + ", got " + e);
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    69
            }
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    70
        }
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    71
    }
f0d7cca4e7fd 8011365: Array.prototype.join and Array.prototype.toString do not throw TypeError on null, undefined
sundar
parents:
diff changeset
    72
}