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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart

Issue 360493002: Emit declarations for typedefs that are needed by reflection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class ClassEmitter extends CodeEmitterHelper { 7 class ClassEmitter extends CodeEmitterHelper {
8 /** 8 /**
9 * Documentation wanted -- johnniwinther 9 * Documentation wanted -- johnniwinther
10 * 10 *
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 fields.add(name); 73 fields.add(name);
74 }); 74 });
75 } 75 }
76 String constructorName = namer.getNameOfClass(classElement); 76 String constructorName = namer.getNameOfClass(classElement);
77 77
78 // TODO(sra): Implement placeholders in VariableDeclaration position: 78 // TODO(sra): Implement placeholders in VariableDeclaration position:
79 // task.precompiledFunction.add(js.statement('function #(#) { #; }', 79 // task.precompiledFunction.add(js.statement('function #(#) { #; }',
80 // [ constructorName, fields, 80 // [ constructorName, fields,
81 // fields.map( 81 // fields.map(
82 // (name) => js('this.# = #', [name, name]))])); 82 // (name) => js('this.# = #', [name, name]))]));
83 task.precompiledFunction.add( 83 jsAst.Expression constructorAst = js('function(#) { #; }',
84 new jsAst.FunctionDeclaration( 84 [fields,
85 new jsAst.VariableDeclaration(constructorName), 85 fields.map((name) => js('this.# = #', [name, name]))]);
86 js('function(#) { #; }', 86 task.emitPrecompiledConstructor(constructorName, constructorAst);
87 [fields,
88 fields.map((name) => js('this.# = #', [name, name]))])));
89 // TODO(floitsch): do we actually need the name field?
90 // TODO(floitsch): these should all go through the namer.
91
92 task.precompiledFunction.add(
93 js.statement(r'''{
94 #.builtin$cls = #;
95 if (!"name" in #)
96 #.name = #;
97 $desc=$collectedClasses.#;
98 if ($desc instanceof Array) $desc = $desc[1];
99 #.prototype = $desc;
100 }''',
101 [ constructorName, js.string(constructorName),
102 constructorName,
103 constructorName, js.string(constructorName),
104 constructorName,
105 constructorName
106 ]));
107
108 task.precompiledConstructorNames.add(js('#', constructorName));
109 } 87 }
110 88
111 /// Returns `true` if fields added. 89 /// Returns `true` if fields added.
112 bool emitFields(Element element, 90 bool emitFields(Element element,
113 ClassBuilder builder, 91 ClassBuilder builder,
114 String superName, 92 String superName,
115 { bool classIsNative: false, 93 { bool classIsNative: false,
116 bool emitStatics: false, 94 bool emitStatics: false,
117 bool onlyForRti: false }) { 95 bool onlyForRti: false }) {
118 assert(!emitStatics || !onlyForRti); 96 assert(!emitStatics || !onlyForRti);
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 js(r'this.$builtinTypeInfo && this.$builtinTypeInfo[#]', index); 600 js(r'this.$builtinTypeInfo && this.$builtinTypeInfo[#]', index);
623 } 601 }
624 jsAst.Expression convertRtiToRuntimeType = 602 jsAst.Expression convertRtiToRuntimeType =
625 namer.elementAccess(backend.findHelper('convertRtiToRuntimeType')); 603 namer.elementAccess(backend.findHelper('convertRtiToRuntimeType'));
626 compiler.dumpInfoTask.registerElementAst(element, 604 compiler.dumpInfoTask.registerElementAst(element,
627 builder.addProperty(name, 605 builder.addProperty(name,
628 js('function () { return #(#) }', 606 js('function () { return #(#) }',
629 [convertRtiToRuntimeType, computeTypeVariable]))); 607 [convertRtiToRuntimeType, computeTypeVariable])));
630 } 608 }
631 } 609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698