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

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

mercurial