nashorn/test/script/basic/JDK-8181191.js
author hannesw
Wed, 14 Jun 2017 10:07:07 +0200
changeset 45483 c7c9c4c0127b
permissions -rw-r--r--
8181191: getUint32 returning Long Reviewed-by: attila, jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45483
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     1
/*
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     4
 * 
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     8
 * 
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    13
 * accompanied this code).
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    14
 * 
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    18
 * 
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    21
 * questions.
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    22
 */
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    23
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    24
/**
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    25
 * JDK-8181191: getUint32 returning Long
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    26
 *
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    27
 * @test
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    28
 * @run
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    29
 */
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    30
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    31
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    32
function uint32(x) {
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    33
    var buffer = new ArrayBuffer(16);
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    34
    var dataview = new DataView(buffer);
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    35
    dataview.setUint32(0, x);
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    36
    return dataview.getUint32(0);
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    37
}
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    38
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    39
Assert.assertTrue(typeof uint32(0x7f) === 'number');
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    40
Assert.assertTrue(typeof uint32(0x80) === 'number');
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    41
Assert.assertTrue(typeof uint32(0xffffffff) === 'number');
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    42
Assert.assertTrue(typeof uint32(0x100000000) === 'number');
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    43
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    44
Assert.assertTrue(uint32(0x7f) === 0x7f);
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    45
Assert.assertTrue(uint32(0x80) === 0x80);
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    46
Assert.assertTrue(uint32(0xffffffff) === 0xffffffff);
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    47
Assert.assertTrue(uint32(0x100000000) === 0x0);
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    48
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    49
Assert.assertTrue(uint32(0x7f) === uint32(0x7f));
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    50
Assert.assertTrue(uint32(0x80) === uint32(0x80));
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    51
Assert.assertTrue(uint32(0xffffffff) === uint32(0xffffffff));
c7c9c4c0127b 8181191: getUint32 returning Long
hannesw
parents:
diff changeset
    52
Assert.assertTrue(uint32(0x100000000) === uint32(0x100000000));