nashorn/test/script/basic/JDK-8044520.js
author martin
Wed, 10 Dec 2014 09:23:00 -0800
changeset 28057 1a47ceecdba5
parent 24778 2ff5d7041566
permissions -rw-r--r--
8065804: JEP 171: Clarifications/corrections for fence intrinsics Reviewed-by: dholmes, shade, dl, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24772
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
     1
/*
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24772
diff changeset
     4
 *
24772
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24772
diff changeset
     8
 *
24772
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    13
 * accompanied this code).
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24772
diff changeset
    14
 *
24772
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24772
diff changeset
    18
 *
24772
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    21
 * questions.
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    22
 */
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    23
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    24
/**
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    25
 * JDK-8044520: Nashorn cannot execute node.js's express module
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    26
 *
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    27
 * @test
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    28
 * @run
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    29
 */
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    30
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    31
function checkNullProto() {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    32
    var obj = {};
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    33
    obj.__proto__ = null;
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    34
    var proto = Object.getPrototypeOf(obj);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    35
    if (typeof proto != 'object' || proto !== null) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    36
        fail("__proto__ can't be set to null!");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    37
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    38
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    39
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    40
checkNullProto();
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    41
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    42
function checkSetProto(proto) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    43
    var obj = {};
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    44
    obj.__proto__ = proto;
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    45
    if (Object.getPrototypeOf(obj) !== Object.prototype) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    46
        fail("obj.__proto__ set not ignored for " + proto);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    47
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    48
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    49
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    50
checkSetProto(undefined);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    51
checkSetProto(42);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    52
checkSetProto(false);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    53
checkSetProto("hello");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    54
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    55
function checkLiteralSetProto(proto) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    56
    var obj = { __proto__: proto };
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    57
    if (obj.__proto__ !== Object.prototype) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    58
        fail("object literal _proto__ set not ignored for " + proto);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    59
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    60
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    61
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    62
checkLiteralSetProto(undefined);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    63
checkLiteralSetProto(34);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    64
checkLiteralSetProto(true);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    65
checkLiteralSetProto("world");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    66
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    67
function checkNullProtoFromLiteral() {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    68
    var obj = { __proto__: null };
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    69
    var proto = Object.getPrototypeOf(obj);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    70
    if (typeof proto != 'object' || proto !== null) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    71
        fail("__proto__ can't be set to null!");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    72
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    73
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    74
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    75
checkNullProtoFromLiteral();
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    76
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    77
function checkSetPrototypeOf(proto) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    78
    try {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    79
        Object.setPrototypeOf({}, proto);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    80
        fail("should have thrown error for " + proto);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    81
    } catch (e) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    82
        if (! (e instanceof TypeError)) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    83
            fail("should have thrown TypeError, got " + e);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    84
        }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    85
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    86
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    87
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    88
checkSetPrototypeOf(undefined);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    89
checkSetPrototypeOf(43);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    90
checkSetPrototypeOf(false);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    91
checkSetPrototypeOf("nashorn");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    92
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    93
function checkNullSetPrototypeOf() {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    94
    var obj = { };
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    95
    Object.setPrototypeOf(obj, null);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    96
    var proto = Object.getPrototypeOf(obj);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    97
    if (typeof proto != 'object' || proto !== null) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    98
        fail("__proto__ can't be set to null!");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
    99
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   100
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   101
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   102
checkNullSetPrototypeOf();
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   103
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   104
var desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   105
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   106
function checkProtoGetterOnPrimitive(value) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   107
    // call __proto__ getter on primitive - check ToObject
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   108
    // is called on 'this' value as per draft spec
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   109
    if (desc.get.call(value) !== Object(value).__proto__) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   110
        fail("can't call __proto__ getter on " + value);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   111
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   112
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   113
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   114
checkProtoGetterOnPrimitive(32);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   115
checkProtoGetterOnPrimitive(false);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   116
checkProtoGetterOnPrimitive("great!");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   117
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   118
function checkProtoSetterOnNonObjectThis(self) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   119
    try {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   120
        desc.set.call(self);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   121
        fail("should have thrown TypeError");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   122
    } catch (e) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   123
        if (! (e instanceof TypeError)) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   124
            fail("should throw TypeError on non-object self, got " +e);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   125
        }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   126
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   127
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   128
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   129
checkProtoSetterOnNonObjectThis(undefined);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   130
checkProtoSetterOnNonObjectThis(null);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   131
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   132
function checkProtoSetterReturnValue(obj, p) {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   133
    if (typeof desc.set.call(obj, p) != "undefined") {
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   134
        fail("__proto__ setter does not return undefined: " + obj + " " + p);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   135
    }
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   136
}
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   137
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   138
// try non-object 'this'. setter is expected to return undefined.
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   139
checkProtoSetterReturnValue(23);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   140
checkProtoSetterReturnValue(false);
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   141
checkProtoSetterReturnValue("foo");
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   142
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   143
// set proper __proto__. Still return value is undefined.
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   144
checkProtoSetterReturnValue({}, {});
0fc1013a1785 8044520: Nashorn cannot execute node.js's express module
sundar
parents:
diff changeset
   145
checkProtoSetterReturnValue({}, null);