diff --git a/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java b/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java index 1829e5946c0..fd31b2fc2b2 100644 --- a/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java +++ b/compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java @@ -2687,11 +2687,13 @@ public class GenerateJavascriptAST { if (typeParams != null && typeParams.size() != 0) { JsArrayLiteral arr = new JsArrayLiteral(); for (Type t : typeParams) { - String typeName = ""; + JsExpression typeName; if (t.getKind() != TypeKind.DYNAMIC) { - typeName = getJsName(t.getElement()).getShortIdent(); + typeName = rtt.getRTTClassId((ClassElement)t.getElement()); + } else { + typeName = string(""); } - arr.getExpressions().add(string(typeName)); + arr.getExpressions().add(typeName); } intern.getArguments().add(arr); } 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 4399656ac06..30103693d3a 100644 --- a/compiler/java/com/google/dart/compiler/backend/js/RuntimeTypeInjector.java +++ b/compiler/java/com/google/dart/compiler/backend/js/RuntimeTypeInjector.java @@ -50,6 +50,7 @@ import com.google.dart.compiler.backend.js.ast.JsProgram; import com.google.dart.compiler.backend.js.ast.JsReturn; import com.google.dart.compiler.backend.js.ast.JsScope; import com.google.dart.compiler.backend.js.ast.JsStatement; +import com.google.dart.compiler.backend.js.ast.JsStringLiteral; import com.google.dart.compiler.backend.js.ast.JsThisRef; import com.google.dart.compiler.common.SourceInfo; import com.google.dart.compiler.resolver.ClassElement; @@ -357,10 +358,16 @@ public class RuntimeTypeInjector { globalBlock.getStatements().add(fnDecl.makeStmt()); } - private JsExpression getRTTClassId(ClassElement classElement) { + static JsExpression getRTTClassId(TranslationContext translationContext, + ClassElement classElement) { JsName classJsName = translationContext.getNames().getName(classElement); JsProgram program = translationContext.getProgram(); - return program.getStringLiteral(classJsName.getShortIdent()); + JsStringLiteral clsid = program.getStringLiteral(classJsName.getShortIdent()); + return call(null, nameref(null, "$cls"), clsid); + } + + JsExpression getRTTClassId(ClassElement classElement) { + return getRTTClassId(translationContext, classElement); } private JsNameRef getRTTLookupMethodName(ClassElement classElement) { diff --git a/compiler/lib/implementation/rtt.js b/compiler/lib/implementation/rtt.js index 68ecb5b3f8d..8bd156bd64f 100644 --- a/compiler/lib/implementation/rtt.js +++ b/compiler/lib/implementation/rtt.js @@ -19,8 +19,8 @@ function RTT(classkey, typekey, typeargs) { // Add self this.implementedTypes[classkey] = this; // Add Object - if (classkey != 'Object') { - this.implementedTypes['Object'] = RTT.objectType; + if (classkey != $cls('Object')) { + this.implementedTypes[$cls('Object')] = RTT.objectType; } } @@ -93,7 +93,7 @@ RTT.getNativeTypeInfo = function(value) { * @return {RTT} The RTT information object */ RTT.create = function(name, implementsSupplier, typeArgs) { - if (name == "Object") return RTT.objectType; + if (name == $cls("Object")) return RTT.objectType; var typekey = RTT.getTypeKey(name, typeArgs); var rtt = RTT.types[typekey]; if (rtt) { @@ -183,18 +183,25 @@ RTT.getTypeArgsFor = function(o, classkey) { // Base types for runtime type information /** @type {!RTT} */ -RTT.objectType = new RTT('Object'); +RTT.objectType = new RTT($cls('Object')); RTT.objectType.implementedBy = function(o) {return true}; RTT.objectType.implementedByType = function(o) {return true}; /** @type {!RTT} */ -RTT.dynamicType = new RTT('Dynamic'); +RTT.dynamicType = new RTT($cls('Dynamic')); RTT.dynamicType.implementedBy = function(o) {return true}; RTT.dynamicType.implementedByType = function(o) {return true}; /** @type {!RTT} */ -RTT.placeholderType = new RTT(''); +RTT.placeholderType = new RTT($cls('::')); RTT.placeholderType.implementedBy = function(o) {return true}; RTT.placeholderType.implementedByType = function(o) {return true}; - +/** + * @param {string} cls + * @return {string} + * @consistentIdGenerator + */ +function $cls(cls) { + return "cls:" + cls; +}