|
1 /* |
|
2 * Copyright (c) 2010, 2013, 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 * Exercise all setters on standard objects. |
|
26 * |
|
27 * @test |
|
28 * @run |
|
29 */ |
|
30 |
|
31 function checkGetterSetter(obj, expectError) { |
|
32 while (obj != undefined && obj != null) { |
|
33 var properties = Object.getOwnPropertyNames(obj); |
|
34 for (var i in properties) { |
|
35 var prop = properties[i]; |
|
36 try { |
|
37 if (!/\d.*/.test(prop)) { |
|
38 eval("obj." + prop + " = " + "obj." + prop + ";"); |
|
39 } |
|
40 obj[prop] = obj[prop]; |
|
41 } catch (e) { |
|
42 if (!expectError || !(e instanceof TypeError)) { |
|
43 fail(e + ": " + obj.toString() +"." + prop, e); |
|
44 } |
|
45 } |
|
46 } |
|
47 obj = Object.getPrototypeOf(obj); |
|
48 } |
|
49 } |
|
50 |
|
51 // objects |
|
52 checkGetterSetter([2, 23]); |
|
53 checkGetterSetter(new Boolean(true)); |
|
54 checkGetterSetter(new Date(0)); |
|
55 checkGetterSetter(new Error()); |
|
56 checkGetterSetter(new EvalError()); |
|
57 if (typeof JSAdapter != 'undefined') { |
|
58 checkGetterSetter(new JSAdapter({})); |
|
59 } |
|
60 if (typeof JavaImporter != 'undefined') { |
|
61 checkGetterSetter(new JavaImporter(java.io)); |
|
62 } |
|
63 checkGetterSetter(function() {}); |
|
64 checkGetterSetter(new Number(42)); |
|
65 checkGetterSetter(new Object()); |
|
66 checkGetterSetter(new RangeError()); |
|
67 checkGetterSetter(new ReferenceError()); |
|
68 checkGetterSetter(/nashorn/); |
|
69 checkGetterSetter(new String('hello')); |
|
70 checkGetterSetter(new SyntaxError()); |
|
71 checkGetterSetter(new TypeError()); |
|
72 checkGetterSetter(new URIError()); |
|
73 |
|
74 // constructors and prototypes |
|
75 checkGetterSetter(Array); |
|
76 checkGetterSetter(Array.prototype); |
|
77 checkGetterSetter(Boolean); |
|
78 checkGetterSetter(Boolean.prototype); |
|
79 checkGetterSetter(Error); |
|
80 checkGetterSetter(Error.prototype); |
|
81 checkGetterSetter(EvalError); |
|
82 checkGetterSetter(EvalError.prototype); |
|
83 checkGetterSetter(Function); |
|
84 checkGetterSetter(Function.prototype); |
|
85 if (typeof JSAdapter != 'undefined') { |
|
86 checkGetterSetter(JSAdapter); |
|
87 checkGetterSetter(JSAdapter.prototype); |
|
88 } |
|
89 if (typeof JavaImporter != 'undefined') { |
|
90 checkGetterSetter(JavaImporter); |
|
91 checkGetterSetter(JavaImporter.prototype); |
|
92 } |
|
93 checkGetterSetter(Number); |
|
94 checkGetterSetter(Number.prototype); |
|
95 checkGetterSetter(Object); |
|
96 checkGetterSetter(Object.prototype); |
|
97 checkGetterSetter(RangeError); |
|
98 checkGetterSetter(RangeError.prototype); |
|
99 checkGetterSetter(ReferenceError); |
|
100 checkGetterSetter(ReferenceError.prototype); |
|
101 checkGetterSetter(RegExp); |
|
102 checkGetterSetter(RegExp.prototype); |
|
103 checkGetterSetter(String); |
|
104 checkGetterSetter(String.prototype); |
|
105 checkGetterSetter(SyntaxError); |
|
106 checkGetterSetter(SyntaxError.prototype); |
|
107 checkGetterSetter(TypeError); |
|
108 checkGetterSetter(TypeError.prototype); |
|
109 checkGetterSetter(URIError); |
|
110 checkGetterSetter(URIError.prototype); |
|
111 |
|
112 // misc. objects |
|
113 checkGetterSetter(this); |
|
114 |
|
115 if (typeof Packages != 'undefined') { |
|
116 checkGetterSetter(Packages); |
|
117 checkGetterSetter(java); |
|
118 checkGetterSetter(javax); |
|
119 } |
|
120 |
|
121 if (typeof Java != 'undefined') { |
|
122 checkGetterSetter(Java); |
|
123 checkGetterSetter(Java.prototype); |
|
124 } |
|
125 |
|
126 if (typeof Debug != 'undefined') { |
|
127 checkGetterSetter(Debug); |
|
128 } |
|
129 |
|
130 checkGetterSetter((function() { return arguments; })()); |
|
131 // TypeError expected on certain property getter/setter for strict arguments |
|
132 checkGetterSetter((function() { 'use strict'; return arguments; })(), true); |
|
133 checkGetterSetter(JSON); |
|
134 checkGetterSetter(JSON.prototype); |
|
135 checkGetterSetter(Math); |
|
136 checkGetterSetter(Math.prototype); |