aboutsummaryrefslogtreecommitdiff
path: root/test/script/basic/globals.js
blob: b3acfe28c491b49efe1c6c8ec4072e5a85a90654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/**
 * Check global functions and properties.
 *
 * @test
 * @run
 */

print(undefined);
print(typeof(undefined));
print(NaN);
print(typeof(NaN));
print(Infinity);
print(typeof(Infinity));
print(isNaN(NaN));
print(isNaN(1.0));
print(isNaN(0.0));
print(isNaN(Infinity));
print(isFinite(Math.PI));
print(isFinite(Infinity));
print(isFinite(NaN));
print(parseInt("4345"));
print(parseInt("100", 8));
print(parseInt("ffff", 16));
print(parseInt("0xffff"));
print(parseInt("0xffff", 16));
print(parseInt("0xffff", 8)); // should be NaN
print(parseInt("")); // should be NaN
print(parseInt("-")); // should be NaN
print(parseInt("+")); // should be NaN
print(parseInt("0x")); // should be NaN
print(parseInt("0X")); // should be NaN
print(parseInt("3.1415")); // should be "3" - ignore the not understood part
print(parseInt("5654gjhkgjdfgk")); // should be "5654" - ignore invalid tail chars

print(parseFloat("-Infinity"));
print(parseFloat("+Infinity"));
print(parseFloat("+3.14"));
print(parseFloat("-3.14"));
print(parseFloat("2.9e+8"));
print(parseFloat("6.62E-34"));

(function() {

function checkProtoImmutable(obj) {
    var attr = Object.getOwnPropertyDescriptor(this[obj], "prototype");
    if (attr.writable) {
        throw new Error(obj + ".prototype writable");
    }
    if (attr.enumerable) {
        throw new Error(obj + ".prototype enumerable");
    }
    if (attr.configurable) {
        throw new Error(obj + ".prototype configurable");
    }
}

checkProtoImmutable("Array");
checkProtoImmutable("Boolean");
checkProtoImmutable("Date");
checkProtoImmutable("Function");
checkProtoImmutable("Number");
checkProtoImmutable("Object");
checkProtoImmutable("RegExp");
checkProtoImmutable("String");

})();

// none of the built-in global properties are enumerable
for (i in this) {
    print(i);
}