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

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

Issue 15026006: Support for extending native classes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months 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 21e7b5ca20fb720a8661c077e3daa58b0f9b5429..f358009ff3259ab197188185596c78744925080c 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
@@ -2627,6 +2627,8 @@ class CodeEmitterTask extends CompilerTask {
for (Element element in Elements.sortedByPosition(staticNonFinalFields)) {
// [:interceptedNames:] is handled in [emitInterceptedNames].
if (element == backend.interceptedNames) continue;
+ // `mapTypeToInterceptor` is handled in [emitMapTypeToInterceptor].
+ if (element == backend.mapTypeToInterceptor) continue;
compiler.withCurrentElement(element, () {
Constant initialValue = handler.getInitialValueFor(element);
jsAst.Expression init =
@@ -3040,9 +3042,8 @@ if (typeof document !== "undefined" && document.readyState !== "complete") {
else if (cls == backend.jsStringClass) hasString = true;
else {
// TODO(sra): The set of classes includes classes mixed-in to
- // interceptor classes.
- // assert(cls == compiler.objectClass || cls.isNative());
- if (cls.isNative()) hasNative = true;
+ // interceptor classes and user extensions of native classes.
+ if (Elements.isNativeOrExtendsNative(cls)) hasNative = true;
}
}
if (hasDouble) {
@@ -3216,9 +3217,13 @@ if (typeof document !== "undefined" && document.readyState !== "complete") {
for (ClassElement element in sortedClasses) {
if (rtiNeededClasses.contains(element)) {
regularClasses.add(element);
- } else if (element.isNative()) {
- // For now, native classes cannot be deferred.
+ } else if (Elements.isNativeOrExtendsNative(element)) {
+ // For now, native classes and related classes cannot be deferred.
nativeClasses.add(element);
+ if (!element.isNative()) {
+ assert(!isDeferred(element));
ahe 2013/08/13 18:31:47 assert(invariant(element, !isDeferred(element));
sra1 2013/08/14 04:36:47 Done.
+ regularClasses.add(element);
+ }
} else if (isDeferred(element)) {
deferredClasses.add(element);
} else {
@@ -3482,6 +3487,37 @@ if (typeof document !== "undefined" && document.readyState !== "complete") {
buffer.write(N);
}
+ /**
+ * Emit initializer for [mapTypeToInterceptor] data structure used by
+ * [findInterceptorForType]. See declaration of [mapTypeToInterceptor] in
+ * `interceptors.dart`.
+ */
+ void emitMapTypeToInterceptor(CodeBuffer buffer) {
+ // TODO(sra): Perhaps inject a constant instead?
+ // TODO(sra): Filter by subclasses of native types.
+ List<jsAst.Expression> elements = <jsAst.Expression>[];
+ ConstantHandler handler = compiler.constantHandler;
+ List<Constant> constants = handler.getConstantsForEmission();
+ for (Constant constant in constants) {
+ if (constant is TypeConstant) {
+ TypeConstant typeConstant = constant;
+ Element element = typeConstant.representedType.element;
+ if (element is ClassElement) {
ahe 2013/08/13 18:31:47 element.isClass()
+ ClassElement classElement = element;
+ elements.add(backend.emitter.constantReference(constant));
+ elements.add(js(namer.isolateAccess(classElement)));
+ }
+ }
+ }
+
+ jsAst.ArrayInitializer array = new jsAst.ArrayInitializer.from(elements);
+ String name = backend.namer.getName(backend.mapTypeToInterceptor);
+ jsAst.Expression assignment = js('$isolateProperties.$name = #', array);
+
+ buffer.write(jsAst.prettyPrint(assignment, compiler));
+ buffer.write(N);
+ }
+
void emitInitFunction(CodeBuffer buffer) {
jsAst.Fun fun = js.fun([], [
js('$isolateProperties = {}'),
@@ -3814,6 +3850,7 @@ if (typeof document !== "undefined" && document.readyState !== "complete") {
emitStaticNonFinalFieldInitializations(mainBuffer);
emitOneShotInterceptors(mainBuffer);
emitInterceptedNames(mainBuffer);
+ emitMapTypeToInterceptor(mainBuffer);
emitLazilyInitializedStaticFields(mainBuffer);
mainBuffer.add(nativeBuffer);

Powered by Google App Engine
This is Rietveld 408576698