Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: compiler/java/com/google/dart/compiler/backend/js/RuntimeTypeInjector.java

Issue 9006012: Workaround for referencing type args in the $named_$lookupRTT method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed formatting issue Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/backend/js/RuntimeTypeInjector.java
diff --git a/compiler/java/com/google/dart/compiler/backend/js/RuntimeTypeInjector.java b/compiler/java/com/google/dart/compiler/backend/js/RuntimeTypeInjector.java
index 46abd298ea63716c1938d3af9cb387410dab6f94..6b07ffe256ee6e5a7b943bca62ff04da0a77657e 100644
--- a/compiler/java/com/google/dart/compiler/backend/js/RuntimeTypeInjector.java
+++ b/compiler/java/com/google/dart/compiler/backend/js/RuntimeTypeInjector.java
@@ -468,8 +468,8 @@ public class RuntimeTypeInjector {
hasTypeArguments = classElement != null ? hasTypeParameters(classElement) : false;
JsProgram program = translationContext.getProgram();
- JsExpression typeArgContextExpr = hasTypeArguments ? buildTypeArgsReference(classElement)
- : null;
+ JsExpression typeArgContextExpr = hasTypeArguments ?
+ buildTypeArgsReferenceFromThis(classElement) : null;
// Build the function
JsFunction lookupFn = new JsFunction(globalScope);
@@ -727,32 +727,33 @@ public class RuntimeTypeInjector {
/**
* Build a class relative type arguments expression
+ *
* @param classElement The class whose type arguments to refer to.
*/
private JsExpression buildTypeArgsReference(ClassElement classElement) {
JsExpression typeArgs;
if (inFactory()) {
- if (classElement.getTypeParameters().isEmpty()) {
- typeArgs = new JsArrayLiteral();
+ if (hasTypeParameters(classElement)) {
+ // There is no inheritence involved with generic factory methods,
+ // so we simply use a hard reference to the type info parameter to the
+ // factory.
+ typeArgs = nameref(null, "$typeArgs");
} else {
- typeArgs = new JsNameRef("$typeArgs");
+ typeArgs = new JsArrayLiteral();
}
} else {
- // build: $getTypeArgsFor(this, 'class')
- // Here build a reference to the type parameter for this class instance, this needs
- // be looked up on a per-class basis.
- typeArgs = call(null,
- newQualifiedNameRef(
- "RTT.getTypeArgsFor"), new JsThisRef(), getRTTClassId(classElement));
+ typeArgs = buildTypeArgsReferenceFromThis(classElement);
}
return typeArgs;
}
- private JsExpression buildFactoryTypeInfoReference() {
- // There is no inheritence involved with generic factory methods,
- // so we simply use a hard reference to the type info parameter to the
- // factory.
- return nameref(null, "$typeArgs");
+ private JsExpression buildTypeArgsReferenceFromThis(ClassElement classElement) {
+ // build: $getTypeArgsFor(this, 'class')
+ // Here build a reference to the type parameter for this class instance, this needs
+ // be looked up on a per-class basis.
+ return call(null,
+ newQualifiedNameRef(
+ "RTT.getTypeArgsFor"), new JsThisRef(), getRTTClassId(classElement));
}
/**
@@ -1095,13 +1096,11 @@ public class RuntimeTypeInjector {
private JsExpression getReifiedTypeVariableRTT(TypeVariable type, ClassElement contextClassElement) {
JsExpression rttContext;
- if (!inFactory()) {
- // build: this.typeinfo.implementedTypes['class'].typeArgs;
- rttContext = buildTypeArgsReference(contextClassElement);
- } else {
- // build: $typeArgs
- rttContext = buildFactoryTypeInfoReference();
- }
+ // this.typeinfo.implementedTypes['class'].typeArgs;
+ // or for a factory method:
+ // $typeArgs
+ rttContext = buildTypeArgsReference(contextClassElement);
+
// rtt = rttContext.typeArgs[x]
JsExpression rtt = buildTypeLookupExpression(type, contextClassElement.getTypeParameters(), rttContext);
return rtt;
« no previous file with comments | « compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698