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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart

Issue 1271953003: dart2js: Add a header to the output of the startup emitter. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add flavor section to generatedBy comment. Created 5 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
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '../../common.dart'; 9 import '../../common.dart';
10 10
(...skipping 16 matching lines...) Expand all
27 JavaScriptBackend, 27 JavaScriptBackend,
28 Namer, 28 Namer,
29 ConstantEmitter; 29 ConstantEmitter;
30 30
31 import '../../util/util.dart' show 31 import '../../util/util.dart' show
32 NO_LOCATION_SPANNABLE; 32 NO_LOCATION_SPANNABLE;
33 33
34 import '../../util/uri_extras.dart' show 34 import '../../util/uri_extras.dart' show
35 relativize; 35 relativize;
36 36
37 import '../headers.dart';
37 import '../js_emitter.dart' show AstContainer, NativeEmitter; 38 import '../js_emitter.dart' show AstContainer, NativeEmitter;
38 39
39 import 'package:js_runtime/shared/embedded_names.dart' show 40 import 'package:js_runtime/shared/embedded_names.dart' show
40 CLASS_FIELDS_EXTRACTOR, 41 CLASS_FIELDS_EXTRACTOR,
41 CLASS_ID_EXTRACTOR, 42 CLASS_ID_EXTRACTOR,
42 CREATE_NEW_ISOLATE, 43 CREATE_NEW_ISOLATE,
43 DEFERRED_INITIALIZED, 44 DEFERRED_INITIALIZED,
44 DEFERRED_LIBRARY_URIS, 45 DEFERRED_LIBRARY_URIS,
45 DEFERRED_LIBRARY_HASHES, 46 DEFERRED_LIBRARY_HASHES,
46 GET_TYPE_FROM_NAME, 47 GET_TYPE_FROM_NAME,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 212
212 if (compiler.deferredMapUri != null) { 213 if (compiler.deferredMapUri != null) {
213 writeDeferredMap(); 214 writeDeferredMap();
214 } 215 }
215 216
216 // Return the total program size. 217 // Return the total program size.
217 return outputBuffers.values.fold(0, (a, b) => a + b.length); 218 return outputBuffers.values.fold(0, (a, b) => a + b.length);
218 } 219 }
219 220
220 /// Generates a simple header that provides the compiler's build id. 221 /// Generates a simple header that provides the compiler's build id.
221 String buildGeneratedBy(compiler) { 222 js.Comment buildGeneratedBy() {
222 var suffix = ''; 223 String flavor = compiler.useContentSecurityPolicy
223 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}'; 224 ? 'fast startup, CSP'
224 return '// Generated by dart2js (fast startup), ' 225 : 'fast startup';
225 'the Dart to JavaScript compiler$suffix.\n'; 226 return new js.Comment(generatedBy(compiler, flavor: flavor));
226 } 227 }
227 228
228 /// Writes all deferred fragment's code into files. 229 /// Writes all deferred fragment's code into files.
229 /// 230 ///
230 /// Returns a map from fragment to its hashcode (as used for the deferred 231 /// Returns a map from fragment to its hashcode (as used for the deferred
231 /// library code). 232 /// library code).
232 /// 233 ///
233 /// Updates the shared [outputBuffers] field with the output. 234 /// Updates the shared [outputBuffers] field with the output.
234 Map<DeferredFragment, String> writeDeferredFragments( 235 Map<DeferredFragment, String> writeDeferredFragments(
235 Map<DeferredFragment, js.Expression> fragmentsCode) { 236 Map<DeferredFragment, js.Expression> fragmentsCode) {
(...skipping 15 matching lines...) Expand all
251 if (shouldGenerateSourceMap) { 252 if (shouldGenerateSourceMap) {
252 lineColumnCollector = new LineColumnCollector(); 253 lineColumnCollector = new LineColumnCollector();
253 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; 254 codeOutputListeners = <CodeOutputListener>[lineColumnCollector];
254 } 255 }
255 256
256 CodeOutput mainOutput = new StreamCodeOutput( 257 CodeOutput mainOutput = new StreamCodeOutput(
257 compiler.outputProvider('', 'js'), 258 compiler.outputProvider('', 'js'),
258 codeOutputListeners); 259 codeOutputListeners);
259 outputBuffers[fragment] = mainOutput; 260 outputBuffers[fragment] = mainOutput;
260 261
261 mainOutput.addBuffer(js.prettyPrint(code, compiler, 262 js.Program program = new js.Program([
263 buildGeneratedBy(),
264 new js.Comment(HOOKS_API_USAGE),
265 code]);
266
267 mainOutput.addBuffer(js.prettyPrint(program, compiler,
262 monitor: compiler.dumpInfoTask)); 268 monitor: compiler.dumpInfoTask));
263 269
264 if (shouldGenerateSourceMap) { 270 if (shouldGenerateSourceMap) {
265 mainOutput.add( 271 mainOutput.add(
266 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); 272 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri));
267 } 273 }
268 274
269 mainOutput.close(); 275 mainOutput.close();
270 276
271 if (shouldGenerateSourceMap) { 277 if (shouldGenerateSourceMap) {
(...skipping 28 matching lines...) Expand all
300 306
301 // The [code] contains the function that must be invoked when the deferred 307 // The [code] contains the function that must be invoked when the deferred
302 // hunk is loaded. 308 // hunk is loaded.
303 // That function must be in a map from its hashcode to the function. Since 309 // That function must be in a map from its hashcode to the function. Since
304 // we don't know the hash before we actually emit the code we store the 310 // we don't know the hash before we actually emit the code we store the
305 // function in a temporary field first: 311 // function in a temporary field first:
306 // 312 //
307 // deferredInitializer.current = <pretty-printed code>; 313 // deferredInitializer.current = <pretty-printed code>;
308 // deferredInitializer[<hash>] = deferredInitializer.current; 314 // deferredInitializer[<hash>] = deferredInitializer.current;
309 315
310 output.add('\n${deferredInitializersGlobal}.current = '); 316 js.Program program = new js.Program([
317 buildGeneratedBy(),
318 js.js.statement('$deferredInitializersGlobal.current = #', code)]);
311 319
312 output.addBuffer(js.prettyPrint(code, compiler, 320 output.addBuffer(js.prettyPrint(program, compiler,
313 monitor: compiler.dumpInfoTask)); 321 monitor: compiler.dumpInfoTask));
314 322
315 // Make a unique hash of the code (before the sourcemaps are added) 323 // Make a unique hash of the code (before the sourcemaps are added)
316 // This will be used to retrieve the initializing function from the global 324 // This will be used to retrieve the initializing function from the global
317 // variable. 325 // variable.
318 String hash = hasher.getHash(); 326 String hash = hasher.getHash();
319 327
320 // Now we copy the deferredInitializer.current into its correct hash. 328 // Now we copy the deferredInitializer.current into its correct hash.
321 output.add('\n${deferredInitializersGlobal}["$hash"] = ' 329 output.add('\n${deferredInitializersGlobal}["$hash"] = '
322 '${deferredInitializersGlobal}.current'); 330 '${deferredInitializersGlobal}.current');
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Json does not support comments, so we embed the explanation in the 397 // Json does not support comments, so we embed the explanation in the
390 // data. 398 // data.
391 mapping["_comment"] = "This mapping shows which compiled `.js` files are " 399 mapping["_comment"] = "This mapping shows which compiled `.js` files are "
392 "needed for a given deferred library import."; 400 "needed for a given deferred library import.";
393 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); 401 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap());
394 compiler.outputProvider(compiler.deferredMapUri.path, 'deferred_map') 402 compiler.outputProvider(compiler.deferredMapUri.path, 'deferred_map')
395 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) 403 ..add(const JsonEncoder.withIndent(" ").convert(mapping))
396 ..close(); 404 ..close();
397 } 405 }
398 } 406 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698