globals.js revision 2:da1e581c933b
1/*
2 * Copyright (c) 2010, 2012, 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 * Check global functions and properties.
26 *
27 * @test
28 * @run
29 */
30
31print(undefined);
32print(typeof(undefined));
33print(NaN);
34print(typeof(NaN));
35print(Infinity);
36print(typeof(Infinity));
37print(isNaN(NaN));
38print(isNaN(1.0));
39print(isNaN(0.0));
40print(isNaN(Infinity));
41print(isFinite(Math.PI));
42print(isFinite(Infinity));
43print(isFinite(NaN));
44print(parseInt("4345"));
45print(parseInt("100", 8));
46print(parseInt("ffff", 16));
47print(parseInt("0xffff"));
48print(parseInt("0xffff", 16));
49print(parseInt("0xffff", 8)); // should be NaN
50print(parseInt("")); // should be NaN
51print(parseInt("-")); // should be NaN
52print(parseInt("+")); // should be NaN
53print(parseInt("0x")); // should be NaN
54print(parseInt("0X")); // should be NaN
55print(parseInt("3.1415")); // should be "3" - ignore the not understood part
56print(parseInt("5654gjhkgjdfgk")); // should be "5654" - ignore invalid tail chars
57
58print(parseFloat("-Infinity"));
59print(parseFloat("+Infinity"));
60print(parseFloat("+3.14"));
61print(parseFloat("-3.14"));
62print(parseFloat("2.9e+8"));
63print(parseFloat("6.62E-34"));
64
65(function() {
66
67function checkProtoImmutable(obj) {
68    var attr = Object.getOwnPropertyDescriptor(this[obj], "prototype");
69    if (attr.writable) {
70        throw new Error(obj + ".prototype writable");
71    }
72    if (attr.enumerable) {
73        throw new Error(obj + ".prototype enumerable");
74    }
75    if (attr.configurable) {
76        throw new Error(obj + ".prototype configurable");
77    }
78}
79
80checkProtoImmutable("Array");
81checkProtoImmutable("Boolean");
82checkProtoImmutable("Date");
83checkProtoImmutable("Function");
84checkProtoImmutable("Number");
85checkProtoImmutable("Object");
86checkProtoImmutable("RegExp");
87checkProtoImmutable("String");
88
89})();
90
91// none of the built-in global properties are enumerable
92for (i in this) {
93    print(i);
94}
95