hannesw@1020: /* hannesw@1020: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. hannesw@1020: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. hannesw@1020: * hannesw@1020: * This code is free software; you can redistribute it and/or modify it hannesw@1020: * under the terms of the GNU General Public License version 2 only, as hannesw@1020: * published by the Free Software Foundation. hannesw@1020: * hannesw@1020: * This code is distributed in the hope that it will be useful, but WITHOUT hannesw@1020: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or hannesw@1020: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License hannesw@1020: * version 2 for more details (a copy is included in the LICENSE file that hannesw@1020: * accompanied this code). hannesw@1020: * hannesw@1020: * You should have received a copy of the GNU General Public License version hannesw@1020: * 2 along with this work; if not, write to the Free Software Foundation, hannesw@1020: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. hannesw@1020: * hannesw@1020: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA hannesw@1020: * or visit www.oracle.com if you need additional information or have any hannesw@1020: * questions. hannesw@1020: */ hannesw@1020: hannesw@1020: /** hannesw@1020: * JDK-8047764: Indexed or polymorphic set on global affects Object.prototype hannesw@1020: * hannesw@1020: * @test hannesw@1020: * @run hannesw@1020: */ hannesw@1020: hannesw@1020: // Test global set operation on properties defined in Object.prototype hannesw@1020: hannesw@1020: Object.defineProperty(Object.prototype, "prop1", { get: function() { return 1; }, set: function(v) { print("setting prop1: " + v); }}); hannesw@1020: Object.defineProperty(Object.prototype, "prop2", { value: 1, writable: false, configurable: false }); hannesw@1020: hannesw@1020: try { hannesw@1020: prop1 = 1; hannesw@1020: print("prop 1: " + prop2); hannesw@1020: } catch (e) { hannesw@1020: print(e.name); hannesw@1020: } hannesw@1020: hannesw@1020: try { hannesw@1020: prop2 = 2; hannesw@1020: print("prop 2: " + prop2); hannesw@1020: } catch (e) { hannesw@1020: print(e.name); hannesw@1020: } hannesw@1020: hannesw@1020: // Make sure various ways of setting global toString don't affect Object.prototype.toString hannesw@1020: hannesw@1020: function checkToString() { hannesw@1020: print(global); hannesw@1020: print(Object.prototype); hannesw@1020: print(global.toString === Object.prototype.toString); hannesw@1020: print(objProtoToString === Object.prototype.toString); hannesw@1020: } hannesw@1020: hannesw@1020: var global = this; hannesw@1020: var objProtoToString = Object.prototype.toString; hannesw@1020: global["toString"] = function() { return "global toString 1"; }; hannesw@1020: checkToString(); hannesw@1020: global.toString = function() { return "global toString 2"; }; hannesw@1020: checkToString(); hannesw@1020: toString = function() { return "global toString 3"; }; hannesw@1020: checkToString(); hannesw@1020: hannesw@1020: // Test setters on 'with' object hannesw@1020: hannesw@1020: var p = { prop3: 3, toString: function() { return "[object p]"; }}; hannesw@1020: Object.defineProperty(p, "prop4", { get: function() { print("get", this); return 4; }, set: function(v) { print("set", this, v); }}); hannesw@1020: var o = Object.create(p); hannesw@1020: o.toString = function() { return "[object o]"; }; hannesw@1020: hannesw@1020: with(o) { hannesw@1020: (function() { hannesw@1020: var m = 5; hannesw@1020: (function() { hannesw@1020: print(prop3); hannesw@1020: prop3 = m; hannesw@1020: print(prop3); hannesw@1020: print(prop4); hannesw@1020: prop4 = m; hannesw@1020: print(prop4); hannesw@1020: })(); hannesw@1020: })(); hannesw@1020: } hannesw@1020: hannesw@1020: print(o.hasOwnProperty("prop3")); hannesw@1020: print(o.prop3); hannesw@1020: print(p.prop3); hannesw@1020: print(o.hasOwnProperty("prop4")); hannesw@1020: print(o.prop4); hannesw@1020: print(p.prop4);