nashorn/test/script/basic/JDK-8011960.js
author attila
Thu, 04 Sep 2014 18:57:14 +0200
changeset 26378 ca7093bd5fd1
parent 24778 2ff5d7041566
permissions -rw-r--r--
8056129: AtomicInteger is treated as primitive number with optimistic compilation Reviewed-by: jlaskey, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16941
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
     1
/*
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16941
diff changeset
     4
 *
16941
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16941
diff changeset
     8
 *
16941
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    13
 * accompanied this code).
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16941
diff changeset
    14
 *
16941
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16941
diff changeset
    18
 *
16941
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    21
 * questions.
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    22
 */
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    23
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    24
/**
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    25
 * JDK-8011960: [2,1].sort(null) should throw TypeError
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    26
 *
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    27
 * @test
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    28
 * @run
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    29
 */
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    30
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    31
function check(func) {
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    32
    try {
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    33
        [2,1].sort(func);
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    34
        fail("should have thrown TypeError for :" + func);
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    35
    } catch (e) {
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    36
        if (! (e instanceof TypeError)) {
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    37
            fail("TypeError not thrown for sort comparefn: " + func);
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    38
        }
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    39
    }
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    40
}
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    41
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    42
// should not result in TypeError for undefined
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    43
[1, 2].sort(undefined);
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    44
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    45
// TypeError for null
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    46
check(null);
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    47
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    48
// should result in TypeError other non-callable params
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    49
check(32);
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    50
check("foo");
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    51
check(false);
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    52
check({});
f5088aaca810 8011960: [2,1].sort(null) should throw TypeError
sundar
parents:
diff changeset
    53
check([]);