nashorn/test/script/basic/allgettersetters.js
author hannesw
Fri, 03 May 2013 22:48:53 +0200
changeset 17521 0522325da5ef
parent 16151 97c1e756ae1e
child 17749 0f0fad887be7
permissions -rw-r--r--
8013873: Regexp regression for escaped dash in character class Reviewed-by: jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 * 
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * 
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * 
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
 * Exercise all setters on standard objects.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
 * @test
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    28
 * @run
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    29
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    30
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    31
function checkGetterSetter(obj, expectError) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    32
    while (obj != undefined && obj != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    33
        var properties = Object.getOwnPropertyNames(obj);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    34
        for (var i in properties) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
            var prop = properties[i];
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    36
            try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    37
                obj[prop] = obj[prop];
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
            } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
                if (!expectError || !(e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
                    fail(e + ": " + obj.toString() +"." + prop, e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    41
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    44
        obj = Object.getPrototypeOf(obj);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    45
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
// objects
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
checkGetterSetter([2, 23]);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
checkGetterSetter(new Boolean(true));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
checkGetterSetter(new Date(0));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
checkGetterSetter(new Error());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
checkGetterSetter(new EvalError());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
if (typeof JSAdapter != 'undefined') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
    checkGetterSetter(new JSAdapter({}));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    56
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    57
if (typeof JavaImporter != 'undefined') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    58
    checkGetterSetter(new JavaImporter(java.io));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    60
checkGetterSetter(function() {});
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    61
checkGetterSetter(new Number(42));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
checkGetterSetter(new Object());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
checkGetterSetter(new RangeError());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
checkGetterSetter(new ReferenceError());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    65
checkGetterSetter(/nashorn/);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    66
checkGetterSetter(new String('hello'));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
checkGetterSetter(new SyntaxError());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
checkGetterSetter(new TypeError());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
checkGetterSetter(new URIError());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
// constructors and prototypes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
checkGetterSetter(Array);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    73
checkGetterSetter(Array.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
checkGetterSetter(Boolean);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
checkGetterSetter(Boolean.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
checkGetterSetter(Error);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    77
checkGetterSetter(Error.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    78
checkGetterSetter(EvalError);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    79
checkGetterSetter(EvalError.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    80
checkGetterSetter(Function);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
checkGetterSetter(Function.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    82
if (typeof JSAdapter != 'undefined') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
    checkGetterSetter(JSAdapter);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
    checkGetterSetter(JSAdapter.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
if (typeof JavaImporter != 'undefined') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
    checkGetterSetter(JavaImporter);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
    checkGetterSetter(JavaImporter.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    89
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
checkGetterSetter(Number);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
checkGetterSetter(Number.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
checkGetterSetter(Object);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    93
checkGetterSetter(Object.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    94
checkGetterSetter(RangeError);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    95
checkGetterSetter(RangeError.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    96
checkGetterSetter(ReferenceError);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
checkGetterSetter(ReferenceError.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    98
checkGetterSetter(RegExp);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    99
checkGetterSetter(RegExp.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
checkGetterSetter(String);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   101
checkGetterSetter(String.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   102
checkGetterSetter(SyntaxError);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
checkGetterSetter(SyntaxError.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   104
checkGetterSetter(TypeError);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   105
checkGetterSetter(TypeError.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   106
checkGetterSetter(URIError);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   107
checkGetterSetter(URIError.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   108
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   109
// misc. objects
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   110
checkGetterSetter(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   111
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   112
if (typeof Packages != 'undefined') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   113
    checkGetterSetter(Packages);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   114
    checkGetterSetter(java);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
    checkGetterSetter(javax);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   117
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
if (typeof Java != 'undefined') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
    checkGetterSetter(Java);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   120
    checkGetterSetter(Java.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   122
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   123
if (typeof Debug != 'undefined') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
    checkGetterSetter(Debug);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   126
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
checkGetterSetter((function() { return arguments; })());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
// TypeError expected on certain property getter/setter for strict arguments
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
checkGetterSetter((function() { 'use strict'; return arguments; })(), true);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   130
checkGetterSetter(JSON);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   131
checkGetterSetter(JSON.prototype);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   132
checkGetterSetter(Math);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   133
checkGetterSetter(Math.prototype);