rt/emul/mini/src/main/java/java/lang/Class.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 31 Aug 2014 22:36:54 +0200
changeset 1676 87f66a77adf9
parent 1634 783acbc99199
child 1688 e709c530c227
permissions -rw-r--r--
Adopting to new names of SPI packages to be introduced by version 1.0 of html4j API
     1 /*
     2  * Copyright (c) 1994, 2010, 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 
    26 package java.lang;
    27 
    28 import java.io.ByteArrayInputStream;
    29 import java.io.InputStream;
    30 import java.lang.annotation.Annotation;
    31 import java.lang.reflect.Array;
    32 import java.lang.reflect.Constructor;
    33 import java.lang.reflect.Field;
    34 import java.lang.reflect.Method;
    35 import java.lang.reflect.TypeVariable;
    36 import java.net.URL;
    37 import org.apidesign.bck2brwsr.core.Exported;
    38 import org.apidesign.bck2brwsr.core.JavaScriptBody;
    39 import org.apidesign.bck2brwsr.core.JavaScriptOnly;
    40 import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
    41 import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
    42 
    43 /**
    44  * Instances of the class {@code Class} represent classes and
    45  * interfaces in a running Java application.  An enum is a kind of
    46  * class and an annotation is a kind of interface.  Every array also
    47  * belongs to a class that is reflected as a {@code Class} object
    48  * that is shared by all arrays with the same element type and number
    49  * of dimensions.  The primitive Java types ({@code boolean},
    50  * {@code byte}, {@code char}, {@code short},
    51  * {@code int}, {@code long}, {@code float}, and
    52  * {@code double}), and the keyword {@code void} are also
    53  * represented as {@code Class} objects.
    54  *
    55  * <p> {@code Class} has no public constructor. Instead {@code Class}
    56  * objects are constructed automatically by the Java Virtual Machine as classes
    57  * are loaded and by calls to the {@code defineClass} method in the class
    58  * loader.
    59  *
    60  * <p> The following example uses a {@code Class} object to print the
    61  * class name of an object:
    62  *
    63  * <p> <blockquote><pre>
    64  *     void printClassName(Object obj) {
    65  *         System.out.println("The class of " + obj +
    66  *                            " is " + obj.getClass().getName());
    67  *     }
    68  * </pre></blockquote>
    69  *
    70  * <p> It is also possible to get the {@code Class} object for a named
    71  * type (or for void) using a class literal.  See Section 15.8.2 of
    72  * <cite>The Java&trade; Language Specification</cite>.
    73  * For example:
    74  *
    75  * <p> <blockquote>
    76  *     {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
    77  * </blockquote>
    78  *
    79  * @param <T> the type of the class modeled by this {@code Class}
    80  * object.  For example, the type of {@code String.class} is {@code
    81  * Class<String>}.  Use {@code Class<?>} if the class being modeled is
    82  * unknown.
    83  *
    84  * @author  unascribed
    85  * @see     java.lang.ClassLoader#defineClass(byte[], int, int)
    86  * @since   JDK1.0
    87  */
    88 public final
    89     class Class<T> implements java.io.Serializable,
    90                               java.lang.reflect.GenericDeclaration,
    91                               java.lang.reflect.Type,
    92                               java.lang.reflect.AnnotatedElement {
    93     private static final int ANNOTATION= 0x00002000;
    94     private static final int ENUM      = 0x00004000;
    95     private static final int SYNTHETIC = 0x00001000;
    96 
    97     /*
    98      * Constructor. Only the Java Virtual Machine creates Class
    99      * objects.
   100      */
   101     private Class() {}
   102 
   103 
   104     /**
   105      * Converts the object to a string. The string representation is the
   106      * string "class" or "interface", followed by a space, and then by the
   107      * fully qualified name of the class in the format returned by
   108      * {@code getName}.  If this {@code Class} object represents a
   109      * primitive type, this method returns the name of the primitive type.  If
   110      * this {@code Class} object represents void this method returns
   111      * "void".
   112      *
   113      * @return a string representation of this class object.
   114      */
   115     public String toString() {
   116         return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
   117             + getName();
   118     }
   119 
   120 
   121     /**
   122      * Returns the {@code Class} object associated with the class or
   123      * interface with the given string name.  Invoking this method is
   124      * equivalent to:
   125      *
   126      * <blockquote>
   127      *  {@code Class.forName(className, true, currentLoader)}
   128      * </blockquote>
   129      *
   130      * where {@code currentLoader} denotes the defining class loader of
   131      * the current class.
   132      *
   133      * <p> For example, the following code fragment returns the
   134      * runtime {@code Class} descriptor for the class named
   135      * {@code java.lang.Thread}:
   136      *
   137      * <blockquote>
   138      *   {@code Class t = Class.forName("java.lang.Thread")}
   139      * </blockquote>
   140      * <p>
   141      * A call to {@code forName("X")} causes the class named
   142      * {@code X} to be initialized.
   143      *
   144      * @param      className   the fully qualified name of the desired class.
   145      * @return     the {@code Class} object for the class with the
   146      *             specified name.
   147      * @exception LinkageError if the linkage fails
   148      * @exception ExceptionInInitializerError if the initialization provoked
   149      *            by this method fails
   150      * @exception ClassNotFoundException if the class cannot be located
   151      */
   152     public static Class<?> forName(String className)
   153     throws ClassNotFoundException {
   154         if (className.startsWith("[")) {
   155             Class<?> arrType = defineArray(className, null);
   156             Class<?> c = arrType;
   157             while (c != null && c.isArray()) {
   158                 c = c.getComponentType0(); // verify component type is sane
   159             }
   160             return arrType;
   161         }
   162         try {
   163             Class<?> c = loadCls(className, className.replace('.', '_'));
   164             if (c == null) {
   165                 throw new ClassNotFoundException(className);
   166             }
   167             return c;
   168         } catch (Throwable ex) {
   169             throw new ClassNotFoundException(className, ex);
   170         }
   171     }
   172 
   173 
   174     /**
   175      * Returns the {@code Class} object associated with the class or
   176      * interface with the given string name, using the given class loader.
   177      * Given the fully qualified name for a class or interface (in the same
   178      * format returned by {@code getName}) this method attempts to
   179      * locate, load, and link the class or interface.  The specified class
   180      * loader is used to load the class or interface.  If the parameter
   181      * {@code loader} is null, the class is loaded through the bootstrap
   182      * class loader.  The class is initialized only if the
   183      * {@code initialize} parameter is {@code true} and if it has
   184      * not been initialized earlier.
   185      *
   186      * <p> If {@code name} denotes a primitive type or void, an attempt
   187      * will be made to locate a user-defined class in the unnamed package whose
   188      * name is {@code name}. Therefore, this method cannot be used to
   189      * obtain any of the {@code Class} objects representing primitive
   190      * types or void.
   191      *
   192      * <p> If {@code name} denotes an array class, the component type of
   193      * the array class is loaded but not initialized.
   194      *
   195      * <p> For example, in an instance method the expression:
   196      *
   197      * <blockquote>
   198      *  {@code Class.forName("Foo")}
   199      * </blockquote>
   200      *
   201      * is equivalent to:
   202      *
   203      * <blockquote>
   204      *  {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
   205      * </blockquote>
   206      *
   207      * Note that this method throws errors related to loading, linking or
   208      * initializing as specified in Sections 12.2, 12.3 and 12.4 of <em>The
   209      * Java Language Specification</em>.
   210      * Note that this method does not check whether the requested class
   211      * is accessible to its caller.
   212      *
   213      * <p> If the {@code loader} is {@code null}, and a security
   214      * manager is present, and the caller's class loader is not null, then this
   215      * method calls the security manager's {@code checkPermission} method
   216      * with a {@code RuntimePermission("getClassLoader")} permission to
   217      * ensure it's ok to access the bootstrap class loader.
   218      *
   219      * @param name       fully qualified name of the desired class
   220      * @param initialize whether the class must be initialized
   221      * @param loader     class loader from which the class must be loaded
   222      * @return           class object representing the desired class
   223      *
   224      * @exception LinkageError if the linkage fails
   225      * @exception ExceptionInInitializerError if the initialization provoked
   226      *            by this method fails
   227      * @exception ClassNotFoundException if the class cannot be located by
   228      *            the specified class loader
   229      *
   230      * @see       java.lang.Class#forName(String)
   231      * @see       java.lang.ClassLoader
   232      * @since     1.2
   233      */
   234     public static Class<?> forName(String name, boolean initialize,
   235                                    ClassLoader loader)
   236         throws ClassNotFoundException
   237     {
   238         return forName(name);
   239     }
   240     
   241     @JavaScriptBody(args = {"n", "c" }, body =
   242         "var m = vm[c];\n"
   243       + "if (!m) {\n"
   244       + "  var l = vm.loadClass ? vm.loadClass : exports ? exports.loadClass : null;\n"
   245       + "  if (l) {\n"
   246       + "    l(n);\n"
   247       + "  }\n"
   248       + "  if (vm[c]) m = vm[c];\n"
   249       + "  else if (exports[c]) m = exports[c];\n"
   250       + "}\n"
   251       + "if (!m) return null;"
   252       + "m(false);"
   253       + "return m.$class;"
   254     )
   255     private static native Class<?> loadCls(String n, String c);
   256 
   257 
   258     /**
   259      * Creates a new instance of the class represented by this {@code Class}
   260      * object.  The class is instantiated as if by a {@code new}
   261      * expression with an empty argument list.  The class is initialized if it
   262      * has not already been initialized.
   263      *
   264      * <p>Note that this method propagates any exception thrown by the
   265      * nullary constructor, including a checked exception.  Use of
   266      * this method effectively bypasses the compile-time exception
   267      * checking that would otherwise be performed by the compiler.
   268      * The {@link
   269      * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
   270      * Constructor.newInstance} method avoids this problem by wrapping
   271      * any exception thrown by the constructor in a (checked) {@link
   272      * java.lang.reflect.InvocationTargetException}.
   273      *
   274      * @return     a newly allocated instance of the class represented by this
   275      *             object.
   276      * @exception  IllegalAccessException  if the class or its nullary
   277      *               constructor is not accessible.
   278      * @exception  InstantiationException
   279      *               if this {@code Class} represents an abstract class,
   280      *               an interface, an array class, a primitive type, or void;
   281      *               or if the class has no nullary constructor;
   282      *               or if the instantiation fails for some other reason.
   283      * @exception  ExceptionInInitializerError if the initialization
   284      *               provoked by this method fails.
   285      * @exception  SecurityException
   286      *             If a security manager, <i>s</i>, is present and any of the
   287      *             following conditions is met:
   288      *
   289      *             <ul>
   290      *
   291      *             <li> invocation of
   292      *             {@link SecurityManager#checkMemberAccess
   293      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   294      *             creation of new instances of this class
   295      *
   296      *             <li> the caller's class loader is not the same as or an
   297      *             ancestor of the class loader for the current class and
   298      *             invocation of {@link SecurityManager#checkPackageAccess
   299      *             s.checkPackageAccess()} denies access to the package
   300      *             of this class
   301      *
   302      *             </ul>
   303      *
   304      */
   305     @JavaScriptBody(args = { "self", "illegal" }, body =
   306           "\nvar c = self.cnstr;"
   307         + "\nif (c['cons__V']) {"
   308         + "\n  if ((c['cons__V'].access & 0x1) != 0) {"
   309         + "\n    var inst = c();"
   310         + "\n    c['cons__V'].call(inst);"
   311         + "\n    return inst;"
   312         + "\n  }"
   313         + "\n  return illegal;"
   314         + "\n}"
   315         + "\nreturn null;"
   316     )
   317     private static native Object newInstance0(Class<?> self, Object illegal);
   318     
   319     public T newInstance()
   320         throws InstantiationException, IllegalAccessException
   321     {
   322         Object illegal = new Object();
   323         Object inst = newInstance0(this, illegal);
   324         if (inst == null) {
   325             throw new InstantiationException(getName());
   326         }
   327         if (inst == illegal) {
   328             throw new IllegalAccessException();
   329         }
   330         return (T)inst;
   331     }
   332 
   333     /**
   334      * Determines if the specified {@code Object} is assignment-compatible
   335      * with the object represented by this {@code Class}.  This method is
   336      * the dynamic equivalent of the Java language {@code instanceof}
   337      * operator. The method returns {@code true} if the specified
   338      * {@code Object} argument is non-null and can be cast to the
   339      * reference type represented by this {@code Class} object without
   340      * raising a {@code ClassCastException.} It returns {@code false}
   341      * otherwise.
   342      *
   343      * <p> Specifically, if this {@code Class} object represents a
   344      * declared class, this method returns {@code true} if the specified
   345      * {@code Object} argument is an instance of the represented class (or
   346      * of any of its subclasses); it returns {@code false} otherwise. If
   347      * this {@code Class} object represents an array class, this method
   348      * returns {@code true} if the specified {@code Object} argument
   349      * can be converted to an object of the array class by an identity
   350      * conversion or by a widening reference conversion; it returns
   351      * {@code false} otherwise. If this {@code Class} object
   352      * represents an interface, this method returns {@code true} if the
   353      * class or any superclass of the specified {@code Object} argument
   354      * implements this interface; it returns {@code false} otherwise. If
   355      * this {@code Class} object represents a primitive type, this method
   356      * returns {@code false}.
   357      *
   358      * @param   obj the object to check
   359      * @return  true if {@code obj} is an instance of this class
   360      *
   361      * @since JDK1.1
   362      */
   363     public boolean isInstance(Object obj) {
   364         if (obj == null) {
   365             return false;
   366         }
   367         if (isArray()) {
   368             return isAssignableFrom(obj.getClass());
   369         }
   370         
   371         String prop = "$instOf_" + getName().replace('.', '_');
   372         return hasProperty(obj, prop);
   373     }
   374     
   375     @JavaScriptBody(args = { "who", "prop" }, body = 
   376         "if (who[prop]) return true; else return false;"
   377     )
   378     private static native boolean hasProperty(Object who, String prop);
   379 
   380 
   381     /**
   382      * Determines if the class or interface represented by this
   383      * {@code Class} object is either the same as, or is a superclass or
   384      * superinterface of, the class or interface represented by the specified
   385      * {@code Class} parameter. It returns {@code true} if so;
   386      * otherwise it returns {@code false}. If this {@code Class}
   387      * object represents a primitive type, this method returns
   388      * {@code true} if the specified {@code Class} parameter is
   389      * exactly this {@code Class} object; otherwise it returns
   390      * {@code false}.
   391      *
   392      * <p> Specifically, this method tests whether the type represented by the
   393      * specified {@code Class} parameter can be converted to the type
   394      * represented by this {@code Class} object via an identity conversion
   395      * or via a widening reference conversion. See <em>The Java Language
   396      * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
   397      *
   398      * @param cls the {@code Class} object to be checked
   399      * @return the {@code boolean} value indicating whether objects of the
   400      * type {@code cls} can be assigned to objects of this class
   401      * @exception NullPointerException if the specified Class parameter is
   402      *            null.
   403      * @since JDK1.1
   404      */
   405     public boolean isAssignableFrom(Class<?> cls) {
   406         if (this == cls) {
   407             return true;
   408         }
   409         if (this == Object.class) {
   410             return true;
   411         }
   412         
   413         if (isArray()) {
   414             final Class<?> cmpType = cls.getComponentType();
   415             if (isPrimitive()) {
   416                 return this == cmpType;
   417             }
   418             return cmpType != null && getComponentType().isAssignableFrom(cmpType);
   419         }
   420         if (isPrimitive()) {
   421             return false;
   422         } else {
   423             if (cls.isPrimitive()) {
   424                 return false;
   425             }
   426             if (cls.isArray()) {
   427                 return false;
   428             }
   429             String prop = "$instOf_" + getName().replace('.', '_');
   430             return hasCnstrProperty(cls, prop);
   431         }
   432     }
   433 
   434     @JavaScriptBody(args = { "who", "prop" }, body = 
   435         "if (who.cnstr.prototype[prop]) return true; else return false;"
   436     )
   437     private static native boolean hasCnstrProperty(Object who, String prop);
   438     
   439     
   440     /**
   441      * Determines if the specified {@code Class} object represents an
   442      * interface type.
   443      *
   444      * @return  {@code true} if this object represents an interface;
   445      *          {@code false} otherwise.
   446      */
   447     public boolean isInterface() {
   448         return (getAccess() & 0x200) != 0;
   449     }
   450     
   451     @JavaScriptBody(args = {}, body = "return this.access;")
   452     private native int getAccess();
   453 
   454 
   455     /**
   456      * Determines if this {@code Class} object represents an array class.
   457      *
   458      * @return  {@code true} if this object represents an array class;
   459      *          {@code false} otherwise.
   460      * @since   JDK1.1
   461      */
   462     public boolean isArray() {
   463         return hasProperty(this, "array"); // NOI18N
   464     }
   465 
   466 
   467     /**
   468      * Determines if the specified {@code Class} object represents a
   469      * primitive type.
   470      *
   471      * <p> There are nine predefined {@code Class} objects to represent
   472      * the eight primitive types and void.  These are created by the Java
   473      * Virtual Machine, and have the same names as the primitive types that
   474      * they represent, namely {@code boolean}, {@code byte},
   475      * {@code char}, {@code short}, {@code int},
   476      * {@code long}, {@code float}, and {@code double}.
   477      *
   478      * <p> These objects may only be accessed via the following public static
   479      * final variables, and are the only {@code Class} objects for which
   480      * this method returns {@code true}.
   481      *
   482      * @return true if and only if this class represents a primitive type
   483      *
   484      * @see     java.lang.Boolean#TYPE
   485      * @see     java.lang.Character#TYPE
   486      * @see     java.lang.Byte#TYPE
   487      * @see     java.lang.Short#TYPE
   488      * @see     java.lang.Integer#TYPE
   489      * @see     java.lang.Long#TYPE
   490      * @see     java.lang.Float#TYPE
   491      * @see     java.lang.Double#TYPE
   492      * @see     java.lang.Void#TYPE
   493      * @since JDK1.1
   494      */
   495     @JavaScriptBody(args = {}, body = 
   496            "if (this.primitive) return true;"
   497         + "else return false;"
   498     )
   499     public native boolean isPrimitive();
   500 
   501     /**
   502      * Returns true if this {@code Class} object represents an annotation
   503      * type.  Note that if this method returns true, {@link #isInterface()}
   504      * would also return true, as all annotation types are also interfaces.
   505      *
   506      * @return {@code true} if this class object represents an annotation
   507      *      type; {@code false} otherwise
   508      * @since 1.5
   509      */
   510     public boolean isAnnotation() {
   511         return (getModifiers() & ANNOTATION) != 0;
   512     }
   513 
   514     /**
   515      * Returns {@code true} if this class is a synthetic class;
   516      * returns {@code false} otherwise.
   517      * @return {@code true} if and only if this class is a synthetic class as
   518      *         defined by the Java Language Specification.
   519      * @since 1.5
   520      */
   521     public boolean isSynthetic() {
   522         return (getModifiers() & SYNTHETIC) != 0;
   523     }
   524 
   525     /**
   526      * Returns the  name of the entity (class, interface, array class,
   527      * primitive type, or void) represented by this {@code Class} object,
   528      * as a {@code String}.
   529      *
   530      * <p> If this class object represents a reference type that is not an
   531      * array type then the binary name of the class is returned, as specified
   532      * by
   533      * <cite>The Java&trade; Language Specification</cite>.
   534      *
   535      * <p> If this class object represents a primitive type or void, then the
   536      * name returned is a {@code String} equal to the Java language
   537      * keyword corresponding to the primitive type or void.
   538      *
   539      * <p> If this class object represents a class of arrays, then the internal
   540      * form of the name consists of the name of the element type preceded by
   541      * one or more '{@code [}' characters representing the depth of the array
   542      * nesting.  The encoding of element type names is as follows:
   543      *
   544      * <blockquote><table summary="Element types and encodings">
   545      * <tr><th> Element Type <th> &nbsp;&nbsp;&nbsp; <th> Encoding
   546      * <tr><td> boolean      <td> &nbsp;&nbsp;&nbsp; <td align=center> Z
   547      * <tr><td> byte         <td> &nbsp;&nbsp;&nbsp; <td align=center> B
   548      * <tr><td> char         <td> &nbsp;&nbsp;&nbsp; <td align=center> C
   549      * <tr><td> class or interface
   550      *                       <td> &nbsp;&nbsp;&nbsp; <td align=center> L<i>classname</i>;
   551      * <tr><td> double       <td> &nbsp;&nbsp;&nbsp; <td align=center> D
   552      * <tr><td> float        <td> &nbsp;&nbsp;&nbsp; <td align=center> F
   553      * <tr><td> int          <td> &nbsp;&nbsp;&nbsp; <td align=center> I
   554      * <tr><td> long         <td> &nbsp;&nbsp;&nbsp; <td align=center> J
   555      * <tr><td> short        <td> &nbsp;&nbsp;&nbsp; <td align=center> S
   556      * </table></blockquote>
   557      *
   558      * <p> The class or interface name <i>classname</i> is the binary name of
   559      * the class specified above.
   560      *
   561      * <p> Examples:
   562      * <blockquote><pre>
   563      * String.class.getName()
   564      *     returns "java.lang.String"
   565      * byte.class.getName()
   566      *     returns "byte"
   567      * (new Object[3]).getClass().getName()
   568      *     returns "[Ljava.lang.Object;"
   569      * (new int[3][4][5][6][7][8][9]).getClass().getName()
   570      *     returns "[[[[[[[I"
   571      * </pre></blockquote>
   572      *
   573      * @return  the name of the class or interface
   574      *          represented by this object.
   575      */
   576     public String getName() {
   577         return jvmName().replace('/', '.');
   578     }
   579 
   580     @JavaScriptBody(args = {}, body = "return this.jvmName;")
   581     private native String jvmName();
   582 
   583     
   584     /**
   585      * Returns an array of {@code TypeVariable} objects that represent the
   586      * type variables declared by the generic declaration represented by this
   587      * {@code GenericDeclaration} object, in declaration order.  Returns an
   588      * array of length 0 if the underlying generic declaration declares no type
   589      * variables.
   590      *
   591      * @return an array of {@code TypeVariable} objects that represent
   592      *     the type variables declared by this generic declaration
   593      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
   594      *     signature of this generic declaration does not conform to
   595      *     the format specified in
   596      *     <cite>The Java&trade; Virtual Machine Specification</cite>
   597      * @since 1.5
   598      */
   599     public TypeVariable<Class<T>>[] getTypeParameters() {
   600         throw new UnsupportedOperationException();
   601     }
   602  
   603     /**
   604      * Returns the {@code Class} representing the superclass of the entity
   605      * (class, interface, primitive type or void) represented by this
   606      * {@code Class}.  If this {@code Class} represents either the
   607      * {@code Object} class, an interface, a primitive type, or void, then
   608      * null is returned.  If this object represents an array class then the
   609      * {@code Class} object representing the {@code Object} class is
   610      * returned.
   611      *
   612      * @return the superclass of the class represented by this object.
   613      */
   614     @JavaScriptBody(args = {}, body = "return this.superclass;")
   615     public native Class<? super T> getSuperclass();
   616 
   617     /**
   618      * Returns the Java language modifiers for this class or interface, encoded
   619      * in an integer. The modifiers consist of the Java Virtual Machine's
   620      * constants for {@code public}, {@code protected},
   621      * {@code private}, {@code final}, {@code static},
   622      * {@code abstract} and {@code interface}; they should be decoded
   623      * using the methods of class {@code Modifier}.
   624      *
   625      * <p> If the underlying class is an array class, then its
   626      * {@code public}, {@code private} and {@code protected}
   627      * modifiers are the same as those of its component type.  If this
   628      * {@code Class} represents a primitive type or void, its
   629      * {@code public} modifier is always {@code true}, and its
   630      * {@code protected} and {@code private} modifiers are always
   631      * {@code false}. If this object represents an array class, a
   632      * primitive type or void, then its {@code final} modifier is always
   633      * {@code true} and its interface modifier is always
   634      * {@code false}. The values of its other modifiers are not determined
   635      * by this specification.
   636      *
   637      * <p> The modifier encodings are defined in <em>The Java Virtual Machine
   638      * Specification</em>, table 4.1.
   639      *
   640      * @return the {@code int} representing the modifiers for this class
   641      * @see     java.lang.reflect.Modifier
   642      * @since JDK1.1
   643      */
   644     public int getModifiers() {
   645         return getAccess();
   646     }
   647 
   648     /**
   649      * If the class or interface represented by this {@code Class} object
   650      * is a member of another class, returns the {@code Class} object
   651      * representing the class in which it was declared.  This method returns
   652      * null if this class or interface is not a member of any other class.  If
   653      * this {@code Class} object represents an array class, a primitive
   654      * type, or void,then this method returns null.
   655      *
   656      * @return the declaring class for this class
   657      * @since JDK1.1
   658      */
   659     public Class<?> getDeclaringClass() {
   660         throw new SecurityException();
   661     }
   662 
   663     /**
   664      * Returns the simple name of the underlying class as given in the
   665      * source code. Returns an empty string if the underlying class is
   666      * anonymous.
   667      *
   668      * <p>The simple name of an array is the simple name of the
   669      * component type with "[]" appended.  In particular the simple
   670      * name of an array whose component type is anonymous is "[]".
   671      *
   672      * @return the simple name of the underlying class
   673      * @since 1.5
   674      */
   675     public String getSimpleName() {
   676         if (isArray())
   677             return getComponentType().getSimpleName()+"[]";
   678 
   679         String simpleName = getSimpleBinaryName();
   680         if (simpleName == null) { // top level class
   681             simpleName = getName();
   682             return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
   683         }
   684         // According to JLS3 "Binary Compatibility" (13.1) the binary
   685         // name of non-package classes (not top level) is the binary
   686         // name of the immediately enclosing class followed by a '$' followed by:
   687         // (for nested and inner classes): the simple name.
   688         // (for local classes): 1 or more digits followed by the simple name.
   689         // (for anonymous classes): 1 or more digits.
   690 
   691         // Since getSimpleBinaryName() will strip the binary name of
   692         // the immediatly enclosing class, we are now looking at a
   693         // string that matches the regular expression "\$[0-9]*"
   694         // followed by a simple name (considering the simple of an
   695         // anonymous class to be the empty string).
   696 
   697         // Remove leading "\$[0-9]*" from the name
   698         int length = simpleName.length();
   699         if (length < 1 || simpleName.charAt(0) != '$')
   700             throw new IllegalStateException("Malformed class name");
   701         int index = 1;
   702         while (index < length && isAsciiDigit(simpleName.charAt(index)))
   703             index++;
   704         // Eventually, this is the empty string iff this is an anonymous class
   705         return simpleName.substring(index);
   706     }
   707 
   708     /**
   709      * Returns the "simple binary name" of the underlying class, i.e.,
   710      * the binary name without the leading enclosing class name.
   711      * Returns {@code null} if the underlying class is a top level
   712      * class.
   713      */
   714     private String getSimpleBinaryName() {
   715         Class<?> enclosingClass = null; // XXX getEnclosingClass();
   716         if (enclosingClass == null) // top level class
   717             return null;
   718         // Otherwise, strip the enclosing class' name
   719         try {
   720             return getName().substring(enclosingClass.getName().length());
   721         } catch (IndexOutOfBoundsException ex) {
   722             throw new IllegalStateException("Malformed class name");
   723         }
   724     }
   725 
   726     /**
   727      * Returns an array containing {@code Field} objects reflecting all
   728      * the accessible public fields of the class or interface represented by
   729      * this {@code Class} object.  The elements in the array returned are
   730      * not sorted and are not in any particular order.  This method returns an
   731      * array of length 0 if the class or interface has no accessible public
   732      * fields, or if it represents an array class, a primitive type, or void.
   733      *
   734      * <p> Specifically, if this {@code Class} object represents a class,
   735      * this method returns the public fields of this class and of all its
   736      * superclasses.  If this {@code Class} object represents an
   737      * interface, this method returns the fields of this interface and of all
   738      * its superinterfaces.
   739      *
   740      * <p> The implicit length field for array class is not reflected by this
   741      * method. User code should use the methods of class {@code Array} to
   742      * manipulate arrays.
   743      *
   744      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
   745      *
   746      * @return the array of {@code Field} objects representing the
   747      * public fields
   748      * @exception  SecurityException
   749      *             If a security manager, <i>s</i>, is present and any of the
   750      *             following conditions is met:
   751      *
   752      *             <ul>
   753      *
   754      *             <li> invocation of
   755      *             {@link SecurityManager#checkMemberAccess
   756      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   757      *             access to the fields within this class
   758      *
   759      *             <li> the caller's class loader is not the same as or an
   760      *             ancestor of the class loader for the current class and
   761      *             invocation of {@link SecurityManager#checkPackageAccess
   762      *             s.checkPackageAccess()} denies access to the package
   763      *             of this class
   764      *
   765      *             </ul>
   766      *
   767      * @since JDK1.1
   768      */
   769     public Field[] getFields() throws SecurityException {
   770         throw new SecurityException();
   771     }
   772 
   773     /**
   774      * Returns an array containing {@code Method} objects reflecting all
   775      * the public <em>member</em> methods of the class or interface represented
   776      * by this {@code Class} object, including those declared by the class
   777      * or interface and those inherited from superclasses and
   778      * superinterfaces.  Array classes return all the (public) member methods
   779      * inherited from the {@code Object} class.  The elements in the array
   780      * returned are not sorted and are not in any particular order.  This
   781      * method returns an array of length 0 if this {@code Class} object
   782      * represents a class or interface that has no public member methods, or if
   783      * this {@code Class} object represents a primitive type or void.
   784      *
   785      * <p> The class initialization method {@code <clinit>} is not
   786      * included in the returned array. If the class declares multiple public
   787      * member methods with the same parameter types, they are all included in
   788      * the returned array.
   789      *
   790      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
   791      *
   792      * @return the array of {@code Method} objects representing the
   793      * public methods of this class
   794      * @exception  SecurityException
   795      *             If a security manager, <i>s</i>, is present and any of the
   796      *             following conditions is met:
   797      *
   798      *             <ul>
   799      *
   800      *             <li> invocation of
   801      *             {@link SecurityManager#checkMemberAccess
   802      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   803      *             access to the methods within this class
   804      *
   805      *             <li> the caller's class loader is not the same as or an
   806      *             ancestor of the class loader for the current class and
   807      *             invocation of {@link SecurityManager#checkPackageAccess
   808      *             s.checkPackageAccess()} denies access to the package
   809      *             of this class
   810      *
   811      *             </ul>
   812      *
   813      * @since JDK1.1
   814      */
   815     public Method[] getMethods() throws SecurityException {
   816         return MethodImpl.findMethods(this, 0x01);
   817     }
   818 
   819     /**
   820      * Returns a {@code Field} object that reflects the specified public
   821      * member field of the class or interface represented by this
   822      * {@code Class} object. The {@code name} parameter is a
   823      * {@code String} specifying the simple name of the desired field.
   824      *
   825      * <p> The field to be reflected is determined by the algorithm that
   826      * follows.  Let C be the class represented by this object:
   827      * <OL>
   828      * <LI> If C declares a public field with the name specified, that is the
   829      *      field to be reflected.</LI>
   830      * <LI> If no field was found in step 1 above, this algorithm is applied
   831      *      recursively to each direct superinterface of C. The direct
   832      *      superinterfaces are searched in the order they were declared.</LI>
   833      * <LI> If no field was found in steps 1 and 2 above, and C has a
   834      *      superclass S, then this algorithm is invoked recursively upon S.
   835      *      If C has no superclass, then a {@code NoSuchFieldException}
   836      *      is thrown.</LI>
   837      * </OL>
   838      *
   839      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
   840      *
   841      * @param name the field name
   842      * @return  the {@code Field} object of this class specified by
   843      * {@code name}
   844      * @exception NoSuchFieldException if a field with the specified name is
   845      *              not found.
   846      * @exception NullPointerException if {@code name} is {@code null}
   847      * @exception  SecurityException
   848      *             If a security manager, <i>s</i>, is present and any of the
   849      *             following conditions is met:
   850      *
   851      *             <ul>
   852      *
   853      *             <li> invocation of
   854      *             {@link SecurityManager#checkMemberAccess
   855      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   856      *             access to the field
   857      *
   858      *             <li> the caller's class loader is not the same as or an
   859      *             ancestor of the class loader for the current class and
   860      *             invocation of {@link SecurityManager#checkPackageAccess
   861      *             s.checkPackageAccess()} denies access to the package
   862      *             of this class
   863      *
   864      *             </ul>
   865      *
   866      * @since JDK1.1
   867      */
   868     public Field getField(String name)
   869         throws SecurityException {
   870         throw new SecurityException();
   871     }
   872     
   873     
   874     /**
   875      * Returns a {@code Method} object that reflects the specified public
   876      * member method of the class or interface represented by this
   877      * {@code Class} object. The {@code name} parameter is a
   878      * {@code String} specifying the simple name of the desired method. The
   879      * {@code parameterTypes} parameter is an array of {@code Class}
   880      * objects that identify the method's formal parameter types, in declared
   881      * order. If {@code parameterTypes} is {@code null}, it is
   882      * treated as if it were an empty array.
   883      *
   884      * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
   885      * {@code NoSuchMethodException} is raised. Otherwise, the method to
   886      * be reflected is determined by the algorithm that follows.  Let C be the
   887      * class represented by this object:
   888      * <OL>
   889      * <LI> C is searched for any <I>matching methods</I>. If no matching
   890      *      method is found, the algorithm of step 1 is invoked recursively on
   891      *      the superclass of C.</LI>
   892      * <LI> If no method was found in step 1 above, the superinterfaces of C
   893      *      are searched for a matching method. If any such method is found, it
   894      *      is reflected.</LI>
   895      * </OL>
   896      *
   897      * To find a matching method in a class C:&nbsp; If C declares exactly one
   898      * public method with the specified name and exactly the same formal
   899      * parameter types, that is the method reflected. If more than one such
   900      * method is found in C, and one of these methods has a return type that is
   901      * more specific than any of the others, that method is reflected;
   902      * otherwise one of the methods is chosen arbitrarily.
   903      *
   904      * <p>Note that there may be more than one matching method in a
   905      * class because while the Java language forbids a class to
   906      * declare multiple methods with the same signature but different
   907      * return types, the Java virtual machine does not.  This
   908      * increased flexibility in the virtual machine can be used to
   909      * implement various language features.  For example, covariant
   910      * returns can be implemented with {@linkplain
   911      * java.lang.reflect.Method#isBridge bridge methods}; the bridge
   912      * method and the method being overridden would have the same
   913      * signature but different return types.
   914      *
   915      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
   916      *
   917      * @param name the name of the method
   918      * @param parameterTypes the list of parameters
   919      * @return the {@code Method} object that matches the specified
   920      * {@code name} and {@code parameterTypes}
   921      * @exception NoSuchMethodException if a matching method is not found
   922      *            or if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
   923      * @exception NullPointerException if {@code name} is {@code null}
   924      * @exception  SecurityException
   925      *             If a security manager, <i>s</i>, is present and any of the
   926      *             following conditions is met:
   927      *
   928      *             <ul>
   929      *
   930      *             <li> invocation of
   931      *             {@link SecurityManager#checkMemberAccess
   932      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   933      *             access to the method
   934      *
   935      *             <li> the caller's class loader is not the same as or an
   936      *             ancestor of the class loader for the current class and
   937      *             invocation of {@link SecurityManager#checkPackageAccess
   938      *             s.checkPackageAccess()} denies access to the package
   939      *             of this class
   940      *
   941      *             </ul>
   942      *
   943      * @since JDK1.1
   944      */
   945     public Method getMethod(String name, Class<?>... parameterTypes)
   946         throws SecurityException, NoSuchMethodException {
   947         Method m = MethodImpl.findMethod(this, name, parameterTypes);
   948         if (m == null) {
   949             StringBuilder sb = new StringBuilder();
   950             sb.append(getName()).append('.').append(name).append('(');
   951             String sep = "";
   952             for (int i = 0; i < parameterTypes.length; i++) {
   953                 sb.append(sep).append(parameterTypes[i].getName());
   954                 sep = ", ";
   955             }
   956             sb.append(')');
   957             throw new NoSuchMethodException(sb.toString());
   958         }
   959         return m;
   960     }
   961     
   962     /**
   963      * Returns an array of {@code Method} objects reflecting all the
   964      * methods declared by the class or interface represented by this
   965      * {@code Class} object. This includes public, protected, default
   966      * (package) access, and private methods, but excludes inherited methods.
   967      * The elements in the array returned are not sorted and are not in any
   968      * particular order.  This method returns an array of length 0 if the class
   969      * or interface declares no methods, or if this {@code Class} object
   970      * represents a primitive type, an array class, or void.  The class
   971      * initialization method {@code <clinit>} is not included in the
   972      * returned array. If the class declares multiple public member methods
   973      * with the same parameter types, they are all included in the returned
   974      * array.
   975      *
   976      * <p> See <em>The Java Language Specification</em>, section 8.2.
   977      *
   978      * @return    the array of {@code Method} objects representing all the
   979      * declared methods of this class
   980      * @exception  SecurityException
   981      *             If a security manager, <i>s</i>, is present and any of the
   982      *             following conditions is met:
   983      *
   984      *             <ul>
   985      *
   986      *             <li> invocation of
   987      *             {@link SecurityManager#checkMemberAccess
   988      *             s.checkMemberAccess(this, Member.DECLARED)} denies
   989      *             access to the declared methods within this class
   990      *
   991      *             <li> the caller's class loader is not the same as or an
   992      *             ancestor of the class loader for the current class and
   993      *             invocation of {@link SecurityManager#checkPackageAccess
   994      *             s.checkPackageAccess()} denies access to the package
   995      *             of this class
   996      *
   997      *             </ul>
   998      *
   999      * @since JDK1.1
  1000      */
  1001     public Method[] getDeclaredMethods() throws SecurityException {
  1002         throw new SecurityException();
  1003     }
  1004     
  1005     /**
  1006      * Returns an array of {@code Field} objects reflecting all the fields
  1007      * declared by the class or interface represented by this
  1008      * {@code Class} object. This includes public, protected, default
  1009      * (package) access, and private fields, but excludes inherited fields.
  1010      * The elements in the array returned are not sorted and are not in any
  1011      * particular order.  This method returns an array of length 0 if the class
  1012      * or interface declares no fields, or if this {@code Class} object
  1013      * represents a primitive type, an array class, or void.
  1014      *
  1015      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
  1016      *
  1017      * @return    the array of {@code Field} objects representing all the
  1018      * declared fields of this class
  1019      * @exception  SecurityException
  1020      *             If a security manager, <i>s</i>, is present and any of the
  1021      *             following conditions is met:
  1022      *
  1023      *             <ul>
  1024      *
  1025      *             <li> invocation of
  1026      *             {@link SecurityManager#checkMemberAccess
  1027      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1028      *             access to the declared fields within this class
  1029      *
  1030      *             <li> the caller's class loader is not the same as or an
  1031      *             ancestor of the class loader for the current class and
  1032      *             invocation of {@link SecurityManager#checkPackageAccess
  1033      *             s.checkPackageAccess()} denies access to the package
  1034      *             of this class
  1035      *
  1036      *             </ul>
  1037      *
  1038      * @since JDK1.1
  1039      */
  1040     public Field[] getDeclaredFields() throws SecurityException {
  1041         throw new SecurityException();
  1042     }
  1043 
  1044     /**
  1045      * <b>Bck2Brwsr</b> emulation can only seek public methods, otherwise it
  1046      * throws a {@code SecurityException}.
  1047      * <p>
  1048      * Returns a {@code Method} object that reflects the specified
  1049      * declared method of the class or interface represented by this
  1050      * {@code Class} object. The {@code name} parameter is a
  1051      * {@code String} that specifies the simple name of the desired
  1052      * method, and the {@code parameterTypes} parameter is an array of
  1053      * {@code Class} objects that identify the method's formal parameter
  1054      * types, in declared order.  If more than one method with the same
  1055      * parameter types is declared in a class, and one of these methods has a
  1056      * return type that is more specific than any of the others, that method is
  1057      * returned; otherwise one of the methods is chosen arbitrarily.  If the
  1058      * name is "&lt;init&gt;"or "&lt;clinit&gt;" a {@code NoSuchMethodException}
  1059      * is raised.
  1060      *
  1061      * @param name the name of the method
  1062      * @param parameterTypes the parameter array
  1063      * @return    the {@code Method} object for the method of this class
  1064      * matching the specified name and parameters
  1065      * @exception NoSuchMethodException if a matching method is not found.
  1066      * @exception NullPointerException if {@code name} is {@code null}
  1067      * @exception  SecurityException
  1068      *             If a security manager, <i>s</i>, is present and any of the
  1069      *             following conditions is met:
  1070      *
  1071      *             <ul>
  1072      *
  1073      *             <li> invocation of
  1074      *             {@link SecurityManager#checkMemberAccess
  1075      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1076      *             access to the declared method
  1077      *
  1078      *             <li> the caller's class loader is not the same as or an
  1079      *             ancestor of the class loader for the current class and
  1080      *             invocation of {@link SecurityManager#checkPackageAccess
  1081      *             s.checkPackageAccess()} denies access to the package
  1082      *             of this class
  1083      *
  1084      *             </ul>
  1085      *
  1086      * @since JDK1.1
  1087      */
  1088     public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
  1089     throws NoSuchMethodException, SecurityException {
  1090         try {
  1091             return getMethod(name, parameterTypes);
  1092         } catch (NoSuchMethodException ex) {
  1093             throw new SecurityException();
  1094         }
  1095     }
  1096 
  1097     /**
  1098      * Returns a {@code Field} object that reflects the specified declared
  1099      * field of the class or interface represented by this {@code Class}
  1100      * object. The {@code name} parameter is a {@code String} that
  1101      * specifies the simple name of the desired field.  Note that this method
  1102      * will not reflect the {@code length} field of an array class.
  1103      *
  1104      * @param name the name of the field
  1105      * @return the {@code Field} object for the specified field in this
  1106      * class
  1107      * @exception NoSuchFieldException if a field with the specified name is
  1108      *              not found.
  1109      * @exception NullPointerException if {@code name} is {@code null}
  1110      * @exception  SecurityException
  1111      *             If a security manager, <i>s</i>, is present and any of the
  1112      *             following conditions is met:
  1113      *
  1114      *             <ul>
  1115      *
  1116      *             <li> invocation of
  1117      *             {@link SecurityManager#checkMemberAccess
  1118      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1119      *             access to the declared field
  1120      *
  1121      *             <li> the caller's class loader is not the same as or an
  1122      *             ancestor of the class loader for the current class and
  1123      *             invocation of {@link SecurityManager#checkPackageAccess
  1124      *             s.checkPackageAccess()} denies access to the package
  1125      *             of this class
  1126      *
  1127      *             </ul>
  1128      *
  1129      * @since JDK1.1
  1130      */
  1131     public Field getDeclaredField(String name)
  1132     throws SecurityException {
  1133         throw new SecurityException();
  1134     }
  1135     
  1136     /**
  1137      * Returns an array containing {@code Constructor} objects reflecting
  1138      * all the public constructors of the class represented by this
  1139      * {@code Class} object.  An array of length 0 is returned if the
  1140      * class has no public constructors, or if the class is an array class, or
  1141      * if the class reflects a primitive type or void.
  1142      *
  1143      * Note that while this method returns an array of {@code
  1144      * Constructor<T>} objects (that is an array of constructors from
  1145      * this class), the return type of this method is {@code
  1146      * Constructor<?>[]} and <em>not</em> {@code Constructor<T>[]} as
  1147      * might be expected.  This less informative return type is
  1148      * necessary since after being returned from this method, the
  1149      * array could be modified to hold {@code Constructor} objects for
  1150      * different classes, which would violate the type guarantees of
  1151      * {@code Constructor<T>[]}.
  1152      *
  1153      * @return the array of {@code Constructor} objects representing the
  1154      *  public constructors of this class
  1155      * @exception  SecurityException
  1156      *             If a security manager, <i>s</i>, is present and any of the
  1157      *             following conditions is met:
  1158      *
  1159      *             <ul>
  1160      *
  1161      *             <li> invocation of
  1162      *             {@link SecurityManager#checkMemberAccess
  1163      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
  1164      *             access to the constructors within this class
  1165      *
  1166      *             <li> the caller's class loader is not the same as or an
  1167      *             ancestor of the class loader for the current class and
  1168      *             invocation of {@link SecurityManager#checkPackageAccess
  1169      *             s.checkPackageAccess()} denies access to the package
  1170      *             of this class
  1171      *
  1172      *             </ul>
  1173      *
  1174      * @since JDK1.1
  1175      */
  1176     public Constructor<?>[] getConstructors() throws SecurityException {
  1177         return MethodImpl.findConstructors(this, 0x01);
  1178     }
  1179 
  1180     /**
  1181      * Returns a {@code Constructor} object that reflects the specified
  1182      * public constructor of the class represented by this {@code Class}
  1183      * object. The {@code parameterTypes} parameter is an array of
  1184      * {@code Class} objects that identify the constructor's formal
  1185      * parameter types, in declared order.
  1186      *
  1187      * If this {@code Class} object represents an inner class
  1188      * declared in a non-static context, the formal parameter types
  1189      * include the explicit enclosing instance as the first parameter.
  1190      *
  1191      * <p> The constructor to reflect is the public constructor of the class
  1192      * represented by this {@code Class} object whose formal parameter
  1193      * types match those specified by {@code parameterTypes}.
  1194      *
  1195      * @param parameterTypes the parameter array
  1196      * @return the {@code Constructor} object of the public constructor that
  1197      * matches the specified {@code parameterTypes}
  1198      * @exception NoSuchMethodException if a matching method is not found.
  1199      * @exception  SecurityException
  1200      *             If a security manager, <i>s</i>, is present and any of the
  1201      *             following conditions is met:
  1202      *
  1203      *             <ul>
  1204      *
  1205      *             <li> invocation of
  1206      *             {@link SecurityManager#checkMemberAccess
  1207      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
  1208      *             access to the constructor
  1209      *
  1210      *             <li> the caller's class loader is not the same as or an
  1211      *             ancestor of the class loader for the current class and
  1212      *             invocation of {@link SecurityManager#checkPackageAccess
  1213      *             s.checkPackageAccess()} denies access to the package
  1214      *             of this class
  1215      *
  1216      *             </ul>
  1217      *
  1218      * @since JDK1.1
  1219      */
  1220     public Constructor<T> getConstructor(Class<?>... parameterTypes)
  1221     throws NoSuchMethodException, SecurityException {
  1222         Constructor c = MethodImpl.findConstructor(this, parameterTypes);
  1223         if (c == null) {
  1224             StringBuilder sb = new StringBuilder();
  1225             sb.append(getName()).append('(');
  1226             String sep = "";
  1227             for (int i = 0; i < parameterTypes.length; i++) {
  1228                 sb.append(sep).append(parameterTypes[i].getName());
  1229                 sep = ", ";
  1230             }
  1231             sb.append(')');
  1232             throw new NoSuchMethodException(sb.toString());
  1233         }
  1234         return c;
  1235     }
  1236 
  1237     /**
  1238      * Returns an array of {@code Constructor} objects reflecting all the
  1239      * constructors declared by the class represented by this
  1240      * {@code Class} object. These are public, protected, default
  1241      * (package) access, and private constructors.  The elements in the array
  1242      * returned are not sorted and are not in any particular order.  If the
  1243      * class has a default constructor, it is included in the returned array.
  1244      * This method returns an array of length 0 if this {@code Class}
  1245      * object represents an interface, a primitive type, an array class, or
  1246      * void.
  1247      *
  1248      * <p> See <em>The Java Language Specification</em>, section 8.2.
  1249      *
  1250      * @return    the array of {@code Constructor} objects representing all the
  1251      * declared constructors of this class
  1252      * @exception  SecurityException
  1253      *             If a security manager, <i>s</i>, is present and any of the
  1254      *             following conditions is met:
  1255      *
  1256      *             <ul>
  1257      *
  1258      *             <li> invocation of
  1259      *             {@link SecurityManager#checkMemberAccess
  1260      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1261      *             access to the declared constructors within this class
  1262      *
  1263      *             <li> the caller's class loader is not the same as or an
  1264      *             ancestor of the class loader for the current class and
  1265      *             invocation of {@link SecurityManager#checkPackageAccess
  1266      *             s.checkPackageAccess()} denies access to the package
  1267      *             of this class
  1268      *
  1269      *             </ul>
  1270      *
  1271      * @since JDK1.1
  1272      */
  1273     public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
  1274         throw new SecurityException();
  1275     }
  1276     /**
  1277      * Returns a {@code Constructor} object that reflects the specified
  1278      * constructor of the class or interface represented by this
  1279      * {@code Class} object.  The {@code parameterTypes} parameter is
  1280      * an array of {@code Class} objects that identify the constructor's
  1281      * formal parameter types, in declared order.
  1282      *
  1283      * If this {@code Class} object represents an inner class
  1284      * declared in a non-static context, the formal parameter types
  1285      * include the explicit enclosing instance as the first parameter.
  1286      *
  1287      * @param parameterTypes the parameter array
  1288      * @return    The {@code Constructor} object for the constructor with the
  1289      * specified parameter list
  1290      * @exception NoSuchMethodException if a matching method is not found.
  1291      * @exception  SecurityException
  1292      *             If a security manager, <i>s</i>, is present and any of the
  1293      *             following conditions is met:
  1294      *
  1295      *             <ul>
  1296      *
  1297      *             <li> invocation of
  1298      *             {@link SecurityManager#checkMemberAccess
  1299      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1300      *             access to the declared constructor
  1301      *
  1302      *             <li> the caller's class loader is not the same as or an
  1303      *             ancestor of the class loader for the current class and
  1304      *             invocation of {@link SecurityManager#checkPackageAccess
  1305      *             s.checkPackageAccess()} denies access to the package
  1306      *             of this class
  1307      *
  1308      *             </ul>
  1309      *
  1310      * @since JDK1.1
  1311      */
  1312     public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
  1313     throws NoSuchMethodException, SecurityException {
  1314         return getConstructor(parameterTypes);
  1315     }
  1316     
  1317     
  1318     /**
  1319      * Character.isDigit answers {@code true} to some non-ascii
  1320      * digits.  This one does not.
  1321      */
  1322     private static boolean isAsciiDigit(char c) {
  1323         return '0' <= c && c <= '9';
  1324     }
  1325 
  1326     /**
  1327      * Returns the canonical name of the underlying class as
  1328      * defined by the Java Language Specification.  Returns null if
  1329      * the underlying class does not have a canonical name (i.e., if
  1330      * it is a local or anonymous class or an array whose component
  1331      * type does not have a canonical name).
  1332      * @return the canonical name of the underlying class if it exists, and
  1333      * {@code null} otherwise.
  1334      * @since 1.5
  1335      */
  1336     public String getCanonicalName() {
  1337         if (isArray()) {
  1338             String canonicalName = getComponentType().getCanonicalName();
  1339             if (canonicalName != null)
  1340                 return canonicalName + "[]";
  1341             else
  1342                 return null;
  1343         }
  1344 //        if (isLocalOrAnonymousClass())
  1345 //            return null;
  1346 //        Class<?> enclosingClass = getEnclosingClass();
  1347         Class<?> enclosingClass = null;
  1348         if (enclosingClass == null) { // top level class
  1349             return getName();
  1350         } else {
  1351             String enclosingName = enclosingClass.getCanonicalName();
  1352             if (enclosingName == null)
  1353                 return null;
  1354             return enclosingName + "." + getSimpleName();
  1355         }
  1356     }
  1357 
  1358     /**
  1359      * Finds a resource with a given name.  The rules for searching resources
  1360      * associated with a given class are implemented by the defining
  1361      * {@linkplain ClassLoader class loader} of the class.  This method
  1362      * delegates to this object's class loader.  If this object was loaded by
  1363      * the bootstrap class loader, the method delegates to {@link
  1364      * ClassLoader#getSystemResourceAsStream}.
  1365      *
  1366      * <p> Before delegation, an absolute resource name is constructed from the
  1367      * given resource name using this algorithm:
  1368      *
  1369      * <ul>
  1370      *
  1371      * <li> If the {@code name} begins with a {@code '/'}
  1372      * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
  1373      * portion of the {@code name} following the {@code '/'}.
  1374      *
  1375      * <li> Otherwise, the absolute name is of the following form:
  1376      *
  1377      * <blockquote>
  1378      *   {@code modified_package_name/name}
  1379      * </blockquote>
  1380      *
  1381      * <p> Where the {@code modified_package_name} is the package name of this
  1382      * object with {@code '/'} substituted for {@code '.'}
  1383      * (<tt>'&#92;u002e'</tt>).
  1384      *
  1385      * </ul>
  1386      *
  1387      * @param  name name of the desired resource
  1388      * @return      A {@link java.io.InputStream} object or {@code null} if
  1389      *              no resource with this name is found
  1390      * @throws  NullPointerException If {@code name} is {@code null}
  1391      * @since  JDK1.1
  1392      */
  1393      public InputStream getResourceAsStream(String name) {
  1394         name = resolveName(name);
  1395         byte[] arr = ClassLoader.getResourceAsStream0(name, 0);
  1396         return arr == null ? null : new ByteArrayInputStream(arr);
  1397      }
  1398     
  1399     /**
  1400      * Finds a resource with a given name.  The rules for searching resources
  1401      * associated with a given class are implemented by the defining
  1402      * {@linkplain ClassLoader class loader} of the class.  This method
  1403      * delegates to this object's class loader.  If this object was loaded by
  1404      * the bootstrap class loader, the method delegates to {@link
  1405      * ClassLoader#getSystemResource}.
  1406      *
  1407      * <p> Before delegation, an absolute resource name is constructed from the
  1408      * given resource name using this algorithm:
  1409      *
  1410      * <ul>
  1411      *
  1412      * <li> If the {@code name} begins with a {@code '/'}
  1413      * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
  1414      * portion of the {@code name} following the {@code '/'}.
  1415      *
  1416      * <li> Otherwise, the absolute name is of the following form:
  1417      *
  1418      * <blockquote>
  1419      *   {@code modified_package_name/name}
  1420      * </blockquote>
  1421      *
  1422      * <p> Where the {@code modified_package_name} is the package name of this
  1423      * object with {@code '/'} substituted for {@code '.'}
  1424      * (<tt>'&#92;u002e'</tt>).
  1425      *
  1426      * </ul>
  1427      *
  1428      * @param  name name of the desired resource
  1429      * @return      A  {@link java.net.URL} object or {@code null} if no
  1430      *              resource with this name is found
  1431      * @since  JDK1.1
  1432      */
  1433     public java.net.URL getResource(String name) {
  1434         return newResourceURL(name, getResourceAsStream(name));
  1435     }
  1436 
  1437     static URL newResourceURL(String name, InputStream is) {
  1438         return is == null ? null : newResourceURL0(URL.class, "res:/" + name, is);
  1439     }
  1440     
  1441     @JavaScriptBody(args = { "url", "spec", "is" }, body = 
  1442         "var u = url.cnstr(true);\n"
  1443       + "u.constructor.cons__VLjava_lang_String_2Ljava_io_InputStream_2.call(u, spec, is);\n"
  1444       + "return u;"
  1445     )
  1446     private static native URL newResourceURL0(Class<URL> url, String spec, InputStream is);
  1447 
  1448    /**
  1449      * Add a package name prefix if the name is not absolute Remove leading "/"
  1450      * if name is absolute
  1451      */
  1452     private String resolveName(String name) {
  1453         if (name == null) {
  1454             return name;
  1455         }
  1456         if (!name.startsWith("/")) {
  1457             Class<?> c = this;
  1458             while (c.isArray()) {
  1459                 c = c.getComponentType();
  1460             }
  1461             String baseName = c.getName();
  1462             int index = baseName.lastIndexOf('.');
  1463             if (index != -1) {
  1464                 name = baseName.substring(0, index).replace('.', '/')
  1465                     +"/"+name;
  1466             }
  1467         } else {
  1468             name = name.substring(1);
  1469         }
  1470         return name;
  1471     }
  1472     
  1473     /**
  1474      * Returns the class loader for the class.  Some implementations may use
  1475      * null to represent the bootstrap class loader. This method will return
  1476      * null in such implementations if this class was loaded by the bootstrap
  1477      * class loader.
  1478      *
  1479      * <p> If a security manager is present, and the caller's class loader is
  1480      * not null and the caller's class loader is not the same as or an ancestor of
  1481      * the class loader for the class whose class loader is requested, then
  1482      * this method calls the security manager's {@code checkPermission}
  1483      * method with a {@code RuntimePermission("getClassLoader")}
  1484      * permission to ensure it's ok to access the class loader for the class.
  1485      *
  1486      * <p>If this object
  1487      * represents a primitive type or void, null is returned.
  1488      *
  1489      * @return  the class loader that loaded the class or interface
  1490      *          represented by this object.
  1491      * @throws SecurityException
  1492      *    if a security manager exists and its
  1493      *    {@code checkPermission} method denies
  1494      *    access to the class loader for the class.
  1495      * @see java.lang.ClassLoader
  1496      * @see SecurityManager#checkPermission
  1497      * @see java.lang.RuntimePermission
  1498      */
  1499     public ClassLoader getClassLoader() {
  1500         return ClassLoader.getSystemClassLoader();
  1501     }
  1502 
  1503     /**
  1504      * Determines the interfaces implemented by the class or interface
  1505      * represented by this object.
  1506      *
  1507      * <p> If this object represents a class, the return value is an array
  1508      * containing objects representing all interfaces implemented by the
  1509      * class. The order of the interface objects in the array corresponds to
  1510      * the order of the interface names in the {@code implements} clause
  1511      * of the declaration of the class represented by this object. For
  1512      * example, given the declaration:
  1513      * <blockquote>
  1514      * {@code class Shimmer implements FloorWax, DessertTopping { ... }}
  1515      * </blockquote>
  1516      * suppose the value of {@code s} is an instance of
  1517      * {@code Shimmer}; the value of the expression:
  1518      * <blockquote>
  1519      * {@code s.getClass().getInterfaces()[0]}
  1520      * </blockquote>
  1521      * is the {@code Class} object that represents interface
  1522      * {@code FloorWax}; and the value of:
  1523      * <blockquote>
  1524      * {@code s.getClass().getInterfaces()[1]}
  1525      * </blockquote>
  1526      * is the {@code Class} object that represents interface
  1527      * {@code DessertTopping}.
  1528      *
  1529      * <p> If this object represents an interface, the array contains objects
  1530      * representing all interfaces extended by the interface. The order of the
  1531      * interface objects in the array corresponds to the order of the interface
  1532      * names in the {@code extends} clause of the declaration of the
  1533      * interface represented by this object.
  1534      *
  1535      * <p> If this object represents a class or interface that implements no
  1536      * interfaces, the method returns an array of length 0.
  1537      *
  1538      * <p> If this object represents a primitive type or void, the method
  1539      * returns an array of length 0.
  1540      *
  1541      * @return an array of interfaces implemented by this class.
  1542      */
  1543     public native Class<?>[] getInterfaces();
  1544     
  1545     /**
  1546      * Returns the {@code Class} representing the component type of an
  1547      * array.  If this class does not represent an array class this method
  1548      * returns null.
  1549      *
  1550      * @return the {@code Class} representing the component type of this
  1551      * class if this class is an array
  1552      * @see     java.lang.reflect.Array
  1553      * @since JDK1.1
  1554      */
  1555     public Class<?> getComponentType() {
  1556         if (isArray()) {
  1557             try {
  1558                 Class<?> c = getComponentTypeByFnc();
  1559                 return c != null ? c : getComponentType0();
  1560             } catch (ClassNotFoundException cnfe) {
  1561                 throw new IllegalStateException(cnfe);
  1562             }
  1563         }
  1564         return null;
  1565     }
  1566     
  1567     @JavaScriptBody(args = {  }, body = 
  1568         "if (this.fnc) {\n"
  1569       + "  var c = this.fnc(false).constructor.$class;\n"
  1570 //      + "  java.lang.System.out.println('will call: ' + (!!this.fnc) + ' res: ' + c.jvmName);\n"
  1571       + "  if (c) return c;\n"
  1572       + "}\n"
  1573       + "return null;"
  1574     )
  1575     private native Class<?> getComponentTypeByFnc();
  1576 
  1577     private Class<?> getComponentType0() throws ClassNotFoundException {
  1578         String n = getName().substring(1);
  1579         switch (n.charAt(0)) {
  1580             case 'L': 
  1581                 n = n.substring(1, n.length() - 1);
  1582                 return Class.forName(n);
  1583             case 'I':
  1584                 return Integer.TYPE;
  1585             case 'J':
  1586                 return Long.TYPE;
  1587             case 'D':
  1588                 return Double.TYPE;
  1589             case 'F':
  1590                 return Float.TYPE;
  1591             case 'B':
  1592                 return Byte.TYPE;
  1593             case 'Z':
  1594                 return Boolean.TYPE;
  1595             case 'S':
  1596                 return Short.TYPE;
  1597             case 'V':
  1598                 return Void.TYPE;
  1599             case 'C':
  1600                 return Character.TYPE;
  1601             case '[':
  1602                 return defineArray(n, null);
  1603             default:
  1604                 throw new ClassNotFoundException("Unknown component type of " + getName());
  1605         }
  1606     }
  1607     
  1608     @JavaScriptBody(args = { "sig", "fnc" }, body = 
  1609         "if (!sig) sig = '[Ljava/lang/Object;';\n" +
  1610         "var c = Array[sig];\n" +
  1611         "if (!c) {\n" +
  1612         "  c = vm.java_lang_Class(true);\n" +
  1613         "  c.jvmName = sig;\n" +
  1614         "  c.superclass = vm.java_lang_Object(false).$class;\n" +
  1615         "  c.array = true;\n" +
  1616         "  Array[sig] = c;\n" +
  1617         "}\n" +
  1618         "if (!c.fnc) c.fnc = fnc;\n" +
  1619         "return c;"
  1620     )
  1621     private static native Class<?> defineArray(String sig, Object fnc);
  1622     
  1623     /**
  1624      * Returns true if and only if this class was declared as an enum in the
  1625      * source code.
  1626      *
  1627      * @return true if and only if this class was declared as an enum in the
  1628      *     source code
  1629      * @since 1.5
  1630      */
  1631     public boolean isEnum() {
  1632         // An enum must both directly extend java.lang.Enum and have
  1633         // the ENUM bit set; classes for specialized enum constants
  1634         // don't do the former.
  1635         return (this.getModifiers() & ENUM) != 0 &&
  1636         this.getSuperclass() == java.lang.Enum.class;
  1637     }
  1638 
  1639     /**
  1640      * Casts an object to the class or interface represented
  1641      * by this {@code Class} object.
  1642      *
  1643      * @param obj the object to be cast
  1644      * @return the object after casting, or null if obj is null
  1645      *
  1646      * @throws ClassCastException if the object is not
  1647      * null and is not assignable to the type T.
  1648      *
  1649      * @since 1.5
  1650      */
  1651     public T cast(Object obj) {
  1652         if (obj != null && !isInstance(obj))
  1653             throw new ClassCastException(cannotCastMsg(obj));
  1654         return (T) obj;
  1655     }
  1656 
  1657     private String cannotCastMsg(Object obj) {
  1658         return "Cannot cast " + obj.getClass().getName() + " to " + getName();
  1659     }
  1660 
  1661     /**
  1662      * Casts this {@code Class} object to represent a subclass of the class
  1663      * represented by the specified class object.  Checks that that the cast
  1664      * is valid, and throws a {@code ClassCastException} if it is not.  If
  1665      * this method succeeds, it always returns a reference to this class object.
  1666      *
  1667      * <p>This method is useful when a client needs to "narrow" the type of
  1668      * a {@code Class} object to pass it to an API that restricts the
  1669      * {@code Class} objects that it is willing to accept.  A cast would
  1670      * generate a compile-time warning, as the correctness of the cast
  1671      * could not be checked at runtime (because generic types are implemented
  1672      * by erasure).
  1673      *
  1674      * @return this {@code Class} object, cast to represent a subclass of
  1675      *    the specified class object.
  1676      * @throws ClassCastException if this {@code Class} object does not
  1677      *    represent a subclass of the specified class (here "subclass" includes
  1678      *    the class itself).
  1679      * @since 1.5
  1680      */
  1681     public <U> Class<? extends U> asSubclass(Class<U> clazz) {
  1682         if (clazz.isAssignableFrom(this))
  1683             return (Class<? extends U>) this;
  1684         else
  1685             throw new ClassCastException(this.toString());
  1686     }
  1687 
  1688     @JavaScriptBody(args = { "ac" }, 
  1689         body = 
  1690           "if (this.anno) {\n"
  1691         + "  var r = this.anno['L' + ac.jvmName + ';'];\n"
  1692         + "  if (typeof r === 'undefined') r = null;\n"
  1693         + "  return r;\n"
  1694         + "} else return null;\n"
  1695     )
  1696     private Object getAnnotationData(Class<?> annotationClass) {
  1697         throw new UnsupportedOperationException();
  1698     }
  1699     /**
  1700      * @throws NullPointerException {@inheritDoc}
  1701      * @since 1.5
  1702      */
  1703     public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
  1704         Object data = getAnnotationData(annotationClass);
  1705         return data == null ? null : AnnotationImpl.create(annotationClass, data);
  1706     }
  1707 
  1708     /**
  1709      * @throws NullPointerException {@inheritDoc}
  1710      * @since 1.5
  1711      */
  1712     @JavaScriptBody(args = { "ac" }, 
  1713         body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
  1714         + "else return false;"
  1715     )
  1716     public boolean isAnnotationPresent(
  1717         Class<? extends Annotation> annotationClass) {
  1718         if (annotationClass == null)
  1719             throw new NullPointerException();
  1720 
  1721         return getAnnotation(annotationClass) != null;
  1722     }
  1723 
  1724     @JavaScriptBody(args = {}, body = "return this.anno;")
  1725     private Object getAnnotationData() {
  1726         throw new UnsupportedOperationException();
  1727     }
  1728 
  1729     /**
  1730      * @since 1.5
  1731      */
  1732     public Annotation[] getAnnotations() {
  1733         Object data = getAnnotationData();
  1734         return data == null ? new Annotation[0] : AnnotationImpl.create(data);
  1735     }
  1736 
  1737     /**
  1738      * @since 1.5
  1739      */
  1740     public Annotation[] getDeclaredAnnotations()  {
  1741         throw new UnsupportedOperationException();
  1742     }
  1743 
  1744     @JavaScriptBody(args = "type", body = ""
  1745         + "var c = vm.java_lang_Class(true);"
  1746         + "c.jvmName = type;"
  1747         + "c.primitive = true;"
  1748         + "return c;"
  1749     )
  1750     native static Class getPrimitiveClass(String type);
  1751 
  1752     @JavaScriptBody(args = {}, body = 
  1753         "return this['desiredAssertionStatus'] ? this['desiredAssertionStatus'] : false;"
  1754     )
  1755     public native boolean desiredAssertionStatus();
  1756 
  1757     public boolean equals(Object obj) {
  1758         if (isPrimitive() && obj instanceof Class) {
  1759             Class c = ((Class)obj);
  1760             return c.isPrimitive() && getName().equals(c.getName());
  1761         }
  1762         return super.equals(obj);
  1763     }
  1764     
  1765     static void registerNatives() {
  1766         boolean assertsOn = false;
  1767         //       assert assertsOn = true;
  1768         if (assertsOn) {
  1769             try {
  1770                 Array.get(null, 0);
  1771             } catch (Throwable ex) {
  1772                 // ignore
  1773             }
  1774         }
  1775     }
  1776 
  1777     @JavaScriptBody(args = {}, body = "var p = vm.java_lang_Object(false);"
  1778             + "p.toString = function() { return this.toString__Ljava_lang_String_2(); };"
  1779     )
  1780     static native void registerToString();
  1781     
  1782     @JavaScriptBody(args = {"self"}, body
  1783             = "var c = self.constructor.$class;\n"
  1784             + "return c ? c : null;\n"
  1785     )
  1786     static native Class<?> classFor(Object self);
  1787     
  1788     @Exported
  1789     @JavaScriptBody(args = { "self" }, body
  1790             = "if (self['$hashCode']) return self['$hashCode'];\n"
  1791             + "var h = self['computeHashCode__I'] ? self['computeHashCode__I']() : Math.random() * Math.pow(2, 31);\n"
  1792             + "return self['$hashCode'] = h & h;"
  1793     )
  1794     static native int defaultHashCode(Object self);
  1795 
  1796     @JavaScriptBody(args = "self", body
  1797             = "\nif (!self['$instOf_java_lang_Cloneable']) {"
  1798             + "\n  return null;"
  1799             + "\n} else {"
  1800             + "\n  var clone = self.constructor(true);"
  1801             + "\n  var props = Object.getOwnPropertyNames(self);"
  1802             + "\n  for (var i = 0; i < props.length; i++) {"
  1803             + "\n    var p = props[i];"
  1804             + "\n    clone[p] = self[p];"
  1805             + "\n  };"
  1806             + "\n  return clone;"
  1807             + "\n}"
  1808     )
  1809     static native Object clone(Object self) throws CloneNotSupportedException;
  1810 
  1811     @JavaScriptOnly(name = "toJS", value = "function(v) {\n"
  1812         + "  if (v === null) return null;\n"
  1813         + "  if (Object.prototype.toString.call(v) === '[object Array]') {\n"
  1814         + "    return vm.org_apidesign_bck2brwsr_emul_lang_System(false).convArray__Ljava_lang_Object_2Ljava_lang_Object_2(v);\n"
  1815         + "  }\n"
  1816         + "  return v.valueOf();\n"
  1817         + "}\n"
  1818     )
  1819     static native int toJS();
  1820 
  1821     @Exported
  1822     @JavaScriptOnly(name = "activate__Ljava_io_Closeable_2Lorg_apidesign_html_boot_spi_Fn$Presenter_2", value = "function() {\n"
  1823         + "  return vm.org_apidesign_bck2brwsr_emul_lang_System(false).activate__Ljava_io_Closeable_2();"
  1824         + "}\n"
  1825     )
  1826     static native int activate();
  1827 
  1828     @Exported
  1829     @JavaScriptOnly(name = "activate__Ljava_io_Closeable_2Lorg_netbeans_html_boot_spi_Fn$Presenter_2", value = "function() {\n"
  1830         + "  return vm.org_apidesign_bck2brwsr_emul_lang_System(false).activate__Ljava_io_Closeable_2();"
  1831         + "}\n"
  1832     )
  1833     static native int activateNew();
  1834     
  1835     private static Object bck2BrwsrCnvrt(Object o) {
  1836         if (o instanceof Throwable) {
  1837             return o;
  1838         }
  1839         final String msg = msg(o);
  1840         if (msg == null || msg.startsWith("TypeError")) {
  1841             return new NullPointerException(msg);
  1842         }
  1843         return new Throwable(msg);
  1844     }
  1845 
  1846     @JavaScriptBody(args = {"o"}, body = "return o ? o.toString() : null;")
  1847     private static native String msg(Object o);
  1848 
  1849     @Exported
  1850     @JavaScriptOnly(name = "bck2BrwsrThrwrbl", value = "c.bck2BrwsrCnvrt__Ljava_lang_Object_2Ljava_lang_Object_2")
  1851     private static void bck2BrwsrCnvrtVM() {
  1852     }
  1853     
  1854 }