nashorn/test/script/basic/JDK-8035712.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 31925 85c87bc2f1f3
permissions -rw-r--r--
8173888: Test for JDK-8169481 causes stack overflows in parser tests Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29283
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
     1
/*
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 29283
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
29283
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 29283
diff changeset
     4
 *
29283
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
     7
 * published by the Free Software Foundation.
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 29283
diff changeset
     8
 *
29283
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    13
 * accompanied this code).
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 29283
diff changeset
    14
 *
29283
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 29283
diff changeset
    18
 *
29283
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    21
 * questions.
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    22
 */
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    23
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    24
/**
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    25
 * JDK-8035712: Restore some of the RuntimeCallSite specializations
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    26
 *
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    27
 * @test
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    28
 * @run
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    29
 */
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    30
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    31
if ((typeof Assert) == "undefined") {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    32
    Assert = { 
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    33
        assertTrue: function(x) { if(!x) { throw "expected true" } },
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    34
        assertFalse: function(x) { if(x) { throw "expected false" } },
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    35
    };
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    36
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    37
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    38
function nop() {}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    39
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    40
function EQ(x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    41
    // Exercise normal evaluation
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    42
    Assert.assertTrue (x == y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    43
    Assert.assertTrue (y == x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    44
    Assert.assertFalse(x != y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    45
    Assert.assertFalse(y != x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    46
    // Exercise the branch optimizer
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    47
    if (x == y) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    48
    if (y == x) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    49
    if (x != y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    50
    if (y != x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    51
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    52
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    53
function NE(x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    54
    // Exercise normal evaluation
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    55
    Assert.assertTrue (x != y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    56
    Assert.assertTrue (y != x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    57
    Assert.assertFalse(x == y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    58
    Assert.assertFalse(y == x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    59
    // Exercise the branch optimizer
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    60
    if (x != y) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    61
    if (y != x) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    62
    if (x == y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    63
    if (y == x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    64
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    65
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    66
function STRICT_EQ(x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    67
    // Exercise normal evaluation
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    68
    Assert.assertTrue (x === y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    69
    Assert.assertTrue (y === x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    70
    Assert.assertFalse(x !== y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    71
    Assert.assertFalse(y !== x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    72
    // Exercise the branch optimizer
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    73
    if (x === y) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    74
    if (y === x) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    75
    if (x !== y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    76
    if (y !== x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    77
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    78
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    79
function STRICT_NE(x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    80
    // Exercise normal evaluation
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    81
    Assert.assertTrue (x !== y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    82
    Assert.assertTrue (y !== x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    83
    Assert.assertFalse(x === y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    84
    Assert.assertFalse(y === x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    85
    // Exercise the branch optimizer
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    86
    if (x !== y) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    87
    if (y !== x) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    88
    if (x === y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    89
    if (y === x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    90
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    91
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    92
function cmpToAnyNumber(cmp, value) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    93
    cmp(1, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    94
    cmp(4294967296, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    95
    cmp(1.2, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    96
    cmp(Infinity, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    97
    cmp(-Infinity, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    98
    cmp(1/Infinity, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
    99
    cmp(0, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   100
    cmp(-0, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   101
    cmp(true, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   102
    cmp(false, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   103
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   104
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   105
function notEqualToAnyNumber(value) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   106
    cmpToAnyNumber(NE, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   107
    cmpToAnyNumber(STRICT_NE, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   108
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   109
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   110
notEqualToAnyNumber(null);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   111
notEqualToAnyNumber(void 0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   112
notEqualToAnyNumber("abc");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   113
notEqualToAnyNumber({});
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   114
notEqualToAnyNumber(["xyz"]);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   115
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   116
function objectWithPrimitiveFunctionNotEqualToAnyNumber(fnName) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   117
    var obj = {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   118
        count: 0
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   119
    };
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   120
    obj[fnName] = function() { this.count++; return "foo"; };
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   121
    notEqualToAnyNumber(obj);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   122
    // Every NE will invoke it 8 times; cmpToAnyNumber has 10 comparisons
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   123
    // STRICT_NE doesn't invoke toString.
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   124
    Assert.assertTrue(80 === obj.count);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   125
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   126
objectWithPrimitiveFunctionNotEqualToAnyNumber("valueOf");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   127
objectWithPrimitiveFunctionNotEqualToAnyNumber("toString");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   128
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   129
function objectEqualButNotStrictlyEqual(val, obj) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   130
    EQ(val, obj);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   131
    STRICT_NE(val, obj);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   132
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   133
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   134
function numberEqualButNotStrictlyEqualToObject(num, obj) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   135
    objectEqualButNotStrictlyEqual(num, obj);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   136
    objectEqualButNotStrictlyEqual(num, [obj]);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   137
    objectEqualButNotStrictlyEqual(num, [[obj]]);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   138
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   139
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   140
function numberEqualButNotStrictlyEqualToZeroObjects(num) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   141
    numberEqualButNotStrictlyEqualToObject(num, [0]);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   142
    numberEqualButNotStrictlyEqualToObject(num, "");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   143
    numberEqualButNotStrictlyEqualToObject(num, []);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   144
    numberEqualButNotStrictlyEqualToObject(num, "0");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   145
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   146
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   147
numberEqualButNotStrictlyEqualToZeroObjects(0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   148
numberEqualButNotStrictlyEqualToZeroObjects(1/Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   149
numberEqualButNotStrictlyEqualToZeroObjects(false);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   150
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   151
function numberEqualButNotStrictlyEqualToObjectEquivalent(num) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   152
    var str = String(num);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   153
    objectEqualButNotStrictlyEqual(num, str);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   154
    objectEqualButNotStrictlyEqual(num, { valueOf:  function() { return str }});
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   155
    objectEqualButNotStrictlyEqual(num, { toString: function() { return str }});
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   156
    objectEqualButNotStrictlyEqual(num, { valueOf:  function() { return num }});
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   157
    objectEqualButNotStrictlyEqual(num, { toString: function() { return num }});
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   158
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   159
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   160
numberEqualButNotStrictlyEqualToObjectEquivalent(1);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   161
numberEqualButNotStrictlyEqualToObjectEquivalent(4294967296);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   162
numberEqualButNotStrictlyEqualToObjectEquivalent(1.2);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   163
numberEqualButNotStrictlyEqualToObjectEquivalent(Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   164
numberEqualButNotStrictlyEqualToObjectEquivalent(-Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   165
numberEqualButNotStrictlyEqualToObjectEquivalent(1/Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   166
numberEqualButNotStrictlyEqualToObjectEquivalent(0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   167
numberEqualButNotStrictlyEqualToObjectEquivalent(-0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   168
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   169
STRICT_EQ(1, new java.lang.Integer(1));
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   170
STRICT_EQ(1, new java.lang.Double(1));
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   171
STRICT_EQ(1.2, new java.lang.Double(1.2));
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   172
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   173
function LE(x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   174
    // Exercise normal evaluation
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   175
    Assert.assertTrue(x <= y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   176
    Assert.assertTrue(y >= x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   177
    Assert.assertFalse(x > y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   178
    Assert.assertFalse(x < y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   179
    // Exercise the branch optimizer
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   180
    if (x <= y) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   181
    if (y >= x) { nop(); } else { Assert.fail(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   182
    if (x > y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   183
    if (y < x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   184
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   185
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   186
function mutuallyLessThanOrEqual(x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   187
    LE(x, y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   188
    LE(y, x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   189
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   190
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   191
mutuallyLessThanOrEqual(0, null);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   192
mutuallyLessThanOrEqual(false, null);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   193
mutuallyLessThanOrEqual(1/Infinity, null);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   194
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   195
function mutuallyLessThanEqualToObjectWithValue(num, val) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   196
    mutuallyLessThanOrEqual(num, { valueOf: function() { return val } });
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   197
    mutuallyLessThanOrEqual(num, { toString: function() { return val } });
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   198
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   199
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   200
mutuallyLessThanEqualToObjectWithValue(false, 0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   201
mutuallyLessThanEqualToObjectWithValue(false, "");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   202
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   203
mutuallyLessThanEqualToObjectWithValue(true, 1);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   204
mutuallyLessThanEqualToObjectWithValue(true, "1");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   205
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   206
function lessThanEqualToObjectEquivalent(num) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   207
    var str = String(num);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   208
    mutuallyLessThanOrEqual(num, str);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   209
    mutuallyLessThanEqualToObjectWithValue(num, num);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   210
    mutuallyLessThanEqualToObjectWithValue(num, str);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   211
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   212
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   213
lessThanEqualToObjectEquivalent(1);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   214
lessThanEqualToObjectEquivalent(4294967296);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   215
lessThanEqualToObjectEquivalent(1.2);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   216
lessThanEqualToObjectEquivalent(Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   217
lessThanEqualToObjectEquivalent(-Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   218
lessThanEqualToObjectEquivalent(1/Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   219
lessThanEqualToObjectEquivalent(0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   220
lessThanEqualToObjectEquivalent(-0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   221
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   222
function INCOMPARABLE(x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   223
    // Exercise normal evaluation
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   224
    Assert.assertFalse(x < y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   225
    Assert.assertFalse(x > y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   226
    Assert.assertFalse(x <= y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   227
    Assert.assertFalse(x >= y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   228
    Assert.assertFalse(y < x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   229
    Assert.assertFalse(y > x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   230
    Assert.assertFalse(y <= x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   231
    Assert.assertFalse(y >= x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   232
    // Exercise the branch optimizer
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   233
    if (x < y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   234
    if (x > y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   235
    if (x <= y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   236
    if (x >= y) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   237
    if (y < x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   238
    if (y > x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   239
    if (y <= x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   240
    if (y >= x) { Assert.fail(); } else { nop(); }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   241
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   242
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   243
function isIncomparable(value) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   244
    cmpToAnyNumber(INCOMPARABLE, value);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   245
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   246
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   247
isIncomparable(void 0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   248
isIncomparable({ valueOf: function() { return NaN }});
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   249
isIncomparable({ toString: function() { return NaN }});
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   250
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   251
// Force ScriptRuntime.LT(Object, Object) etc. comparisons
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   252
function cmpObj(fn, x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   253
    fn({valueOf: function() { return x }}, {valueOf: function() { return y }});
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   254
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   255
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   256
function LT(x, y) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   257
    Assert.assertTrue(x < y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   258
    Assert.assertTrue(y > x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   259
    Assert.assertFalse(x >= y);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   260
    Assert.assertFalse(y <= x);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   261
}
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   262
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   263
cmpObj(LT, 1, 2);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   264
cmpObj(LT, 1, "2");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   265
cmpObj(LT, "1", 2);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   266
cmpObj(LT, "a", "b");
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   267
cmpObj(LT, -Infinity, 0);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   268
cmpObj(LT, 0, Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   269
cmpObj(LT, -Infinity, Infinity);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   270
cmpObj(INCOMPARABLE, 1, NaN);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   271
cmpObj(INCOMPARABLE, NaN, NaN);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   272
cmpObj(INCOMPARABLE, "boo", NaN);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   273
cmpObj(INCOMPARABLE, 1, "boo"); // boo number value will be NaN
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   274
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   275
// Test that a comparison call site can deoptimize from (int, int) to (object, object)
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   276
(function(){
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   277
    var x = [1,  2,  "a"];
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   278
    var y = [2, "3", "b"];
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   279
    for(var i = 0; i < 3; ++i) {
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   280
        Assert.assertTrue(x[i] < y[i]);
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   281
    }
fb47e4d25a9f 8035712: Restore some of the RuntimeCallSite specializations
attila
parents:
diff changeset
   282
})();