test/script/basic/JDK-8047764-strict.js

Sun, 24 Jun 2018 23:15:05 +0100

author
alitvinov
date
Sun, 24 Jun 2018 23:15:05 +0100
changeset 2351
41ac91662b75
parent 1020
9ee8fd4a7266
permissions
-rw-r--r--

Merge

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 // Same as JDK-8047764.js but running in strict mode
hannesw@1020 32 "use strict";
hannesw@1020 33
hannesw@1020 34 // Test global set operation on properties defined in Object.prototype
hannesw@1020 35
hannesw@1020 36 Object.defineProperty(Object.prototype, "prop1", { get: function() { return 1; }, set: function(v) { print("setting prop1: " + v); }});
hannesw@1020 37 Object.defineProperty(Object.prototype, "prop2", { value: 1, writable: false, configurable: false });
hannesw@1020 38
hannesw@1020 39 try {
hannesw@1020 40 prop1 = 1;
hannesw@1020 41 print("prop 1: " + prop2);
hannesw@1020 42 } catch (e) {
hannesw@1020 43 print(e.name);
hannesw@1020 44 }
hannesw@1020 45
hannesw@1020 46 try {
hannesw@1020 47 prop2 = 2;
hannesw@1020 48 print("prop 2: " + prop2);
hannesw@1020 49 } catch (e) {
hannesw@1020 50 print(e.name);
hannesw@1020 51 }
hannesw@1020 52
hannesw@1020 53 // Make sure various ways of setting global toString don't affect Object.prototype.toString
hannesw@1020 54
hannesw@1020 55 function checkToString() {
hannesw@1020 56 print(global);
hannesw@1020 57 print(Object.prototype);
hannesw@1020 58 print(global.toString === Object.prototype.toString);
hannesw@1020 59 print(objProtoToString === Object.prototype.toString);
hannesw@1020 60 }
hannesw@1020 61
hannesw@1020 62 var global = this;
hannesw@1020 63 var objProtoToString = Object.prototype.toString;
hannesw@1020 64 global["toString"] = function() { return "global toString 1"; };
hannesw@1020 65 checkToString();
hannesw@1020 66 global.toString = function() { return "global toString 2"; };
hannesw@1020 67 checkToString();
hannesw@1020 68 toString = function() { return "global toString 3"; };
hannesw@1020 69 checkToString();

mercurial