< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java

Print this page




1751             this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class);
1752         }
1753         return this.builtinFloat32Array;
1754     }
1755 
1756     ScriptObject getFloat32ArrayPrototype() {
1757         return ScriptFunction.getPrototype(getBuiltinFloat32Array());
1758     }
1759 
1760     private synchronized ScriptFunction getBuiltinFloat64Array() {
1761         if (this.builtinFloat64Array == null) {
1762             this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class);
1763         }
1764         return this.builtinFloat64Array;
1765     }
1766 
1767     ScriptObject getFloat64ArrayPrototype() {
1768         return ScriptFunction.getPrototype(getBuiltinFloat64Array());
1769     }
1770 
1771     private ScriptFunction getBuiltinArray() {
1772         return builtinArray;
1773     }
1774 
1775     ScriptFunction getTypeErrorThrower() {
1776         return typeErrorThrower;
1777     }
1778 
1779     /**
1780      * Called from compiled script code to test if builtin has been overridden
1781      *
1782      * @return true if builtin array has not been overridden
1783      */
1784     public static boolean isBuiltinArray() {
1785         final Global instance = Global.instance();
1786         return instance.array == instance.getBuiltinArray();
1787     }
1788 
1789     private ScriptFunction getBuiltinBoolean() {
1790         return builtinBoolean;
1791     }
1792 
1793     /**
1794      * Called from compiled script code to test if builtin has been overridden
1795      *
1796      * @return true if builtin boolean has not been overridden
1797      */
1798     public static boolean isBuiltinBoolean() {
1799         final Global instance = Global.instance();
1800         return instance._boolean == instance.getBuiltinBoolean();
1801     }
1802 
1803     private synchronized ScriptFunction getBuiltinDate() {
1804         if (this.builtinDate == null) {
1805             this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class);
1806             final ScriptObject dateProto = ScriptFunction.getPrototype(builtinDate);
1807             // initialize default date
1808             this.DEFAULT_DATE = new NativeDate(NaN, dateProto);
1809         }
1810         return this.builtinDate;
1811     }
1812 
1813     /**
1814      * Called from compiled script code to test if builtin has been overridden
1815      *
1816      * @return true if builtin date has not been overridden
1817      */
1818     public static boolean isBuiltinDate() {
1819         final Global instance = Global.instance();
1820         return instance.date == LAZY_SENTINEL || instance.date == instance.getBuiltinDate();
1821     }
1822 
1823     private ScriptFunction getBuiltinError() {
1824         return builtinError;
1825     }
1826 
1827     /**
1828      * Called from compiled script code to test if builtin has been overridden
1829      *
1830      * @return true if builtin error has not been overridden
1831      */
1832     public static boolean isBuiltinError() {
1833         final Global instance = Global.instance();
1834         return instance.error == instance.getBuiltinError();
1835     }
1836 
1837     private synchronized ScriptFunction getBuiltinEvalError() {
1838         if (this.builtinEvalError == null) {
1839             this.builtinEvalError = initErrorSubtype("EvalError", getErrorPrototype());
1840         }
1841         return this.builtinEvalError;
1842     }
1843 
1844     /**
1845      * Called from compiled script code to test if builtin has been overridden
1846      *
1847      * @return true if builtin eval error has not been overridden
1848      */
1849     public static boolean isBuiltinEvalError() {
1850         final Global instance = Global.instance();
1851         return instance.evalError == LAZY_SENTINEL || instance.evalError == instance.getBuiltinEvalError();
1852     }
1853 
1854     private ScriptFunction getBuiltinFunction() {
1855         return builtinFunction;
1856     }
1857 
1858     /**
1859      * Called from compiled script code to test if builtin has been overridden
1860      *
1861      * @return true if builtin function has not been overridden
1862      */
1863     public static boolean isBuiltinFunction() {
1864         final Global instance = Global.instance();
1865         return instance.function == instance.getBuiltinFunction();
1866     }
1867 
1868     /**
1869      * Get the switchpoint used to check property changes for Function.prototype.apply
1870      * @return the switchpoint guarding apply (same as guarding call, and everything else in function)
1871      */
1872     public static SwitchPoint getBuiltinFunctionApplySwitchPoint() {
1873         return ScriptFunction.getPrototype(Global.instance().getBuiltinFunction()).getProperty("apply").getBuiltinSwitchPoint();
1874     }
1875 
1876     private static boolean isBuiltinFunctionProperty(final String name) {
1877         final Global instance = Global.instance();
1878         final ScriptFunction builtinFunction = instance.getBuiltinFunction();
1879         if (builtinFunction == null) {
1880             return false; //conservative for compile-only mode
1881         }
1882         final boolean isBuiltinFunction = instance.function == builtinFunction;
1883         return isBuiltinFunction && ScriptFunction.getPrototype(builtinFunction).getProperty(name).isBuiltin();
1884     }
1885 
1886     /**
1887      * Check if the Function.prototype.apply has not been replaced
1888      * @return true if Function.prototype.apply has been replaced
1889      */
1890     public static boolean isBuiltinFunctionPrototypeApply() {
1891         return isBuiltinFunctionProperty("apply");
1892     }
1893 
1894     /**
1895      * Check if the Function.prototype.apply has not been replaced
1896      * @return true if Function.prototype.call has been replaced
1897      */
1898     public static boolean isBuiltinFunctionPrototypeCall() {
1899         return isBuiltinFunctionProperty("call");
1900     }
1901 
1902     private synchronized ScriptFunction getBuiltinJSAdapter() {
1903         if (this.builtinJSAdapter == null) {
1904             this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class);
1905         }
1906         return builtinJSAdapter;
1907     }
1908 
1909     /**
1910      * Called from compiled script code to test if builtin has been overridden
1911      *
1912      * @return true if builtin JSAdapter has not been overridden
1913      */
1914     public static boolean isBuiltinJSAdapter() {
1915         final Global instance = Global.instance();
1916         return instance.jsadapter == LAZY_SENTINEL || instance.jsadapter == instance.getBuiltinJSAdapter();
1917     }
1918 
1919     private synchronized ScriptObject getBuiltinJSON() {
1920         if (this.builtinJSON == null) {
1921             this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class);
1922         }
1923         return this.builtinJSON;
1924     }
1925 
1926     /**
1927      * Called from compiled script code to test if builtin has been overridden
1928      *
1929      * @return true if builtin JSON has has not been overridden
1930      */
1931     public static boolean isBuiltinJSON() {
1932         final Global instance = Global.instance();
1933         return instance.json == LAZY_SENTINEL || instance.json == instance.getBuiltinJSON();
1934     }
1935 
1936     private ScriptObject getBuiltinJava() {
1937         return builtinJava;
1938     }
1939 
1940     /**
1941      * Called from compiled script code to test if builtin has been overridden
1942      *
1943      * @return true if builtin Java has not been overridden
1944      */
1945     public static boolean isBuiltinJava() {
1946         final Global instance = Global.instance();
1947         return instance.java == instance.getBuiltinJava();
1948     }
1949 
1950     private ScriptObject getBuiltinJavax() {
1951         return builtinJavax;
1952     }
1953 
1954     /**
1955      * Called from compiled script code to test if builtin has been overridden
1956      *
1957      * @return true if builtin Javax has not been overridden
1958      */
1959     public static boolean isBuiltinJavax() {
1960         final Global instance = Global.instance();
1961         return instance.javax == instance.getBuiltinJavax();
1962     }
1963 
1964     private synchronized ScriptFunction getBuiltinJavaImporter() {
1965         if (this.builtinJavaImporter == null) {
1966             this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
1967         }
1968         return this.builtinJavaImporter;
1969     }
1970 
1971     private synchronized ScriptObject getBuiltinJavaApi() {
1972         if (this.builtinJavaApi == null) {
1973             this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
1974         }
1975         return this.builtinJavaApi;
1976     }
1977 
1978     /**
1979      * Called from compiled script code to test if builtin has been overridden
1980      *
1981      * @return true if builtin Java importer has not been overridden
1982      */
1983     public static boolean isBuiltinJavaImporter() {
1984         final Global instance = Global.instance();
1985         return instance.javaImporter == LAZY_SENTINEL || instance.javaImporter == instance.getBuiltinJavaImporter();
1986     }
1987 
1988     /**
1989      * Called from compiled script code to test if builtin has been overridden
1990      *
1991      * @return true if builtin math has not been overridden
1992      */
1993     public static boolean isBuiltinMath() {
1994         final Global instance = Global.instance();
1995         return instance.math == instance.builtinMath;
1996     }
1997 
1998     private ScriptFunction getBuiltinNumber() {
1999         return builtinNumber;
2000     }
2001 
2002     /**
2003      * Called from compiled script code to test if builtin has been overridden
2004      *
2005      * @return true if builtin number has not been overridden
2006      */
2007     public static boolean isBuiltinNumber() {
2008         final Global instance = Global.instance();
2009         return instance.number == instance.getBuiltinNumber();
2010     }
2011 
2012     private ScriptFunction getBuiltinObject() {
2013         return builtinObject;
2014     }
2015 
2016     /**
2017      * Called from compiled script code to test if builtin has been overridden
2018      *
2019      * @return true if builtin object has not been overridden
2020      */
2021     public static boolean isBuiltinObject() {
2022         final Global instance = Global.instance();
2023         return instance.object == instance.getBuiltinObject();
2024     }
2025 
2026     private ScriptObject getBuiltinPackages() {
2027         return builtinPackages;
2028     }
2029 
2030     /**
2031      * Called from compiled script code to test if builtin has been overridden
2032      *
2033      * @return true if builtin package has not been overridden
2034      */
2035     public static boolean isBuiltinPackages() {
2036         final Global instance = Global.instance();
2037         return instance.packages == instance.getBuiltinPackages();
2038     }
2039 
2040     private synchronized ScriptFunction getBuiltinRangeError() {
2041         if (this.builtinRangeError == null) {
2042             this.builtinRangeError = initErrorSubtype("RangeError", getErrorPrototype());
2043         }
2044         return builtinRangeError;
2045     }
2046 
2047     /**
2048      * Called from compiled script code to test if builtin has been overridden
2049      *
2050      * @return true if builtin range error has not been overridden
2051      */
2052     public static boolean isBuiltinRangeError() {
2053         final Global instance = Global.instance();
2054         return instance.rangeError == LAZY_SENTINEL || instance.rangeError == instance.getBuiltinRangeError();
2055     }
2056 
2057     private synchronized ScriptFunction getBuiltinReferenceError() {
2058         return builtinReferenceError;
2059     }
2060 
2061     /**
2062      * Called from compiled script code to test if builtin has been overridden
2063      *
2064      * @return true if builtin reference error has not been overridden
2065      */
2066     public static boolean isBuiltinReferenceError() {
2067         final Global instance = Global.instance();
2068         return instance.referenceError == instance.getBuiltinReferenceError();
2069     }
2070 
2071     private synchronized ScriptFunction getBuiltinRegExp() {
2072         if (this.builtinRegExp == null) {
2073             this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
2074             final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
2075             // initialize default regexp object
2076             this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
2077             // RegExp.prototype should behave like a RegExp object. So copy the
2078             // properties.
2079             regExpProto.addBoundProperties(DEFAULT_REGEXP);
2080         }
2081         return builtinRegExp;
2082     }
2083 
2084     /**
2085      * Called from compiled script code to test if builtin has been overridden
2086      *
2087      * @return true if builtin regexp has not been overridden
2088      */
2089     public static boolean isBuiltinRegExp() {
2090         final Global instance = Global.instance();
2091         return instance.regexp == LAZY_SENTINEL || instance.regexp == instance.getBuiltinRegExp();
2092     }
2093 
2094     private ScriptFunction getBuiltinString() {
2095         return builtinString;
2096     }
2097 
2098     /**
2099      * Called from compiled script code to test if builtin has been overridden
2100      *
2101      * @return true if builtin Java has not been overridden
2102      */
2103     public static boolean isBuiltinString() {
2104         final Global instance = Global.instance();
2105         return instance.string == instance.getBuiltinString();
2106     }
2107 
2108     private ScriptFunction getBuiltinSyntaxError() {
2109         return builtinSyntaxError;
2110     }
2111 
2112     /**
2113      * Called from compiled script code to test if builtin has been overridden
2114      *
2115      * @return true if builtin syntax error has not been overridden
2116      */
2117     public static boolean isBuiltinSyntaxError() {
2118         final Global instance = Global.instance();
2119         return instance.syntaxError == instance.getBuiltinSyntaxError();
2120     }
2121 
2122     private ScriptFunction getBuiltinTypeError() {
2123         return builtinTypeError;
2124     }
2125 
2126     /**
2127      * Called from compiled script code to test if builtin has been overridden
2128      *
2129      * @return true if builtin type error has not been overridden
2130      */
2131     public static boolean isBuiltinTypeError() {
2132         final Global instance = Global.instance();
2133         return instance.typeError == instance.getBuiltinTypeError();
2134     }
2135 
2136     private synchronized ScriptFunction getBuiltinURIError() {
2137         if (this.builtinURIError == null) {
2138             this.builtinURIError = initErrorSubtype("URIError", getErrorPrototype());
2139         }
2140         return this.builtinURIError;
2141     }
2142 
2143     /**
2144      * Called from compiled script code to test if builtin has been overridden
2145      *
2146      * @return true if builtin URI error has not been overridden
2147      */
2148     public static boolean isBuiltinURIError() {
2149         final Global instance = Global.instance();
2150         return instance.uriError == LAZY_SENTINEL || instance.uriError == instance.getBuiltinURIError();
2151     }
2152 
2153     @Override
2154     public String getClassName() {
2155         return "global";
2156     }
2157 
2158     /**
2159      * Copy function used to clone NativeRegExp objects.
2160      *
2161      * @param regexp a NativeRegExp to clone
2162      *
2163      * @return copy of the given regexp object
2164      */
2165     public static Object regExpCopy(final Object regexp) {
2166         return new NativeRegExp((NativeRegExp)regexp);
2167     }
2168 
2169     /**
2170      * Convert given object to NativeRegExp type.




1751             this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class);
1752         }
1753         return this.builtinFloat32Array;
1754     }
1755 
1756     ScriptObject getFloat32ArrayPrototype() {
1757         return ScriptFunction.getPrototype(getBuiltinFloat32Array());
1758     }
1759 
1760     private synchronized ScriptFunction getBuiltinFloat64Array() {
1761         if (this.builtinFloat64Array == null) {
1762             this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class);
1763         }
1764         return this.builtinFloat64Array;
1765     }
1766 
1767     ScriptObject getFloat64ArrayPrototype() {
1768         return ScriptFunction.getPrototype(getBuiltinFloat64Array());
1769     }
1770 




1771     ScriptFunction getTypeErrorThrower() {
1772         return typeErrorThrower;
1773     }
1774 
























1775     private synchronized ScriptFunction getBuiltinDate() {
1776         if (this.builtinDate == null) {
1777             this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class);
1778             final ScriptObject dateProto = ScriptFunction.getPrototype(builtinDate);
1779             // initialize default date
1780             this.DEFAULT_DATE = new NativeDate(NaN, dateProto);
1781         }
1782         return this.builtinDate;
1783     }
1784 
























1785     private synchronized ScriptFunction getBuiltinEvalError() {
1786         if (this.builtinEvalError == null) {
1787             this.builtinEvalError = initErrorSubtype("EvalError", getErrorPrototype());
1788         }
1789         return this.builtinEvalError;
1790     }
1791 










1792     private ScriptFunction getBuiltinFunction() {
1793         return builtinFunction;
1794     }
1795 
1796     /**










1797      * Get the switchpoint used to check property changes for Function.prototype.apply
1798      * @return the switchpoint guarding apply (same as guarding call, and everything else in function)
1799      */
1800     public static SwitchPoint getBuiltinFunctionApplySwitchPoint() {
1801         return ScriptFunction.getPrototype(Global.instance().getBuiltinFunction()).getProperty("apply").getBuiltinSwitchPoint();
1802     }
1803 
1804     private static boolean isBuiltinFunctionProperty(final String name) {
1805         final Global instance = Global.instance();
1806         final ScriptFunction builtinFunction = instance.getBuiltinFunction();
1807         if (builtinFunction == null) {
1808             return false; //conservative for compile-only mode
1809         }
1810         final boolean isBuiltinFunction = instance.function == builtinFunction;
1811         return isBuiltinFunction && ScriptFunction.getPrototype(builtinFunction).getProperty(name).isBuiltin();
1812     }
1813 
1814     /**
1815      * Check if the Function.prototype.apply has not been replaced
1816      * @return true if Function.prototype.apply has been replaced
1817      */
1818     public static boolean isBuiltinFunctionPrototypeApply() {
1819         return isBuiltinFunctionProperty("apply");
1820     }
1821 
1822     /**
1823      * Check if the Function.prototype.apply has not been replaced
1824      * @return true if Function.prototype.call has been replaced
1825      */
1826     public static boolean isBuiltinFunctionPrototypeCall() {
1827         return isBuiltinFunctionProperty("call");
1828     }
1829 
1830     private synchronized ScriptFunction getBuiltinJSAdapter() {
1831         if (this.builtinJSAdapter == null) {
1832             this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class);
1833         }
1834         return builtinJSAdapter;
1835     }
1836     










