nashorn/test/script/basic/dataview_new.js
author sundar
Thu, 13 Mar 2014 15:58:24 +0530
changeset 23374 f470afc89c6c
child 24727 611ba7e2101f
permissions -rw-r--r--
8015958: DataView constructor is not defined Reviewed-by: attila, hannesw, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23374
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     1
/*
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     4
 * 
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     8
 * 
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    13
 * accompanied this code).
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    14
 * 
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    18
 * 
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    21
 * questions.
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    22
 */
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    23
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    24
/**
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    25
 * JDK-8015958: DataView constructor is not defined
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    26
 *
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    27
 * @test
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    28
 * @run
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    29
 */
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    30
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    31
// basic DataView constructor checks.
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    32
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    33
// check ArrayBufferView property values of DataView instance
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    34
function check(dv, buf, offset, length) {
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    35
    if (dv.buffer !== buf) {
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    36
        fail("DataView.buffer is wrong");
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    37
    }
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    38
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    39
    if (dv.byteOffset != offset) {
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    40
        fail("DataView.byteOffset = " + dv.byteOffset + ", expected " + offset);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    41
    }
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    42
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    43
    if (dv.byteLength != length) {
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    44
        fail("DataView.byteLength = " + dv.byteLength + ", expected " + length);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    45
    }
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    46
}
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    47
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    48
var buffer = new ArrayBuffer(12);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    49
check(new DataView(buffer), buffer, 0, 12);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    50
check(new DataView(buffer, 2), buffer, 2, 10);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    51
check(new DataView(buffer, 4, 8), buffer, 4, 8);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    52
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    53
// make sure expected error is thrown
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    54
function checkError(callback, ErrorType) {
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    55
    try {
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    56
        callback();
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    57
        fail("Should have thrown " + ErrorType.name);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    58
    } catch (e) {
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    59
        if (! (e instanceof ErrorType)) {
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    60
            fail("Expected " + ErrorType.name + " got " + e);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    61
        }
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    62
    }
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    63
}
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    64
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    65
// non ArrayBuffer as first arg
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    66
checkError(function() { new DataView(344) }, TypeError);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    67
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    68
// illegal offset/length values
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    69
checkError(function() { new DataView(buffer, -1) }, RangeError);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    70
checkError(function() { new DataView(buffer, 15) }, RangeError);
f470afc89c6c 8015958: DataView constructor is not defined
sundar
parents:
diff changeset
    71
checkError(function() { new DataView(buffer, 1, 32) }, RangeError);