nashorn/test/script/nosecurity/JDK-8067215.js
author chegar
Wed, 10 Feb 2016 22:58:27 +0000
changeset 35743 80ba74046cf1
parent 34732 6605efbe8447
child 36517 41a1c20eb619
permissions -rw-r--r--
8148861: Update jaxws to use the new non-inheriting thread-local Thread constructor Reviewed-by: mkos, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     1
/*
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     4
 * 
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     8
 * 
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    13
 * accompanied this code).
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    14
 * 
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    18
 * 
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    21
 * questions.
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    22
 */
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    23
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    24
/**
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    25
 * JDK-8067215: Disable dual fields when not using optimistic types
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    26
 *
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    27
 * @test
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    28
 * @run
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    29
 * @option -Dnashorn.debug=true
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    30
 * @fork
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    31
 */
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    32
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    33
var intType    = Java.type("int");
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    34
var doubleType = Java.type("double");
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    35
var objectType = Java.type("java.lang.Object");
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    36
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    37
var Context = Java.type("jdk.nashorn.internal.runtime.Context");
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    38
var JSType  = Java.type("jdk.nashorn.internal.runtime.JSType");
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    39
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    40
var context = Context.getContext();
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    41
var dualFields = context.useDualFields();
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    42
var optimisticTypes = context.getEnv()._optimistic_types;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    43
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    44
if (dualFields != optimisticTypes) {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    45
    throw new Error("Wrong dual fields setting");
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    46
}
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    47
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    48
function testMap(obj) {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    49
    obj.x = "foo";
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    50
    obj["y"] = 0;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    51
    Object.defineProperty(obj, "z", {value: 0.5});
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    52
    var map = Debug.map(obj);
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    53
    for (var key in obj) {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    54
        var prop = map.findProperty(key);
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    55
        if (prop.hasDualFields() !== dualFields) {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    56
            throw new Error("Wrong property flags: " + prop);
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    57
        }
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    58
        if (prop.getType() != getExpectedType(obj[key])) {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    59
            throw new Error("Wrong property type: " + prop.getType() + " // " + getExpectedType(obj[key]));
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    60
        }
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    61
    }
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    62
}
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    63
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    64
function getExpectedType(value) {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    65
    if (!dualFields) {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    66
        return objectType.class;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    67
    }
34732
6605efbe8447 8144020: Remove long as an internal numeric type
hannesw
parents: 29834
diff changeset
    68
    if (typeof value === "number") {
6605efbe8447 8144020: Remove long as an internal numeric type
hannesw
parents: 29834
diff changeset
    69
        return JSType.isRepresentableAsInt(value) ? intType.class : doubleType.class;
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    70
    }
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    71
    return objectType.class;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    72
}
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    73
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    74
var o = {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    75
    a: 1,
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    76
    b: 2.5,
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    77
    c: 0x10000000000,
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    78
    d: true
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    79
};
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    80
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    81
function C() {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    82
    this.a = 1;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    83
    this.b = 2.5;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    84
    this.c = 0x10000000000;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    85
    this.d = true;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    86
}
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    87
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    88
var a = 1;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    89
var b = 2.5;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    90
var c = 0x10000000000;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    91
var d = true;
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    92
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    93
testMap(o);
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    94
testMap(new C());
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    95
testMap(JSON.parse('{ "a": 1, "b": 2.5, "c": 1099511627776, "d": true }'));
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents:
diff changeset
    96
testMap(this);