Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart |
| index c1fd0aa0ee4e94219216e1d698f47885a4541dcb..00838165278853028cc1b5aa72691dc6a0d29462 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart |
| @@ -1222,19 +1222,26 @@ class JavaScriptBackend extends Backend { |
| void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| world.registerInstantiatedClass(compiler.boolClass, elements); |
| bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; |
| + bool isCheckedMode = compiler.enableTypeAssertions; |
|
ngeoffray
2013/05/13 09:10:59
isCheckedMode -> inCheckedMode ?
karlklose
2013/05/14 13:49:41
Done.
|
| if (!type.isRaw || isTypeVariable) { |
| enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
| enqueueInResolution(getGetRuntimeTypeArgument(), elements); |
| + if (isCheckedMode) { |
| + enqueueInResolution(getAssertSubtype(), elements); |
| + } |
| enqueueInResolution(getCheckSubtype(), elements); |
| if (isTypeVariable) { |
| - enqueueInResolution(getGetObjectIsSubtype(), elements); |
| + enqueueInResolution(getObjectIsSubtype(), elements); |
| + if (isCheckedMode) { |
| + enqueueInResolution(getAssertObjectIsSubtype(), elements); |
| + } |
| } |
| world.registerInstantiatedClass(compiler.listClass, elements); |
| } |
| // [registerIsCheck] is also called for checked mode checks, so we |
| // need to register checked mode helpers. |
| - if (compiler.enableTypeAssertions) { |
| + if (isCheckedMode) { |
| Element e = getCheckedModeHelper(type, typeCast: false); |
| if (e != null) world.addToWorkList(e); |
| // We also need the native variant of the check (for DOM types). |
| @@ -1320,8 +1327,9 @@ class JavaScriptBackend extends Backend { |
| } |
| bool needsRti(ClassElement cls) { |
| - return rti.classesNeedingRti.contains(cls.declaration) |
| - || compiler.enabledRuntimeType; |
| + return rti.classesNeedingRti.contains(cls.declaration) || |
| + compiler.enabledRuntimeType || |
| + (compiler.enableTypeAssertions && !cls.typeVariables.isEmpty); |
|
ngeoffray
2013/05/13 09:10:59
Why would a class with type variable need rti? Wha
karlklose
2013/05/14 13:49:41
Removed, it was not necessary.
|
| } |
| bool isDefaultNoSuchMethodImplementation(Element element) { |
| @@ -1586,8 +1594,9 @@ class JavaScriptBackend extends Backend { |
| * backend with implementation types (JSInt, JSString, ...). |
| */ |
| Element getCheckedModeHelper(DartType type, {bool typeCast}) { |
| - return compiler.findHelper(getCheckedModeHelperName( |
| - type, typeCast: typeCast, nativeCheckOnly: false)); |
| + SourceString name = getCheckedModeHelperName( |
| + type, typeCast: typeCast, nativeCheckOnly: false); |
| + return compiler.findHelper(name); |
| } |
| /** |
| @@ -1692,13 +1701,22 @@ class JavaScriptBackend extends Backend { |
| } |
| } else { |
| if (nativeCheck) { |
| + // TODO(karlklose): can we get rid of this branch when we use |
| + // interceptors? |
| return typeCast |
| ? const SourceString("interceptedTypeCast") |
| : const SourceString('interceptedTypeCheck'); |
| } else { |
| - return typeCast |
| - ? const SourceString("propertyTypeCast") |
| - : const SourceString('propertyTypeCheck'); |
| + if (typeCast) { |
| + return const SourceString("propertyTypeCast"); |
| + } |
| + if (type.kind == TypeKind.INTERFACE && !type.isRaw) { |
| + return const SourceString('assertSubtype'); |
| + } else if (type.kind == TypeKind.TYPE_VARIABLE) { |
| + return const SourceString('assertObjectIsSubtype'); |
|
ngeoffray
2013/05/13 09:10:59
Why is that called assertObjectIsSubtype? For me i
karlklose
2013/05/14 13:49:41
I renamed the functions.
|
| + } else { |
| + return const SourceString('propertyTypeCheck'); |
| + } |
| } |
| } |
| } |
| @@ -1781,10 +1799,18 @@ class JavaScriptBackend extends Backend { |
| return compiler.findHelper(const SourceString('checkSubtype')); |
| } |
| - Element getGetObjectIsSubtype() { |
| + Element getAssertSubtype() { |
| + return compiler.findHelper(const SourceString('assertSubtype')); |
| + } |
| + |
| + Element getObjectIsSubtype() { |
| return compiler.findHelper(const SourceString('objectIsSubtype')); |
| } |
| + Element getAssertObjectIsSubtype() { |
| + return compiler.findHelper(const SourceString('assertObjectIsSubtype')); |
| + } |
| + |
| Element getThrowNoSuchMethod() { |
| return compiler.findHelper(const SourceString('throwNoSuchMethod')); |
| } |