1 /*
   2  * Copyright (c) 2010, 2013, 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 
  31 print(undefined);
  32 print(typeof(undefined));
  33 print(NaN);
  34 print(typeof(NaN));
  35 print(Infinity);
  36 print(typeof(Infinity));
  37 print(isNaN(NaN));
  38 print(isNaN(1.0));
  39 print(isNaN(0.0));
  40 print(isNaN(Infinity));
  41 print(isFinite(Math.PI));
  42 print(isFinite(Infinity));
  43 print(isFinite(NaN));
  44 print(parseInt("4345"));
  45 print(parseInt("100", 8));
  46 print(parseInt("ffff", 16));
  47 print(parseInt("0xffff"));
  48 print(parseInt("0xffff", 16));
  49 print(parseInt("0xffff", 8)); // should be NaN
  50 print(parseInt("")); // should be NaN
  51 print(parseInt("-")); // should be NaN
  52 print(parseInt("+")); // should be NaN
  53 print(parseInt("0x")); // should be NaN
  54 print(parseInt("0X")); // should be NaN
  55 print(parseInt("3.1415")); // should be "3" - ignore the not understood part
  56 print(parseInt("5654gjhkgjdfgk")); // should be "5654" - ignore invalid tail chars
  57 
  58 print(parseFloat("-Infinity"));
  59 print(parseFloat("+Infinity"));
  60 print(parseFloat("+3.14"));
  61 print(parseFloat("-3.14"));
  62 print(parseFloat("2.9e+8"));
  63 print(parseFloat("6.62E-34"));
  64 
  65 (function() {
  66 
  67 function 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 
  80 checkProtoImmutable("Array");
  81 checkProtoImmutable("Boolean");
  82 checkProtoImmutable("Date");
  83 checkProtoImmutable("Function");
  84 checkProtoImmutable("Number");
  85 checkProtoImmutable("Object");
  86 checkProtoImmutable("RegExp");
  87 checkProtoImmutable("String");
  88 
  89 })();
  90 
  91 // none of the built-in global properties are enumerable
  92 for (i in this) {
  93     print(i);
  94 }