| 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 import 'dart:math' show Random; | 8 import 'dart:math' show Random; |
| 9 | 9 |
| 10 import 'package:js_runtime/shared/embedded_names.dart' | 10 import 'package:js_runtime/shared/embedded_names.dart' |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 void writeMainFragment(MainFragment fragment, js.Statement code, | 260 void writeMainFragment(MainFragment fragment, js.Statement code, |
| 261 {bool isSplit}) { | 261 {bool isSplit}) { |
| 262 LocationCollector locationCollector; | 262 LocationCollector locationCollector; |
| 263 List<CodeOutputListener> codeOutputListeners; | 263 List<CodeOutputListener> codeOutputListeners; |
| 264 if (shouldGenerateSourceMap) { | 264 if (shouldGenerateSourceMap) { |
| 265 locationCollector = new LocationCollector(); | 265 locationCollector = new LocationCollector(); |
| 266 codeOutputListeners = <CodeOutputListener>[locationCollector]; | 266 codeOutputListeners = <CodeOutputListener>[locationCollector]; |
| 267 } | 267 } |
| 268 | 268 |
| 269 CodeOutput mainOutput = new StreamCodeOutput( | 269 CodeOutput mainOutput = new StreamCodeOutput( |
| 270 compiler.outputProvider('', 'js', OutputType.js), codeOutputListeners); | 270 compiler.outputProvider.createOutputSink('', 'js', OutputType.js), |
| 271 codeOutputListeners); |
| 271 outputBuffers[fragment] = mainOutput; | 272 outputBuffers[fragment] = mainOutput; |
| 272 | 273 |
| 273 js.Program program = new js.Program([ | 274 js.Program program = new js.Program([ |
| 274 buildGeneratedBy(), | 275 buildGeneratedBy(), |
| 275 new js.Comment(HOOKS_API_USAGE), | 276 new js.Comment(HOOKS_API_USAGE), |
| 276 isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), | 277 isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), |
| 277 code | 278 code |
| 278 ]); | 279 ]); |
| 279 | 280 |
| 280 mainOutput.addBuffer(js.createCodeBuffer( | 281 mainOutput.addBuffer(js.createCodeBuffer( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 311 | 312 |
| 312 LocationCollector locationCollector; | 313 LocationCollector locationCollector; |
| 313 if (shouldGenerateSourceMap) { | 314 if (shouldGenerateSourceMap) { |
| 314 locationCollector = new LocationCollector(); | 315 locationCollector = new LocationCollector(); |
| 315 outputListeners.add(locationCollector); | 316 outputListeners.add(locationCollector); |
| 316 } | 317 } |
| 317 | 318 |
| 318 String hunkPrefix = fragment.outputFileName; | 319 String hunkPrefix = fragment.outputFileName; |
| 319 | 320 |
| 320 CodeOutput output = new StreamCodeOutput( | 321 CodeOutput output = new StreamCodeOutput( |
| 321 compiler.outputProvider( | 322 compiler.outputProvider |
| 322 hunkPrefix, deferredExtension, OutputType.jsPart), | 323 .createOutputSink(hunkPrefix, deferredExtension, OutputType.jsPart), |
| 323 outputListeners); | 324 outputListeners); |
| 324 | 325 |
| 325 outputBuffers[fragment] = output; | 326 outputBuffers[fragment] = output; |
| 326 | 327 |
| 327 // The [code] contains the function that must be invoked when the deferred | 328 // The [code] contains the function that must be invoked when the deferred |
| 328 // hunk is loaded. | 329 // hunk is loaded. |
| 329 // That function must be in a map from its hashcode to the function. Since | 330 // That function must be in a map from its hashcode to the function. Since |
| 330 // we don't know the hash before we actually emit the code we store the | 331 // we don't know the hash before we actually emit the code we store the |
| 331 // function in a temporary field first: | 332 // function in a temporary field first: |
| 332 // | 333 // |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 /// | 390 /// |
| 390 /// The output is written into a separate file that can be used by outside | 391 /// The output is written into a separate file that can be used by outside |
| 391 /// tools. | 392 /// tools. |
| 392 void writeDeferredMap() { | 393 void writeDeferredMap() { |
| 393 Map<String, dynamic> mapping = new Map<String, dynamic>(); | 394 Map<String, dynamic> mapping = new Map<String, dynamic>(); |
| 394 // Json does not support comments, so we embed the explanation in the | 395 // Json does not support comments, so we embed the explanation in the |
| 395 // data. | 396 // data. |
| 396 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 397 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 397 "needed for a given deferred library import."; | 398 "needed for a given deferred library import."; |
| 398 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 399 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 399 compiler.outputProvider( | 400 compiler.outputProvider.createOutputSink( |
| 400 compiler.options.deferredMapUri.path, '', OutputType.info) | 401 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 401 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 402 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 402 ..close(); | 403 ..close(); |
| 403 } | 404 } |
| 404 } | 405 } |
| OLD | NEW |