| 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 20 matching lines...) Expand all Loading... |
| 31 TYPES; | 31 TYPES; |
| 32 | 32 |
| 33 import '../../../compiler_new.dart'; | 33 import '../../../compiler_new.dart'; |
| 34 import '../../common.dart'; | 34 import '../../common.dart'; |
| 35 import '../../compiler.dart' show Compiler; | 35 import '../../compiler.dart' show Compiler; |
| 36 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; | 36 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; |
| 37 import '../../common_elements.dart' show CommonElements; | 37 import '../../common_elements.dart' show CommonElements; |
| 38 import '../../elements/elements.dart' show ClassElement, MethodElement; | 38 import '../../elements/elements.dart' show ClassElement, MethodElement; |
| 39 import '../../hash/sha1.dart' show Hasher; | 39 import '../../hash/sha1.dart' show Hasher; |
| 40 import '../../io/code_output.dart'; | 40 import '../../io/code_output.dart'; |
| 41 import '../../io/line_column_provider.dart' show LineColumnCollector; | 41 import '../../io/location_provider.dart' show LocationCollector; |
| 42 import '../../io/source_map_builder.dart' show SourceMapBuilder; | 42 import '../../io/source_map_builder.dart' show SourceMapBuilder; |
| 43 import '../../js/js.dart' as js; | 43 import '../../js/js.dart' as js; |
| 44 import '../../js_backend/js_backend.dart' | 44 import '../../js_backend/js_backend.dart' |
| 45 show JavaScriptBackend, Namer, ConstantEmitter; | 45 show JavaScriptBackend, Namer, ConstantEmitter; |
| 46 import '../constant_ordering.dart' show deepCompareConstants; | 46 import '../constant_ordering.dart' show deepCompareConstants; |
| 47 import '../headers.dart'; | 47 import '../headers.dart'; |
| 48 import '../js_emitter.dart' show NativeEmitter; | 48 import '../js_emitter.dart' show NativeEmitter; |
| 49 import '../js_emitter.dart' show buildTearOffCode, NativeGenerator; | 49 import '../js_emitter.dart' show buildTearOffCode, NativeGenerator; |
| 50 import '../model.dart'; | 50 import '../model.dart'; |
| 51 | 51 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 'self.#deferredInitializers = ' | 235 'self.#deferredInitializers = ' |
| 236 'self.#deferredInitializers || Object.create(null);', | 236 'self.#deferredInitializers || Object.create(null);', |
| 237 {'deferredInitializers': deferredInitializersGlobal}); | 237 {'deferredInitializers': deferredInitializersGlobal}); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Writes the given [fragment]'s [code] into a file. | 240 // Writes the given [fragment]'s [code] into a file. |
| 241 // | 241 // |
| 242 // Updates the shared [outputBuffers] field with the output. | 242 // Updates the shared [outputBuffers] field with the output. |
| 243 void writeMainFragment(MainFragment fragment, js.Statement code, | 243 void writeMainFragment(MainFragment fragment, js.Statement code, |
| 244 {bool isSplit}) { | 244 {bool isSplit}) { |
| 245 LineColumnCollector lineColumnCollector; | 245 LocationCollector locationCollector; |
| 246 List<CodeOutputListener> codeOutputListeners; | 246 List<CodeOutputListener> codeOutputListeners; |
| 247 if (shouldGenerateSourceMap) { | 247 if (shouldGenerateSourceMap) { |
| 248 lineColumnCollector = new LineColumnCollector(); | 248 locationCollector = new LocationCollector(); |
| 249 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; | 249 codeOutputListeners = <CodeOutputListener>[locationCollector]; |
| 250 } | 250 } |
| 251 | 251 |
| 252 CodeOutput mainOutput = new StreamCodeOutput( | 252 CodeOutput mainOutput = new StreamCodeOutput( |
| 253 compiler.outputProvider('', 'js', OutputType.js), codeOutputListeners); | 253 compiler.outputProvider('', 'js', OutputType.js), codeOutputListeners); |
| 254 outputBuffers[fragment] = mainOutput; | 254 outputBuffers[fragment] = mainOutput; |
| 255 | 255 |
| 256 js.Program program = new js.Program([ | 256 js.Program program = new js.Program([ |
| 257 buildGeneratedBy(), | 257 buildGeneratedBy(), |
| 258 new js.Comment(HOOKS_API_USAGE), | 258 new js.Comment(HOOKS_API_USAGE), |
| 259 isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), | 259 isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), |
| 260 code | 260 code |
| 261 ]); | 261 ]); |
| 262 | 262 |
| 263 mainOutput.addBuffer( | 263 mainOutput.addBuffer( |
| 264 js.createCodeBuffer(program, compiler, monitor: compiler.dumpInfoTask)); | 264 js.createCodeBuffer(program, compiler, monitor: compiler.dumpInfoTask)); |
| 265 | 265 |
| 266 if (shouldGenerateSourceMap) { | 266 if (shouldGenerateSourceMap) { |
| 267 mainOutput.add(SourceMapBuilder.generateSourceMapTag( | 267 mainOutput.add(SourceMapBuilder.generateSourceMapTag( |
| 268 compiler.options.sourceMapUri, compiler.options.outputUri)); | 268 compiler.options.sourceMapUri, compiler.options.outputUri)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 mainOutput.close(); | 271 mainOutput.close(); |
| 272 | 272 |
| 273 if (shouldGenerateSourceMap) { | 273 if (shouldGenerateSourceMap) { |
| 274 SourceMapBuilder.outputSourceMap( | 274 SourceMapBuilder.outputSourceMap( |
| 275 mainOutput, | 275 mainOutput, |
| 276 lineColumnCollector, | 276 locationCollector, |
| 277 '', | 277 '', |
| 278 compiler.options.sourceMapUri, | 278 compiler.options.sourceMapUri, |
| 279 compiler.options.outputUri, | 279 compiler.options.outputUri, |
| 280 compiler.outputProvider); | 280 compiler.outputProvider); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 // Writes the given [fragment]'s [code] into a file. | 284 // Writes the given [fragment]'s [code] into a file. |
| 285 // | 285 // |
| 286 // Returns the deferred fragment's hash. | 286 // Returns the deferred fragment's hash. |
| 287 // | 287 // |
| 288 // Updates the shared [outputBuffers] field with the output. | 288 // Updates the shared [outputBuffers] field with the output. |
| 289 String writeDeferredFragment(DeferredFragment fragment, js.Expression code) { | 289 String writeDeferredFragment(DeferredFragment fragment, js.Expression code) { |
| 290 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; | 290 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; |
| 291 Hasher hasher = new Hasher(); | 291 Hasher hasher = new Hasher(); |
| 292 outputListeners.add(hasher); | 292 outputListeners.add(hasher); |
| 293 | 293 |
| 294 LineColumnCollector lineColumnCollector; | 294 LocationCollector locationCollector; |
| 295 if (shouldGenerateSourceMap) { | 295 if (shouldGenerateSourceMap) { |
| 296 lineColumnCollector = new LineColumnCollector(); | 296 locationCollector = new LocationCollector(); |
| 297 outputListeners.add(lineColumnCollector); | 297 outputListeners.add(locationCollector); |
| 298 } | 298 } |
| 299 | 299 |
| 300 String hunkPrefix = fragment.outputFileName; | 300 String hunkPrefix = fragment.outputFileName; |
| 301 | 301 |
| 302 CodeOutput output = new StreamCodeOutput( | 302 CodeOutput output = new StreamCodeOutput( |
| 303 compiler.outputProvider( | 303 compiler.outputProvider( |
| 304 hunkPrefix, deferredExtension, OutputType.jsPart), | 304 hunkPrefix, deferredExtension, OutputType.jsPart), |
| 305 outputListeners); | 305 outputListeners); |
| 306 | 306 |
| 307 outputBuffers[fragment] = output; | 307 outputBuffers[fragment] = output; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 350 |
| 351 if (outputUri != null) { | 351 if (outputUri != null) { |
| 352 List<String> partSegments = outputUri.pathSegments.toList(); | 352 List<String> partSegments = outputUri.pathSegments.toList(); |
| 353 partSegments[partSegments.length - 1] = hunkFileName; | 353 partSegments[partSegments.length - 1] = hunkFileName; |
| 354 partUri = | 354 partUri = |
| 355 compiler.options.outputUri.replace(pathSegments: partSegments); | 355 compiler.options.outputUri.replace(pathSegments: partSegments); |
| 356 } | 356 } |
| 357 | 357 |
| 358 output.add(SourceMapBuilder.generateSourceMapTag(mapUri, partUri)); | 358 output.add(SourceMapBuilder.generateSourceMapTag(mapUri, partUri)); |
| 359 output.close(); | 359 output.close(); |
| 360 SourceMapBuilder.outputSourceMap(output, lineColumnCollector, partName, | 360 SourceMapBuilder.outputSourceMap(output, locationCollector, partName, |
| 361 mapUri, partUri, compiler.outputProvider); | 361 mapUri, partUri, compiler.outputProvider); |
| 362 } else { | 362 } else { |
| 363 output.close(); | 363 output.close(); |
| 364 } | 364 } |
| 365 | 365 |
| 366 return hash; | 366 return hash; |
| 367 } | 367 } |
| 368 | 368 |
| 369 /// Writes a mapping from library-name to hunk files. | 369 /// Writes a mapping from library-name to hunk files. |
| 370 /// | 370 /// |
| 371 /// The output is written into a separate file that can be used by outside | 371 /// The output is written into a separate file that can be used by outside |
| 372 /// tools. | 372 /// tools. |
| 373 void writeDeferredMap() { | 373 void writeDeferredMap() { |
| 374 Map<String, dynamic> mapping = new Map<String, dynamic>(); | 374 Map<String, dynamic> mapping = new Map<String, dynamic>(); |
| 375 // Json does not support comments, so we embed the explanation in the | 375 // Json does not support comments, so we embed the explanation in the |
| 376 // data. | 376 // data. |
| 377 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 377 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 378 "needed for a given deferred library import."; | 378 "needed for a given deferred library import."; |
| 379 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 379 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 380 compiler.outputProvider( | 380 compiler.outputProvider( |
| 381 compiler.options.deferredMapUri.path, '', OutputType.info) | 381 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 382 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 382 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 383 ..close(); | 383 ..close(); |
| 384 } | 384 } |
| 385 } | 385 } |
| OLD | NEW |