Wed, 01 Oct 2014 07:47:24 -0700
Added tag jdk8u40-b08 for changeset 89551828b279
sundar@513 | 1 | /* |
sundar@513 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
sundar@513 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sundar@513 | 4 | * |
sundar@513 | 5 | * This code is free software; you can redistribute it and/or modify it |
sundar@513 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sundar@513 | 7 | * published by the Free Software Foundation. |
sundar@513 | 8 | * |
sundar@513 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sundar@513 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sundar@513 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sundar@513 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sundar@513 | 13 | * accompanied this code). |
sundar@513 | 14 | * |
sundar@513 | 15 | * You should have received a copy of the GNU General Public License version |
sundar@513 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sundar@513 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sundar@513 | 18 | * |
sundar@513 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sundar@513 | 20 | * or visit www.oracle.com if you need additional information or have any |
sundar@513 | 21 | * questions. |
sundar@513 | 22 | */ |
sundar@513 | 23 | |
sundar@513 | 24 | /** |
sundar@513 | 25 | * JDK-8023368: Instance __proto__ property should exist and be writable. |
sundar@513 | 26 | * |
sundar@513 | 27 | * @test |
sundar@513 | 28 | * @run |
sundar@513 | 29 | */ |
sundar@513 | 30 | |
sundar@513 | 31 | // function to force same callsites |
sundar@513 | 32 | function check(obj) { |
sundar@513 | 33 | print(obj.func()); |
sundar@513 | 34 | print(obj.x); |
sundar@513 | 35 | print(obj.toString()); |
sundar@513 | 36 | } |
sundar@513 | 37 | |
sundar@513 | 38 | function Func() { |
sundar@513 | 39 | } |
sundar@513 | 40 | |
sundar@513 | 41 | Func.prototype.func = function() { |
sundar@513 | 42 | return "Func.prototype.func"; |
sundar@513 | 43 | } |
sundar@513 | 44 | |
sundar@513 | 45 | Func.prototype.x = "hello"; |
sundar@513 | 46 | |
sundar@513 | 47 | var obj = new Func(); |
sundar@513 | 48 | var obj2 = Object.create(obj); |
sundar@513 | 49 | |
sundar@513 | 50 | // check direct and indirect __proto__ change |
sundar@513 | 51 | check(obj); |
sundar@513 | 52 | check(obj2); |
sundar@513 | 53 | obj.__proto__ = { |
sundar@513 | 54 | func: function() { |
sundar@513 | 55 | return "obj.__proto__.func @ " + __LINE__; |
sundar@513 | 56 | }, |
sundar@513 | 57 | x: 344 |
sundar@513 | 58 | }; |
sundar@513 | 59 | |
sundar@513 | 60 | check(obj); |
sundar@513 | 61 | check(obj2); |
sundar@513 | 62 | |
sundar@513 | 63 | // check indirect (1 and 2 levels) __proto__ function change |
sundar@513 | 64 | obj.__proto__.__proto__ = { |
sundar@513 | 65 | toString: function() { |
sundar@513 | 66 | return "new object.toString"; |
sundar@513 | 67 | } |
sundar@513 | 68 | }; |
sundar@513 | 69 | |
sundar@513 | 70 | check(obj); |
sundar@513 | 71 | check(obj2); |