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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 11557010: Implement subtype checks on type arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update test expectations. Created 8 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
Index: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
index 7b7df7049c2abed7692025b1268dc227ab6a7322..71e618f7e7c7f0b2078763eb95e3dfa66d5dc97c 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
@@ -63,6 +63,11 @@ class CodeEmitterTask extends CompilerTask {
final bool generateSourceMap;
+ RuntimeTypeInformation get rti {
ngeoffray 2012/12/12 12:09:11 I'd rather not have this getter.
karlklose 2012/12/12 14:50:47 Done.
+ JavaScriptBackend backend = compiler.backend;
+ return backend.rti;
+ }
+
CodeEmitterTask(Compiler compiler, Namer namer, this.generateSourceMap)
: boundClosureBuffer = new CodeBuffer(),
mainBuffer = new CodeBuffer(),
@@ -753,6 +758,33 @@ $lazyInitializerLogic
}
}
+ void emitRuntimeClassesAndTests(CodeBuffer buffer) {
+ TypeChecks typeChecks = rti.computeRequiredChecks();
+ // Create an object that holds the class name and the checks for all classes
+ // that are needed but do not have a JS constructor.
ngeoffray 2012/12/12 12:09:11 do not -> do not
ngeoffray 2012/12/12 12:09:11 What are those? Please add a comment.
karlklose 2012/12/12 14:50:47 Done.
karlklose 2012/12/12 14:50:47 Done.
+ for (ClassElement requiredClass in rti.requiredClasses) {
+ String holder = namer.isolateAccess(requiredClass);
+ String name = namer.getName(requiredClass);
+ buffer.add("$holder = {builtin\$cls: '$name'");
+ typeChecks[requiredClass].forEach((check) {
+ buffer.add(', is\$${namer.getName(check)}: true');
+ });
+ buffer.add('};\n');
+ }
+ // Add checks to the constructors of instantiated classes.
+ for (ClassElement cls in typeChecks) {
+ if (rti.requiredClasses.contains(cls)) {
+ // We already emitted the is-checks in the object definition for this
+ // class.
+ continue;
+ }
+ String holder = namer.isolateAccess(cls);
+ typeChecks[cls].forEach((check) {
+ buffer.add('$holder.is\$${namer.getName(check)} = true;\n');
+ });
+ }
+ }
+
/**
* Documentation wanted -- johnniwinther
*
@@ -1918,6 +1950,7 @@ if (typeof document !== 'undefined' && document.readyState !== 'complete') {
// We need to finish the classes before we construct compile time
// constants.
emitFinishClassesInvocationIfNecessary(mainBuffer);
+ emitRuntimeClassesAndTests(mainBuffer);
emitCompileTimeConstants(mainBuffer);
// Static field initializations require the classes and compile-time
// constants to be set up.

Powered by Google App Engine
This is Rietveld 408576698