Index: sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart |
index 746df0e8314b54715af2dd13d17c024902cec9ad..772b00f7602071def04c6091ff95bfbb05e59138 100644 |
--- a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart |
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart |
@@ -21,13 +21,74 @@ class RuntimeTypeInformation { |
/// instantiations and checks. |
Set<ClassElement> allArguments; |
- bool isJsNative(Element element) { |
- return (element == compiler.intClass || |
- element == compiler.boolClass || |
- element == compiler.numClass || |
- element == compiler.doubleClass || |
- element == compiler.stringClass || |
- element == compiler.listClass); |
+ /** |
+ * Contains the classes for which we use builtin JavaScript datatypes and |
+ * therefore cannot install subtyping flags and substitutions, and instead use |
+ * native checks. |
+ */ |
+ Collection<Element> get jsNatives { |
+ if (cachedJsNatives == null) { |
+ cachedJsNatives = <Element>[compiler.intClass, |
+ compiler.boolClass, |
+ compiler.numClass, |
+ compiler.doubleClass, |
+ compiler.stringClass, |
+ compiler.listClass]; |
+ } |
+ return cachedJsNatives; |
+ } |
+ Collection<Element> cachedJsNatives; |
+ |
+ bool isJsNative(Element element) => jsNatives.contains(element); |
+ |
+ bool needsNativeCheck(Element element) { |
+ return element == compiler.objectClass || isJsNative(element); |
ngeoffray
2013/02/22 11:04:30
I don't think you answered my question about super
|
+ } |
+ |
+ /** |
+ * Constructs the native check function for the class [element]. |
+ * |
+ * This function will be put on the type representation for native classes |
+ * (and Object) and is called by the helper function [:objectIsSubtype:], if |
+ * it is on the object that represents the type to test against. We have to |
+ * put a trivial native check on object when it is used as a type argument in |
+ * a check because the native objects cannot have [:$isObject:] bits set on |
+ * them. |
+ * |
+ * TODO(karlklose): use the interceptors instead of holders for native classes |
+ * and implement the native checks on them. |
+ */ |
+ jsAst.Expression getNativeCheck(Element element) { |
+ final String parameterName = 'object'; |
+ final jsAst.VariableUse variable = new jsAst.VariableUse(parameterName); |
+ |
+ jsAst.Expression typeTest(String typeName) { |
+ return js.strictEquals( |
+ new jsAst.LiteralExpression.withData('typeof #', [variable]), |
+ new jsAst.LiteralString("'$typeName'")); |
+ } |
+ |
+ jsAst.Expression test; |
+ if (element == compiler.objectClass) { |
+ test = new jsAst.LiteralBool(true); |
+ } else if (element == compiler.intClass) { |
+ test = js['Math']['floor'](variable).equals(variable); |
+ } else if (element == compiler.boolClass) { |
+ test = typeTest('boolean'); |
+ } else if (element == compiler.numClass) { |
+ test = typeTest('number'); |
+ } else if (element == compiler.doubleClass) { |
+ test = typeTest('number'); |
+ } else if (element == compiler.stringClass) { |
+ test = typeTest('string'); |
+ } else if (element == compiler.listClass) { |
+ test = js.equals( |
+ new jsAst.LiteralExpression.withData('#.constructor', [variable]), |
+ new jsAst.LiteralExpression('Array')); |
+ } else { |
+ return null; |
+ } |
+ return js.fun([parameterName], js.block(js.return_(test))); |
} |
TypeChecks cachedRequiredChecks; |
@@ -294,4 +355,14 @@ class TypeCheckMapping implements TypeChecks { |
} |
Iterator<ClassElement> get iterator => map.keys.iterator; |
+ |
+ String toString() { |
+ StringBuffer sb = new StringBuffer(); |
+ for (ClassElement holder in this) { |
+ for (ClassElement check in [holder]) { |
+ sb.add('${holder.name.slowToString()}.${check.name.slowToString()}, '); |
+ } |
+ } |
+ return '[$sb]'; |
+ } |
} |