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