nashorn/test/script/basic/JDK-8007140.js
author hannesw
Thu, 11 Apr 2013 12:16:39 +0200
changeset 16943 a1b9b7970813
parent 16204 c53eef0eb729
child 24778 2ff5d7041566
permissions -rw-r--r--
8011980: Allow NUL character in character class Reviewed-by: sundar, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16204
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     1
/*
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     4
 * 
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     8
 * 
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    13
 * accompanied this code).
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    14
 * 
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    18
 * 
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    21
 * questions.
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    22
 */
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    23
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    24
/**
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    25
 * JDK-8007140: Java.extend crashes when attempting to extend java.lang.Object
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    26
 *
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    27
 * @test
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    28
 * @run
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    29
 */
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    30
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    31
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    32
// try various Java.extend cases
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    33
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    34
// Single interface
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    35
var runReached = false;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    36
var r = new (Java.extend(java.lang.Runnable)) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    37
    run: function() {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    38
        runReached = true;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    39
    }
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    40
};
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    41
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    42
r.run();
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    43
if (! runReached) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    44
    fail("run was not called");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    45
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    46
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    47
if (! (r instanceof java.lang.Runnable)) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    48
    fail("r is not a Runnable");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    49
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    50
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    51
// Multiple intefaces
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    52
var runReached = false;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    53
var actionPerformedReached = false;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    54
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    55
var obj = new (Java.extend(java.awt.event.ActionListener, java.lang.Runnable)) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    56
    actionPerformed : function(e) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    57
        actionPerformedReached = true;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    58
    },
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    59
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    60
    run: function() {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    61
        runReached = true;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    62
    }
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    63
};
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    64
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    65
obj.actionPerformed(null);
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    66
if (! actionPerformedReached) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    67
    fail("actionPerformed was not called");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    68
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    69
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    70
obj.run();
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    71
if (! runReached) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    72
    fail("run was not called");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    73
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    74
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    75
if (! (obj instanceof java.lang.Runnable)) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    76
    fail("obj is not a Runnable");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    77
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    78
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    79
if (! (obj instanceof java.awt.event.ActionListener)) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    80
    fail("obj is not an ActionListener");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    81
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    82
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    83
// Single class
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    84
var obj = new (Java.extend(java.lang.Object)) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    85
    toString: function() { return "I am an Object"; }
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    86
};
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    87
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    88
if (! (obj instanceof java.lang.Object)) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    89
    fail("obj is not an instance of java.lang.Object");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    90
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    91
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    92
if (obj.toString() != "I am an Object") {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    93
    fail("Object.toString did not get called");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    94
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    95
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    96
// Single class and single interface
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    97
var runReached = false;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    98
var obj = new (Java.extend(java.lang.Object, java.lang.Runnable)) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
    99
    run: function() {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   100
        runReached = true;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   101
    },
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   102
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   103
    hashCode: function() {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   104
        return 12;
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   105
    }
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   106
};
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   107
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   108
obj.run();
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   109
if (! runReached) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   110
    fail("run was not called");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   111
}
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   112
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   113
if (obj.hashCode() != 12) {
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   114
    fail("hashCode does not return 12");
c53eef0eb729 8007140: Java.extend crashes when attempting to extend java.lang.Object
sundar
parents:
diff changeset
   115
}