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