Tue, 16 Aug 2016 21:41:28 -0700
Added tag jdk8u102-b33 for changeset 36e3c21b5fca
hannesw@1020 | 1 | /* |
hannesw@1020 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
hannesw@1020 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
hannesw@1020 | 4 | * |
hannesw@1020 | 5 | * This code is free software; you can redistribute it and/or modify it |
hannesw@1020 | 6 | * under the terms of the GNU General Public License version 2 only, as |
hannesw@1020 | 7 | * published by the Free Software Foundation. |
hannesw@1020 | 8 | * |
hannesw@1020 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
hannesw@1020 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
hannesw@1020 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
hannesw@1020 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
hannesw@1020 | 13 | * accompanied this code). |
hannesw@1020 | 14 | * |
hannesw@1020 | 15 | * You should have received a copy of the GNU General Public License version |
hannesw@1020 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
hannesw@1020 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
hannesw@1020 | 18 | * |
hannesw@1020 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
hannesw@1020 | 20 | * or visit www.oracle.com if you need additional information or have any |
hannesw@1020 | 21 | * questions. |
hannesw@1020 | 22 | */ |
hannesw@1020 | 23 | |
hannesw@1020 | 24 | /** |
hannesw@1020 | 25 | * JDK-8047764: Indexed or polymorphic set on global affects Object.prototype |
hannesw@1020 | 26 | * |
hannesw@1020 | 27 | * @test |
hannesw@1020 | 28 | * @run |
hannesw@1020 | 29 | */ |
hannesw@1020 | 30 | |
hannesw@1020 | 31 | // Test global set operation on properties defined in Object.prototype |
hannesw@1020 | 32 | |
hannesw@1020 | 33 | Object.defineProperty(Object.prototype, "prop1", { get: function() { return 1; }, set: function(v) { print("setting prop1: " + v); }}); |
hannesw@1020 | 34 | Object.defineProperty(Object.prototype, "prop2", { value: 1, writable: false, configurable: false }); |
hannesw@1020 | 35 | |
hannesw@1020 | 36 | try { |
hannesw@1020 | 37 | prop1 = 1; |
hannesw@1020 | 38 | print("prop 1: " + prop2); |
hannesw@1020 | 39 | } catch (e) { |
hannesw@1020 | 40 | print(e.name); |
hannesw@1020 | 41 | } |
hannesw@1020 | 42 | |
hannesw@1020 | 43 | try { |
hannesw@1020 | 44 | prop2 = 2; |
hannesw@1020 | 45 | print("prop 2: " + prop2); |
hannesw@1020 | 46 | } catch (e) { |
hannesw@1020 | 47 | print(e.name); |
hannesw@1020 | 48 | } |
hannesw@1020 | 49 | |
hannesw@1020 | 50 | // Make sure various ways of setting global toString don't affect Object.prototype.toString |
hannesw@1020 | 51 | |
hannesw@1020 | 52 | function checkToString() { |
hannesw@1020 | 53 | print(global); |
hannesw@1020 | 54 | print(Object.prototype); |
hannesw@1020 | 55 | print(global.toString === Object.prototype.toString); |
hannesw@1020 | 56 | print(objProtoToString === Object.prototype.toString); |
hannesw@1020 | 57 | } |
hannesw@1020 | 58 | |
hannesw@1020 | 59 | var global = this; |
hannesw@1020 | 60 | var objProtoToString = Object.prototype.toString; |
hannesw@1020 | 61 | global["toString"] = function() { return "global toString 1"; }; |
hannesw@1020 | 62 | checkToString(); |
hannesw@1020 | 63 | global.toString = function() { return "global toString 2"; }; |
hannesw@1020 | 64 | checkToString(); |
hannesw@1020 | 65 | toString = function() { return "global toString 3"; }; |
hannesw@1020 | 66 | checkToString(); |
hannesw@1020 | 67 | |
hannesw@1020 | 68 | // Test setters on 'with' object |
hannesw@1020 | 69 | |
hannesw@1020 | 70 | var p = { prop3: 3, toString: function() { return "[object p]"; }}; |
hannesw@1020 | 71 | Object.defineProperty(p, "prop4", { get: function() { print("get", this); return 4; }, set: function(v) { print("set", this, v); }}); |
hannesw@1020 | 72 | var o = Object.create(p); |
hannesw@1020 | 73 | o.toString = function() { return "[object o]"; }; |
hannesw@1020 | 74 | |
hannesw@1020 | 75 | with(o) { |
hannesw@1020 | 76 | (function() { |
hannesw@1020 | 77 | var m = 5; |
hannesw@1020 | 78 | (function() { |
hannesw@1020 | 79 | print(prop3); |
hannesw@1020 | 80 | prop3 = m; |
hannesw@1020 | 81 | print(prop3); |
hannesw@1020 | 82 | print(prop4); |
hannesw@1020 | 83 | prop4 = m; |
hannesw@1020 | 84 | print(prop4); |
hannesw@1020 | 85 | })(); |
hannesw@1020 | 86 | })(); |
hannesw@1020 | 87 | } |
hannesw@1020 | 88 | |
hannesw@1020 | 89 | print(o.hasOwnProperty("prop3")); |
hannesw@1020 | 90 | print(o.prop3); |
hannesw@1020 | 91 | print(p.prop3); |
hannesw@1020 | 92 | print(o.hasOwnProperty("prop4")); |
hannesw@1020 | 93 | print(o.prop4); |
hannesw@1020 | 94 | print(p.prop4); |