test/script/nosecurity/JDK-8067215.js

Fri, 22 Jan 2016 16:18:19 +0100

author
hannesw
date
Fri, 22 Jan 2016 16:18:19 +0100
changeset 1720
c09b105e7be5
parent 1330
d82b07c9c6e3
permissions
-rw-r--r--

8144020: Remove long as an internal numeric type
Reviewed-by: attila, mhaupt

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

mercurial