aoqi@0: /* aoqi@0: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@962: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. attila@962: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). attila@962: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@962: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * Exercise all setters on standard objects. aoqi@0: * aoqi@0: * @test aoqi@0: * @run aoqi@0: */ aoqi@0: aoqi@0: function checkGetterSetter(obj, expectError) { aoqi@0: while (obj != undefined && obj != null) { aoqi@0: var properties = Object.getOwnPropertyNames(obj); aoqi@0: for (var i in properties) { aoqi@0: var prop = properties[i]; aoqi@0: try { aoqi@0: if (!/\d.*/.test(prop)) { aoqi@0: eval("obj." + prop + " = " + "obj." + prop + ";"); aoqi@0: } aoqi@0: obj[prop] = obj[prop]; aoqi@0: } catch (e) { aoqi@0: if (!expectError || !(e instanceof TypeError)) { aoqi@0: fail(e + ": " + obj.toString() +"." + prop, e); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: obj = Object.getPrototypeOf(obj); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // objects aoqi@0: checkGetterSetter([2, 23]); aoqi@0: checkGetterSetter(new Boolean(true)); aoqi@0: checkGetterSetter(new Date(0)); aoqi@0: checkGetterSetter(new Error()); aoqi@0: checkGetterSetter(new EvalError()); aoqi@0: if (typeof JSAdapter != 'undefined') { aoqi@0: checkGetterSetter(new JSAdapter({})); aoqi@0: } aoqi@0: if (typeof JavaImporter != 'undefined') { aoqi@0: checkGetterSetter(new JavaImporter(java.io)); aoqi@0: } aoqi@0: checkGetterSetter(function() {}); aoqi@0: checkGetterSetter(new Number(42)); aoqi@0: checkGetterSetter(new Object()); aoqi@0: checkGetterSetter(new RangeError()); aoqi@0: checkGetterSetter(new ReferenceError()); aoqi@0: checkGetterSetter(/nashorn/); aoqi@0: checkGetterSetter(new String('hello')); aoqi@0: checkGetterSetter(new SyntaxError()); aoqi@0: checkGetterSetter(new TypeError()); aoqi@0: checkGetterSetter(new URIError()); aoqi@0: aoqi@0: // constructors and prototypes aoqi@0: checkGetterSetter(Array); aoqi@0: checkGetterSetter(Array.prototype); aoqi@0: checkGetterSetter(Boolean); aoqi@0: checkGetterSetter(Boolean.prototype); aoqi@0: checkGetterSetter(Error); aoqi@0: checkGetterSetter(Error.prototype); aoqi@0: checkGetterSetter(EvalError); aoqi@0: checkGetterSetter(EvalError.prototype); aoqi@0: checkGetterSetter(Function); aoqi@0: checkGetterSetter(Function.prototype); aoqi@0: if (typeof JSAdapter != 'undefined') { aoqi@0: checkGetterSetter(JSAdapter); aoqi@0: checkGetterSetter(JSAdapter.prototype); aoqi@0: } aoqi@0: if (typeof JavaImporter != 'undefined') { aoqi@0: checkGetterSetter(JavaImporter); aoqi@0: checkGetterSetter(JavaImporter.prototype); aoqi@0: } aoqi@0: checkGetterSetter(Number); aoqi@0: checkGetterSetter(Number.prototype); aoqi@0: checkGetterSetter(Object); aoqi@0: checkGetterSetter(Object.prototype); aoqi@0: checkGetterSetter(RangeError); aoqi@0: checkGetterSetter(RangeError.prototype); aoqi@0: checkGetterSetter(ReferenceError); aoqi@0: checkGetterSetter(ReferenceError.prototype); aoqi@0: checkGetterSetter(RegExp); aoqi@0: checkGetterSetter(RegExp.prototype); aoqi@0: checkGetterSetter(String); aoqi@0: checkGetterSetter(String.prototype); aoqi@0: checkGetterSetter(SyntaxError); aoqi@0: checkGetterSetter(SyntaxError.prototype); aoqi@0: checkGetterSetter(TypeError); aoqi@0: checkGetterSetter(TypeError.prototype); aoqi@0: checkGetterSetter(URIError); aoqi@0: checkGetterSetter(URIError.prototype); aoqi@0: aoqi@0: // misc. objects aoqi@0: checkGetterSetter(this); aoqi@0: aoqi@0: if (typeof Packages != 'undefined') { aoqi@0: checkGetterSetter(Packages); aoqi@0: checkGetterSetter(java); aoqi@0: checkGetterSetter(javax); aoqi@0: } aoqi@0: aoqi@0: if (typeof Java != 'undefined') { aoqi@0: checkGetterSetter(Java); aoqi@0: checkGetterSetter(Java.prototype); aoqi@0: } aoqi@0: aoqi@0: if (typeof Debug != 'undefined') { aoqi@0: checkGetterSetter(Debug); aoqi@0: } aoqi@0: aoqi@0: checkGetterSetter((function() { return arguments; })()); aoqi@0: // TypeError expected on certain property getter/setter for strict arguments aoqi@0: checkGetterSetter((function() { 'use strict'; return arguments; })(), true); aoqi@0: checkGetterSetter(JSON); aoqi@0: checkGetterSetter(JSON.prototype); aoqi@0: checkGetterSetter(Math); aoqi@0: checkGetterSetter(Math.prototype);