1837     private synchronized ScriptObject getBuiltinJSON() {
1838         if (this.builtinJSON == null) {
1839             this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class);
1840         }
1841         return this.builtinJSON;
1842     }
1843 






































1844     private synchronized ScriptFunction getBuiltinJavaImporter() {
1845         if (this.builtinJavaImporter == null) {
1846             this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
1847         }
1848         return this.builtinJavaImporter;
1849     }
1850 
1851     private synchronized ScriptObject getBuiltinJavaApi() {
1852         if (this.builtinJavaApi == null) {
1853             this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
1854         }
1855         return this.builtinJavaApi;
1856     }
1857 






























































1858     private synchronized ScriptFunction getBuiltinRangeError() {
1859         if (this.builtinRangeError == null) {
1860             this.builtinRangeError = initErrorSubtype("RangeError", getErrorPrototype());
1861         }
1862         return builtinRangeError;
1863     }
1864 
























1865     private synchronized ScriptFunction getBuiltinRegExp() {
1866         if (this.builtinRegExp == null) {
1867             this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
1868             final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
1869             // initialize default regexp object
1870             this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
1871             // RegExp.prototype should behave like a RegExp object. So copy the
1872             // properties.
1873             regExpProto.addBoundProperties(DEFAULT_REGEXP);
1874         }
1875         return builtinRegExp;
1876     }
1877 




















































1878     private synchronized ScriptFunction getBuiltinURIError() {
1879         if (this.builtinURIError == null) {
1880             this.builtinURIError = initErrorSubtype("URIError", getErrorPrototype());
1881         }
1882         return this.builtinURIError;










1883     }
1884 
1885     @Override
1886     public String getClassName() {
1887         return "global";
1888     }
1889 
1890     /**
1891      * Copy function used to clone NativeRegExp objects.
1892      *
1893      * @param regexp a NativeRegExp to clone
1894      *
1895      * @return copy of the given regexp object
1896      */
1897     public static Object regExpCopy(final Object regexp) {
1898         return new NativeRegExp((NativeRegExp)regexp);
1899     }
1900 
1901     /**
1902      * Convert given object to NativeRegExp type.


< prev index next >