| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.js_emitter.startup_emitter.model_emitter; | 5 library dart2js.js_emitter.startup_emitter.model_emitter; |
| 6 | 6 |
| 7 import 'dart:convert' show JsonEncoder; | 7 import 'dart:convert' show JsonEncoder; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' | 9 import 'package:js_runtime/shared/embedded_names.dart' |
| 10 show | 10 show |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 IS_HUNK_LOADED, | 23 IS_HUNK_LOADED, |
| 24 LEAF_TAGS, | 24 LEAF_TAGS, |
| 25 MANGLED_GLOBAL_NAMES, | 25 MANGLED_GLOBAL_NAMES, |
| 26 MANGLED_NAMES, | 26 MANGLED_NAMES, |
| 27 METADATA, | 27 METADATA, |
| 28 NATIVE_SUPERCLASS_TAG_NAME, | 28 NATIVE_SUPERCLASS_TAG_NAME, |
| 29 STATIC_FUNCTION_NAME_TO_CLOSURE, | 29 STATIC_FUNCTION_NAME_TO_CLOSURE, |
| 30 TYPE_TO_INTERCEPTOR_MAP, | 30 TYPE_TO_INTERCEPTOR_MAP, |
| 31 TYPES; | 31 TYPES; |
| 32 | 32 |
| 33 import '../../../compiler_new.dart'; |
| 33 import '../../common.dart'; | 34 import '../../common.dart'; |
| 34 import '../../compiler.dart' show Compiler; | 35 import '../../compiler.dart' show Compiler; |
| 35 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; | 36 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; |
| 36 import '../../core_types.dart' show CommonElements; | 37 import '../../core_types.dart' show CommonElements; |
| 37 import '../../elements/elements.dart' show ClassElement, MethodElement; | 38 import '../../elements/elements.dart' show ClassElement, MethodElement; |
| 38 import '../../hash/sha1.dart' show Hasher; | 39 import '../../hash/sha1.dart' show Hasher; |
| 39 import '../../io/code_output.dart'; | 40 import '../../io/code_output.dart'; |
| 40 import '../../io/line_column_provider.dart' | 41 import '../../io/line_column_provider.dart' |
| 41 show LineColumnCollector, LineColumnProvider; | 42 show LineColumnCollector, LineColumnProvider; |
| 42 import '../../io/source_map_builder.dart' show SourceMapBuilder; | 43 import '../../io/source_map_builder.dart' show SourceMapBuilder; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 void writeMainFragment(MainFragment fragment, js.Statement code, | 245 void writeMainFragment(MainFragment fragment, js.Statement code, |
| 245 {bool isSplit}) { | 246 {bool isSplit}) { |
| 246 LineColumnCollector lineColumnCollector; | 247 LineColumnCollector lineColumnCollector; |
| 247 List<CodeOutputListener> codeOutputListeners; | 248 List<CodeOutputListener> codeOutputListeners; |
| 248 if (shouldGenerateSourceMap) { | 249 if (shouldGenerateSourceMap) { |
| 249 lineColumnCollector = new LineColumnCollector(); | 250 lineColumnCollector = new LineColumnCollector(); |
| 250 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; | 251 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; |
| 251 } | 252 } |
| 252 | 253 |
| 253 CodeOutput mainOutput = new StreamCodeOutput( | 254 CodeOutput mainOutput = new StreamCodeOutput( |
| 254 compiler.outputProvider('', 'js'), codeOutputListeners); | 255 compiler.outputProvider('', 'js', OutputType.js), codeOutputListeners); |
| 255 outputBuffers[fragment] = mainOutput; | 256 outputBuffers[fragment] = mainOutput; |
| 256 | 257 |
| 257 js.Program program = new js.Program([ | 258 js.Program program = new js.Program([ |
| 258 buildGeneratedBy(), | 259 buildGeneratedBy(), |
| 259 new js.Comment(HOOKS_API_USAGE), | 260 new js.Comment(HOOKS_API_USAGE), |
| 260 isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), | 261 isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), |
| 261 code | 262 code |
| 262 ]); | 263 ]); |
| 263 | 264 |
| 264 mainOutput.addBuffer( | 265 mainOutput.addBuffer( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 289 | 290 |
| 290 LineColumnCollector lineColumnCollector; | 291 LineColumnCollector lineColumnCollector; |
| 291 if (shouldGenerateSourceMap) { | 292 if (shouldGenerateSourceMap) { |
| 292 lineColumnCollector = new LineColumnCollector(); | 293 lineColumnCollector = new LineColumnCollector(); |
| 293 outputListeners.add(lineColumnCollector); | 294 outputListeners.add(lineColumnCollector); |
| 294 } | 295 } |
| 295 | 296 |
| 296 String hunkPrefix = fragment.outputFileName; | 297 String hunkPrefix = fragment.outputFileName; |
| 297 | 298 |
| 298 CodeOutput output = new StreamCodeOutput( | 299 CodeOutput output = new StreamCodeOutput( |
| 299 compiler.outputProvider(hunkPrefix, deferredExtension), | 300 compiler.outputProvider(hunkPrefix, deferredExtension, OutputType.part), |
| 300 outputListeners); | 301 outputListeners); |
| 301 | 302 |
| 302 outputBuffers[fragment] = output; | 303 outputBuffers[fragment] = output; |
| 303 | 304 |
| 304 // The [code] contains the function that must be invoked when the deferred | 305 // The [code] contains the function that must be invoked when the deferred |
| 305 // hunk is loaded. | 306 // hunk is loaded. |
| 306 // That function must be in a map from its hashcode to the function. Since | 307 // That function must be in a map from its hashcode to the function. Since |
| 307 // we don't know the hash before we actually emit the code we store the | 308 // we don't know the hash before we actually emit the code we store the |
| 308 // function in a temporary field first: | 309 // function in a temporary field first: |
| 309 // | 310 // |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 void outputSourceMap( | 375 void outputSourceMap( |
| 375 CodeOutput output, LineColumnProvider lineColumnProvider, String name, | 376 CodeOutput output, LineColumnProvider lineColumnProvider, String name, |
| 376 [Uri sourceMapUri, Uri fileUri]) { | 377 [Uri sourceMapUri, Uri fileUri]) { |
| 377 if (!shouldGenerateSourceMap) return; | 378 if (!shouldGenerateSourceMap) return; |
| 378 // Create a source file for the compilation output. This allows using | 379 // Create a source file for the compilation output. This allows using |
| 379 // [:getLine:] to transform offsets to line numbers in [SourceMapBuilder]. | 380 // [:getLine:] to transform offsets to line numbers in [SourceMapBuilder]. |
| 380 SourceMapBuilder sourceMapBuilder = | 381 SourceMapBuilder sourceMapBuilder = |
| 381 new SourceMapBuilder(sourceMapUri, fileUri, lineColumnProvider); | 382 new SourceMapBuilder(sourceMapUri, fileUri, lineColumnProvider); |
| 382 output.forEachSourceLocation(sourceMapBuilder.addMapping); | 383 output.forEachSourceLocation(sourceMapBuilder.addMapping); |
| 383 String sourceMap = sourceMapBuilder.build(); | 384 String sourceMap = sourceMapBuilder.build(); |
| 384 compiler.outputProvider(name, 'js.map') | 385 compiler.outputProvider(name, 'js.map', OutputType.js_map) |
| 385 ..add(sourceMap) | 386 ..add(sourceMap) |
| 386 ..close(); | 387 ..close(); |
| 387 } | 388 } |
| 388 | 389 |
| 389 /// Writes a mapping from library-name to hunk files. | 390 /// Writes a mapping from library-name to hunk files. |
| 390 /// | 391 /// |
| 391 /// The output is written into a separate file that can be used by outside | 392 /// The output is written into a separate file that can be used by outside |
| 392 /// tools. | 393 /// tools. |
| 393 void writeDeferredMap() { | 394 void writeDeferredMap() { |
| 394 Map<String, dynamic> mapping = new Map<String, dynamic>(); | 395 Map<String, dynamic> mapping = new Map<String, dynamic>(); |
| 395 // Json does not support comments, so we embed the explanation in the | 396 // Json does not support comments, so we embed the explanation in the |
| 396 // data. | 397 // data. |
| 397 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 398 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 398 "needed for a given deferred library import."; | 399 "needed for a given deferred library import."; |
| 399 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 400 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 400 compiler.outputProvider( | 401 compiler.outputProvider( |
| 401 compiler.options.deferredMapUri.path, 'deferred_map') | 402 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 402 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 403 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 403 ..close(); | 404 ..close(); |
| 404 } | 405 } |
| 405 } | 406 } |
| OLD | NEW |