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