| Index: sdk/lib/_internal/compiler/implementation/js_emitter/new_emitter/model_emitter.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/new_emitter/model_emitter.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/new_emitter/model_emitter.dart
|
| index ed94cf2f2da54c895b8a0b65def49e851b298422..581f77e4ae94fd8b36ec2cbe69f8dd76784bd2bc 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/js_emitter/new_emitter/model_emitter.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/js_emitter/new_emitter/model_emitter.dart
|
| @@ -6,6 +6,7 @@ library dart2js.new_js_emitter.model_emitter;
|
|
|
| import '../../dart2jslib.dart' show Compiler;
|
| import '../../js/js.dart' as js;
|
| +import '../../js_backend/js_backend.dart' show Namer, ConstantEmitter;
|
| import '../../../js_lib/shared/embedded_names.dart' show
|
| DEFERRED_LIBRARY_URIS,
|
| DEFERRED_LIBRARY_HASHES,
|
| @@ -16,6 +17,8 @@ import '../model.dart';
|
|
|
| class ModelEmitter {
|
| final Compiler compiler;
|
| + final Namer namer;
|
| + final ConstantEmitter constantEmitter;
|
|
|
| /// For deferred loading we communicate the initializers via this global var.
|
| static const String deferredInitializersGlobal =
|
| @@ -23,7 +26,10 @@ class ModelEmitter {
|
|
|
| static const String deferredExtension = ".part.js";
|
|
|
| - ModelEmitter(this.compiler);
|
| + ModelEmitter(Compiler compiler, Namer namer)
|
| + : this.compiler = compiler,
|
| + this.namer = namer,
|
| + constantEmitter = new ConstantEmitter(compiler, namer);
|
|
|
| void emitProgram(Program program) {
|
| List<Output> outputs = program.outputs;
|
| @@ -66,6 +72,7 @@ class ModelEmitter {
|
| [emitDeferredInitializerGlobal(loadMap),
|
| emitHolders(unit.holders),
|
| emitEmbeddedGlobals(loadMap),
|
| + emitConstants(unit.constants),
|
| unit.main,
|
| program]);
|
| }
|
| @@ -167,11 +174,24 @@ class ModelEmitter {
|
| js.Expression emitDeferredUnit(DeferredOutput unit, List<Holder> holders) {
|
| // TODO(floitsch): the hash must depend on the output.
|
| int hash = this.hashCode;
|
| + if (unit.constants.isNotEmpty) {
|
| + throw new UnimplementedError("constants in deferred units");
|
| + }
|
| js.ArrayInitializer content =
|
| new js.ArrayInitializer.from(unit.libraries.map(emitLibrary));
|
| return js.js("$deferredInitializersGlobal[$hash] = #", content);
|
| }
|
|
|
| + js.Block emitConstants(List<Constant> constants) {
|
| + Iterable<js.Statement> statements = constants.map((Constant constant) {
|
| + js.Expression code =
|
| + constantEmitter.initializationExpression(constant.value);
|
| + return js.js.statement("#.# = #;",
|
| + [constant.holder.name, constant.name, code]);
|
| + });
|
| + return new js.Block(statements.toList());
|
| + }
|
| +
|
| js.Expression emitLibrary(Library library) {
|
| Iterable staticDescriptors = library.statics.expand((e) =>
|
| [ js.string(e.name), js.number(e.holder.index), emitStaticMethod(e) ]);
|
| @@ -294,6 +314,9 @@ final String boilerplate = r"""
|
| // Initialize globals.
|
| #;
|
|
|
| + // Initialize constants.
|
| + #;
|
| +
|
| var end = Date.now();
|
| print('Setup: ' + (end - start) + ' ms.');
|
|
|
|
|