@@ -29,8 +29,8 @@ public class JavaClassHierarchySetupUtil {
2929
3030 /**
3131 * If not already created it creates the prototype for the class and stores it in
32- * {@code prototypesByTypeId}. If superTypeId is null, it means that the class being defined
33- * is the topmost class (i.e. java.lang.Object) and creates an empty prototype for it.
32+ * {@code prototypesByTypeId}. If superTypeIdOrPrototype is null, it means that the class being
33+ * defined is the topmost class (i.e. java.lang.Object) and creates an empty prototype for it.
3434 * Otherwise it creates the prototype for the class by calling {@code createSubclassPrototype()}.
3535 * It also assigns the castable type map and sets the constructors prototype field to the
3636 * current prototype.
@@ -39,80 +39,43 @@ public class JavaClassHierarchySetupUtil {
3939 * code-split fragments. In that case Class.createFor* methods will have created a placeholder and
4040 * stored in {@code prototypesByTypeId} the class literal.
4141 * <p>
42- * As a prerequisite if superTypeId is not null, it is assumed that defineClass for the supertype
43- * has already been called.
42+ * As a prerequisite if superTypeIdOrPrototype is not null, it is assumed that defineClass for the
43+ * supertype has already been called.
4444 * <p>
4545 * This method has the effect of assigning the newly created prototype to the global temp variable
4646 * '_'.
4747 */
4848 public static native void defineClass (JavaScriptObject typeId ,
49- JavaScriptObject superTypeId , JavaScriptObject castableTypeMap ) /*-{
49+ JavaScriptObject superTypeIdOrPrototype , JavaScriptObject castableTypeMap ) /*-{
5050 // Setup aliases for (horribly long) JSNI references.
51- var prototypesByTypeId = @com.google.gwt.lang.JavaClassHierarchySetupUtil::prototypesByTypeId;
52- var createSubclassPrototype =
53- @com.google.gwt.lang.JavaClassHierarchySetupUtil::createSubclassPrototype(*)
54- var maybeGetClassLiteralFromPlaceHolder = @com.google.gwt.lang.JavaClassHierarchySetupUtil::
55- maybeGetClassLiteralFromPlaceHolder(*);
51+ var prototypesByTypeId = @JavaClassHierarchySetupUtil::prototypesByTypeId;
5652 // end of alias definitions.
5753
5854 var prototype = prototypesByTypeId[typeId];
59- var clazz = maybeGetClassLiteralFromPlaceHolder(prototype);
55+ var clazz = @JavaClassHierarchySetupUtil:: maybeGetClassLiteralFromPlaceHolder(*) (prototype);
6056 if (prototype && !clazz) {
6157 // not a placeholder entry setup by Class.setClassLiteral
6258 _ = prototype;
6359 } else {
64- _ = prototypesByTypeId[typeId] = (!superTypeId) ? {} : createSubclassPrototype(superTypeId );
65- _.@java.lang. Object::castableTypeMap = castableTypeMap;
60+ _ = @JavaClassHierarchySetupUtil:: createSubclassPrototype(*)(superTypeIdOrPrototype );
61+ _.@Object::castableTypeMap = castableTypeMap;
6662 _.constructor = _;
67- if (!superTypeId ) {
63+ if (!superTypeIdOrPrototype ) {
6864 // Set the typeMarker on java.lang.Object's prototype, implicitly setting it for all
6965 // Java subclasses (String and Arrays have special handling in Cast and Array respectively).
70- 71- @JavaClassHierarchySetupUtil::typeMarkerFn(*);
66+ _.@Object::typeMarker = @JavaClassHierarchySetupUtil::typeMarkerFn(*);
7267 }
68+ prototypesByTypeId[typeId] = _;
7369 }
7470 for (var i = 3; i < arguments.length; ++i) {
7571 // Assign the type prototype to each constructor.
7672 arguments[i].prototype = _;
7773 }
7874 if (clazz) {
79- _.@java.lang. Object::___clazz = clazz;
75+ _.@Object::___clazz = clazz;
8076 }
8177 }-*/ ;
8278
83- /**
84- * Like defineClass() but second parameter is a native JS prototype reference.
85- */
86- public static native void defineClassWithPrototype (int typeId ,
87- JavaScriptObject jsSuperClass , JavaScriptObject castableTypeMap ) /*-{
88- // Setup aliases for (horribly long) JSNI references.
89- var prototypesByTypeId = @com.google.gwt.lang.JavaClassHierarchySetupUtil::prototypesByTypeId;
90-
91- var maybeGetClassLiteralFromPlaceHolder = @com.google.gwt.lang.JavaClassHierarchySetupUtil::
92- maybeGetClassLiteralFromPlaceHolder(Lcom/google/gwt/core/client/JavaScriptObject;);
93- // end of alias definitions.
94-
95- var prototype = prototypesByTypeId[typeId];
96- var clazz = maybeGetClassLiteralFromPlaceHolder(prototype);
97-
98- if (prototype && !clazz) {
99- // not a placeholder entry setup by Class.setClassLiteral
100- _ = prototype;
101- } else {
102- var superPrototype = jsSuperClass && jsSuperClass.prototype || {};
103- _ = prototypesByTypeId[typeId] = @com.google.gwt.lang.JavaClassHierarchySetupUtil::
104- portableObjCreate(Lcom/google/gwt/core/client/JavaScriptObject;)(superPrototype);
105- [email protected] ::castableTypeMap = castableTypeMap; 106- }
107- for (var i = 3; i < arguments.length; ++i) {
108- // Assign the type prototype to each constructor.
109- arguments[i].prototype = _;
110- }
111- if (clazz) {
112- [email protected] ::___clazz = clazz; 113- }
114- }-*/ ;
115-
11679 private static native JavaScriptObject portableObjCreate (JavaScriptObject obj ) /*-{
11780 function F() {};
11881 F.prototype = obj || {};
@@ -122,12 +85,17 @@ private static native JavaScriptObject portableObjCreate(JavaScriptObject obj) /
12285 /**
12386 * Create a subclass prototype.
12487 */
125- public static native JavaScriptObject createSubclassPrototype (JavaScriptObject superTypeId ) /*-{
126- // Setup aliases for (horribly long) JSNI references.
127- var prototypesByTypeId = @com.google.gwt.lang.JavaClassHierarchySetupUtil::prototypesByTypeId;
128- // end of alias definitions.
129- return @com.google.gwt.lang.JavaClassHierarchySetupUtil::
130- portableObjCreate(Lcom/google/gwt/core/client/JavaScriptObject;)(prototypesByTypeId[superTypeId]);
88+ private static native JavaScriptObject createSubclassPrototype (
89+ JavaScriptObject superTypeIdOrPrototype ) /*-{
90+ var superPrototype;
91+ if (typeof superTypeIdOrPrototype != 'number') {
92+ // Either it is null or the prototype of the super type.
93+ superPrototype = (superTypeIdOrPrototype && superTypeIdOrPrototype.prototype) || {};
94+ } else {
95+ superPrototype = @JavaClassHierarchySetupUtil::prototypesByTypeId[superTypeIdOrPrototype];
96+ }
97+
98+ return @JavaClassHierarchySetupUtil::portableObjCreate(*)(superPrototype);
13199 }-*/ ;
132100
133101 /**
@@ -220,9 +188,7 @@ public static native void modernizeBrowser() /*-{
220188 * Retrieves the prototype for a type if it exists, null otherwise.
221189 */
222190 public static native JavaScriptObject getClassPrototype (JavaScriptObject typeId ) /*-{
223- var prototypeForTypeId =
224- @com.google.gwt.lang.JavaClassHierarchySetupUtil::prototypesByTypeId[typeId];
225- return prototypeForTypeId;
191+ return @JavaClassHierarchySetupUtil::prototypesByTypeId[typeId];
226192 }-*/ ;
227193
228194 /**
0 commit comments