Skip to content

Commit 5cc145f

Browse files
committed
Merges defineClass and defineClassWithPrototype
Change-Id: Ibb362c62caa371c19bb933f846ad17d501b055ab
1 parent 0674916 commit 5cc145f

File tree

5 files changed

+29
-76
lines changed

5 files changed

+29
-76
lines changed

dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,9 +2572,7 @@ private void generateCallToDefineClass(JClassType x, List<JsStatement> globalStm
25722572
// choose appropriate setup function
25732573
// JavaClassHierarchySetupUtil.defineClass(typeId, superTypeId, castableMap, constructors)
25742574
JsStatement defineClassStatement = constructInvocation(x.getSourceInfo(),
2575-
jsPrototype == null ? "JavaClassHierarchySetupUtil.defineClass" :
2576-
"JavaClassHierarchySetupUtil.defineClassWithPrototype",
2577-
defineClassArguments).makeStmt();
2575+
"JavaClassHierarchySetupUtil.defineClass", defineClassArguments).makeStmt();
25782576
globalStmts.add(defineClassStatement);
25792577
typeForStatMap.put(defineClassStatement, x);
25802578
}

dev/core/src/com/google/gwt/dev/jjs/impl/codesplitter/FragmentExtractor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,7 @@ private JClassType vtableTypeAssigned(JsStatement stat) {
442442
JsNameRef func = (JsNameRef) call.getQualifier();
443443
JsFunction defineClassJsFunc =
444444
jsprogram.getIndexedFunction("JavaClassHierarchySetupUtil.defineClass");
445-
JsFunction defineClassJsProtoFunc =
446-
jsprogram.getIndexedFunction(
447-
"JavaClassHierarchySetupUtil.defineClassWithPrototype");
448-
if (func.getName() != defineClassJsFunc.getName() && func.getName() !=
449-
defineClassJsProtoFunc.getName()) {
445+
if (func.getName() != defineClassJsFunc.getName()) {
450446
return null;
451447
}
452448
return map.typeForStatement(stat);

dev/core/src/com/google/gwt/dev/js/JsInliner.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,9 @@ public InliningVisitor(JsProgram program, Set<JsNode> whitelist) {
644644
this.whitelist = whitelist;
645645
invocationCountingVisitor.accept(program);
646646
JsName defineClass = getFunctionName(program, "JavaClassHierarchySetupUtil.defineClass");
647-
JsName defineClassProto = getFunctionName(program,
648-
"JavaClassHierarchySetupUtil.defineClassWithPrototype");
649647
// JsInlinerTest doesn't have these functions, but doesn't need them
650-
safeToInlineAtTopLevel = defineClass != null ? ImmutableSet.of(
651-
defineClass, defineClassProto) : ImmutableSet.<JsName>of();
648+
safeToInlineAtTopLevel = defineClass != null ? ImmutableSet.of(defineClass)
649+
: ImmutableSet.<JsName>of();
652650
}
653651

654652
private static JsName getFunctionName(JsProgram program, String name) {

dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/JavaClassHierarchySetupUtil.java

Lines changed: 25 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
[email protected]::typeMarker =
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
/**

dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,6 @@ public CharSequence getContent() {
262262
" public static Object defineClass(int typeId, int superTypeId, Object map) {",
263263
" return null;",
264264
" }",
265-
" public static Object defineClassWithPrototype(int typeId, "
266-
+ "int superTypeId, ",
267-
" Object map) {",
268-
" return null;",
269-
" }",
270265
" public static void modernizeBrowser() {}",
271266
" public static void emptyMethod() {}",
272267
"}"

0 commit comments

Comments
 (0)